more refactoring
authorAnatoly Baksheev <no@email>
Tue, 7 Jan 2014 17:13:15 +0000 (21:13 +0400)
committerAnatoly Baksheev <no@email>
Sun, 19 Jan 2014 14:38:48 +0000 (18:38 +0400)
modules/viz/include/opencv2/viz/widgets.hpp
modules/viz/src/precomp.hpp
modules/viz/src/vizcore.cpp
modules/viz/test/test_viz3d.cpp

index 2868880..b487952 100644 (file)
@@ -227,7 +227,7 @@ namespace cv
         class CV_EXPORTS WCoordinateSystem : public Widget3D
         {
         public:
-            WCoordinateSystem(float scale = 1.f);
+            WCoordinateSystem(double scale = 1.f);
         };
 
         class CV_EXPORTS WGrid : public Widget3D
@@ -263,7 +263,7 @@ namespace cv
             enum {FRAMES = 1, PATH = 2, BOTH = FRAMES + PATH };
 
             //! Takes vector<Affine3<T>> and displays trajectory of the given path either by coordinate frames or polyline
-            WTrajectory(InputArray path, int display_mode = WTrajectory::PATH, float scale = 1.f, const Color &color = Color::white());
+            WTrajectory(InputArray path, int display_mode = WTrajectory::PATH, double scale = 1.f, const Color &color = Color::white());
         };
 
         class CV_EXPORTS WTrajectoryFrustums : public Widget3D
index 85977a8..b91e50c 100644 (file)
@@ -172,10 +172,40 @@ namespace cv
             friend class Viz3d;
         };
 
-        template<typename _Tp> bool isNan(const _Tp* data)
+        template<typename _Tp> inline bool isNan(const _Tp* data)
         {
             return isNan(data[0]) || isNan(data[1]) || isNan(data[2]);
         }
+
+        inline vtkSmartPointer<vtkPolyData> getPolyData(const Widget3D& widget)
+        {
+            vtkSmartPointer<vtkProp> prop = WidgetAccessor::getProp(widget);
+            vtkSmartPointer<vtkMapper> mapper = vtkActor::SafeDownCast(prop)->GetMapper();
+            return vtkPolyData::SafeDownCast(mapper->GetInput());
+        }
+
+        struct VtkUtils
+        {
+            template<class Filter>
+            static inline void SetInputData(vtkSmartPointer<Filter> filter, vtkPolyData *polydata)
+            {
+            #if VTK_MAJOR_VERSION <= 5
+                filter->SetInput(polydata);
+            #else
+                filter->SetInputData(polydata);
+            #endif
+            }
+
+            template<class Filter>
+            static inline void AddInputData(vtkSmartPointer<Filter> filter, vtkPolyData *polydata)
+            {
+            #if VTK_MAJOR_VERSION <= 5
+                filter->AddInput(polydata);
+            #else
+                filter->AddInputData(polydata);
+            #endif
+            }
+        };
     }
 }
 
