added test for textured mesh
authorAnatoly Baksheev <no@email>
Mon, 13 Jan 2014 21:01:51 +0000 (01:01 +0400)
committerAnatoly Baksheev <no@email>
Sun, 19 Jan 2014 14:38:59 +0000 (18:38 +0400)
modules/viz/include/opencv2/viz.hpp
modules/viz/include/opencv2/viz/types.hpp
modules/viz/src/types.cpp
modules/viz/test/test_viz3d.cpp
modules/viz/test/tests_simple.cpp

index a532ba7..bf44a2c 100644 (file)
@@ -99,8 +99,7 @@ namespace cv
         CV_EXPORTS Mat  readCloud (const String& file, OutputArray colors = noArray(), OutputArray normals = noArray());
 
         ///////////////////////////////////////////////////////////////////////////////////////////////
-        /// Reads mesh. Only ply format is supported now. The function tries to read texture from png-file,
-        /// and in case of faulure, just leaves the texture field empty.
+        /// Reads mesh. Only ply format is supported now and no texture load support
 
         CV_EXPORTS Mesh readMesh(const String& file);
 
index cdd89d3..e61c837 100644 (file)
@@ -115,7 +115,7 @@ namespace cv
 
             Mat texture, tcoords;
 
-            //! Loads mesh from a given ply file
+            //! Loads mesh from a given ply file (no texture load support for now)
             static Mesh load(const String& file);
         };
 
index bf61432..2e32a63 100644 (file)
@@ -73,7 +73,6 @@ cv::viz::Mesh cv::viz::Mesh::load(const String& file)
     sink->Write();
 
     // Now handle the polygons
-
     vtkSmartPointer<vtkCellArray> polygons = polydata->GetPolys();
     mesh.polygons.create(1, polygons->GetSize(), CV_32SC1);
     int* poly_ptr = mesh.polygons.ptr<int>();
@@ -87,25 +86,6 @@ cv::viz::Mesh cv::viz::Mesh::load(const String& file)
             *poly_ptr++ = (int)cell_points[i];
     }
 
-    String::size_type pos = file.find_last_of('.');
-    String png = (pos == String::npos) ? file : file.substr(0, pos+1) + "png";
-
-    vtkSmartPointer<vtkPNGReader> png_reader = vtkSmartPointer<vtkPNGReader>::New();
-
-    if (png_reader->CanReadFile(png.c_str()))
-    {
-        png_reader->SetFileName(png.c_str());
-        png_reader->Update();
-        vtkSmartPointer<vtkImageData> imagedata = png_reader->GetOutput();
-
-        Size sz(imagedata->GetDimensions()[0], imagedata->GetDimensions()[1]);
-        int channels = imagedata->GetNumberOfScalarComponents();
-        CV_Assert(imagedata->GetScalarType() == VTK_UNSIGNED_CHAR);
-
-        void *ptr = imagedata->GetScalarPointer(0,0,0);
-        Mat(sz, CV_8UC(channels), ptr).copyTo(mesh.texture);
-    }
-
     return mesh;
 }
 
index 66ec25d..bdfda6d 100644 (file)
@@ -47,19 +47,11 @@ TEST(Viz_viz3d, develop)
 {
     cv::Mat cloud = cv::viz::readCloud(get_dragon_ply_file_path());
 
-    //cv::viz::Mesh3d mesh = cv::viz::Mesh3d::load(get_dragon_ply_file_path());
-    //theRNG().fill(mesh.colors, RNG::UNIFORM, 0, 255);
-
     cv::viz::Viz3d viz("abc");
     viz.setBackgroundMeshLab();
     viz.showWidget("coo", cv::viz::WCoordinateSystem(1));
-    //viz.showWidget("cloud", cv::viz::WPaintedCloud(cloud, Vec3d(0.0, 0.0, -1.0), Vec3d(0.0, 0.0, 1.0)));
-    //viz.showWidget("cloud", cv::viz::WPaintedCloud(cloud, Vec3d(0.0, 0.0, -1.0), Vec3d(0.0, 0.0, 1.0), cv::viz::Color::green(), cv::viz::Color::red()));
     viz.showWidget("cloud", cv::viz::WPaintedCloud(cloud));
 
-    //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)));
-
     //---->>>>> <to_test_in_future>
     //std::vector<cv::Affine3d> gt, es;
     //cv::viz::readTrajectory(gt, "d:/Datasets/trajs/gt%05d.xml");
@@ -67,12 +59,5 @@ TEST(Viz_viz3d, develop)
     //cv::Mat cloud = cv::viz::readCloud(get_dragon_ply_file_path());
     //---->>>>> </to_test_in_future>
 
-    //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()));
-
-    //viz.showWidget("l", cv::viz::WLine(Point3f(0,0,0), Point3f(1,1,1)));
-    //viz.showWidget("s", cv::viz::WSphere(Point3f(0,0,0), 1));
-    //viz.showWidget("d", cv::viz::WCircle(Point3f(0,0,0), 1));
     viz.spin();
 }
index 7f91c89..ec47558 100644 (file)
@@ -145,6 +145,42 @@ TEST(Viz, show_mesh_random_colors)
     viz.spin();
 }
 
+TEST(Viz, show_textured_mesh)
+{
+    Mat lena = imread(Path::combine(cvtest::TS::ptr()->get_data_path(), "lena.png"));
+
+    std::vector<Vec3d> points;
+    std::vector<Vec2d> tcoords;
+    std::vector<int> polygons;
+    for(size_t i = 0; i < 64; ++i)
+    {
+        double angle = CV_PI/2 * i/64.0;
+        points.push_back(Vec3d(0.00, cos(angle), sin(angle))*0.75);
+        points.push_back(Vec3d(1.57, cos(angle), sin(angle))*0.75);
+        tcoords.push_back(Vec2d(0.0, i/64.0));
+        tcoords.push_back(Vec2d(1.0, i/64.0));
+    }
+
+    for(size_t i = 0; i < points.size()/2-1; ++i)
+    {
+        int polys[] = {3, 2*i, 2*i+1, 2*i+2, 3, 2*i+1, 2*i+2, 2*i+3};
+        polygons.insert(polygons.end(), polys, polys + sizeof(polys)/sizeof(polys[0]));
+    }
+
+    cv::viz::Mesh mesh;
+    mesh.cloud = Mat(points, true).reshape(3, 1);
+    mesh.tcoords = Mat(tcoords, true).reshape(2, 1);
+    mesh.polygons = Mat(polygons, true).reshape(1, 1);
+    mesh.texture = lena;
+
+    Viz3d viz("show_textured_mesh");
+    viz.setBackgroundMeshLab();
+    viz.showWidget("coosys", WCoordinateSystem());
+    viz.showWidget("mesh", WMesh(mesh));
+    viz.setRenderingProperty("mesh", SHADING, SHADING_PHONG);
+    viz.spin();
+}
+
 TEST(Viz, show_polyline)
 {
     Mat polyline(1, 32, CV_64FC3);