showCylinder and showCircle implementations
authorozantonkal <ozantonkal@gmail.com>
Wed, 26 Jun 2013 09:32:12 +0000 (11:32 +0200)
committerozantonkal <ozantonkal@gmail.com>
Wed, 26 Jun 2013 09:32:12 +0000 (11:32 +0200)
modules/viz/include/opencv2/viz/viz3d.hpp
modules/viz/src/q/viz3d_impl.hpp
modules/viz/src/viz3d.cpp
modules/viz/src/viz3d_impl.cpp
modules/viz/test/test_viz3d.cpp

index 3db8996..0f5937a 100644 (file)
@@ -37,6 +37,7 @@ namespace temp_viz
         void showPlane(const String &id, const Vec4f &coefs, const Point3f &pt, const Color &color = Color(255,255,255));
         void showCube(const String &id, const Point3f &pt1, const Point3f &pt2, const Color &color = Color(255,255,255));
         void showCylinder(const String &id, const Point3f &pt_on_axis, const Point3f &axis_direction, double radius, int num_sides, const Color &color = Color(255,255,255));
+        void showCircle(const String &id, const Point3f &pt, double radius, const Color &color = Color(255,255,255));
 
         bool addPlane (const ModelCoefficients &coefficients, const String &id = "plane");
         bool addPlane (const ModelCoefficients &coefficients, double x, double y, double z, const String &id = "plane");
index 07e7508..e5a6cba 100644 (file)
@@ -143,6 +143,7 @@ public:
     void showPlane (const String &id ,const cv::Vec4f &coefs, const cv::Point3f &pt, const Color &color);
     void showCube (const String &id, const Point3f &pt1, const Point3f &pt2, const Color &color);
     void showCylinder (const String &id, const Point3f &pt_on_axis, const Point3f &axis_direction, double radius, int num_sides, const Color &color);
+    void showCircle (const String &id, const Point3f &pt, double radius, const Color &color);
 
     bool addPolygon(const cv::Mat& cloud, const Color& color, const std::string &id = "polygon");
     bool addArrow (const cv::Point3f &pt1, const cv::Point3f &pt2, const Color& color, bool display_length, const std::string &id = "arrow");
index c9bf0d9..887d100 100644 (file)
@@ -103,6 +103,11 @@ void temp_viz::Viz3d::showCylinder(const String &id, const Point3f &pt_on_axis,
     impl_->showCylinder(id, pt_on_axis, axis_direction, radius, num_sides, color);
 }
 
+void temp_viz::Viz3d::showCircle(const String &id, const Point3f &pt, double radius, const Color &color)
+{
+    impl_->showCircle(id, pt, radius, color);
+}
+
 bool temp_viz::Viz3d::removeCoordinateSystem (const String &id)
 {
     return impl_->removeCoordinateSystem(id);
index 63187c5..0c9718f 100644 (file)
@@ -442,6 +442,41 @@ void temp_viz::Viz3d::VizImpl::showCylinder (const String &id, const Point3f &pt
     }
 }
 
+void temp_viz::Viz3d::VizImpl::showCircle (const String &id, const Point3f &pt, double radius, const Color &color)
+{
+    // Check if this Id already exists
+    ShapeActorMap::iterator am_it = shape_actor_map_->find (id);
+    bool exists = (am_it != shape_actor_map_->end());
+    Color c = vtkcolor(color);
+    // If it exists just update
+    if (exists)
+    {
+        vtkSmartPointer<vtkLODActor> actor = vtkLODActor::SafeDownCast (am_it->second);
+        reinterpret_cast<vtkDataSetMapper*>(actor->GetMapper ())->SetInput(create2DCircle(pt, radius));
+        actor->GetProperty ()->SetColor (c.val);
+        actor->GetMapper ()->ScalarVisibilityOff ();
+        actor->Modified ();
+    }
+    else
+    {
+        // Create a plane
+        vtkSmartPointer<vtkDataSet> data = create2DCircle(pt, radius);
+
+        // Create an Actor
+        vtkSmartPointer<vtkLODActor> actor;
+        createActorFromVTKDataSet (data, actor);
+        //  actor->GetProperty ()->SetRepresentationToWireframe ();
+        actor->GetProperty ()->SetRepresentationToSurface ();
+        actor->GetProperty ()->SetLighting (false);
+        actor->GetProperty ()->SetColor (c.val);
+        actor->GetMapper ()->ScalarVisibilityOff ();
+        renderer_->AddActor(actor);
+
+        // Save the pointer/ID pair to the global actor map
+        (*shape_actor_map_)[id] = actor;
+    }
+}
+
 bool temp_viz::Viz3d::VizImpl::addPolygonMesh (const Mesh3d& mesh, const Mat& mask, const std::string &id)
 {
     CV_Assert(mesh.cloud.type() == CV_32FC3 && mesh.cloud.rows == 1 && !mesh.polygons.empty ());
index 1fd5131..1d09a16 100644 (file)
@@ -105,7 +105,7 @@ TEST(Viz_viz3d, accuracy)
         v.showPlane("plane1", cv::Vec4f(pos_x*pos_y,pos_y,pos_z,pos_x+pos_y*pos_z), temp_viz::Color(255-col_blue, 255-col_green, 255-col_red));
         v.showCube("cube1", cv::Point3f(pos_x, pos_y, pos_z), cv::Point3f(pos_x+0.5, pos_y+0.5, pos_z+0.5), temp_viz::Color(255,150,50));
         v.showCylinder("cylinder1", cv::Point3f(0,0,0), cv::Point3f(pos_x, 1.0, 1.0), 0.5, 5*pos_x+3, temp_viz::Color(0,255,0));
-        
+        v.showCircle("circle1", cv::Point3f(0,0,0), fabs(pos_x), temp_viz::Color(0,255,0));
         
         angle_x += 0.1f;
         angle_y -= 0.1f;