index d01b947..ffb2d84 100644 (file)
@@ -305,9 +305,7 @@ void cv::viz::writeTrajectory(InputArray _traj, const String& files_format, int
 
 void cv::viz::computeNormals(const Mesh3d& mesh, OutputArray _normals)
 {
-    vtkSmartPointer<vtkProp> prop = WidgetAccessor::getProp(WMesh(mesh));
-    vtkSmartPointer<vtkMapper> mapper = vtkActor::SafeDownCast(prop)->GetMapper();
-    vtkSmartPointer<vtkPolyData> polydata = vtkPolyData::SafeDownCast(mapper->GetInput());
+    vtkSmartPointer<vtkPolyData> polydata = getPolyData(WMesh(mesh));
 
     vtkSmartPointer<vtkPolyDataNormals> normal_generator = vtkSmartPointer<vtkPolyDataNormals>::New();
 #if VTK_MAJOR_VERSION <= 5
index ce0344f..6bc3622 100644 (file)
@@ -45,37 +45,51 @@ using namespace cv;
 
 TEST(Viz_viz3d, develop)
 {
-    std::cout << std::string(cvtest::TS::ptr()->get_data_path()) + "dragon.ply" << std::endl;
+    cv::Mat cloud = cv::viz::readCloud(get_dragon_ply_file_path());
 
-    cv::Mat cloud = cv::viz::readCloud(String(cvtest::TS::ptr()->get_data_path()) + "dragon.ply");
+    //cv::viz::Mesh3d mesh = cv::viz::Mesh3d::load(get_dragon_ply_file_path());
 
-
-//    for(size_t i = 0; i < cloud.total(); ++i)
-//    {
-//        if (i % 15 == 0)
-//            continue;
-//        const static float qnan = std::numeric_limits<float>::quiet_NaN();
-//        cloud.at<Vec3f>(i) = Vec3f(qnan, qnan, qnan);
-//    }
+    //theRNG().fill(mesh.colors, RNG::UNIFORM, 0, 255);
 
     cv::viz::Viz3d viz("abc");
     viz.setBackgroundColor(cv::viz::Color::mlab());
     viz.showWidget("coo", cv::viz::WCoordinateSystem(0.1));
 
-    cv::Mat colors(cloud.size(), CV_8UC3, cv::Scalar(0, 255, 0));
+
+//    double c = cos(CV_PI/6);
+//    std::vector<Vec3d> pts;
+//    pts.push_back(Vec3d(0, 0.0, -1.0));
+//    pts.push_back(Vec3d(1,   c, -0.5));
+//    pts.push_back(Vec3d(2,   c,  0.5));
+//    pts.push_back(Vec3d(3, 0.0,  1.0));
+//    pts.push_back(Vec3d(4,  -c,  0.5));
+//    pts.push_back(Vec3d(5,  -c, -0.5));
+
+//    viz.showWidget("pl", cv::viz::WPolyLine(Mat(pts), cv::viz::Color::green()));
+
+    //viz.showWidget("pl", cv::viz::WPolyLine(cloud.colRange(0, 100), cv::viz::Color::green()));
+    //viz.spin();
+
+    //cv::Mat colors(cloud.size(), CV_8UC3, cv::Scalar(0, 255, 0));
 
     //viz.showWidget("h", cv::viz::Widget::fromPlyFile("d:/horse-red.ply"));
     //viz.showWidget("a", cv::viz::WArrow(cv::Point3f(0,0,0), cv::Point3f(1,1,1)));
 
     std::vector<cv::Affine3d> gt, es;
     cv::viz::readTrajectory(gt, "d:/Datasets/trajs/gt%05d.xml");
-    cv::viz::readTrajectory(es, "d:/Datasets/trajs/es%05d.xml");
+    //cv::viz::readTrajectory(es, "d:/Datasets/trajs/es%05d.xml");
+    gt.resize(20);
+
+    Affine3d inv = gt[0].inv();
+    for(size_t i = 0; i < gt.size(); ++i)
+        gt[i] = inv * gt[i];
+
+    //viz.showWidget("gt", viz::WTrajectory(gt, viz::WTrajectory::PATH, 1.f, viz::Color::blue()), gt[0].inv());
+    viz.showWidget("gt", viz::WTrajectory(gt, viz::WTrajectory::BOTH, 0.01f, viz::Color::blue()));
 
-    viz.showWidget("gt", viz::WTrajectory(gt, viz::WTrajectory::PATH, 1.f, viz::Color::blue()), gt[0].inv());
-    viz.showWidget("tr", viz::WTrajectory(es, viz::WTrajectory::PATH, 1.f, viz::Color::red()), gt[0].inv());
+    //viz.showWidget("tr", viz::WTrajectory(es, viz::WTrajectory::PATH, 1.f, viz::Color::red()), gt[0].inv());
 
-    cv::RNG rng;
-    rng.fill(colors, cv::RNG::UNIFORM, 0, 255);
+    //theRNG().fill(colors, cv::RNG::UNIFORM, 0, 255);
     //viz.showWidget("c", cv::viz::WCloud(cloud, colors));
     //viz.showWidget("c", cv::viz::WCloud(cloud, cv::viz::Color::bluberry()));