From f1c062c30ab9eb02ea1b1bd8d221dc85ad7b2d27 Mon Sep 17 00:00:00 2001 From: Anatoly Baksheev Date: Mon, 10 Feb 2014 13:27:08 +0400 Subject: [PATCH] cloud collection finalize --- modules/viz/doc/widget.rst | 8 ++++++++ modules/viz/include/opencv2/viz/widgets.hpp | 2 ++ modules/viz/src/clouds.cpp | 18 ++++++++++++++++++ modules/viz/test/tests_simple.cpp | 1 + 4 files changed, 29 insertions(+) diff --git a/modules/viz/doc/widget.rst b/modules/viz/doc/widget.rst index 008e0e68a5..2802edff79 100644 --- a/modules/viz/doc/widget.rst +++ b/modules/viz/doc/widget.rst @@ -934,6 +934,8 @@ This 3D Widget defines a collection of clouds. :: void addCloud(InputArray cloud, InputArray colors, const Affine3d &pose = Affine3d::Identity()); //! All points in cloud have the same color void addCloud(InputArray cloud, const Color &color = Color::white(), Affine3d &pose = Affine3d::Identity()); + //! Repacks internal structure to sinle cloud + void finalize(); }; viz::WCloudCollection::WCloudCollection @@ -964,6 +966,12 @@ Adds a cloud to the collection. .. note:: In case there are four channels in the cloud, fourth channel is ignored. +viz::WCloudCollection::finalize +------------------------------- +Finalizes cloud data by repacking to single cloud. Useful for large cloud collections to reduce memory usage + +.. ocv:function:: void finalize() + viz::WCloudNormals ------------------ .. ocv:class:: WCloudNormals diff --git a/modules/viz/include/opencv2/viz/widgets.hpp b/modules/viz/include/opencv2/viz/widgets.hpp index 2c49b9d0e2..6910196c3d 100644 --- a/modules/viz/include/opencv2/viz/widgets.hpp +++ b/modules/viz/include/opencv2/viz/widgets.hpp @@ -345,6 +345,8 @@ namespace cv void addCloud(InputArray cloud, InputArray colors, const Affine3d &pose = Affine3d::Identity()); //! All points in cloud have the same color void addCloud(InputArray cloud, const Color &color = Color::white(), const Affine3d &pose = Affine3d::Identity()); + //! Repacks internal structure to sinle cloud + void finalize(); }; class CV_EXPORTS WCloudNormals : public Widget3D diff --git a/modules/viz/src/clouds.cpp b/modules/viz/src/clouds.cpp index c2c78d5523..349de2f5f2 100644 --- a/modules/viz/src/clouds.cpp +++ b/modules/viz/src/clouds.cpp @@ -242,6 +242,24 @@ void cv::viz::WCloudCollection::addCloud(InputArray cloud, const Color &color, c addCloud(cloud, Mat(cloud.size(), CV_8UC3, color), pose); } +void cv::viz::WCloudCollection::finalize() +{ + vtkSmartPointer actor = vtkLODActor::SafeDownCast(WidgetAccessor::getProp(*this)); + CV_Assert("Incompatible widget type." && actor); + + vtkSmartPointer mapper = vtkPolyDataMapper::SafeDownCast(actor->GetMapper()); + CV_Assert("Need to add at least one cloud." && mapper); + + vtkSmartPointer producer = mapper->GetInputConnection(0, 0)->GetProducer(); + vtkSmartPointer append_filter = vtkAppendPolyData::SafeDownCast(producer); + append_filter->Update(); + + vtkSmartPointer polydata = append_filter->GetOutput(); + mapper->RemoveInputConnection(0, 0); + VtkUtils::SetInputData(mapper, polydata); + mapper->Modified(); +} + template<> cv::viz::WCloudCollection cv::viz::Widget::cast() { Widget3D widget = this->cast(); diff --git a/modules/viz/test/tests_simple.cpp b/modules/viz/test/tests_simple.cpp index 4edb324f4f..10c1d81808 100644 --- a/modules/viz/test/tests_simple.cpp +++ b/modules/viz/test/tests_simple.cpp @@ -103,6 +103,7 @@ TEST(Viz, show_cloud_collection) ccol.addCloud(cloud, Color::white(), Affine3d().translate(Vec3d(0, 0, 0)).rotate(Vec3d(CV_PI/2, 0, 0))); ccol.addCloud(cloud, Color::blue(), Affine3d().translate(Vec3d(1, 0, 0))); ccol.addCloud(cloud, Color::red(), Affine3d().translate(Vec3d(2, 0, 0))); + ccol.finalize(); Viz3d viz("show_cloud_collection"); viz.setBackgroundColor(Color::mlab());