diff --git a/modules/viz/include/opencv2/viz/viz3d.hpp b/modules/viz/include/opencv2/viz/viz3d.hpp index 9d0e60f688..806f782478 100644 --- a/modules/viz/include/opencv2/viz/viz3d.hpp +++ b/modules/viz/include/opencv2/viz/viz3d.hpp @@ -33,8 +33,8 @@ namespace temp_viz bool addPointCloudNormals (const Mat &cloud, const Mat& normals, int level = 100, float scale = 0.02f, const String &id = "cloud"); void showLine(const String &id, const Point3f &pt1, const Point3f &pt2, const Color &color); - void showPlane(const String &id, const Vec4f &coefs); - void showPlane(const String &id, const Vec4f &coefs, const Point3f &pt); + void showPlane(const String &id, const Vec4f &coefs, const Color &color); + void showPlane(const String &id, const Vec4f &coefs, const Point3f &pt, const Color &color); bool addPlane (const ModelCoefficients &coefficients, const String &id = "plane"); bool addPlane (const ModelCoefficients &coefficients, double x, double y, double z, const String &id = "plane"); diff --git a/modules/viz/src/q/viz3d_impl.hpp b/modules/viz/src/q/viz3d_impl.hpp index bff67e71f5..fb1855de95 100644 --- a/modules/viz/src/q/viz3d_impl.hpp +++ b/modules/viz/src/q/viz3d_impl.hpp @@ -139,8 +139,8 @@ public: } void showLine (const String &id, const cv::Point3f &pt1, const cv::Point3f &pt2, const Color &color); - void showPlane (const String &id, const cv::Vec4f &coefs); - void showPlane (const String &id ,const cv::Vec4f &coefs, const cv::Point3f &pt); + void showPlane (const String &id, const cv::Vec4f &coefs, const Color &color); + void showPlane (const String &id ,const cv::Vec4f &coefs, const cv::Point3f &pt, 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"); diff --git a/modules/viz/src/viz3d.cpp b/modules/viz/src/viz3d.cpp index 5f0342a400..ec8cf73c9c 100644 --- a/modules/viz/src/viz3d.cpp +++ b/modules/viz/src/viz3d.cpp @@ -83,14 +83,14 @@ void temp_viz::Viz3d::showLine(const String &id, const Point3f &pt1, const Point impl_->showLine(id, pt1, pt2, color); } -void temp_viz::Viz3d::showPlane(const String &id, const Vec4f &coefs) +void temp_viz::Viz3d::showPlane(const String &id, const Vec4f &coefs, const Color &color) { - impl_->showPlane(id, coefs); + impl_->showPlane(id, coefs, color); } -void temp_viz::Viz3d::showPlane(const String &id, const Vec4f &coefs, const Point3f &pt) +void temp_viz::Viz3d::showPlane(const String &id, const Vec4f &coefs, const Point3f &pt, const Color &color) { - impl_->showPlane(id, coefs, pt); + impl_->showPlane(id, coefs, pt, color); } bool temp_viz::Viz3d::removeCoordinateSystem (const String &id) diff --git a/modules/viz/src/viz3d_impl.cpp b/modules/viz/src/viz3d_impl.cpp index 15938f8204..dfa64d9310 100644 --- a/modules/viz/src/viz3d_impl.cpp +++ b/modules/viz/src/viz3d_impl.cpp @@ -302,17 +302,19 @@ void temp_viz::Viz3d::VizImpl::showLine (const String &id, const cv::Point3f &pt } } -void temp_viz::Viz3d::VizImpl::showPlane (const String &id, const cv::Vec4f &coefs) +void temp_viz::Viz3d::VizImpl::showPlane (const String &id, const cv::Vec4f &coefs, 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 actor = vtkLODActor::SafeDownCast (am_it->second); reinterpret_cast(actor->GetMapper ())->SetInput(createPlane(coefs)); + actor->GetProperty ()->SetColor (c.val); + actor->GetMapper ()->ScalarVisibilityOff (); actor->Modified (); } else @@ -326,6 +328,8 @@ void temp_viz::Viz3d::VizImpl::showPlane (const String &id, const cv::Vec4f &coe // 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 @@ -333,17 +337,19 @@ void temp_viz::Viz3d::VizImpl::showPlane (const String &id, const cv::Vec4f &coe } } -void temp_viz::Viz3d::VizImpl::showPlane (const String &id ,const cv::Vec4f &coefs, const cv::Point3f &pt) +void temp_viz::Viz3d::VizImpl::showPlane (const String &id ,const cv::Vec4f &coefs, const cv::Point3f &pt, 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 actor = vtkLODActor::SafeDownCast (am_it->second); reinterpret_cast(actor->GetMapper ())->SetInput(createPlane(coefs, pt)); + actor->GetProperty ()->SetColor (c.val); + actor->GetMapper ()->ScalarVisibilityOff (); actor->Modified (); } else @@ -357,6 +363,8 @@ void temp_viz::Viz3d::VizImpl::showPlane (const String &id ,const cv::Vec4f &coe // 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 diff --git a/modules/viz/test/test_viz3d.cpp b/modules/viz/test/test_viz3d.cpp index 17a6dc4768..3d3d2c108d 100644 --- a/modules/viz/test/test_viz3d.cpp +++ b/modules/viz/test/test_viz3d.cpp @@ -93,8 +93,6 @@ TEST(Viz_viz3d, accuracy) int col_green = 0; int col_red = 0; - v.showPlane("plane1", cv::Vec4f(1.0f,1.0f,1.0f,1.0f)); - while(!v.wasStopped()) { // Creating new point cloud with id cloud1 @@ -104,7 +102,7 @@ TEST(Viz_viz3d, accuracy) v.showLine("line2", cv::Point3f(0.0,0.0,0.0), cv::Point3f(1.0f-pos_x, pos_y, pos_z) , temp_viz::Color(255-col_blue, 255-col_green, 255-col_red)); v.showLine("line3", cv::Point3f(0.0,0.0,0.0), cv::Point3f(pos_x, 1.0f-pos_y, pos_z) , temp_viz::Color(255-col_blue, 255-col_green, 255-col_red)); v.showLine("line4", cv::Point3f(0.0,0.0,0.0), cv::Point3f(pos_x, pos_y, 1.0f-pos_z) , temp_viz::Color(255-col_blue, 255-col_green, 255-col_red)); - v.showPlane("plane1", cv::Vec4f(pos_x*pos_y,pos_y,pos_z,pos_x+pos_y*pos_z)); + 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)); angle_x += 0.1f; angle_y -= 0.1f;