From e106dcc606fe6b185e8799467ea0b2088be5912a Mon Sep 17 00:00:00 2001 From: ozantonkal Date: Thu, 22 Aug 2013 18:28:37 +0200 Subject: [PATCH 01/29] remove include vtk headers from outside of precomp.hpp --- modules/viz/src/viz3d_impl.cpp | 1 - modules/viz/src/widget.cpp | 1 - 2 files changed, 2 deletions(-) diff --git a/modules/viz/src/viz3d_impl.cpp b/modules/viz/src/viz3d_impl.cpp index 95f93b1154..4b7d1271f0 100644 --- a/modules/viz/src/viz3d_impl.cpp +++ b/modules/viz/src/viz3d_impl.cpp @@ -1,7 +1,6 @@ #include "precomp.hpp" #include "viz3d_impl.hpp" -#include #ifndef __APPLE__ vtkRenderWindowInteractor* vtkRenderWindowInteractorFixNew () { diff --git a/modules/viz/src/widget.cpp b/modules/viz/src/widget.cpp index b295843f98..65c5b1aca9 100644 --- a/modules/viz/src/widget.cpp +++ b/modules/viz/src/widget.cpp @@ -1,4 +1,3 @@ - #include "precomp.hpp" /////////////////////////////////////////////////////////////////////////////////////////////// From 0bbaf5d47a104b338aa18442049d4360415b1274 Mon Sep 17 00:00:00 2001 From: ozantonkal Date: Thu, 22 Aug 2013 19:04:42 +0200 Subject: [PATCH 02/29] removeAllWidgets implementation, removed other remove methods --- modules/viz/include/opencv2/viz/viz3d.hpp | 1 + modules/viz/src/viz3d.cpp | 1 + modules/viz/src/viz3d_impl.cpp | 99 +---------------------- modules/viz/src/viz3d_impl.hpp | 18 +---- 4 files changed, 7 insertions(+), 112 deletions(-) diff --git a/modules/viz/include/opencv2/viz/viz3d.hpp b/modules/viz/include/opencv2/viz/viz3d.hpp index f4adcd8355..96f999bed8 100644 --- a/modules/viz/include/opencv2/viz/viz3d.hpp +++ b/modules/viz/include/opencv2/viz/viz3d.hpp @@ -37,6 +37,7 @@ namespace cv void showWidget(const String &id, const Widget &widget, const Affine3f &pose = Affine3f::Identity()); void removeWidget(const String &id); Widget getWidget(const String &id) const; + void removeAllWidgets(); void setWidgetPose(const String &id, const Affine3f &pose); void updateWidgetPose(const String &id, const Affine3f &pose); diff --git a/modules/viz/src/viz3d.cpp b/modules/viz/src/viz3d.cpp index 583ece096b..bb88e1337d 100644 --- a/modules/viz/src/viz3d.cpp +++ b/modules/viz/src/viz3d.cpp @@ -79,6 +79,7 @@ void cv::viz::Viz3d::registerMouseCallback(MouseCallback callback, void* cookie) void cv::viz::Viz3d::showWidget(const String &id, const Widget &widget, const Affine3f &pose) { impl_->showWidget(id, widget, pose); } void cv::viz::Viz3d::removeWidget(const String &id) { impl_->removeWidget(id); } cv::viz::Widget cv::viz::Viz3d::getWidget(const String &id) const { return impl_->getWidget(id); } +void cv::viz::Viz3d::removeAllWidgets() { impl_->removeAllWidgets(); } void cv::viz::Viz3d::setWidgetPose(const String &id, const Affine3f &pose) { impl_->setWidgetPose(id, pose); } void cv::viz::Viz3d::updateWidgetPose(const String &id, const Affine3f &pose) { impl_->updateWidgetPose(id, pose); } cv::Affine3f cv::viz::Viz3d::getWidgetPose(const String &id) const { return impl_->getWidgetPose(id); } diff --git a/modules/viz/src/viz3d_impl.cpp b/modules/viz/src/viz3d_impl.cpp index 4b7d1271f0..12a3de15f5 100644 --- a/modules/viz/src/viz3d_impl.cpp +++ b/modules/viz/src/viz3d_impl.cpp @@ -128,104 +128,13 @@ void cv::viz::Viz3d::VizImpl::spinOnce (int time, bool force_redraw) } } -///////////////////////////////////////////////////////////////////////////////////////////// -bool cv::viz::Viz3d::VizImpl::removePointCloud (const std::string &id) +////////////////////////////////////////////////////////////////////////////////////////// +void cv::viz::Viz3d::VizImpl::removeAllWidgets() { - CloudActorMap::iterator am_it = cloud_actor_map_->find (id); - if (am_it == cloud_actor_map_->end ()) - return false; - - if (removeActorFromRenderer (am_it->second.actor)) - return cloud_actor_map_->erase (am_it), true; - - return false; + widget_actor_map_->clear(); + renderer_->RemoveAllViewProps(); } -///////////////////////////////////////////////////////////////////////////////////////////// -bool cv::viz::Viz3d::VizImpl::removeShape (const std::string &id) -{ - // Check to see if the given ID entry exists - ShapeActorMap::iterator am_it = shape_actor_map_->find (id); - // Extra step: check if there is a cloud with the same ID - CloudActorMap::iterator ca_it = cloud_actor_map_->find (id); - - bool shape = true; - // Try to find a shape first - if (am_it == shape_actor_map_->end ()) - { - // There is no cloud or shape with this ID, so just exit - if (ca_it == cloud_actor_map_->end ()) - return false; - // Cloud found, set shape to false - shape = false; - } - - // Remove the pointer/ID pair to the global actor map - if (shape) - { - if (removeActorFromRenderer (am_it->second)) - { - shape_actor_map_->erase (am_it); - return (true); - } - } - else - { - if (removeActorFromRenderer (ca_it->second.actor)) - { - cloud_actor_map_->erase (ca_it); - return true; - } - } - return false; -} - -///////////////////////////////////////////////////////////////////////////////////////////// -bool cv::viz::Viz3d::VizImpl::removeText3D (const std::string &id) -{ - // Check to see if the given ID entry exists - ShapeActorMap::iterator am_it = shape_actor_map_->find (id); - if (am_it == shape_actor_map_->end ()) - return false; - - // Remove it from all renderers - if (removeActorFromRenderer (am_it->second)) - return shape_actor_map_->erase (am_it), true; - - return false; -} - -///////////////////////////////////////////////////////////////////////////////////////////// -bool cv::viz::Viz3d::VizImpl::removeAllPointClouds () -{ - // Check to see if the given ID entry exists - CloudActorMap::iterator am_it = cloud_actor_map_->begin (); - while (am_it != cloud_actor_map_->end () ) - { - if (removePointCloud (am_it->first)) - am_it = cloud_actor_map_->begin (); - else - ++am_it; - } - return (true); -} - -///////////////////////////////////////////////////////////////////////////////////////////// -bool cv::viz::Viz3d::VizImpl::removeAllShapes () -{ - // Check to see if the given ID entry exists - ShapeActorMap::iterator am_it = shape_actor_map_->begin (); - while (am_it != shape_actor_map_->end ()) - { - if (removeShape (am_it->first)) - am_it = shape_actor_map_->begin (); - else - ++am_it; - } - return (true); -} - - ////////////////////////////////////////////////////////////////////////////////////////// bool cv::viz::Viz3d::VizImpl::removeActorFromRenderer (const vtkSmartPointer &actor) { diff --git a/modules/viz/src/viz3d_impl.hpp b/modules/viz/src/viz3d_impl.hpp index ef23cc1b90..83e41e4996 100644 --- a/modules/viz/src/viz3d_impl.hpp +++ b/modules/viz/src/viz3d_impl.hpp @@ -17,23 +17,7 @@ public: VizImpl (const String &name); virtual ~VizImpl (); - - - - - - - - - //to refactor - bool removePointCloud (const String& id = "cloud"); - inline bool removePolygonMesh (const String& id = "polygon") { return removePointCloud (id); } - bool removeShape (const String& id = "cloud"); - bool removeText3D (const String& id = "cloud"); - bool removeAllPointClouds (); - - //create Viz3d::removeAllWidgets() - bool removeAllShapes (); + void removeAllWidgets(); //to refactor bool addPolygonMesh (const Mesh3d& mesh, const cv::Mat& mask, const String& id = "polygon"); From b032b4dded5f62e8893737166a0a58e31b71c5c5 Mon Sep 17 00:00:00 2001 From: ozantonkal Date: Thu, 22 Aug 2013 19:42:19 +0200 Subject: [PATCH 03/29] move frompolyfile to widget class as static method, remove addpolygon and its alikes --- modules/viz/include/opencv2/viz/viz3d.hpp | 7 - modules/viz/include/opencv2/viz/widgets.hpp | 2 + modules/viz/src/shape_widgets.cpp | 1 - modules/viz/src/viz3d.cpp | 22 +- modules/viz/src/viz3d_impl.cpp | 609 -------------------- modules/viz/src/viz3d_impl.hpp | 43 -- modules/viz/src/widget.cpp | 40 ++ 7 files changed, 43 insertions(+), 681 deletions(-) diff --git a/modules/viz/include/opencv2/viz/viz3d.hpp b/modules/viz/include/opencv2/viz/viz3d.hpp index 96f999bed8..c27b08df59 100644 --- a/modules/viz/include/opencv2/viz/viz3d.hpp +++ b/modules/viz/include/opencv2/viz/viz3d.hpp @@ -27,13 +27,6 @@ namespace cv void setBackgroundColor(const Color& color = Color::black()); - //to refactor - bool addPolygonMesh(const Mesh3d& mesh, const String& id = "polygon"); - bool updatePolygonMesh(const Mesh3d& mesh, const String& id = "polygon"); - bool addPolylineFromPolygonMesh (const Mesh3d& mesh, const String& id = "polyline"); - bool addPolygon(const Mat& cloud, const Color& color, const String& id = "polygon"); - - void showWidget(const String &id, const Widget &widget, const Affine3f &pose = Affine3f::Identity()); void removeWidget(const String &id); Widget getWidget(const String &id) const; diff --git a/modules/viz/include/opencv2/viz/widgets.hpp b/modules/viz/include/opencv2/viz/widgets.hpp index c746330498..8ad9b3d310 100644 --- a/modules/viz/include/opencv2/viz/widgets.hpp +++ b/modules/viz/include/opencv2/viz/widgets.hpp @@ -16,6 +16,8 @@ namespace cv Widget(); Widget(const Widget &other); Widget& operator =(const Widget &other); + + static Widget fromPlyFile(const String &file_name); ~Widget(); diff --git a/modules/viz/src/shape_widgets.cpp b/modules/viz/src/shape_widgets.cpp index 050b978ef6..cb66e80b39 100644 --- a/modules/viz/src/shape_widgets.cpp +++ b/modules/viz/src/shape_widgets.cpp @@ -969,7 +969,6 @@ cv::viz::CameraPositionWidget::CameraPositionWidget(const Matx33f &K, const Mat // Create a camera vtkSmartPointer camera = vtkSmartPointer::New(); - float f_x = K(0,0); float f_y = K(1,1); float c_y = K(1,2); float aspect_ratio = float(image.cols)/float(image.rows); diff --git a/modules/viz/src/viz3d.cpp b/modules/viz/src/viz3d.cpp index bb88e1337d..696976d763 100644 --- a/modules/viz/src/viz3d.cpp +++ b/modules/viz/src/viz3d.cpp @@ -44,26 +44,6 @@ void cv::viz::Viz3d::release() void cv::viz::Viz3d::setBackgroundColor(const Color& color) { impl_->setBackgroundColor(color); } -bool cv::viz::Viz3d::addPolygonMesh (const Mesh3d& mesh, const String& id) -{ - return impl_->addPolygonMesh(mesh, Mat(), id); -} - -bool cv::viz::Viz3d::updatePolygonMesh (const Mesh3d& mesh, const String& id) -{ - return impl_->updatePolygonMesh(mesh, Mat(), id); -} - -bool cv::viz::Viz3d::addPolylineFromPolygonMesh (const Mesh3d& mesh, const String& id) -{ - return impl_->addPolylineFromPolygonMesh(mesh, id); -} - -bool cv::viz::Viz3d::addPolygon(const Mat& cloud, const Color& color, const String& id) -{ - return impl_->addPolygon(cloud, color, id); -} - void cv::viz::Viz3d::spin() { impl_->spin(); } void cv::viz::Viz3d::spinOnce (int time, bool force_redraw) { impl_->spinOnce(time, force_redraw); } bool cv::viz::Viz3d::wasStopped() const { return impl_->wasStopped(); } @@ -94,4 +74,4 @@ void cv::viz::Viz3d::converTo3DRay(const Point3d &window_coord, Point3d &origin, cv::Size cv::viz::Viz3d::getWindowSize() const { return impl_->getWindowSize(); } void cv::viz::Viz3d::setWindowSize(const Size &window_size) { impl_->setWindowSize(window_size.width, window_size.height); } -cv::String cv::viz::Viz3d::getWindowName() const { return impl_->getWindowName(); } \ No newline at end of file +cv::String cv::viz::Viz3d::getWindowName() const { return impl_->getWindowName(); } diff --git a/modules/viz/src/viz3d_impl.cpp b/modules/viz/src/viz3d_impl.cpp index 12a3de15f5..f1417053b3 100644 --- a/modules/viz/src/viz3d_impl.cpp +++ b/modules/viz/src/viz3d_impl.cpp @@ -331,29 +331,6 @@ bool cv::viz::Viz3d::VizImpl::setPointCloudRenderingProperties (int property, do return true; } -///////////////////////////////////////////////////////////////////////////////////////////// -bool cv::viz::Viz3d::VizImpl::setPointCloudSelected (const bool selected, const std::string &id) -{ - CloudActorMap::iterator am_it = cloud_actor_map_->find (id); - if (am_it == cloud_actor_map_->end ()) - return std::cout << "[setPointCloudRenderingProperties] Could not find any PointCloud datasets with id <" << id << ">!" << std::endl, false; - - vtkLODActor* actor = vtkLODActor::SafeDownCast (am_it->second.actor); - if (selected) - { - actor->GetProperty ()->EdgeVisibilityOn (); - actor->GetProperty ()->SetEdgeColor (1.0, 0.0, 0.0); - actor->Modified (); - } - else - { - actor->GetProperty ()->EdgeVisibilityOff (); - actor->Modified (); - } - - return true; -} - ///////////////////////////////////////////////////////////////////////////////////////////// bool cv::viz::Viz3d::VizImpl::setShapeRenderingProperties (int property, double value, const std::string &id) { @@ -618,148 +595,6 @@ void cv::viz::Viz3d::VizImpl::resetCameraViewpoint (const std::string &id) renderer_->Render (); } -//////////////////////////////////////////////////////////////////////////////////////////// -bool cv::viz::Viz3d::VizImpl::addModelFromPolyData (vtkSmartPointer polydata, const std::string & id) -{ - ShapeActorMap::iterator am_it = shape_actor_map_->find (id); - if (am_it != shape_actor_map_->end ()) - { - std::cout << "[addModelFromPolyData] A shape with id <" << id << "> already exists! Please choose a different id and retry." << std::endl; - return (false); - } - - vtkSmartPointer actor; - createActorFromVTKDataSet (polydata, actor); - actor->GetProperty ()->SetRepresentationToWireframe (); - renderer_->AddActor(actor); - - // Save the pointer/ID pair to the global actor map - (*shape_actor_map_)[id] = actor; - return (true); -} - -//////////////////////////////////////////////////////////////////////////////////////////// -bool cv::viz::Viz3d::VizImpl::addModelFromPolyData (vtkSmartPointer polydata, vtkSmartPointer transform, const std::string & id) -{ - ShapeActorMap::iterator am_it = shape_actor_map_->find (id); - if (am_it != shape_actor_map_->end ()) - { - std::cout << "[addModelFromPolyData] A shape with id <"< already exists! Please choose a different id and retry." << std::endl; - return (false); - } - - vtkSmartPointer trans_filter = vtkSmartPointer::New (); - trans_filter->SetTransform (transform); - trans_filter->SetInput (polydata); - trans_filter->Update(); - - // Create an Actor - vtkSmartPointer actor; - createActorFromVTKDataSet (trans_filter->GetOutput (), actor); - actor->GetProperty ()->SetRepresentationToWireframe (); - renderer_->AddActor(actor); - - // Save the pointer/ID pair to the global actor map - (*shape_actor_map_)[id] = actor; - return (true); -} - - -//////////////////////////////////////////////////////////////////////////////////////////// -bool cv::viz::Viz3d::VizImpl::addModelFromPLYFile (const std::string &filename, const std::string &id) -{ - ShapeActorMap::iterator am_it = shape_actor_map_->find (id); - if (am_it != shape_actor_map_->end ()) - return std::cout << "[addModelFromPLYFile] A shape with id <"< already exists! Please choose a different id and retry.." << std::endl, false; - - vtkSmartPointer reader = vtkSmartPointer::New (); - reader->SetFileName (filename.c_str ()); - - vtkSmartPointer actor; - createActorFromVTKDataSet (reader->GetOutput (), actor); - actor->GetProperty ()->SetRepresentationToWireframe (); - renderer_->AddActor(actor); - - (*shape_actor_map_)[id] = actor; - return true; -} - -//////////////////////////////////////////////////////////////////////////////////////////// -bool cv::viz::Viz3d::VizImpl::addModelFromPLYFile (const std::string &filename, vtkSmartPointer transform, const std::string &id) -{ - ShapeActorMap::iterator am_it = shape_actor_map_->find (id); - if (am_it != shape_actor_map_->end ()) - return std::cout << "[addModelFromPLYFile] A shape with id <"< already exists! Please choose a different id and retry." << std::endl, false; - - vtkSmartPointer reader = vtkSmartPointer::New (); - reader->SetFileName (filename.c_str ()); - - vtkSmartPointer trans_filter = vtkSmartPointer::New (); - trans_filter->SetTransform (transform); - trans_filter->SetInputConnection (reader->GetOutputPort ()); - - vtkSmartPointer actor; - createActorFromVTKDataSet (trans_filter->GetOutput (), actor); - actor->GetProperty ()->SetRepresentationToWireframe (); - renderer_->AddActor(actor); - - (*shape_actor_map_)[id] = actor; - return (true); -} - -bool cv::viz::Viz3d::VizImpl::addPolylineFromPolygonMesh (const Mesh3d& /*mesh*/, const std::string &/*id*/) -{ -// CV_Assert(mesh.cloud.rows == 1 && mesh.cloud.type() == CV_32FC3); -// -// ShapeActorMap::iterator am_it = shape_actor_map_->find (id); -// if (am_it != shape_actor_map_->end ()) -// return std::cout << "[addPolylineFromPolygonMesh] A shape with id <"<< id << "> already exists! Please choose a different id and retry.\n" << std::endl, false; -// -// vtkSmartPointer poly_points = vtkSmartPointer::New (); -// poly_points->SetNumberOfPoints (mesh.cloud.size().area()); -// -// const cv::Point3f *cdata = mesh.cloud.ptr(); -// for (int i = 0; i < mesh.cloud.cols; ++i) -// poly_points->InsertPoint (i, cdata[i].x, cdata[i].y,cdata[i].z); -// -// -// // Create a cell array to store the lines in and add the lines to it -// vtkSmartPointer cells = vtkSmartPointer::New (); -// vtkSmartPointer polyData; -// allocVtkPolyData (polyData); -// -// for (size_t i = 0; i < mesh.polygons.size (); i++) -// { -// vtkSmartPointer polyLine = vtkSmartPointer::New(); -// polyLine->GetPointIds()->SetNumberOfIds(mesh.polygons[i].vertices.size()); -// for(unsigned int k = 0; k < mesh.polygons[i].vertices.size(); k++) -// { -// polyLine->GetPointIds()->SetId(k,mesh. polygons[i].vertices[k]); -// } -// -// cells->InsertNextCell (polyLine); -// } -// -// // Add the points to the dataset -// polyData->SetPoints (poly_points); -// -// // Add the lines to the dataset -// polyData->SetLines (cells); -// -// // Setup actor and mapper -// vtkSmartPointer < vtkPolyDataMapper > mapper = vtkSmartPointer::New (); -// mapper->SetInput (polyData); -// -// vtkSmartPointer actor = vtkSmartPointer::New (); -// actor->SetMapper (mapper); -// renderer_->AddActor(actor); -// -// // Save the pointer/ID pair to the global actor map -// (*shape_actor_map_)[id] = actor; - return (true); -} - - /////////////////////////////////////////////////////////////////////////////////// void cv::viz::Viz3d::VizImpl::setRepresentationToSurfaceForAllActors () { @@ -883,450 +718,6 @@ void cv::viz::Viz3d::VizImpl::setWindowPosition (int x, int y) { window_->SetPos void cv::viz::Viz3d::VizImpl::setWindowSize (int xw, int yw) { window_->SetSize (xw, yw); } cv::Size cv::viz::Viz3d::VizImpl::getWindowSize() const { return Size(window_->GetSize()[0], window_->GetSize()[1]); } -bool cv::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 ()); -// CV_Assert(mesh.colors.empty() || (!mesh.colors.empty() && mesh.colors.size() == mesh.cloud.size() && mesh.colors.type() == CV_8UC3)); -// CV_Assert(mask.empty() || (!mask.empty() && mask.size() == mesh.cloud.size() && mask.type() == CV_8U)); -// -// if (cloud_actor_map_->find (id) != cloud_actor_map_->end ()) -// return std::cout << "[addPolygonMesh] A shape with id <" << id << "> already exists! Please choose a different id and retry." << std::endl, false; -// -// // int rgb_idx = -1; -// // std::vector fields; -// -// -// // rgb_idx = temp_viz::getFieldIndex (*cloud, "rgb", fields); -// // if (rgb_idx == -1) -// // rgb_idx = temp_viz::getFieldIndex (*cloud, "rgba", fields); -// -// vtkSmartPointer colors_array; -// #if 1 -// if (!mesh.colors.empty()) -// { -// colors_array = vtkSmartPointer::New (); -// colors_array->SetNumberOfComponents (3); -// colors_array->SetName ("Colors"); -// -// const unsigned char* data = mesh.colors.ptr(); -// -// //TODO check mask -// CV_Assert(mask.empty()); //because not implemented; -// -// for(int i = 0; i < mesh.colors.cols; ++i) -// colors_array->InsertNextTupleValue(&data[i*3]); -// -// // temp_viz::RGB rgb_data; -// // for (size_t i = 0; i < cloud->size (); ++i) -// // { -// // if (!isFinite (cloud->points[i])) -// // continue; -// // memcpy (&rgb_data, reinterpret_cast (&cloud->points[i]) + fields[rgb_idx].offset, sizeof (temp_viz::RGB)); -// // unsigned char color[3]; -// // color[0] = rgb_data.r; -// // color[1] = rgb_data.g; -// // color[2] = rgb_data.b; -// // colors->InsertNextTupleValue (color); -// // } -// } -// #endif -// -// // Create points from polyMesh.cloud -// vtkSmartPointer points = vtkSmartPointer::New (); -// vtkIdType nr_points = mesh.cloud.size().area(); -// -// points->SetNumberOfPoints (nr_points); -// -// -// // Get a pointer to the beginning of the data array -// float *data = static_cast (points->GetData ())->GetPointer (0); -// -// -// std::vector lookup; -// // If the dataset is dense (no NaNs) -// if (mask.empty()) -// { -// cv::Mat hdr(mesh.cloud.size(), CV_32FC3, (void*)data); -// mesh.cloud.copyTo(hdr); -// } -// else -// { -// lookup.resize (nr_points); -// -// const unsigned char *mdata = mask.ptr(); -// const cv::Point3f *cdata = mesh.cloud.ptr(); -// cv::Point3f* out = reinterpret_cast(data); -// -// int j = 0; // true point index -// for (int i = 0; i < nr_points; ++i) -// if(mdata[i]) -// { -// lookup[i] = j; -// out[j++] = cdata[i]; -// } -// nr_points = j; -// points->SetNumberOfPoints (nr_points); -// } -// -// // Get the maximum size of a polygon -// int max_size_of_polygon = -1; -// for (size_t i = 0; i < mesh.polygons.size (); ++i) -// if (max_size_of_polygon < static_cast (mesh.polygons[i].vertices.size ())) -// max_size_of_polygon = static_cast (mesh.polygons[i].vertices.size ()); -// -// vtkSmartPointer actor; -// -// if (mesh.polygons.size () > 1) -// { -// // Create polys from polyMesh.polygons -// vtkSmartPointer cell_array = vtkSmartPointer::New (); -// vtkIdType *cell = cell_array->WritePointer (mesh.polygons.size (), mesh.polygons.size () * (max_size_of_polygon + 1)); -// int idx = 0; -// if (lookup.size () > 0) -// { -// for (size_t i = 0; i < mesh.polygons.size (); ++i, ++idx) -// { -// size_t n_points = mesh.polygons[i].vertices.size (); -// *cell++ = n_points; -// //cell_array->InsertNextCell (n_points); -// for (size_t j = 0; j < n_points; j++, ++idx) -// *cell++ = lookup[mesh.polygons[i].vertices[j]]; -// //cell_array->InsertCellPoint (lookup[vertices[i].vertices[j]]); -// } -// } -// else -// { -// for (size_t i = 0; i < mesh.polygons.size (); ++i, ++idx) -// { -// size_t n_points = mesh.polygons[i].vertices.size (); -// *cell++ = n_points; -// //cell_array->InsertNextCell (n_points); -// for (size_t j = 0; j < n_points; j++, ++idx) -// *cell++ = mesh.polygons[i].vertices[j]; -// //cell_array->InsertCellPoint (vertices[i].vertices[j]); -// } -// } -// vtkSmartPointer polydata; -// allocVtkPolyData (polydata); -// cell_array->GetData ()->SetNumberOfValues (idx); -// cell_array->Squeeze (); -// polydata->SetStrips (cell_array); -// polydata->SetPoints (points); -// -// if (colors_array) -// polydata->GetPointData ()->SetScalars (colors_array); -// -// createActorFromVTKDataSet (polydata, actor, false); -// } -// else -// { -// vtkSmartPointer polygon = vtkSmartPointer::New (); -// size_t n_points = mesh.polygons[0].vertices.size (); -// polygon->GetPointIds ()->SetNumberOfIds (n_points - 1); -// -// if (lookup.size () > 0) -// { -// for (size_t j = 0; j < n_points - 1; ++j) -// polygon->GetPointIds ()->SetId (j, lookup[mesh.polygons[0].vertices[j]]); -// } -// else -// { -// for (size_t j = 0; j < n_points - 1; ++j) -// polygon->GetPointIds ()->SetId (j, mesh.polygons[0].vertices[j]); -// } -// vtkSmartPointer poly_grid; -// allocVtkUnstructuredGrid (poly_grid); -// poly_grid->Allocate (1, 1); -// poly_grid->InsertNextCell (polygon->GetCellType (), polygon->GetPointIds ()); -// poly_grid->SetPoints (points); -// poly_grid->Update (); -// if (colors_array) -// poly_grid->GetPointData ()->SetScalars (colors_array); -// -// createActorFromVTKDataSet (poly_grid, actor, false); -// } -// renderer_->AddActor (actor); -// actor->GetProperty ()->SetRepresentationToSurface (); -// // Backface culling renders the visualization slower, but guarantees that we see all triangles -// actor->GetProperty ()->BackfaceCullingOff (); -// actor->GetProperty ()->SetInterpolationToFlat (); -// actor->GetProperty ()->EdgeVisibilityOff (); -// actor->GetProperty ()->ShadingOff (); -// -// // Save the pointer/ID pair to the global actor map -// (*cloud_actor_map_)[id].actor = actor; -// //if (vertices.size () > 1) -// // (*cloud_actor_map_)[id].cells = static_cast(actor->GetMapper ())->GetInput ()->GetVerts ()->GetData (); -// -// const Eigen::Vector4f& sensor_origin = Eigen::Vector4f::Zero (); -// const Eigen::Quaternion& sensor_orientation = Eigen::Quaternionf::Identity (); -// -// // Save the viewpoint transformation matrix to the global actor map -// vtkSmartPointer transformation = vtkSmartPointer::New(); -// convertToVtkMatrix (sensor_origin, sensor_orientation, transformation); -// (*cloud_actor_map_)[id].viewpoint_transformation_ = transformation; -// -// return (true); -return true; -} - - -bool cv::viz::Viz3d::VizImpl::updatePolygonMesh (const Mesh3d& /*mesh*/, const cv::Mat& /*mask*/, const std::string &/*id*/) -{ -// CV_Assert(mesh.cloud.type() == CV_32FC3 && mesh.cloud.rows == 1 && !mesh.polygons.empty ()); -// CV_Assert(mesh.colors.empty() || (!mesh.colors.empty() && mesh.colors.size() == mesh.cloud.size() && mesh.colors.type() == CV_8UC3)); -// CV_Assert(mask.empty() || (!mask.empty() && mask.size() == mesh.cloud.size() && mask.type() == CV_8U)); -// -// // Check to see if this ID entry already exists (has it been already added to the visualizer?) -// CloudActorMap::iterator am_it = cloud_actor_map_->find (id); -// if (am_it == cloud_actor_map_->end ()) -// return (false); -// -// // Get the current poly data -// vtkSmartPointer polydata = static_cast(am_it->second.actor->GetMapper ())->GetInput (); -// if (!polydata) -// return (false); -// vtkSmartPointer cells = polydata->GetStrips (); -// if (!cells) -// return (false); -// vtkSmartPointer points = polydata->GetPoints (); -// // Copy the new point array in -// vtkIdType nr_points = mesh.cloud.size().area(); -// points->SetNumberOfPoints (nr_points); -// -// // Get a pointer to the beginning of the data array -// float *data = (static_cast (points->GetData ()))->GetPointer (0); -// -// int ptr = 0; -// std::vector lookup; -// // If the dataset is dense (no NaNs) -// if (mask.empty()) -// { -// cv::Mat hdr(mesh.cloud.size(), CV_32FC3, (void*)data); -// mesh.cloud.copyTo(hdr); -// -// } -// else -// { -// lookup.resize (nr_points); -// -// const unsigned char *mdata = mask.ptr(); -// const cv::Point3f *cdata = mesh.cloud.ptr(); -// cv::Point3f* out = reinterpret_cast(data); -// -// int j = 0; // true point index -// for (int i = 0; i < nr_points; ++i) -// if(mdata[i]) -// { -// lookup[i] = j; -// out[j++] = cdata[i]; -// } -// nr_points = j; -// points->SetNumberOfPoints (nr_points);; -// } -// -// // Update colors -// vtkUnsignedCharArray* colors_array = vtkUnsignedCharArray::SafeDownCast (polydata->GetPointData ()->GetScalars ()); -// -// if (!mesh.colors.empty() && colors_array) -// { -// if (mask.empty()) -// { -// const unsigned char* data = mesh.colors.ptr(); -// for(int i = 0; i < mesh.colors.cols; ++i) -// colors_array->InsertNextTupleValue(&data[i*3]); -// } -// else -// { -// const unsigned char* color = mesh.colors.ptr(); -// const unsigned char* mdata = mask.ptr(); -// -// int j = 0; -// for(int i = 0; i < mesh.colors.cols; ++i) -// if (mdata[i]) -// colors_array->SetTupleValue (j++, &color[i*3]); -// -// } -// } -// -// // Get the maximum size of a polygon -// int max_size_of_polygon = -1; -// for (size_t i = 0; i < mesh.polygons.size (); ++i) -// if (max_size_of_polygon < static_cast (mesh.polygons[i].vertices.size ())) -// max_size_of_polygon = static_cast (mesh.polygons[i].vertices.size ()); -// -// // Update the cells -// cells = vtkSmartPointer::New (); -// vtkIdType *cell = cells->WritePointer (mesh.polygons.size (), mesh.polygons.size () * (max_size_of_polygon + 1)); -// int idx = 0; -// if (lookup.size () > 0) -// { -// for (size_t i = 0; i < mesh.polygons.size (); ++i, ++idx) -// { -// size_t n_points = mesh.polygons[i].vertices.size (); -// *cell++ = n_points; -// for (size_t j = 0; j < n_points; j++, cell++, ++idx) -// *cell = lookup[mesh.polygons[i].vertices[j]]; -// } -// } -// else -// { -// for (size_t i = 0; i < mesh.polygons.size (); ++i, ++idx) -// { -// size_t n_points = mesh.polygons[i].vertices.size (); -// *cell++ = n_points; -// for (size_t j = 0; j < n_points; j++, cell++, ++idx) -// *cell = mesh.polygons[i].vertices[j]; -// } -// } -// cells->GetData ()->SetNumberOfValues (idx); -// cells->Squeeze (); -// // Set the the vertices -// polydata->SetStrips (cells); -// polydata->Update (); - return (true); -} - -//////////////////////////////////////////////////////////////////////////////////////////// -bool cv::viz::Viz3d::VizImpl::addArrow (const cv::Point3f &p1, const cv::Point3f &p2, const Color& color, bool display_length, const std::string &id) -{ - // Check to see if this ID entry already exists (has it been already added to the visualizer?) - ShapeActorMap::iterator am_it = shape_actor_map_->find (id); - if (am_it != shape_actor_map_->end ()) - return std::cout << "[addArrow] A shape with id <" << id << "> already exists! Please choose a different id and retry." << std::endl, false; - - // Create an Actor - vtkSmartPointer leader = vtkSmartPointer::New (); - leader->GetPositionCoordinate()->SetCoordinateSystemToWorld (); - leader->GetPositionCoordinate()->SetValue (p1.x, p1.y, p1.z); - leader->GetPosition2Coordinate()->SetCoordinateSystemToWorld (); - leader->GetPosition2Coordinate()->SetValue (p2.x, p2.y, p2.z); - leader->SetArrowStyleToFilled(); - leader->SetArrowPlacementToPoint2 (); - - if (display_length) - leader->AutoLabelOn (); - else - leader->AutoLabelOff (); - - Color c = vtkcolor(color); - leader->GetProperty ()->SetColor (c.val); - renderer_->AddActor (leader); - - // Save the pointer/ID pair to the global actor map - (*shape_actor_map_)[id] = leader; - return (true); -} -//////////////////////////////////////////////////////////////////////////////////////////// -bool cv::viz::Viz3d::VizImpl::addArrow (const cv::Point3f &p1, const cv::Point3f &p2, const Color& color_line, const Color& color_text, const std::string &id) -{ - // Check to see if this ID entry already exists (has it been already added to the visualizer?) - ShapeActorMap::iterator am_it = shape_actor_map_->find (id); - if (am_it != shape_actor_map_->end ()) - { - std::cout << "[addArrow] A shape with id <" << id << "> already exists! Please choose a different id and retry." << std::endl; - return (false); - } - - // Create an Actor - vtkSmartPointer leader = vtkSmartPointer::New (); - leader->GetPositionCoordinate ()->SetCoordinateSystemToWorld (); - leader->GetPositionCoordinate ()->SetValue (p1.x, p1.y, p1.z); - leader->GetPosition2Coordinate ()->SetCoordinateSystemToWorld (); - leader->GetPosition2Coordinate ()->SetValue (p2.x, p2.y, p2.z); - leader->SetArrowStyleToFilled (); - leader->AutoLabelOn (); - - Color ct = vtkcolor(color_text); - leader->GetLabelTextProperty()->SetColor(ct.val); - - Color cl = vtkcolor(color_line); - leader->GetProperty ()->SetColor (cl.val); - renderer_->AddActor (leader); - - // Save the pointer/ID pair to the global actor map - (*shape_actor_map_)[id] = leader; - return (true); -} - -bool cv::viz::Viz3d::VizImpl::addPolygon (const cv::Mat& cloud, const Color& color, const std::string &id) -{ - CV_Assert(cloud.type() == CV_32FC3 && cloud.rows == 1); - - vtkSmartPointer points = vtkSmartPointer::New (); - vtkSmartPointer polygon = vtkSmartPointer::New (); - - int total = cloud.size().area(); - points->SetNumberOfPoints (total); - polygon->GetPointIds ()->SetNumberOfIds (total); - - for (int i = 0; i < total; ++i) - { - cv::Point3f p = cloud.ptr()[i]; - points->SetPoint (i, p.x, p.y, p.z); - polygon->GetPointIds ()->SetId (i, i); - } - - vtkSmartPointer poly_grid; - allocVtkUnstructuredGrid (poly_grid); - poly_grid->Allocate (1, 1); - poly_grid->InsertNextCell (polygon->GetCellType (), polygon->GetPointIds ()); - poly_grid->SetPoints (points); - poly_grid->Update (); - - - ////////////////////////////////////////////////////// - vtkSmartPointer data = poly_grid; - - Color c = vtkcolor(color); - - // Check to see if this ID entry already exists (has it been already added to the visualizer?) - ShapeActorMap::iterator am_it = shape_actor_map_->find (id); - if (am_it != shape_actor_map_->end ()) - { - vtkSmartPointer all_data = vtkSmartPointer::New (); - - // Add old data - all_data->AddInput (reinterpret_cast ((vtkActor::SafeDownCast (am_it->second))->GetMapper ())->GetInput ()); - - // Add new data - vtkSmartPointer surface_filter = vtkSmartPointer::New (); - surface_filter->SetInput (vtkUnstructuredGrid::SafeDownCast (data)); - vtkSmartPointer poly_data = surface_filter->GetOutput (); - all_data->AddInput (poly_data); - - // Create an Actor - vtkSmartPointer actor; - createActorFromVTKDataSet (all_data->GetOutput (), actor); - actor->GetProperty ()->SetRepresentationToWireframe (); - actor->GetProperty ()->SetColor (c.val); - actor->GetMapper ()->ScalarVisibilityOff (); - actor->GetProperty ()->BackfaceCullingOff (); - - removeActorFromRenderer (am_it->second); - renderer_->AddActor (actor); - - // Save the pointer/ID pair to the global actor map - (*shape_actor_map_)[id] = actor; - } - else - { - // Create an Actor - vtkSmartPointer actor; - createActorFromVTKDataSet (data, actor); - actor->GetProperty ()->SetRepresentationToWireframe (); - actor->GetProperty ()->SetColor (c.val); - actor->GetMapper ()->ScalarVisibilityOff (); - actor->GetProperty ()->BackfaceCullingOff (); - renderer_->AddActor (actor); - - // Save the pointer/ID pair to the global actor map - (*shape_actor_map_)[id] = actor; - } - - return (true); -} - void cv::viz::Viz3d::VizImpl::showWidget(const String &id, const Widget &widget, const Affine3f &pose) { WidgetActorMap::iterator wam_itr = widget_actor_map_->find(id); diff --git a/modules/viz/src/viz3d_impl.hpp b/modules/viz/src/viz3d_impl.hpp index 83e41e4996..085a718c14 100644 --- a/modules/viz/src/viz3d_impl.hpp +++ b/modules/viz/src/viz3d_impl.hpp @@ -19,30 +19,11 @@ public: void removeAllWidgets(); - //to refactor - bool addPolygonMesh (const Mesh3d& mesh, const cv::Mat& mask, const String& id = "polygon"); - bool updatePolygonMesh (const Mesh3d& mesh, const cv::Mat& mask, const String& id = "polygon"); - bool addPolylineFromPolygonMesh (const Mesh3d& mesh, const String& id = "polyline"); - // to refactor: Widget3D:: & Viz3d:: bool setPointCloudRenderingProperties (int property, double value, const String& id = "cloud"); bool getPointCloudRenderingProperties (int property, double &value, const String& id = "cloud"); bool setShapeRenderingProperties (int property, double value, const String& id); - /** \brief Set whether the point cloud is selected or not - * \param[in] selected whether the cloud is selected or not (true = selected) - * \param[in] id the point cloud object id (default: cloud) - */ - // probably should just remove - bool setPointCloudSelected (const bool selected, const String& id = "cloud" ); - - - - - - - - /** \brief Returns true when the user tried to close the window */ bool wasStopped () const { if (interactor_ != NULL) return (stopped_); else return true; } @@ -60,30 +41,6 @@ public: } } - - - - - - - - - - - // to refactor - bool addPolygon(const cv::Mat& cloud, const Color& color, const String& id = "polygon"); - bool addArrow (const Point3f& pt1, const Point3f& pt2, const Color& color, bool display_length, const String& id = "arrow"); - bool addArrow (const Point3f& pt1, const Point3f& pt2, const Color& color_line, const Color& color_text, const String& id = "arrow"); - - // Probably remove this - bool addModelFromPolyData (vtkSmartPointer polydata, const String& id = "PolyData"); - bool addModelFromPolyData (vtkSmartPointer polydata, vtkSmartPointer transform, const String& id = "PolyData"); - - // I think this should be moved to 'static Widget Widget::fromPlyFile(const String&)'; - bool addModelFromPLYFile (const String &filename, const String& id = "PLYModel"); - bool addModelFromPLYFile (const String &filename, vtkSmartPointer transform, const String& id = "PLYModel"); - - // to implement in Viz3d with shorter name void setRepresentationToSurfaceForAllActors(); void setRepresentationToPointsForAllActors(); diff --git a/modules/viz/src/widget.cpp b/modules/viz/src/widget.cpp index 65c5b1aca9..a70409772d 100644 --- a/modules/viz/src/widget.cpp +++ b/modules/viz/src/widget.cpp @@ -54,6 +54,46 @@ void cv::viz::Widget::release() } } +cv::viz::Widget cv::viz::Widget::fromPlyFile(const String &file_name) +{ + vtkSmartPointer reader = vtkSmartPointer::New (); + reader->SetFileName (file_name.c_str ()); + + vtkSmartPointer data = reader->GetOutput(); + CV_Assert(data); + + vtkSmartPointer actor = vtkSmartPointer::New(); + + vtkSmartPointer mapper = vtkSmartPointer::New (); + mapper->SetInput (data); + + vtkSmartPointer scalars = data->GetPointData ()->GetScalars (); + if (scalars) + { + cv::Vec3d minmax(scalars->GetRange()); + mapper->SetScalarRange(minmax.val); + mapper->SetScalarModeToUsePointData (); + + // interpolation OFF, if data is a vtkPolyData that contains only vertices, ON for anything else. + vtkPolyData* polyData = vtkPolyData::SafeDownCast (data); + bool interpolation = (polyData && polyData->GetNumberOfCells () != polyData->GetNumberOfVerts ()); + + mapper->SetInterpolateScalarsBeforeMapping (interpolation); + mapper->ScalarVisibilityOn (); + } + mapper->ImmediateModeRenderingOff (); + + actor->SetNumberOfCloudPoints (int (std::max (1, data->GetNumberOfPoints () / 10))); + actor->GetProperty ()->SetInterpolationToFlat (); + actor->GetProperty ()->BackfaceCullingOn (); + + actor->SetMapper (mapper); + + Widget widget; + widget.impl_->prop = actor; + return widget; +} + /////////////////////////////////////////////////////////////////////////////////////////////// /// widget accessor implementaion From cf36b8f817b025ad4b9e4883e12355680ce5685e Mon Sep 17 00:00:00 2001 From: ozantonkal Date: Sat, 24 Aug 2013 11:49:56 +0200 Subject: [PATCH 04/29] rendering properties in Widget and Viz3d --- modules/viz/include/opencv2/viz/viz3d.hpp | 4 +- modules/viz/include/opencv2/viz/widgets.hpp | 7 +- modules/viz/src/viz3d.cpp | 5 +- modules/viz/src/viz3d_impl.cpp | 173 -------------------- modules/viz/src/viz3d_impl.hpp | 6 +- modules/viz/src/widget.cpp | 125 ++++++++++++++ 6 files changed, 137 insertions(+), 183 deletions(-) diff --git a/modules/viz/include/opencv2/viz/viz3d.hpp b/modules/viz/include/opencv2/viz/viz3d.hpp index c27b08df59..7b0875513a 100644 --- a/modules/viz/include/opencv2/viz/viz3d.hpp +++ b/modules/viz/include/opencv2/viz/viz3d.hpp @@ -7,7 +7,6 @@ #include #include #include -#include namespace cv { @@ -55,6 +54,9 @@ namespace cv void registerKeyboardCallback(KeyboardCallback callback, void* cookie = 0); void registerMouseCallback(MouseCallback callback, void* cookie = 0); + + void setRenderingProperty(int property, double value, const String &id); + double getRenderingProperty(int property, const String &id); private: struct VizImpl; diff --git a/modules/viz/include/opencv2/viz/widgets.hpp b/modules/viz/include/opencv2/viz/widgets.hpp index 8ad9b3d310..99f4bd4207 100644 --- a/modules/viz/include/opencv2/viz/widgets.hpp +++ b/modules/viz/include/opencv2/viz/widgets.hpp @@ -16,10 +16,12 @@ namespace cv Widget(); Widget(const Widget &other); Widget& operator =(const Widget &other); + ~Widget(); static Widget fromPlyFile(const String &file_name); - - ~Widget(); + + void setRenderingProperty(int property, double value); + double getRenderingProperty(int property) const; template _W cast(); private: @@ -43,7 +45,6 @@ namespace cv Affine3f getPose() const; void setColor(const Color &color); - private: struct MatrixConverter; diff --git a/modules/viz/src/viz3d.cpp b/modules/viz/src/viz3d.cpp index 696976d763..fc9ce01c0e 100644 --- a/modules/viz/src/viz3d.cpp +++ b/modules/viz/src/viz3d.cpp @@ -54,8 +54,6 @@ void cv::viz::Viz3d::registerKeyboardCallback(KeyboardCallback callback, void* c void cv::viz::Viz3d::registerMouseCallback(MouseCallback callback, void* cookie) { impl_->registerMouseCallback(callback, cookie); } - - void cv::viz::Viz3d::showWidget(const String &id, const Widget &widget, const Affine3f &pose) { impl_->showWidget(id, widget, pose); } void cv::viz::Viz3d::removeWidget(const String &id) { impl_->removeWidget(id); } cv::viz::Widget cv::viz::Viz3d::getWidget(const String &id) const { return impl_->getWidget(id); } @@ -75,3 +73,6 @@ void cv::viz::Viz3d::converTo3DRay(const Point3d &window_coord, Point3d &origin, cv::Size cv::viz::Viz3d::getWindowSize() const { return impl_->getWindowSize(); } void cv::viz::Viz3d::setWindowSize(const Size &window_size) { impl_->setWindowSize(window_size.width, window_size.height); } cv::String cv::viz::Viz3d::getWindowName() const { return impl_->getWindowName(); } + +void cv::viz::Viz3d::setRenderingProperty(int property, double value, const String &id) { getWidget(id).setRenderingProperty(property, value); } +double cv::viz::Viz3d::getRenderingProperty(int property, const String &id) { return getWidget(id).getRenderingProperty(property); } diff --git a/modules/viz/src/viz3d_impl.cpp b/modules/viz/src/viz3d_impl.cpp index f1417053b3..aa51b10150 100644 --- a/modules/viz/src/viz3d_impl.cpp +++ b/modules/viz/src/viz3d_impl.cpp @@ -249,179 +249,6 @@ void cv::viz::Viz3d::VizImpl::setBackgroundColor (const Color& color) renderer_->SetBackground (c.val); } -///////////////////////////////////////////////////////////////////////////////////////////// -bool cv::viz::Viz3d::VizImpl::getPointCloudRenderingProperties (int property, double &value, const std::string &id) -{ - CloudActorMap::iterator am_it = cloud_actor_map_->find (id); - if (am_it == cloud_actor_map_->end ()) - return false; - - vtkLODActor* actor = vtkLODActor::SafeDownCast (am_it->second.actor); - - switch (property) - { - case VIZ_POINT_SIZE: - { - value = actor->GetProperty ()->GetPointSize (); - actor->Modified (); - break; - } - case VIZ_OPACITY: - { - value = actor->GetProperty ()->GetOpacity (); - actor->Modified (); - break; - } - case VIZ_LINE_WIDTH: - { - value = actor->GetProperty ()->GetLineWidth (); - actor->Modified (); - break; - } - default: - CV_Assert("getPointCloudRenderingProperties: Unknown property"); - } - - return true; -} - -///////////////////////////////////////////////////////////////////////////////////////////// -bool cv::viz::Viz3d::VizImpl::setPointCloudRenderingProperties (int property, double value, const std::string &id) -{ - CloudActorMap::iterator am_it = cloud_actor_map_->find (id); - if (am_it == cloud_actor_map_->end ()) - return std::cout << "[setPointCloudRenderingProperties] Could not find any PointCloud datasets with id <" << id << ">!" << std::endl, false; - - vtkLODActor* actor = vtkLODActor::SafeDownCast (am_it->second.actor); - - switch (property) - { - case VIZ_POINT_SIZE: - { - actor->GetProperty ()->SetPointSize (float (value)); - actor->Modified (); - break; - } - case VIZ_OPACITY: - { - actor->GetProperty ()->SetOpacity (value); - actor->Modified (); - break; - } - // Turn on/off flag to control whether data is rendered using immediate - // mode or note. Immediate mode rendering tends to be slower but it can - // handle larger datasets. The default value is immediate mode off. If you - // are having problems rendering a large dataset you might want to consider - // using immediate more rendering. - case VIZ_IMMEDIATE_RENDERING: - { - actor->GetMapper ()->SetImmediateModeRendering (int (value)); - actor->Modified (); - break; - } - case VIZ_LINE_WIDTH: - { - actor->GetProperty ()->SetLineWidth (float (value)); - actor->Modified (); - break; - } - default: - CV_Assert("setPointCloudRenderingProperties: Unknown property"); - } - return true; -} - -///////////////////////////////////////////////////////////////////////////////////////////// -bool cv::viz::Viz3d::VizImpl::setShapeRenderingProperties (int property, double value, const std::string &id) -{ - ShapeActorMap::iterator am_it = shape_actor_map_->find (id); - if (am_it == shape_actor_map_->end ()) - return std::cout << "[setShapeRenderingProperties] Could not find any shape with id <" << id << ">!\n" << std::endl, false; - - vtkActor* actor = vtkActor::SafeDownCast (am_it->second); - - switch (property) - { - case VIZ_POINT_SIZE: - { - actor->GetProperty ()->SetPointSize (float (value)); - actor->Modified (); - break; - } - case VIZ_OPACITY: - { - actor->GetProperty ()->SetOpacity (value); - actor->Modified (); - break; - } - case VIZ_LINE_WIDTH: - { - actor->GetProperty ()->SetLineWidth (float (value)); - actor->Modified (); - break; - } - case VIZ_FONT_SIZE: - { - vtkTextActor* text_actor = vtkTextActor::SafeDownCast (am_it->second); - vtkSmartPointer tprop = text_actor->GetTextProperty (); - tprop->SetFontSize (int (value)); - text_actor->Modified (); - break; - } - case VIZ_REPRESENTATION: - { - switch (int (value)) - { - case REPRESENTATION_POINTS: actor->GetProperty ()->SetRepresentationToPoints (); break; - case REPRESENTATION_WIREFRAME: actor->GetProperty ()->SetRepresentationToWireframe (); break; - case REPRESENTATION_SURFACE: actor->GetProperty ()->SetRepresentationToSurface (); break; - } - actor->Modified (); - break; - } - case VIZ_SHADING: - { - switch (int (value)) - { - case SHADING_FLAT: actor->GetProperty ()->SetInterpolationToFlat (); break; - case SHADING_GOURAUD: - { - if (!actor->GetMapper ()->GetInput ()->GetPointData ()->GetNormals ()) - { - std::cout << "[cv::viz::PCLVisualizer::setShapeRenderingProperties] Normals do not exist in the dataset, but Gouraud shading was requested. Estimating normals...\n" << std::endl; - - vtkSmartPointer normals = vtkSmartPointer::New (); - normals->SetInput (actor->GetMapper ()->GetInput ()); - normals->Update (); - vtkDataSetMapper::SafeDownCast (actor->GetMapper ())->SetInput (normals->GetOutput ()); - } - actor->GetProperty ()->SetInterpolationToGouraud (); - break; - } - case SHADING_PHONG: - { - if (!actor->GetMapper ()->GetInput ()->GetPointData ()->GetNormals ()) - { - std::cout << "[cv::viz::PCLVisualizer::setShapeRenderingProperties] Normals do not exist in the dataset, but Phong shading was requested. Estimating normals...\n" << std::endl; - vtkSmartPointer normals = vtkSmartPointer::New (); - normals->SetInput (actor->GetMapper ()->GetInput ()); - normals->Update (); - vtkDataSetMapper::SafeDownCast (actor->GetMapper ())->SetInput (normals->GetOutput ()); - } - actor->GetProperty ()->SetInterpolationToPhong (); - break; - } - } - actor->Modified (); - break; - } - default: - CV_Assert("setShapeRenderingProperties: Unknown property"); - - } - return true; -} - ///////////////////////////////////////////////////////////////////////////////////////////// void cv::viz::Viz3d::VizImpl::initCameraParameters () { diff --git a/modules/viz/src/viz3d_impl.hpp b/modules/viz/src/viz3d_impl.hpp index 085a718c14..60ec707623 100644 --- a/modules/viz/src/viz3d_impl.hpp +++ b/modules/viz/src/viz3d_impl.hpp @@ -19,10 +19,8 @@ public: void removeAllWidgets(); - // to refactor: Widget3D:: & Viz3d:: - bool setPointCloudRenderingProperties (int property, double value, const String& id = "cloud"); - bool getPointCloudRenderingProperties (int property, double &value, const String& id = "cloud"); - bool setShapeRenderingProperties (int property, double value, const String& id); + void setRenderingProperty(int property, double value, const String &id); + double getRenderingProperty(int property, const String &id); /** \brief Returns true when the user tried to close the window */ bool wasStopped () const { if (interactor_ != NULL) return (stopped_); else return true; } diff --git a/modules/viz/src/widget.cpp b/modules/viz/src/widget.cpp index a70409772d..808e3f047b 100644 --- a/modules/viz/src/widget.cpp +++ b/modules/viz/src/widget.cpp @@ -94,6 +94,131 @@ cv::viz::Widget cv::viz::Widget::fromPlyFile(const String &file_name) return widget; } +void cv::viz::Widget::setRenderingProperty(int property, double value) +{ + vtkActor *actor = vtkActor::SafeDownCast(WidgetAccessor::getProp(*this)); + CV_Assert(actor); + + switch (property) + { + case VIZ_POINT_SIZE: + { + actor->GetProperty ()->SetPointSize (float (value)); + actor->Modified (); + break; + } + case VIZ_OPACITY: + { + actor->GetProperty ()->SetOpacity (value); + actor->Modified (); + break; + } + // Turn on/off flag to control whether data is rendered using immediate + // mode or note. Immediate mode rendering tends to be slower but it can + // handle larger datasets. The default value is immediate mode off. If you + // are having problems rendering a large dataset you might want to consider + // using immediate more rendering. + case VIZ_IMMEDIATE_RENDERING: + { + actor->GetMapper ()->SetImmediateModeRendering (int (value)); + actor->Modified (); + break; + } + case VIZ_LINE_WIDTH: + { + actor->GetProperty ()->SetLineWidth (float (value)); + actor->Modified (); + break; + } + default: + CV_Assert("setPointCloudRenderingProperties: Unknown property"); + } +} + +double cv::viz::Widget::getRenderingProperty(int property) const +{ + vtkActor *actor = vtkActor::SafeDownCast(WidgetAccessor::getProp(*this)); + CV_Assert(actor); + + double value = 0.0; + switch (property) + { + case VIZ_POINT_SIZE: + { + value = actor->GetProperty ()->GetPointSize (); + actor->Modified (); + break; + } + case VIZ_OPACITY: + { + value = actor->GetProperty ()->GetOpacity (); + actor->Modified (); + break; + } + case VIZ_LINE_WIDTH: + { + value = actor->GetProperty ()->GetLineWidth (); + actor->Modified (); + break; + } + case VIZ_FONT_SIZE: + { + vtkTextActor* text_actor = vtkTextActor::SafeDownCast (actor); + vtkSmartPointer tprop = text_actor->GetTextProperty (); + tprop->SetFontSize (int (value)); + text_actor->Modified (); + break; + } + case VIZ_REPRESENTATION: + { + switch (int (value)) + { + case REPRESENTATION_POINTS: actor->GetProperty ()->SetRepresentationToPoints (); break; + case REPRESENTATION_WIREFRAME: actor->GetProperty ()->SetRepresentationToWireframe (); break; + case REPRESENTATION_SURFACE: actor->GetProperty ()->SetRepresentationToSurface (); break; + } + actor->Modified (); + break; + } + case VIZ_SHADING: + { + switch (int (value)) + { + case SHADING_FLAT: actor->GetProperty ()->SetInterpolationToFlat (); break; + case SHADING_GOURAUD: + { + if (!actor->GetMapper ()->GetInput ()->GetPointData ()->GetNormals ()) + { + vtkSmartPointer normals = vtkSmartPointer::New (); + normals->SetInput (actor->GetMapper ()->GetInput ()); + normals->Update (); + vtkDataSetMapper::SafeDownCast (actor->GetMapper ())->SetInput (normals->GetOutput ()); + } + actor->GetProperty ()->SetInterpolationToGouraud (); + break; + } + case SHADING_PHONG: + { + if (!actor->GetMapper ()->GetInput ()->GetPointData ()->GetNormals ()) + { + vtkSmartPointer normals = vtkSmartPointer::New (); + normals->SetInput (actor->GetMapper ()->GetInput ()); + normals->Update (); + vtkDataSetMapper::SafeDownCast (actor->GetMapper ())->SetInput (normals->GetOutput ()); + } + actor->GetProperty ()->SetInterpolationToPhong (); + break; + } + } + actor->Modified (); + break; + } + default: + CV_Assert("getPointCloudRenderingProperties: Unknown property"); + } + return value; +} + /////////////////////////////////////////////////////////////////////////////////////////////// /// widget accessor implementaion From 4f416352e1143f1d29d04292426f8003e67f5370 Mon Sep 17 00:00:00 2001 From: ozantonkal Date: Sat, 24 Aug 2013 11:58:32 +0200 Subject: [PATCH 05/29] implemented actor representation methods in viz3d --- modules/viz/include/opencv2/viz/viz3d.hpp | 4 +++ modules/viz/src/viz3d.cpp | 4 +++ modules/viz/src/viz3d_impl.cpp | 30 +++++++++++------------ modules/viz/src/viz3d_impl.hpp | 13 +++------- 4 files changed, 26 insertions(+), 25 deletions(-) diff --git a/modules/viz/include/opencv2/viz/viz3d.hpp b/modules/viz/include/opencv2/viz/viz3d.hpp index 7b0875513a..16e4911447 100644 --- a/modules/viz/include/opencv2/viz/viz3d.hpp +++ b/modules/viz/include/opencv2/viz/viz3d.hpp @@ -57,6 +57,10 @@ namespace cv void setRenderingProperty(int property, double value, const String &id); double getRenderingProperty(int property, const String &id); + + void setRepresentationToSurface(); + void setRepresentationToWireframe(); + void setRepresentationToPoints(); private: struct VizImpl; diff --git a/modules/viz/src/viz3d.cpp b/modules/viz/src/viz3d.cpp index fc9ce01c0e..8f1d12c89b 100644 --- a/modules/viz/src/viz3d.cpp +++ b/modules/viz/src/viz3d.cpp @@ -76,3 +76,7 @@ cv::String cv::viz::Viz3d::getWindowName() const { return impl_->getWindowName() void cv::viz::Viz3d::setRenderingProperty(int property, double value, const String &id) { getWidget(id).setRenderingProperty(property, value); } double cv::viz::Viz3d::getRenderingProperty(int property, const String &id) { return getWidget(id).getRenderingProperty(property); } + +void cv::viz::Viz3d::setRepresentationToSurface() { impl_->setRepresentationToSurface(); } +void cv::viz::Viz3d::setRepresentationToWireframe() { impl_->setRepresentationToWireframe(); } +void cv::viz::Viz3d::setRepresentationToPoints() { impl_->setRepresentationToPoints(); } diff --git a/modules/viz/src/viz3d_impl.cpp b/modules/viz/src/viz3d_impl.cpp index aa51b10150..880224799b 100644 --- a/modules/viz/src/viz3d_impl.cpp +++ b/modules/viz/src/viz3d_impl.cpp @@ -423,33 +423,33 @@ void cv::viz::Viz3d::VizImpl::resetCameraViewpoint (const std::string &id) } /////////////////////////////////////////////////////////////////////////////////// -void cv::viz::Viz3d::VizImpl::setRepresentationToSurfaceForAllActors () +void cv::viz::Viz3d::VizImpl::setRepresentationToSurface() { - vtkActorCollection * actors = renderer_->GetActors (); - actors->InitTraversal (); + vtkActorCollection * actors = renderer_->GetActors(); + actors->InitTraversal(); vtkActor * actor; - while ((actor = actors->GetNextActor ()) != NULL) - actor->GetProperty ()->SetRepresentationToSurface (); + while ((actor = actors->GetNextActor()) != NULL) + actor->GetProperty()->SetRepresentationToSurface(); } /////////////////////////////////////////////////////////////////////////////////// -void cv::viz::Viz3d::VizImpl::setRepresentationToPointsForAllActors () +void cv::viz::Viz3d::VizImpl::setRepresentationToPoints() { - vtkActorCollection * actors = renderer_->GetActors (); - actors->InitTraversal (); + vtkActorCollection * actors = renderer_->GetActors(); + actors->InitTraversal(); vtkActor * actor; - while ((actor = actors->GetNextActor ()) != NULL) - actor->GetProperty ()->SetRepresentationToPoints (); + while ((actor = actors->GetNextActor()) != NULL) + actor->GetProperty()->SetRepresentationToPoints(); } /////////////////////////////////////////////////////////////////////////////////// -void cv::viz::Viz3d::VizImpl::setRepresentationToWireframeForAllActors () +void cv::viz::Viz3d::VizImpl::setRepresentationToWireframe() { - vtkActorCollection * actors = renderer_->GetActors (); - actors->InitTraversal (); + vtkActorCollection * actors = renderer_->GetActors(); + actors->InitTraversal(); vtkActor *actor; - while ((actor = actors->GetNextActor ()) != NULL) - actor->GetProperty ()->SetRepresentationToWireframe (); + while ((actor = actors->GetNextActor()) != NULL) + actor->GetProperty()->SetRepresentationToWireframe(); } ////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/modules/viz/src/viz3d_impl.hpp b/modules/viz/src/viz3d_impl.hpp index 60ec707623..7bb008a3a8 100644 --- a/modules/viz/src/viz3d_impl.hpp +++ b/modules/viz/src/viz3d_impl.hpp @@ -39,16 +39,9 @@ public: } } - // to implement in Viz3d with shorter name - void setRepresentationToSurfaceForAllActors(); - void setRepresentationToPointsForAllActors(); - void setRepresentationToWireframeForAllActors(); - - - - - - + void setRepresentationToSurface(); + void setRepresentationToPoints(); + void setRepresentationToWireframe(); // //////////////////////////////////////////////////////////////////////////////////// From f6e1a093cd401ced065f9b50b325be5d6d166319 Mon Sep 17 00:00:00 2001 From: ozantonkal Date: Sat, 24 Aug 2013 12:18:42 +0200 Subject: [PATCH 06/29] implement window relevant methods in Viz3d --- modules/viz/include/opencv2/viz/viz3d.hpp | 8 +++-- modules/viz/src/viz3d.cpp | 7 +++-- modules/viz/src/viz3d_impl.cpp | 30 ------------------ modules/viz/src/viz3d_impl.hpp | 38 +++++------------------ 4 files changed, 18 insertions(+), 65 deletions(-) diff --git a/modules/viz/include/opencv2/viz/viz3d.hpp b/modules/viz/include/opencv2/viz/viz3d.hpp index 16e4911447..89e1841dbb 100644 --- a/modules/viz/include/opencv2/viz/viz3d.hpp +++ b/modules/viz/include/opencv2/viz/viz3d.hpp @@ -24,8 +24,6 @@ namespace cv Viz3d& operator=(const Viz3d&); ~Viz3d(); - void setBackgroundColor(const Color& color = Color::black()); - void showWidget(const String &id, const Widget &widget, const Affine3f &pose = Affine3f::Identity()); void removeWidget(const String &id); Widget getWidget(const String &id) const; @@ -45,8 +43,12 @@ namespace cv Size getWindowSize() const; void setWindowSize(const Size &window_size); - String getWindowName() const; + void saveScreenshot (const String &file); + void setWindowPosition (int x, int y); + void setFullScreen (bool mode); + void setWindowName (const String &name); + void setBackgroundColor(const Color& color = Color::black()); void spin(); void spinOnce(int time = 1, bool force_redraw = false); diff --git a/modules/viz/src/viz3d.cpp b/modules/viz/src/viz3d.cpp index 8f1d12c89b..5a2ae0531c 100644 --- a/modules/viz/src/viz3d.cpp +++ b/modules/viz/src/viz3d.cpp @@ -42,8 +42,6 @@ void cv::viz::Viz3d::release() } } -void cv::viz::Viz3d::setBackgroundColor(const Color& color) { impl_->setBackgroundColor(color); } - void cv::viz::Viz3d::spin() { impl_->spin(); } void cv::viz::Viz3d::spinOnce (int time, bool force_redraw) { impl_->spinOnce(time, force_redraw); } bool cv::viz::Viz3d::wasStopped() const { return impl_->wasStopped(); } @@ -73,6 +71,11 @@ void cv::viz::Viz3d::converTo3DRay(const Point3d &window_coord, Point3d &origin, cv::Size cv::viz::Viz3d::getWindowSize() const { return impl_->getWindowSize(); } void cv::viz::Viz3d::setWindowSize(const Size &window_size) { impl_->setWindowSize(window_size.width, window_size.height); } cv::String cv::viz::Viz3d::getWindowName() const { return impl_->getWindowName(); } +void cv::viz::Viz3d::saveScreenshot (const String &file) { impl_->saveScreenshot(file); } +void cv::viz::Viz3d::setWindowPosition (int x, int y) { impl_->setWindowPosition(x,y); } +void cv::viz::Viz3d::setFullScreen (bool mode) { impl_->setFullScreen(mode); } +void cv::viz::Viz3d::setWindowName (const String &name) { impl_->setWindowName(name); } +void cv::viz::Viz3d::setBackgroundColor(const Color& color) { impl_->setBackgroundColor(color); } void cv::viz::Viz3d::setRenderingProperty(int property, double value, const String &id) { getWidget(id).setRenderingProperty(property, value); } double cv::viz::Viz3d::getRenderingProperty(int property, const String &id) { return getWidget(id).getRenderingProperty(property); } diff --git a/modules/viz/src/viz3d_impl.cpp b/modules/viz/src/viz3d_impl.cpp index 880224799b..1c35216fca 100644 --- a/modules/viz/src/viz3d_impl.cpp +++ b/modules/viz/src/viz3d_impl.cpp @@ -249,30 +249,6 @@ void cv::viz::Viz3d::VizImpl::setBackgroundColor (const Color& color) renderer_->SetBackground (c.val); } -///////////////////////////////////////////////////////////////////////////////////////////// -void cv::viz::Viz3d::VizImpl::initCameraParameters () -{ - Vec2i window_size(window_->GetScreenSize()); - window_size /= 2; - - Camera camera_temp(Vec2f(0.0,0.8575), Size(window_size[0], window_size[1])); - setCamera(camera_temp); - setViewerPose(makeCameraPose(Vec3f(0.0f,0.0f,0.0f), Vec3f(0.0f, 0.0f, 1.0f), Vec3f(0.0f, 1.0f, 0.0f))); -} - -///////////////////////////////////////////////////////////////////////////////////////////// -bool cv::viz::Viz3d::VizImpl::cameraParamsSet () const { return (camera_set_); } - -///////////////////////////////////////////////////////////////////////////////////////////// -void cv::viz::Viz3d::VizImpl::updateCamera () -{ - std::cout << "[cv::viz::PCLVisualizer::updateCamera()] This method was deprecated, just re-rendering all scenes now." << std::endl; - //rens_->InitTraversal (); - // Update the camera parameters - - renderer_->Render (); -} - ///////////////////////////////////////////////////////////////////////////////////////////// void cv::viz::Viz3d::VizImpl::setCamera(const Camera &camera) { @@ -379,12 +355,6 @@ void cv::viz::Viz3d::VizImpl::converTo3DRay(const Point3d &window_coord, Point3d direction = normalize(Vec3d(world_pt.val) - cam_pos); } -///////////////////////////////////////////////////////////////////////////////////////////// -void cv::viz::Viz3d::VizImpl::resetCamera () -{ - renderer_->ResetCamera (); -} - ///////////////////////////////////////////////////////////////////////////////////////////// void cv::viz::Viz3d::VizImpl::resetCameraViewpoint (const std::string &id) { diff --git a/modules/viz/src/viz3d_impl.hpp b/modules/viz/src/viz3d_impl.hpp index 7bb008a3a8..67f7c27017 100644 --- a/modules/viz/src/viz3d_impl.hpp +++ b/modules/viz/src/viz3d_impl.hpp @@ -16,8 +16,15 @@ public: VizImpl (const String &name); virtual ~VizImpl (); - + + void showWidget(const String &id, const Widget &widget, const Affine3f &pose = Affine3f::Identity()); + void removeWidget(const String &id); + Widget getWidget(const String &id) const; void removeAllWidgets(); + + void setWidgetPose(const String &id, const Affine3f &pose); + void updateWidgetPose(const String &id, const Affine3f &pose); + Affine3f getWidgetPose(const String &id) const; void setRenderingProperty(int property, double value, const String &id); double getRenderingProperty(int property, const String &id); @@ -51,29 +58,16 @@ public: void setCamera(const Camera &camera); Camera getCamera() const; - void initCameraParameters (); /** \brief Initialize camera parameters with some default values. */ - bool cameraParamsSet () const; /** \brief Checks whether the camera parameters were manually loaded from file.*/ - void updateCamera (); /** \brief Update camera parameters and render. */ - void resetCamera (); /** \brief Reset camera parameters and render. */ - /** \brief Reset the camera direction from {0, 0, 0} to the center_{x, y, z} of a given dataset. * \param[in] id the point cloud object id (default: cloud) */ void resetCameraViewpoint (const String& id = "cloud"); - //to implement Viz3d set/getViewerPose() void setViewerPose(const Affine3f &pose); Affine3f getViewerPose(); void convertToWindowCoordinates(const Point3d &pt, Point3d &window_coord); void converTo3DRay(const Point3d &window_coord, Point3d &origin, Vec3d &direction); - - - - - - - //to implemnt in Viz3d void saveScreenshot (const String &file); void setWindowPosition (int x, int y); Size getWindowSize() const; @@ -89,22 +83,6 @@ public: void registerKeyboardCallback(KeyboardCallback callback, void* cookie = 0); void registerMouseCallback(MouseCallback callback, void* cookie = 0); - - - - - - - - //declare above (to move to up) - void showWidget(const String &id, const Widget &widget, const Affine3f &pose = Affine3f::Identity()); - void removeWidget(const String &id); - Widget getWidget(const String &id) const; - - void setWidgetPose(const String &id, const Affine3f &pose); - void updateWidgetPose(const String &id, const Affine3f &pose); - Affine3f getWidgetPose(const String &id) const; - private: vtkSmartPointer interactor_; From f98614ece0de86c26ea59ee3d2a47c9c212503ec Mon Sep 17 00:00:00 2001 From: ozantonkal Date: Sat, 24 Aug 2013 12:52:34 +0200 Subject: [PATCH 07/29] remove cloudactormap, shapeactormap. only vtkProp is stored and view transformation can be obtained using GetUserMatrix of vtkProp3D --- modules/viz/src/interactor_style.cpp | 38 ++++++++++++++-------------- modules/viz/src/interactor_style.h | 6 ++--- modules/viz/src/viz3d_impl.cpp | 32 ++++++++++------------- modules/viz/src/viz3d_impl.hpp | 4 +-- modules/viz/src/viz_types.h | 24 +----------------- 5 files changed, 39 insertions(+), 65 deletions(-) diff --git a/modules/viz/src/interactor_style.cpp b/modules/viz/src/interactor_style.cpp index 2daec81261..db3d979791 100644 --- a/modules/viz/src/interactor_style.cpp +++ b/modules/viz/src/interactor_style.cpp @@ -432,17 +432,17 @@ cv::viz::InteractorStyle::OnKeyDown () vtkSmartPointer cam = CurrentRenderer->GetActiveCamera (); - static CloudActorMap::iterator it = actors_->begin (); + static WidgetActorMap::iterator it = widget_actor_map_->begin (); // it might be that some actors don't have a valid transformation set -> we skip them to avoid a seg fault. bool found_transformation = false; - for (size_t idx = 0; idx < actors_->size (); ++idx, ++it) + for (size_t idx = 0; idx < widget_actor_map_->size (); ++idx, ++it) { - if (it == actors_->end ()) - it = actors_->begin (); - - const CloudActor& actor = it->second; - if (actor.viewpoint_transformation_.GetPointer ()) + if (it == widget_actor_map_->end ()) + it = widget_actor_map_->begin (); + + vtkProp3D * actor = vtkProp3D::SafeDownCast(it->second); + if (actor && actor->GetUserMatrix()) { found_transformation = true; break; @@ -452,18 +452,18 @@ cv::viz::InteractorStyle::OnKeyDown () // if a valid transformation was found, use it otherwise fall back to default view point. if (found_transformation) { - const CloudActor& actor = it->second; - cam->SetPosition (actor.viewpoint_transformation_->GetElement (0, 3), - actor.viewpoint_transformation_->GetElement (1, 3), - actor.viewpoint_transformation_->GetElement (2, 3)); + vtkProp3D * actor = vtkProp3D::SafeDownCast(it->second); + cam->SetPosition (actor->GetUserMatrix()->GetElement (0, 3), + actor->GetUserMatrix()->GetElement (1, 3), + actor->GetUserMatrix()->GetElement (2, 3)); - cam->SetFocalPoint (actor.viewpoint_transformation_->GetElement (0, 3) - actor.viewpoint_transformation_->GetElement (0, 2), - actor.viewpoint_transformation_->GetElement (1, 3) - actor.viewpoint_transformation_->GetElement (1, 2), - actor.viewpoint_transformation_->GetElement (2, 3) - actor.viewpoint_transformation_->GetElement (2, 2)); + cam->SetFocalPoint (actor->GetUserMatrix()->GetElement (0, 3) - actor->GetUserMatrix()->GetElement (0, 2), + actor->GetUserMatrix()->GetElement (1, 3) - actor->GetUserMatrix()->GetElement (1, 2), + actor->GetUserMatrix()->GetElement (2, 3) - actor->GetUserMatrix()->GetElement (2, 2)); - cam->SetViewUp (actor.viewpoint_transformation_->GetElement (0, 1), - actor.viewpoint_transformation_->GetElement (1, 1), - actor.viewpoint_transformation_->GetElement (2, 1)); + cam->SetViewUp (actor->GetUserMatrix()->GetElement (0, 1), + actor->GetUserMatrix()->GetElement (1, 1), + actor->GetUserMatrix()->GetElement (2, 1)); } else { @@ -473,10 +473,10 @@ cv::viz::InteractorStyle::OnKeyDown () } // go to the next actor for the next key-press event. - if (it != actors_->end ()) + if (it != widget_actor_map_->end ()) ++it; else - it = actors_->begin (); + it = widget_actor_map_->begin (); CurrentRenderer->SetActiveCamera (cam); CurrentRenderer->ResetCameraClippingRange (); diff --git a/modules/viz/src/interactor_style.h b/modules/viz/src/interactor_style.h index db20a1ad9d..aba03a373d 100644 --- a/modules/viz/src/interactor_style.h +++ b/modules/viz/src/interactor_style.h @@ -50,7 +50,7 @@ namespace cv /** \brief Initialization routine. Must be called before anything else. */ virtual void Initialize (); - inline void setCloudActorMap (const Ptr& actors) { actors_ = actors; } + inline void setWidgetActorMap (const Ptr& actors) { widget_actor_map_ = actors; } void setRenderer (vtkSmartPointer& ren) { renderer_ = ren; } void registerMouseCallback(void (*callback)(const MouseEvent&, void*), void* cookie = 0); void registerKeyboardCallback(void (*callback)(const KeyboardEvent&, void*), void * cookie = 0); @@ -73,8 +73,8 @@ namespace cv vtkSmartPointer renderer_; /** \brief Actor map stored internally. */ - cv::Ptr actors_; - + cv::Ptr widget_actor_map_; + /** \brief The current window width/height. */ Vec2i win_size_; diff --git a/modules/viz/src/viz3d_impl.cpp b/modules/viz/src/viz3d_impl.cpp index 1c35216fca..6e91338d3f 100644 --- a/modules/viz/src/viz3d_impl.cpp +++ b/modules/viz/src/viz3d_impl.cpp @@ -11,8 +11,6 @@ vtkRenderWindowInteractor* vtkRenderWindowInteractorFixNew () ///////////////////////////////////////////////////////////////////////////////////////////// cv::viz::Viz3d::VizImpl::VizImpl (const std::string &name) : style_ (vtkSmartPointer::New ()) - , cloud_actor_map_ (new CloudActorMap) - , shape_actor_map_ (new ShapeActorMap) , widget_actor_map_ (new WidgetActorMap) , s_lastDone_(0.0) { @@ -30,7 +28,7 @@ cv::viz::Viz3d::VizImpl::VizImpl (const std::string &name) // Create the interactor style style_->Initialize (); style_->setRenderer (renderer_); - style_->setCloudActorMap (cloud_actor_map_); + style_->setWidgetActorMap (widget_actor_map_); style_->UseTimersOn (); ///////////////////////////////////////////////// @@ -358,11 +356,13 @@ void cv::viz::Viz3d::VizImpl::converTo3DRay(const Point3d &window_coord, Point3d ///////////////////////////////////////////////////////////////////////////////////////////// void cv::viz::Viz3d::VizImpl::resetCameraViewpoint (const std::string &id) { - // TODO Cloud actor is not used vtkSmartPointer camera_pose; - static CloudActorMap::iterator it = cloud_actor_map_->find (id); - if (it != cloud_actor_map_->end ()) - camera_pose = it->second.viewpoint_transformation_; + static WidgetActorMap::iterator it = widget_actor_map_->find (id); + if (it != widget_actor_map_->end ()) + { + vtkProp3D *actor = vtkProp3D::SafeDownCast(it->second); + camera_pose = actor->GetUserMatrix(); + } else return; @@ -370,10 +370,6 @@ void cv::viz::Viz3d::VizImpl::resetCameraViewpoint (const std::string &id) if (!camera_pose) return; - // set all renderer to this viewpoint - //rens_->InitTraversal (); - - vtkSmartPointer cam = renderer_->GetActiveCamera (); cam->SetPosition (camera_pose->GetElement (0, 3), camera_pose->GetElement (1, 3), @@ -522,7 +518,7 @@ void cv::viz::Viz3d::VizImpl::showWidget(const String &id, const Widget &widget, if (exists) { // Remove it if it exists and add it again - removeActorFromRenderer(wam_itr->second.actor); + removeActorFromRenderer(wam_itr->second); } // Get the actor and set the user matrix vtkProp3D *actor = vtkProp3D::SafeDownCast(WidgetAccessor::getProp(widget)); @@ -541,7 +537,7 @@ void cv::viz::Viz3d::VizImpl::showWidget(const String &id, const Widget &widget, } renderer_->AddActor(WidgetAccessor::getProp(widget)); - (*widget_actor_map_)[id].actor = WidgetAccessor::getProp(widget); + (*widget_actor_map_)[id] = WidgetAccessor::getProp(widget); } void cv::viz::Viz3d::VizImpl::removeWidget(const String &id) @@ -549,7 +545,7 @@ void cv::viz::Viz3d::VizImpl::removeWidget(const String &id) WidgetActorMap::iterator wam_itr = widget_actor_map_->find(id); bool exists = wam_itr != widget_actor_map_->end(); CV_Assert(exists); - CV_Assert(removeActorFromRenderer (wam_itr->second.actor)); + CV_Assert(removeActorFromRenderer (wam_itr->second)); widget_actor_map_->erase(wam_itr); } @@ -560,7 +556,7 @@ cv::viz::Widget cv::viz::Viz3d::VizImpl::getWidget(const String &id) const CV_Assert(exists); Widget widget; - WidgetAccessor::setProp(widget, wam_itr->second.actor); + WidgetAccessor::setProp(widget, wam_itr->second); return widget; } @@ -570,7 +566,7 @@ void cv::viz::Viz3d::VizImpl::setWidgetPose(const String &id, const Affine3f &po bool exists = wam_itr != widget_actor_map_->end(); CV_Assert(exists); - vtkProp3D *actor = vtkProp3D::SafeDownCast(wam_itr->second.actor); + vtkProp3D *actor = vtkProp3D::SafeDownCast(wam_itr->second); CV_Assert(actor); vtkSmartPointer matrix = convertToVtkMatrix(pose.matrix); @@ -584,7 +580,7 @@ void cv::viz::Viz3d::VizImpl::updateWidgetPose(const String &id, const Affine3f bool exists = wam_itr != widget_actor_map_->end(); CV_Assert(exists); - vtkProp3D *actor = vtkProp3D::SafeDownCast(wam_itr->second.actor); + vtkProp3D *actor = vtkProp3D::SafeDownCast(wam_itr->second); CV_Assert(actor); vtkSmartPointer matrix = actor->GetUserMatrix(); @@ -607,7 +603,7 @@ cv::Affine3f cv::viz::Viz3d::VizImpl::getWidgetPose(const String &id) const bool exists = wam_itr != widget_actor_map_->end(); CV_Assert(exists); - vtkProp3D *actor = vtkProp3D::SafeDownCast(wam_itr->second.actor); + vtkProp3D *actor = vtkProp3D::SafeDownCast(wam_itr->second); CV_Assert(actor); vtkSmartPointer matrix = actor->GetUserMatrix(); diff --git a/modules/viz/src/viz3d_impl.hpp b/modules/viz/src/viz3d_impl.hpp index 67f7c27017..988b732f17 100644 --- a/modules/viz/src/viz3d_impl.hpp +++ b/modules/viz/src/viz3d_impl.hpp @@ -144,10 +144,10 @@ private: vtkSmartPointer style_; /** \brief Internal list with actor pointers and name IDs for point clouds. */ - cv::Ptr cloud_actor_map_; +// cv::Ptr cloud_actor_map_; /** \brief Internal list with actor pointers and name IDs for shapes. */ - cv::Ptr shape_actor_map_; +// cv::Ptr shape_actor_map_; /** \brief Internal list with actor pointers and name IDs for all widget actors */ cv::Ptr widget_actor_map_; diff --git a/modules/viz/src/viz_types.h b/modules/viz/src/viz_types.h index 9d47a0c8b1..33de56af33 100644 --- a/modules/viz/src/viz_types.h +++ b/modules/viz/src/viz_types.h @@ -6,29 +6,7 @@ namespace cv { namespace viz { - struct CV_EXPORTS CloudActor - { - /** \brief The actor holding the data to render. */ - vtkSmartPointer actor; - - /** \brief The viewpoint transformation matrix. */ - vtkSmartPointer viewpoint_transformation_; - - /** \brief Internal cell array. Used for optimizing updatePointCloud. */ - vtkSmartPointer cells; - }; - - // TODO This will be used to contain both cloud and shape actors - struct CV_EXPORTS WidgetActor - { - vtkSmartPointer actor; - vtkSmartPointer viewpoint_transformation_; - vtkSmartPointer cells; - }; - - typedef std::map CloudActorMap; - typedef std::map > ShapeActorMap; - typedef std::map WidgetActorMap; + typedef std::map > WidgetActorMap; } } From 08917908f3c0ed5300a13e115c611e3efa9dd7c7 Mon Sep 17 00:00:00 2001 From: ozantonkal Date: Sat, 24 Aug 2013 13:15:44 +0200 Subject: [PATCH 08/29] remove eigen dependency --- modules/viz/src/precomp.hpp | 2 -- modules/viz/src/viz3d_impl.cpp | 18 ------------------ modules/viz/src/viz3d_impl.hpp | 8 -------- 3 files changed, 28 deletions(-) diff --git a/modules/viz/src/precomp.hpp b/modules/viz/src/precomp.hpp index 12a042c154..69d20a5351 100644 --- a/modules/viz/src/precomp.hpp +++ b/modules/viz/src/precomp.hpp @@ -5,8 +5,6 @@ #include #include -#include - #if defined __GNUC__ #pragma GCC system_header #ifdef __DEPRECATED diff --git a/modules/viz/src/viz3d_impl.cpp b/modules/viz/src/viz3d_impl.cpp index 6e91338d3f..f6d560da97 100644 --- a/modules/viz/src/viz3d_impl.cpp +++ b/modules/viz/src/viz3d_impl.cpp @@ -472,24 +472,6 @@ void cv::viz::Viz3d::VizImpl::allocVtkUnstructuredGrid (vtkSmartPointer::New (); } ////////////////////////////////////////////////////////////////////////////////////////////// -void cv::viz::convertToVtkMatrix (const Eigen::Vector4f &origin, const Eigen::Quaternion &orientation, vtkSmartPointer &vtk_matrix) -{ - // set rotation - Eigen::Matrix3f rot = orientation.toRotationMatrix (); - for (int i = 0; i < 3; i++) - for (int k = 0; k < 3; k++) - vtk_matrix->SetElement (i, k, rot (i, k)); - - // set translation - vtk_matrix->SetElement (0, 3, origin (0)); - vtk_matrix->SetElement (1, 3, origin (1)); - vtk_matrix->SetElement (2, 3, origin (2)); - vtk_matrix->SetElement (3, 3, 1.0f); -} - - -////////////////////////////////////////////////////////////////////////////////////////////// - void cv::viz::Viz3d::VizImpl::setFullScreen (bool mode) { if (window_) diff --git a/modules/viz/src/viz3d_impl.hpp b/modules/viz/src/viz3d_impl.hpp index 988b732f17..5dcd4bf857 100644 --- a/modules/viz/src/viz3d_impl.hpp +++ b/modules/viz/src/viz3d_impl.hpp @@ -190,17 +190,9 @@ namespace cv { namespace viz { - //void getTransformationMatrix (const Eigen::Vector4f &origin, const Eigen::Quaternionf& orientation, Eigen::Matrix4f &transformation); vtkSmartPointer convertToVtkMatrix (const cv::Matx44f &m); cv::Matx44f convertToMatx(const vtkSmartPointer& vtk_matrix); - /** \brief Convert origin and orientation to vtkMatrix4x4 - * \param[in] origin the point cloud origin - * \param[in] orientation the point cloud orientation - * \param[out] vtk_matrix the resultant VTK 4x4 matrix - */ - void convertToVtkMatrix (const Eigen::Vector4f &origin, const Eigen::Quaternion &orientation, vtkSmartPointer &vtk_matrix); - struct NanFilter { template From ed0162ad0b943bf5bf14ecf7531c0a615834ca00 Mon Sep 17 00:00:00 2001 From: ozantonkal Date: Sat, 24 Aug 2013 15:12:16 +0200 Subject: [PATCH 09/29] remove reference counting in widgets --- modules/viz/include/opencv2/viz/widgets.hpp | 6 --- modules/viz/src/widget.cpp | 43 +-------------------- 2 files changed, 1 insertion(+), 48 deletions(-) diff --git a/modules/viz/include/opencv2/viz/widgets.hpp b/modules/viz/include/opencv2/viz/widgets.hpp index 99f4bd4207..caaee9e698 100644 --- a/modules/viz/include/opencv2/viz/widgets.hpp +++ b/modules/viz/include/opencv2/viz/widgets.hpp @@ -14,9 +14,6 @@ namespace cv { public: Widget(); - Widget(const Widget &other); - Widget& operator =(const Widget &other); - ~Widget(); static Widget fromPlyFile(const String &file_name); @@ -28,9 +25,6 @@ namespace cv class Impl; Impl *impl_; friend struct WidgetAccessor; - - void create(); - void release(); }; ///////////////////////////////////////////////////////////////////////////// diff --git a/modules/viz/src/widget.cpp b/modules/viz/src/widget.cpp index 808e3f047b..485e35ed74 100644 --- a/modules/viz/src/widget.cpp +++ b/modules/viz/src/widget.cpp @@ -7,52 +7,11 @@ class cv::viz::Widget::Impl { public: vtkSmartPointer prop; - int ref_counter; Impl() : prop(0) {} }; -cv::viz::Widget::Widget() : impl_(0) -{ - create(); -} - -cv::viz::Widget::Widget(const Widget &other) : impl_(other.impl_) -{ - if (impl_) CV_XADD(&impl_->ref_counter, 1); -} - -cv::viz::Widget& cv::viz::Widget::operator=(const Widget &other) -{ - if (this != &other) - { - release(); - impl_ = other.impl_; - if (impl_) CV_XADD(&impl_->ref_counter, 1); - } - return *this; -} - -cv::viz::Widget::~Widget() -{ - release(); -} - -void cv::viz::Widget::create() -{ - if (impl_) release(); - impl_ = new Impl(); - impl_->ref_counter = 1; -} - -void cv::viz::Widget::release() -{ - if (impl_ && CV_XADD(&impl_->ref_counter, -1) == 1) - { - delete impl_; - impl_ = 0; - } -} +cv::viz::Widget::Widget() : impl_( new Impl() ) { } cv::viz::Widget cv::viz::Widget::fromPlyFile(const String &file_name) { From 3038ffb886bc696efac112a746f29ac29b96bd1c Mon Sep 17 00:00:00 2001 From: ozantonkal Date: Sun, 25 Aug 2013 12:24:59 +0200 Subject: [PATCH 10/29] setDesiredUpdateRate implementation in Viz3d --- modules/viz/include/opencv2/viz/viz3d.hpp | 3 + modules/viz/src/viz3d.cpp | 5 +- modules/viz/src/viz3d_impl.cpp | 221 ++++++++++++---------- modules/viz/src/viz3d_impl.hpp | 4 +- 4 files changed, 130 insertions(+), 103 deletions(-) diff --git a/modules/viz/include/opencv2/viz/viz3d.hpp b/modules/viz/include/opencv2/viz/viz3d.hpp index 89e1841dbb..a80fd37486 100644 --- a/modules/viz/include/opencv2/viz/viz3d.hpp +++ b/modules/viz/include/opencv2/viz/viz3d.hpp @@ -60,6 +60,9 @@ namespace cv void setRenderingProperty(int property, double value, const String &id); double getRenderingProperty(int property, const String &id); + void setDesiredUpdateRate(double time); + double getDesiredUpdateRate(); + void setRepresentationToSurface(); void setRepresentationToWireframe(); void setRepresentationToPoints(); diff --git a/modules/viz/src/viz3d.cpp b/modules/viz/src/viz3d.cpp index 5a2ae0531c..96483f43aa 100644 --- a/modules/viz/src/viz3d.cpp +++ b/modules/viz/src/viz3d.cpp @@ -80,6 +80,9 @@ void cv::viz::Viz3d::setBackgroundColor(const Color& color) { impl_->setBackgrou void cv::viz::Viz3d::setRenderingProperty(int property, double value, const String &id) { getWidget(id).setRenderingProperty(property, value); } double cv::viz::Viz3d::getRenderingProperty(int property, const String &id) { return getWidget(id).getRenderingProperty(property); } +void cv::viz::Viz3d::setDesiredUpdateRate(double time) { impl_->setDesiredUpdateRate(time); } +double cv::viz::Viz3d::getDesiredUpdateRate() { return impl_->getDesiredUpdateRate(); } + void cv::viz::Viz3d::setRepresentationToSurface() { impl_->setRepresentationToSurface(); } void cv::viz::Viz3d::setRepresentationToWireframe() { impl_->setRepresentationToWireframe(); } -void cv::viz::Viz3d::setRepresentationToPoints() { impl_->setRepresentationToPoints(); } +void cv::viz::Viz3d::setRepresentationToPoints() { impl_->setRepresentationToPoints(); } \ No newline at end of file diff --git a/modules/viz/src/viz3d_impl.cpp b/modules/viz/src/viz3d_impl.cpp index f6d560da97..f0157331ec 100644 --- a/modules/viz/src/viz3d_impl.cpp +++ b/modules/viz/src/viz3d_impl.cpp @@ -84,6 +84,127 @@ cv::viz::Viz3d::VizImpl::~VizImpl () if (renderer_) renderer_->Clear(); } +///////////////////////////////////////////////////////////////////////////////////////////// +void cv::viz::Viz3d::VizImpl::showWidget(const String &id, const Widget &widget, const Affine3f &pose) +{ + WidgetActorMap::iterator wam_itr = widget_actor_map_->find(id); + bool exists = wam_itr != widget_actor_map_->end(); + if (exists) + { + // Remove it if it exists and add it again + removeActorFromRenderer(wam_itr->second); + } + // Get the actor and set the user matrix + vtkProp3D *actor = vtkProp3D::SafeDownCast(WidgetAccessor::getProp(widget)); + if (actor) + { + // If the actor is 3D, apply pose + vtkSmartPointer matrix = convertToVtkMatrix(pose.matrix); + actor->SetUserMatrix (matrix); + actor->Modified(); + } + // If the actor is a vtkFollower, then it should always face the camera + vtkFollower *follower = vtkFollower::SafeDownCast(actor); + if (follower) + { + follower->SetCamera(renderer_->GetActiveCamera()); + } + + renderer_->AddActor(WidgetAccessor::getProp(widget)); + (*widget_actor_map_)[id] = WidgetAccessor::getProp(widget); +} + +///////////////////////////////////////////////////////////////////////////////////////////// +void cv::viz::Viz3d::VizImpl::removeWidget(const String &id) +{ + WidgetActorMap::iterator wam_itr = widget_actor_map_->find(id); + bool exists = wam_itr != widget_actor_map_->end(); + CV_Assert(exists); + CV_Assert(removeActorFromRenderer (wam_itr->second)); + widget_actor_map_->erase(wam_itr); +} + +///////////////////////////////////////////////////////////////////////////////////////////// +cv::viz::Widget cv::viz::Viz3d::VizImpl::getWidget(const String &id) const +{ + WidgetActorMap::const_iterator wam_itr = widget_actor_map_->find(id); + bool exists = wam_itr != widget_actor_map_->end(); + CV_Assert(exists); + + Widget widget; + WidgetAccessor::setProp(widget, wam_itr->second); + return widget; +} + +///////////////////////////////////////////////////////////////////////////////////////////// +void cv::viz::Viz3d::VizImpl::setWidgetPose(const String &id, const Affine3f &pose) +{ + WidgetActorMap::iterator wam_itr = widget_actor_map_->find(id); + bool exists = wam_itr != widget_actor_map_->end(); + CV_Assert(exists); + + vtkProp3D *actor = vtkProp3D::SafeDownCast(wam_itr->second); + CV_Assert(actor); + + vtkSmartPointer matrix = convertToVtkMatrix(pose.matrix); + actor->SetUserMatrix (matrix); + actor->Modified (); +} + +///////////////////////////////////////////////////////////////////////////////////////////// +void cv::viz::Viz3d::VizImpl::updateWidgetPose(const String &id, const Affine3f &pose) +{ + WidgetActorMap::iterator wam_itr = widget_actor_map_->find(id); + bool exists = wam_itr != widget_actor_map_->end(); + CV_Assert(exists); + + vtkProp3D *actor = vtkProp3D::SafeDownCast(wam_itr->second); + CV_Assert(actor); + + vtkSmartPointer matrix = actor->GetUserMatrix(); + if (!matrix) + { + setWidgetPose(id, pose); + return ; + } + Matx44f matrix_cv = convertToMatx(matrix); + Affine3f updated_pose = pose * Affine3f(matrix_cv); + matrix = convertToVtkMatrix(updated_pose.matrix); + + actor->SetUserMatrix (matrix); + actor->Modified (); +} + +///////////////////////////////////////////////////////////////////////////////////////////// +cv::Affine3f cv::viz::Viz3d::VizImpl::getWidgetPose(const String &id) const +{ + WidgetActorMap::const_iterator wam_itr = widget_actor_map_->find(id); + bool exists = wam_itr != widget_actor_map_->end(); + CV_Assert(exists); + + vtkProp3D *actor = vtkProp3D::SafeDownCast(wam_itr->second); + CV_Assert(actor); + + vtkSmartPointer matrix = actor->GetUserMatrix(); + Matx44f matrix_cv = convertToMatx(matrix); + return Affine3f(matrix_cv); +} + +///////////////////////////////////////////////////////////////////////////////////////////// +void cv::viz::Viz3d::VizImpl::setDesiredUpdateRate(double time) +{ + if (interactor_) + interactor_->SetDesiredUpdateRate(time); +} + +///////////////////////////////////////////////////////////////////////////////////////////// +double cv::viz::Viz3d::VizImpl::getDesiredUpdateRate() +{ + if (interactor_) + return interactor_->GetDesiredUpdateRate(); + return 0.0; +} + ///////////////////////////////////////////////////////////////////////////////////////////// void cv::viz::Viz3d::VizImpl::saveScreenshot (const std::string &file) { style_->saveScreenshot (file); } @@ -492,103 +613,3 @@ cv::String cv::viz::Viz3d::VizImpl::getWindowName() const void cv::viz::Viz3d::VizImpl::setWindowPosition (int x, int y) { window_->SetPosition (x, y); } void cv::viz::Viz3d::VizImpl::setWindowSize (int xw, int yw) { window_->SetSize (xw, yw); } cv::Size cv::viz::Viz3d::VizImpl::getWindowSize() const { return Size(window_->GetSize()[0], window_->GetSize()[1]); } - -void cv::viz::Viz3d::VizImpl::showWidget(const String &id, const Widget &widget, const Affine3f &pose) -{ - WidgetActorMap::iterator wam_itr = widget_actor_map_->find(id); - bool exists = wam_itr != widget_actor_map_->end(); - if (exists) - { - // Remove it if it exists and add it again - removeActorFromRenderer(wam_itr->second); - } - // Get the actor and set the user matrix - vtkProp3D *actor = vtkProp3D::SafeDownCast(WidgetAccessor::getProp(widget)); - if (actor) - { - // If the actor is 3D, apply pose - vtkSmartPointer matrix = convertToVtkMatrix(pose.matrix); - actor->SetUserMatrix (matrix); - actor->Modified(); - } - // If the actor is a vtkFollower, then it should always face the camera - vtkFollower *follower = vtkFollower::SafeDownCast(actor); - if (follower) - { - follower->SetCamera(renderer_->GetActiveCamera()); - } - - renderer_->AddActor(WidgetAccessor::getProp(widget)); - (*widget_actor_map_)[id] = WidgetAccessor::getProp(widget); -} - -void cv::viz::Viz3d::VizImpl::removeWidget(const String &id) -{ - WidgetActorMap::iterator wam_itr = widget_actor_map_->find(id); - bool exists = wam_itr != widget_actor_map_->end(); - CV_Assert(exists); - CV_Assert(removeActorFromRenderer (wam_itr->second)); - widget_actor_map_->erase(wam_itr); -} - -cv::viz::Widget cv::viz::Viz3d::VizImpl::getWidget(const String &id) const -{ - WidgetActorMap::const_iterator wam_itr = widget_actor_map_->find(id); - bool exists = wam_itr != widget_actor_map_->end(); - CV_Assert(exists); - - Widget widget; - WidgetAccessor::setProp(widget, wam_itr->second); - return widget; -} - -void cv::viz::Viz3d::VizImpl::setWidgetPose(const String &id, const Affine3f &pose) -{ - WidgetActorMap::iterator wam_itr = widget_actor_map_->find(id); - bool exists = wam_itr != widget_actor_map_->end(); - CV_Assert(exists); - - vtkProp3D *actor = vtkProp3D::SafeDownCast(wam_itr->second); - CV_Assert(actor); - - vtkSmartPointer matrix = convertToVtkMatrix(pose.matrix); - actor->SetUserMatrix (matrix); - actor->Modified (); -} - -void cv::viz::Viz3d::VizImpl::updateWidgetPose(const String &id, const Affine3f &pose) -{ - WidgetActorMap::iterator wam_itr = widget_actor_map_->find(id); - bool exists = wam_itr != widget_actor_map_->end(); - CV_Assert(exists); - - vtkProp3D *actor = vtkProp3D::SafeDownCast(wam_itr->second); - CV_Assert(actor); - - vtkSmartPointer matrix = actor->GetUserMatrix(); - if (!matrix) - { - setWidgetPose(id, pose); - return ; - } - Matx44f matrix_cv = convertToMatx(matrix); - Affine3f updated_pose = pose * Affine3f(matrix_cv); - matrix = convertToVtkMatrix(updated_pose.matrix); - - actor->SetUserMatrix (matrix); - actor->Modified (); -} - -cv::Affine3f cv::viz::Viz3d::VizImpl::getWidgetPose(const String &id) const -{ - WidgetActorMap::const_iterator wam_itr = widget_actor_map_->find(id); - bool exists = wam_itr != widget_actor_map_->end(); - CV_Assert(exists); - - vtkProp3D *actor = vtkProp3D::SafeDownCast(wam_itr->second); - CV_Assert(actor); - - vtkSmartPointer matrix = actor->GetUserMatrix(); - Matx44f matrix_cv = convertToMatx(matrix); - return Affine3f(matrix_cv); -} diff --git a/modules/viz/src/viz3d_impl.hpp b/modules/viz/src/viz3d_impl.hpp index 5dcd4bf857..4d24fb86e6 100644 --- a/modules/viz/src/viz3d_impl.hpp +++ b/modules/viz/src/viz3d_impl.hpp @@ -26,8 +26,8 @@ public: void updateWidgetPose(const String &id, const Affine3f &pose); Affine3f getWidgetPose(const String &id) const; - void setRenderingProperty(int property, double value, const String &id); - double getRenderingProperty(int property, const String &id); + void setDesiredUpdateRate(double time); + double getDesiredUpdateRate(); /** \brief Returns true when the user tried to close the window */ bool wasStopped () const { if (interactor_ != NULL) return (stopped_); else return true; } From 9086cf5d79ceb3fa10fcc6a8ecf618a0f530b772 Mon Sep 17 00:00:00 2001 From: ozantonkal Date: Sun, 25 Aug 2013 15:39:39 +0200 Subject: [PATCH 11/29] remove unused includes and libraries from linking --- modules/viz/CMakeLists.txt | 1 - modules/viz/src/precomp.hpp | 79 +--------------------------------- modules/viz/src/viz3d_impl.cpp | 12 +----- modules/viz/src/viz3d_impl.hpp | 4 -- 4 files changed, 3 insertions(+), 93 deletions(-) diff --git a/modules/viz/CMakeLists.txt b/modules/viz/CMakeLists.txt index 05388d745d..5de29bbc65 100644 --- a/modules/viz/CMakeLists.txt +++ b/modules/viz/CMakeLists.txt @@ -49,4 +49,3 @@ if(BUILD_opencv_viz) target_link_libraries(opencv_viz "-framework Cocoa") endif() endif() - diff --git a/modules/viz/src/precomp.hpp b/modules/viz/src/precomp.hpp index 69d20a5351..9dafeecc8f 100644 --- a/modules/viz/src/precomp.hpp +++ b/modules/viz/src/precomp.hpp @@ -15,34 +15,19 @@ #include #include -#include -#include -#include -#include -#include #include -#include -#include #include -#include -#include -#include #include -#include #include #include -#include -#include #include #include #include -#include #include #include #include #include #include -#include #include #include #include @@ -57,18 +42,12 @@ #include #include #include -#include #include -#include #include #include #include -#include #include -#include -#include #include -#include #include #include #include @@ -76,78 +55,22 @@ #include #include #include -#include -#include -#include #include -#include #include -#include #include -#include -#include -#include -#include #include -#include #include #include -#include -#include #include -#include #include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - #include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include #include #include #include - #include -#include -#include -#include -#include -#include -#include -#include -#include #include - - #if defined __GNUC__ && defined __DEPRECATED_DISABLED__ #define __DEPRECATED #undef __DEPRECATED_DISABLED__ diff --git a/modules/viz/src/viz3d_impl.cpp b/modules/viz/src/viz3d_impl.cpp index f0157331ec..d04bb5426e 100644 --- a/modules/viz/src/viz3d_impl.cpp +++ b/modules/viz/src/viz3d_impl.cpp @@ -582,16 +582,6 @@ void cv::viz::Viz3d::VizImpl::updateCells (vtkSmartPointer &cell } } -////////////////////////////////////////////////////////////////////////////////////////////// -void cv::viz::Viz3d::VizImpl::allocVtkPolyData (vtkSmartPointer &polydata) -{polydata = vtkSmartPointer::New (); } - -void cv::viz::Viz3d::VizImpl::allocVtkPolyData (vtkSmartPointer &polydata) -{ polydata = vtkSmartPointer::New (); } - -void cv::viz::Viz3d::VizImpl::allocVtkUnstructuredGrid (vtkSmartPointer &polydata) -{ polydata = vtkSmartPointer::New (); } - ////////////////////////////////////////////////////////////////////////////////////////////// void cv::viz::Viz3d::VizImpl::setFullScreen (bool mode) { @@ -599,6 +589,7 @@ void cv::viz::Viz3d::VizImpl::setFullScreen (bool mode) window_->SetFullScreen (mode); } +////////////////////////////////////////////////////////////////////////////////////////////// void cv::viz::Viz3d::VizImpl::setWindowName (const std::string &name) { if (window_) @@ -610,6 +601,7 @@ cv::String cv::viz::Viz3d::VizImpl::getWindowName() const return (window_ ? window_->GetWindowName() : ""); } +////////////////////////////////////////////////////////////////////////////////////////////// void cv::viz::Viz3d::VizImpl::setWindowPosition (int x, int y) { window_->SetPosition (x, y); } void cv::viz::Viz3d::VizImpl::setWindowSize (int xw, int yw) { window_->SetSize (xw, yw); } cv::Size cv::viz::Viz3d::VizImpl::getWindowSize() const { return Size(window_->GetSize()[0], window_->GetSize()[1]); } diff --git a/modules/viz/src/viz3d_impl.hpp b/modules/viz/src/viz3d_impl.hpp index 4d24fb86e6..61948f912d 100644 --- a/modules/viz/src/viz3d_impl.hpp +++ b/modules/viz/src/viz3d_impl.hpp @@ -178,10 +178,6 @@ private: * generate */ void updateCells (vtkSmartPointer &cells, vtkSmartPointer &initcells, vtkIdType nr_points); - - void allocVtkPolyData (vtkSmartPointer &polydata); - void allocVtkPolyData (vtkSmartPointer &polydata); - void allocVtkUnstructuredGrid (vtkSmartPointer &polydata); }; From 3da7dd9849c41ae19f4bc4b584c0dba34b40df8b Mon Sep 17 00:00:00 2001 From: ozantonkal Date: Sun, 25 Aug 2013 15:55:36 +0200 Subject: [PATCH 12/29] fix yellow and magenta color bgr codes --- modules/viz/src/types.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/viz/src/types.cpp b/modules/viz/src/types.cpp index 104fc5a1ed..6d3e3d5898 100644 --- a/modules/viz/src/types.cpp +++ b/modules/viz/src/types.cpp @@ -14,8 +14,8 @@ cv::viz::Color cv::viz::Color::blue() { return Color(255, 0, 0); } cv::viz::Color cv::viz::Color::cyan() { return Color(255, 255, 0); } cv::viz::Color cv::viz::Color::red() { return Color( 0, 0, 255); } -cv::viz::Color cv::viz::Color::magenta() { return Color( 0, 255, 255); } -cv::viz::Color cv::viz::Color::yellow() { return Color(255, 0, 255); } +cv::viz::Color cv::viz::Color::yellow() { return Color( 0, 255, 255); } +cv::viz::Color cv::viz::Color::magenta() { return Color(255, 0, 255); } cv::viz::Color cv::viz::Color::white() { return Color(255, 255, 255); } cv::viz::Color cv::viz::Color::gray() { return Color(128, 128, 128); } From e4b13f2ef0148d1704d1af194c738701652584b5 Mon Sep 17 00:00:00 2001 From: ozantonkal Date: Tue, 27 Aug 2013 20:09:54 +0200 Subject: [PATCH 13/29] update reader after setting file name --- modules/viz/src/widget.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/viz/src/widget.cpp b/modules/viz/src/widget.cpp index 485e35ed74..ba21b67855 100644 --- a/modules/viz/src/widget.cpp +++ b/modules/viz/src/widget.cpp @@ -17,6 +17,7 @@ cv::viz::Widget cv::viz::Widget::fromPlyFile(const String &file_name) { vtkSmartPointer reader = vtkSmartPointer::New (); reader->SetFileName (file_name.c_str ()); + reader->Update(); vtkSmartPointer data = reader->GetOutput(); CV_Assert(data); From 8007e07ad2ded72132f8a15e71e28519ffd540d1 Mon Sep 17 00:00:00 2001 From: ozantonkal Date: Wed, 28 Aug 2013 19:13:34 +0200 Subject: [PATCH 14/29] load mesh function is finalized: color range is always 0-255 and RGB due to vtkPLYReader limitations --- modules/viz/src/types.cpp | 19 ++++++------------- modules/viz/src/widget.cpp | 1 - 2 files changed, 6 insertions(+), 14 deletions(-) diff --git a/modules/viz/src/types.cpp b/modules/viz/src/types.cpp index 6d3e3d5898..64d6f91a15 100644 --- a/modules/viz/src/types.cpp +++ b/modules/viz/src/types.cpp @@ -72,11 +72,12 @@ struct cv::viz::Mesh3d::loadMeshImpl vtkSmartPointer reader = vtkSmartPointer::New(); reader->SetFileName(file.c_str()); reader->Update(); + vtkSmartPointer poly_data = reader->GetOutput (); + CV_Assert(poly_data); vtkSmartPointer mesh_points = poly_data->GetPoints (); vtkIdType nr_points = mesh_points->GetNumberOfPoints (); - //vtkIdType nr_polygons = poly_data->GetNumberOfPolys (); mesh.cloud.create(1, nr_points, CV_32FC3); @@ -89,18 +90,10 @@ struct cv::viz::Mesh3d::loadMeshImpl } // Then the color information, if any - vtkUnsignedCharArray* poly_colors = NULL; - if (poly_data->GetPointData() != NULL) - poly_colors = vtkUnsignedCharArray::SafeDownCast (poly_data->GetPointData ()->GetScalars ("Colors")); - - // some applications do not save the name of scalars (including PCL's native vtk_io) - if (!poly_colors && poly_data->GetPointData () != NULL) - poly_colors = vtkUnsignedCharArray::SafeDownCast (poly_data->GetPointData ()->GetScalars ("scalars")); - - if (!poly_colors && poly_data->GetPointData () != NULL) - poly_colors = vtkUnsignedCharArray::SafeDownCast (poly_data->GetPointData ()->GetScalars ("RGB")); - - // TODO: currently only handles rgb values with 3 components + vtkUnsignedCharArray* poly_colors = 0; + if (poly_data->GetPointData()) + poly_colors = vtkUnsignedCharArray::SafeDownCast(poly_data->GetPointData()->GetScalars()); + if (poly_colors && (poly_colors->GetNumberOfComponents () == 3)) { mesh.colors.create(1, nr_points, CV_8UC3); diff --git a/modules/viz/src/widget.cpp b/modules/viz/src/widget.cpp index ba21b67855..485e35ed74 100644 --- a/modules/viz/src/widget.cpp +++ b/modules/viz/src/widget.cpp @@ -17,7 +17,6 @@ cv::viz::Widget cv::viz::Widget::fromPlyFile(const String &file_name) { vtkSmartPointer reader = vtkSmartPointer::New (); reader->SetFileName (file_name.c_str ()); - reader->Update(); vtkSmartPointer data = reader->GetOutput(); CV_Assert(data); From 4b443059ec5a5cf33bd2a55be6dd3e137579d743 Mon Sep 17 00:00:00 2001 From: ozantonkal Date: Wed, 28 Aug 2013 21:27:30 +0200 Subject: [PATCH 15/29] reverted widget reference count in order to avoid memory leak --- modules/viz/include/opencv2/viz/widgets.hpp | 6 +++ modules/viz/src/widget.cpp | 43 ++++++++++++++++++++- 2 files changed, 48 insertions(+), 1 deletion(-) diff --git a/modules/viz/include/opencv2/viz/widgets.hpp b/modules/viz/include/opencv2/viz/widgets.hpp index caaee9e698..01ed3ea8da 100644 --- a/modules/viz/include/opencv2/viz/widgets.hpp +++ b/modules/viz/include/opencv2/viz/widgets.hpp @@ -14,6 +14,9 @@ namespace cv { public: Widget(); + Widget(const Widget& other); + Widget& operator=(const Widget& other); + ~Widget(); static Widget fromPlyFile(const String &file_name); @@ -25,6 +28,9 @@ namespace cv class Impl; Impl *impl_; friend struct WidgetAccessor; + + void create(); + void release(); }; ///////////////////////////////////////////////////////////////////////////// diff --git a/modules/viz/src/widget.cpp b/modules/viz/src/widget.cpp index 485e35ed74..b3f1479781 100644 --- a/modules/viz/src/widget.cpp +++ b/modules/viz/src/widget.cpp @@ -7,11 +7,52 @@ class cv::viz::Widget::Impl { public: vtkSmartPointer prop; + int ref_counter; Impl() : prop(0) {} }; -cv::viz::Widget::Widget() : impl_( new Impl() ) { } +cv::viz::Widget::Widget() : impl_(0) +{ + create(); +} + +cv::viz::Widget::Widget(const Widget& other) : impl_(other.impl_) +{ + if (impl_) CV_XADD(&impl_->ref_counter, 1); +} + +cv::viz::Widget& cv::viz::Widget::operator=(const Widget& other) +{ + if (this != &other) + { + release(); + impl_ = other.impl_; + if (impl_) CV_XADD(&impl_->ref_counter, 1); + } + return *this; +} + +cv::viz::Widget::~Widget() +{ + release(); +} + +void cv::viz::Widget::create() +{ + if (impl_) release(); + impl_ = new Impl(); + impl_->ref_counter = 1; +} + +void cv::viz::Widget::release() +{ + if (impl_ && CV_XADD(&impl_->ref_counter, -1) == 1) + { + delete impl_; + impl_ = 0; + } +} cv::viz::Widget cv::viz::Widget::fromPlyFile(const String &file_name) { From 6c0c21756280eca3181d9ef0a0b9037ad8bd9f9d Mon Sep 17 00:00:00 2001 From: ozantonkal Date: Thu, 29 Aug 2013 18:41:12 +0200 Subject: [PATCH 16/29] removed reference counter in widgets, fixed memory leak --- modules/viz/include/opencv2/viz/widgets.hpp | 3 -- modules/viz/src/widget.cpp | 32 ++++----------------- 2 files changed, 6 insertions(+), 29 deletions(-) diff --git a/modules/viz/include/opencv2/viz/widgets.hpp b/modules/viz/include/opencv2/viz/widgets.hpp index 01ed3ea8da..3f631c0118 100644 --- a/modules/viz/include/opencv2/viz/widgets.hpp +++ b/modules/viz/include/opencv2/viz/widgets.hpp @@ -28,9 +28,6 @@ namespace cv class Impl; Impl *impl_; friend struct WidgetAccessor; - - void create(); - void release(); }; ///////////////////////////////////////////////////////////////////////////// diff --git a/modules/viz/src/widget.cpp b/modules/viz/src/widget.cpp index b3f1479781..b0b76c4352 100644 --- a/modules/viz/src/widget.cpp +++ b/modules/viz/src/widget.cpp @@ -7,47 +7,27 @@ class cv::viz::Widget::Impl { public: vtkSmartPointer prop; - int ref_counter; Impl() : prop(0) {} }; -cv::viz::Widget::Widget() : impl_(0) -{ - create(); -} +cv::viz::Widget::Widget() : impl_( new Impl() ) { } -cv::viz::Widget::Widget(const Widget& other) : impl_(other.impl_) +cv::viz::Widget::Widget(const Widget& other) : impl_( new Impl() ) { - if (impl_) CV_XADD(&impl_->ref_counter, 1); + if (other.impl_ && other.impl_->prop) impl_->prop = other.impl_->prop; } cv::viz::Widget& cv::viz::Widget::operator=(const Widget& other) { - if (this != &other) - { - release(); - impl_ = other.impl_; - if (impl_) CV_XADD(&impl_->ref_counter, 1); - } + if (!impl_) impl_ = new Impl(); + if (other.impl_) impl_->prop = other.impl_->prop; return *this; } cv::viz::Widget::~Widget() { - release(); -} - -void cv::viz::Widget::create() -{ - if (impl_) release(); - impl_ = new Impl(); - impl_->ref_counter = 1; -} - -void cv::viz::Widget::release() -{ - if (impl_ && CV_XADD(&impl_->ref_counter, -1) == 1) + if (impl_) { delete impl_; impl_ = 0; From 69f135ec57e02f2c6315063eede1f64a9df079cf Mon Sep 17 00:00:00 2001 From: ozantonkal Date: Thu, 29 Aug 2013 19:06:12 +0200 Subject: [PATCH 17/29] fix memory leak in viz3d --- modules/viz/src/viz3d.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/modules/viz/src/viz3d.cpp b/modules/viz/src/viz3d.cpp index 96483f43aa..48f6ea3042 100644 --- a/modules/viz/src/viz3d.cpp +++ b/modules/viz/src/viz3d.cpp @@ -33,7 +33,9 @@ void cv::viz::Viz3d::create(const String &window_name) void cv::viz::Viz3d::release() { - if (impl_ && CV_XADD(&impl_->ref_counter, -1) == 1) + // If the current referene count is equal to 2, we can delete it + // - 2 : because minimum there will be two instances, one of which is in the map + if (impl_ && CV_XADD(&impl_->ref_counter, -1) == 2) { // Erase the window cv::viz::VizAccessor::getInstance().remove(getWindowName()); From af8a918e04f58afdd28bdc4d94191533943b8653 Mon Sep 17 00:00:00 2001 From: ozantonkal Date: Sat, 31 Aug 2013 11:30:37 +0200 Subject: [PATCH 18/29] fix minor bug, minor cleaning, cv_assert with messages --- modules/viz/include/opencv2/viz/widgets.hpp | 3 - modules/viz/src/cloud_widgets.cpp | 6 +- modules/viz/src/interactor_style.cpp | 14 +--- modules/viz/src/shape_widgets.cpp | 32 +++------ modules/viz/src/types.cpp | 2 +- modules/viz/src/viz3d_impl.cpp | 72 +++------------------ modules/viz/src/viz3d_impl.hpp | 12 +--- modules/viz/src/widget.cpp | 20 +++--- 8 files changed, 36 insertions(+), 125 deletions(-) diff --git a/modules/viz/include/opencv2/viz/widgets.hpp b/modules/viz/include/opencv2/viz/widgets.hpp index 3f631c0118..9f1d14f13c 100644 --- a/modules/viz/include/opencv2/viz/widgets.hpp +++ b/modules/viz/include/opencv2/viz/widgets.hpp @@ -61,9 +61,6 @@ namespace cv { public: LineWidget(const Point3f &pt1, const Point3f &pt2, const Color &color = Color::white()); - - void setLineWidth(float line_width); - float getLineWidth(); }; class CV_EXPORTS PlaneWidget : public Widget3D diff --git a/modules/viz/src/cloud_widgets.cpp b/modules/viz/src/cloud_widgets.cpp index a30c97a32a..adf842a0f2 100644 --- a/modules/viz/src/cloud_widgets.cpp +++ b/modules/viz/src/cloud_widgets.cpp @@ -298,7 +298,7 @@ struct cv::viz::CloudCollectionWidget::CreateCloudWidget } vtkPolyData *data = vtkPolyData::SafeDownCast(mapper->GetInput()); - CV_Assert(data); + CV_Assert("Cloud Widget without data" && data); vtkSmartPointer appendFilter = vtkSmartPointer::New(); appendFilter->AddInputConnection(mapper->GetInput()->GetProducerPort()); @@ -357,7 +357,7 @@ void cv::viz::CloudCollectionWidget::addCloud(InputArray _cloud, InputArray _col transform_filter->Update(); vtkLODActor *actor = vtkLODActor::SafeDownCast(WidgetAccessor::getProp(*this)); - CV_Assert(actor); + CV_Assert("Incompatible widget type." && actor); Vec3d minmax(scalars->GetRange()); CreateCloudWidget::createMapper(actor, transform_filter->GetOutput(), minmax); @@ -392,7 +392,7 @@ void cv::viz::CloudCollectionWidget::addCloud(InputArray _cloud, const Color &co transform_filter->Update(); vtkLODActor *actor = vtkLODActor::SafeDownCast(WidgetAccessor::getProp(*this)); - CV_Assert(actor); + CV_Assert("Incompatible widget type." && actor); Vec3d minmax(scalars->GetRange()); CreateCloudWidget::createMapper(actor, transform_filter->GetOutput(), minmax); diff --git a/modules/viz/src/interactor_style.cpp b/modules/viz/src/interactor_style.cpp index db3d979791..06e7af4c20 100644 --- a/modules/viz/src/interactor_style.cpp +++ b/modules/viz/src/interactor_style.cpp @@ -152,17 +152,9 @@ void cv::viz::InteractorStyle::registerKeyboardCallback(void (*callback)(const K void cv::viz::InteractorStyle::OnKeyDown () { - if (!init_) - { - std::cout << "Interactor style not initialized. Please call Initialize () before continuing" << std::endl; - return; - } - - if (!renderer_) - { - std::cout << "No renderer given! Use SetRendererCollection () before continuing." << std::endl; - return; - } + + CV_Assert("Interactor style not initialized. Please call Initialize () before continuing" && init_); + CV_Assert("No renderer given! Use SetRendererCollection () before continuing." && renderer_); FindPokedRenderer (Interactor->GetEventPosition ()[0], Interactor->GetEventPosition ()[1]); diff --git a/modules/viz/src/shape_widgets.cpp b/modules/viz/src/shape_widgets.cpp index cb66e80b39..84fdc77287 100644 --- a/modules/viz/src/shape_widgets.cpp +++ b/modules/viz/src/shape_widgets.cpp @@ -27,20 +27,6 @@ cv::viz::LineWidget::LineWidget(const Point3f &pt1, const Point3f &pt2, const Co setColor(color); } -void cv::viz::LineWidget::setLineWidth(float line_width) -{ - vtkActor *actor = vtkActor::SafeDownCast(WidgetAccessor::getProp(*this)); - CV_Assert(actor); - actor->GetProperty()->SetLineWidth(line_width); -} - -float cv::viz::LineWidget::getLineWidth() -{ - vtkActor *actor = vtkActor::SafeDownCast(WidgetAccessor::getProp(*this)); - CV_Assert(actor); - return actor->GetProperty()->GetLineWidth(); -} - template<> cv::viz::LineWidget cv::viz::Widget::cast() { Widget3D widget = this->cast(); @@ -556,12 +542,12 @@ cv::viz::Text3DWidget::Text3DWidget(const String &text, const Point3f &position, void cv::viz::Text3DWidget::setText(const String &text) { vtkFollower *actor = vtkFollower::SafeDownCast(WidgetAccessor::getProp(*this)); - CV_Assert(actor); + CV_Assert("This widget does not support text." && actor); // Update text source vtkPolyDataMapper *mapper = vtkPolyDataMapper::SafeDownCast(actor->GetMapper()); vtkVectorText * textSource = vtkVectorText::SafeDownCast(mapper->GetInputConnection(0,0)->GetProducer()); - CV_Assert(textSource); + CV_Assert("This widget does not support text." && textSource); textSource->SetText(text.c_str()); textSource->Update(); @@ -570,11 +556,11 @@ void cv::viz::Text3DWidget::setText(const String &text) cv::String cv::viz::Text3DWidget::getText() const { vtkFollower *actor = vtkFollower::SafeDownCast(WidgetAccessor::getProp(*this)); - CV_Assert(actor); + CV_Assert("This widget does not support text." && actor); vtkPolyDataMapper *mapper = vtkPolyDataMapper::SafeDownCast(actor->GetMapper()); vtkVectorText * textSource = vtkVectorText::SafeDownCast(mapper->GetInputConnection(0,0)->GetProducer()); - CV_Assert(textSource); + CV_Assert("This widget does not support text." && textSource); return textSource->GetText(); } @@ -615,14 +601,14 @@ template<> cv::viz::TextWidget cv::viz::Widget::cast() void cv::viz::TextWidget::setText(const String &text) { vtkTextActor *actor = vtkTextActor::SafeDownCast(WidgetAccessor::getProp(*this)); - CV_Assert(actor); + CV_Assert("This widget does not support text." && actor); actor->SetInput(text.c_str()); } cv::String cv::viz::TextWidget::getText() const { vtkTextActor *actor = vtkTextActor::SafeDownCast(WidgetAccessor::getProp(*this)); - CV_Assert(actor); + CV_Assert("This widget does not support text." && actor); return actor->GetInput(); } @@ -671,10 +657,10 @@ void cv::viz::ImageOverlayWidget::setImage(const Mat &image) CV_Assert(!image.empty() && image.depth() == CV_8U); vtkActor2D *actor = vtkActor2D::SafeDownCast(WidgetAccessor::getProp(*this)); - CV_Assert(actor); + CV_Assert("This widget does not support overlay image." && actor); vtkImageMapper *mapper = vtkImageMapper::SafeDownCast(actor->GetMapper()); - CV_Assert(mapper); + CV_Assert("This widget does not support overlay image." && mapper); // Create the vtk image and set its parameters based on input image vtkSmartPointer vtk_image = vtkSmartPointer::New(); @@ -821,7 +807,7 @@ void cv::viz::Image3DWidget::setImage(const Mat &image) CV_Assert(!image.empty() && image.depth() == CV_8U); vtkActor *actor = vtkActor::SafeDownCast(WidgetAccessor::getProp(*this)); - CV_Assert(actor); + CV_Assert("This widget does not support 3D image." && actor); // Create the vtk image and set its parameters based on input image vtkSmartPointer vtk_image = vtkSmartPointer::New(); diff --git a/modules/viz/src/types.cpp b/modules/viz/src/types.cpp index 64d6f91a15..e915207e30 100644 --- a/modules/viz/src/types.cpp +++ b/modules/viz/src/types.cpp @@ -74,7 +74,7 @@ struct cv::viz::Mesh3d::loadMeshImpl reader->Update(); vtkSmartPointer poly_data = reader->GetOutput (); - CV_Assert(poly_data); + CV_Assert("File does not exist or file format is not supported." && poly_data); vtkSmartPointer mesh_points = poly_data->GetPoints (); vtkIdType nr_points = mesh_points->GetNumberOfPoints (); diff --git a/modules/viz/src/viz3d_impl.cpp b/modules/viz/src/viz3d_impl.cpp index d04bb5426e..7a1518c2c0 100644 --- a/modules/viz/src/viz3d_impl.cpp +++ b/modules/viz/src/viz3d_impl.cpp @@ -34,9 +34,6 @@ cv::viz::Viz3d::VizImpl::VizImpl (const std::string &name) ///////////////////////////////////////////////// interactor_ = vtkSmartPointer ::Take (vtkRenderWindowInteractorFixNew ()); - //win_->PointSmoothingOn (); - //win_->LineSmoothingOn (); - //win_->PolygonSmoothingOn (); window_->AlphaBitPlanesOff (); window_->PointSmoothingOff (); window_->LineSmoothingOff (); @@ -46,7 +43,6 @@ cv::viz::Viz3d::VizImpl::VizImpl (const std::string &name) interactor_->SetRenderWindow (window_); interactor_->SetInteractorStyle (style_); - //interactor_->SetStillUpdateRate (30.0); interactor_->SetDesiredUpdateRate (30.0); // Initialize and create timer, also create window @@ -119,8 +115,8 @@ void cv::viz::Viz3d::VizImpl::removeWidget(const String &id) { WidgetActorMap::iterator wam_itr = widget_actor_map_->find(id); bool exists = wam_itr != widget_actor_map_->end(); - CV_Assert(exists); - CV_Assert(removeActorFromRenderer (wam_itr->second)); + CV_Assert("Widget does not exist." && exists); + CV_Assert("Widget could not be removed." && removeActorFromRenderer (wam_itr->second)); widget_actor_map_->erase(wam_itr); } @@ -129,7 +125,7 @@ cv::viz::Widget cv::viz::Viz3d::VizImpl::getWidget(const String &id) const { WidgetActorMap::const_iterator wam_itr = widget_actor_map_->find(id); bool exists = wam_itr != widget_actor_map_->end(); - CV_Assert(exists); + CV_Assert("Widget does not exist." && exists); Widget widget; WidgetAccessor::setProp(widget, wam_itr->second); @@ -141,10 +137,10 @@ void cv::viz::Viz3d::VizImpl::setWidgetPose(const String &id, const Affine3f &po { WidgetActorMap::iterator wam_itr = widget_actor_map_->find(id); bool exists = wam_itr != widget_actor_map_->end(); - CV_Assert(exists); + CV_Assert("Widget does not exist." && exists); vtkProp3D *actor = vtkProp3D::SafeDownCast(wam_itr->second); - CV_Assert(actor); + CV_Assert("Widget is not 3D." && actor); vtkSmartPointer matrix = convertToVtkMatrix(pose.matrix); actor->SetUserMatrix (matrix); @@ -156,10 +152,10 @@ void cv::viz::Viz3d::VizImpl::updateWidgetPose(const String &id, const Affine3f { WidgetActorMap::iterator wam_itr = widget_actor_map_->find(id); bool exists = wam_itr != widget_actor_map_->end(); - CV_Assert(exists); + CV_Assert("Widget does not exist." && exists); vtkProp3D *actor = vtkProp3D::SafeDownCast(wam_itr->second); - CV_Assert(actor); + CV_Assert("Widget is not 3D." && actor); vtkSmartPointer matrix = actor->GetUserMatrix(); if (!matrix) @@ -180,10 +176,10 @@ cv::Affine3f cv::viz::Viz3d::VizImpl::getWidgetPose(const String &id) const { WidgetActorMap::const_iterator wam_itr = widget_actor_map_->find(id); bool exists = wam_itr != widget_actor_map_->end(); - CV_Assert(exists); + CV_Assert("Widget does not exist." && exists); vtkProp3D *actor = vtkProp3D::SafeDownCast(wam_itr->second); - CV_Assert(actor); + CV_Assert("Widget is not 3D." && actor); vtkSmartPointer matrix = actor->GetUserMatrix(); Matx44f matrix_cv = convertToMatx(matrix); @@ -254,56 +250,6 @@ void cv::viz::Viz3d::VizImpl::removeAllWidgets() renderer_->RemoveAllViewProps(); } -////////////////////////////////////////////////////////////////////////////////////////// -bool cv::viz::Viz3d::VizImpl::removeActorFromRenderer (const vtkSmartPointer &actor) -{ - vtkLODActor* actor_to_remove = vtkLODActor::SafeDownCast (actor); - - - - // Iterate over all actors in this renderer - vtkPropCollection* actors = renderer_->GetViewProps (); - actors->InitTraversal (); - - vtkProp* current_actor = NULL; - while ((current_actor = actors->GetNextProp ()) != NULL) - { - if (current_actor != actor_to_remove) - continue; - renderer_->RemoveActor (actor); - // renderer->Render (); - // Found the correct viewport and removed the actor - return (true); - } - - return false; -} - -////////////////////////////////////////////////////////////////////////////////////////// -bool cv::viz::Viz3d::VizImpl::removeActorFromRenderer (const vtkSmartPointer &actor) -{ - vtkActor* actor_to_remove = vtkActor::SafeDownCast (actor); - - // Add it to all renderers - //rens_->InitTraversal (); - - - // Iterate over all actors in this renderer - vtkPropCollection* actors = renderer_->GetViewProps (); - actors->InitTraversal (); - vtkProp* current_actor = NULL; - while ((current_actor = actors->GetNextProp ()) != NULL) - { - if (current_actor != actor_to_remove) - continue; - renderer_->RemoveActor (actor); - // renderer->Render (); - // Found the correct viewport and removed the actor - return (true); - } - return false; -} - ///////////////////////////////////////////////////////////////////////////////////////////// bool cv::viz::Viz3d::VizImpl::removeActorFromRenderer (const vtkSmartPointer &actor) { diff --git a/modules/viz/src/viz3d_impl.hpp b/modules/viz/src/viz3d_impl.hpp index 61948f912d..b2339c40c8 100644 --- a/modules/viz/src/viz3d_impl.hpp +++ b/modules/viz/src/viz3d_impl.hpp @@ -119,6 +119,7 @@ private: if (event_id == vtkCommand::ExitEvent) { viz_->stopped_ = true; + viz_->interactor_->GetRenderWindow()->Finalize(); viz_->interactor_->TerminateApp (); } } @@ -142,12 +143,6 @@ private: /** \brief The render window interactor style. */ vtkSmartPointer style_; - - /** \brief Internal list with actor pointers and name IDs for point clouds. */ -// cv::Ptr cloud_actor_map_; - - /** \brief Internal list with actor pointers and name IDs for shapes. */ -// cv::Ptr shape_actor_map_; /** \brief Internal list with actor pointers and name IDs for all widget actors */ cv::Ptr widget_actor_map_; @@ -155,13 +150,8 @@ private: /** \brief Boolean that holds whether or not the camera parameters were manually initialized*/ bool camera_set_; - bool removeActorFromRenderer (const vtkSmartPointer &actor); - bool removeActorFromRenderer (const vtkSmartPointer &actor); bool removeActorFromRenderer (const vtkSmartPointer &actor); - //void addActorToRenderer (const vtkSmartPointer &actor); - - /** \brief Internal method. Creates a vtk actor from a vtk polydata object. * \param[in] data the vtk polydata object to create an actor for * \param[out] actor the resultant vtk actor object diff --git a/modules/viz/src/widget.cpp b/modules/viz/src/widget.cpp index b0b76c4352..196ec99399 100644 --- a/modules/viz/src/widget.cpp +++ b/modules/viz/src/widget.cpp @@ -40,7 +40,7 @@ cv::viz::Widget cv::viz::Widget::fromPlyFile(const String &file_name) reader->SetFileName (file_name.c_str ()); vtkSmartPointer data = reader->GetOutput(); - CV_Assert(data); + CV_Assert("File does not exist or file format is not supported." && data); vtkSmartPointer actor = vtkSmartPointer::New(); @@ -77,7 +77,7 @@ cv::viz::Widget cv::viz::Widget::fromPlyFile(const String &file_name) void cv::viz::Widget::setRenderingProperty(int property, double value) { vtkActor *actor = vtkActor::SafeDownCast(WidgetAccessor::getProp(*this)); - CV_Assert(actor); + CV_Assert("Widget type is not supported." && actor); switch (property) { @@ -118,7 +118,7 @@ void cv::viz::Widget::setRenderingProperty(int property, double value) double cv::viz::Widget::getRenderingProperty(int property) const { vtkActor *actor = vtkActor::SafeDownCast(WidgetAccessor::getProp(*this)); - CV_Assert(actor); + CV_Assert("Widget type is not supported." && actor); double value = 0.0; switch (property) @@ -239,7 +239,7 @@ struct cv::viz::Widget3D::MatrixConverter void cv::viz::Widget3D::setPose(const Affine3f &pose) { vtkProp3D *actor = vtkProp3D::SafeDownCast(WidgetAccessor::getProp(*this)); - CV_Assert(actor); + CV_Assert("Widget is not 3D." && actor); vtkSmartPointer matrix = convertToVtkMatrix(pose.matrix); actor->SetUserMatrix (matrix); @@ -249,7 +249,7 @@ void cv::viz::Widget3D::setPose(const Affine3f &pose) void cv::viz::Widget3D::updatePose(const Affine3f &pose) { vtkProp3D *actor = vtkProp3D::SafeDownCast(WidgetAccessor::getProp(*this)); - CV_Assert(actor); + CV_Assert("Widget is not 3D." && actor); vtkSmartPointer matrix = actor->GetUserMatrix(); if (!matrix) @@ -269,7 +269,7 @@ void cv::viz::Widget3D::updatePose(const Affine3f &pose) cv::Affine3f cv::viz::Widget3D::getPose() const { vtkProp3D *actor = vtkProp3D::SafeDownCast(WidgetAccessor::getProp(*this)); - CV_Assert(actor); + CV_Assert("Widget is not 3D." && actor); vtkSmartPointer matrix = actor->GetUserMatrix(); Matx44f matrix_cv = MatrixConverter::convertToMatx(matrix); @@ -280,7 +280,7 @@ void cv::viz::Widget3D::setColor(const Color &color) { // Cast to actor instead of prop3d since prop3d doesn't provide getproperty vtkActor *actor = vtkActor::SafeDownCast(WidgetAccessor::getProp(*this)); - CV_Assert(actor); + CV_Assert("Widget type is not supported." && actor); Color c = vtkcolor(color); actor->GetMapper ()->ScalarVisibilityOff (); @@ -292,7 +292,7 @@ void cv::viz::Widget3D::setColor(const Color &color) template<> cv::viz::Widget3D cv::viz::Widget::cast() { vtkProp3D *actor = vtkProp3D::SafeDownCast(WidgetAccessor::getProp(*this)); - CV_Assert(actor); + CV_Assert("Widget cannot be cast." && actor); Widget3D widget; WidgetAccessor::setProp(widget, actor); @@ -305,7 +305,7 @@ template<> cv::viz::Widget3D cv::viz::Widget::cast() void cv::viz::Widget2D::setColor(const Color &color) { vtkActor2D *actor = vtkActor2D::SafeDownCast(WidgetAccessor::getProp(*this)); - CV_Assert(actor); + CV_Assert("Widget type is not supported." && actor); Color c = vtkcolor(color); actor->GetProperty ()->SetColor (c.val); actor->Modified (); @@ -314,7 +314,7 @@ void cv::viz::Widget2D::setColor(const Color &color) template<> cv::viz::Widget2D cv::viz::Widget::cast() { vtkActor2D *actor = vtkActor2D::SafeDownCast(WidgetAccessor::getProp(*this)); - CV_Assert(actor); + CV_Assert("Widget cannot be cast." && actor); Widget2D widget; WidgetAccessor::setProp(widget, actor); From 4aa61dee5046b185cbbe1a43093c4e4f2e0c7ddd Mon Sep 17 00:00:00 2001 From: ozantonkal Date: Sat, 31 Aug 2013 11:54:49 +0200 Subject: [PATCH 19/29] minor refactoring interactor_style --- modules/viz/src/interactor_style.cpp | 27 ++++++--------------------- 1 file changed, 6 insertions(+), 21 deletions(-) diff --git a/modules/viz/src/interactor_style.cpp b/modules/viz/src/interactor_style.cpp index 06e7af4c20..ace60c860f 100644 --- a/modules/viz/src/interactor_style.cpp +++ b/modules/viz/src/interactor_style.cpp @@ -1,9 +1,6 @@ #include "precomp.hpp" - #include "interactor_style.h" -//#include - using namespace cv; ////////////////////////////////////////////////////////////////////////////////////////////// @@ -227,7 +224,7 @@ cv::viz::InteractorStyle::OnKeyDown () { for (actor->InitPathTraversal (); vtkAssemblyPath* path = actor->GetNextPath (); ) { - vtkSmartPointer apart = reinterpret_cast (path->GetLastNode ()->GetViewProp ()); + vtkActor* apart = reinterpret_cast (path->GetLastNode ()->GetViewProp ()); apart->GetProperty ()->SetRepresentationToPoints (); } } @@ -250,15 +247,12 @@ cv::viz::InteractorStyle::OnKeyDown () cam->GetFocalPoint (focal); cam->GetPosition (pos); cam->GetViewUp (view); -#ifndef M_PI - # define M_PI 3.14159265358979323846 // pi -#endif int *win_pos = Interactor->GetRenderWindow ()->GetPosition (); int *win_size = Interactor->GetRenderWindow ()->GetSize (); ofs_cam << clip[0] << "," << clip[1] << "/" << focal[0] << "," << focal[1] << "," << focal[2] << "/" << pos[0] << "," << pos[1] << "," << pos[2] << "/" << view[0] << "," << view[1] << "," << view[2] << "/" << - cam->GetViewAngle () / 180.0 * M_PI << "/" << win_size[0] << "," << win_size[1] << "/" << win_pos[0] << "," << win_pos[1] + cam->GetViewAngle () / 180.0 * CV_PI << "/" << win_size[0] << "," << win_size[1] << "/" << win_pos[0] << "," << win_pos[1] << endl; ofs_cam.close (); @@ -302,7 +296,7 @@ cv::viz::InteractorStyle::OnKeyDown () { for (actor->InitPathTraversal (); vtkAssemblyPath* path = actor->GetNextPath (); ) { - vtkSmartPointer apart = reinterpret_cast (path->GetLastNode ()->GetViewProp ()); + vtkActor* apart = reinterpret_cast (path->GetLastNode ()->GetViewProp ()); float psize = apart->GetProperty ()->GetPointSize (); if (psize < 63.0f) apart->GetProperty ()->SetPointSize (psize + 1.0f); @@ -323,7 +317,7 @@ cv::viz::InteractorStyle::OnKeyDown () { for (actor->InitPathTraversal (); vtkAssemblyPath* path = actor->GetNextPath (); ) { - vtkSmartPointer apart = static_cast (path->GetLastNode ()->GetViewProp ()); + vtkActor* apart = static_cast (path->GetLastNode ()->GetViewProp ()); float psize = apart->GetProperty ()->GetPointSize (); if (psize > 1.0f) apart->GetProperty ()->SetPointSize (psize - 1.0f); @@ -651,17 +645,8 @@ void cv::viz::InteractorStyle::OnMouseWheelBackward () ////////////////////////////////////////////////////////////////////////////////////////////// void cv::viz::InteractorStyle::OnTimer () { - if (!init_) - { - std::cout << "[PCLVisualizerInteractorStyle] Interactor style not initialized. Please call Initialize () before continuing.\n" << std::endl; - return; - } - - if (!renderer_) - { - std::cout << "[PCLVisualizerInteractorStyle] No renderer collection given! Use SetRendererCollection () before continuing." << std::endl; - return; - } + CV_Assert("Interactor style not initialized." && init_); + CV_Assert("Renderer has not been set." && renderer_); renderer_->Render (); Interactor->Render (); } From ffbb5e9524816450eb429fb10ab082aa3913f0fc Mon Sep 17 00:00:00 2001 From: ozantonkal Date: Sat, 31 Aug 2013 12:16:47 +0200 Subject: [PATCH 20/29] resetCamera, resetViewpoint in Viz3d --- modules/viz/include/opencv2/viz/viz3d.hpp | 3 +++ modules/viz/src/viz3d.cpp | 3 +++ modules/viz/src/viz3d_impl.cpp | 12 +++++++++--- modules/viz/src/viz3d_impl.hpp | 8 ++------ 4 files changed, 17 insertions(+), 9 deletions(-) diff --git a/modules/viz/include/opencv2/viz/viz3d.hpp b/modules/viz/include/opencv2/viz/viz3d.hpp index a80fd37486..a54493611d 100644 --- a/modules/viz/include/opencv2/viz/viz3d.hpp +++ b/modules/viz/include/opencv2/viz/viz3d.hpp @@ -38,6 +38,9 @@ namespace cv Affine3f getViewerPose(); void setViewerPose(const Affine3f &pose); + void resetCameraViewpoint (const String &id); + void resetCamera(); + void convertToWindowCoordinates(const Point3d &pt, Point3d &window_coord); void converTo3DRay(const Point3d &window_coord, Point3d &origin, Vec3d &direction); diff --git a/modules/viz/src/viz3d.cpp b/modules/viz/src/viz3d.cpp index 48f6ea3042..61911ca42c 100644 --- a/modules/viz/src/viz3d.cpp +++ b/modules/viz/src/viz3d.cpp @@ -67,6 +67,9 @@ cv::viz::Camera cv::viz::Viz3d::getCamera() const { return impl_->getCamera(); } void cv::viz::Viz3d::setViewerPose(const Affine3f &pose) { impl_->setViewerPose(pose); } cv::Affine3f cv::viz::Viz3d::getViewerPose() { return impl_->getViewerPose(); } +void cv::viz::Viz3d::resetCameraViewpoint (const String &id) { impl_->resetCameraViewpoint(id); } +void cv::viz::Viz3d::resetCamera() { impl_->resetCamera(); } + void cv::viz::Viz3d::convertToWindowCoordinates(const Point3d &pt, Point3d &window_coord) { impl_->convertToWindowCoordinates(pt, window_coord); } void cv::viz::Viz3d::converTo3DRay(const Point3d &window_coord, Point3d &origin, Vec3d &direction) { impl_->converTo3DRay(window_coord, origin, direction); } diff --git a/modules/viz/src/viz3d_impl.cpp b/modules/viz/src/viz3d_impl.cpp index 7a1518c2c0..00a5cae787 100644 --- a/modules/viz/src/viz3d_impl.cpp +++ b/modules/viz/src/viz3d_impl.cpp @@ -421,21 +421,21 @@ void cv::viz::Viz3d::VizImpl::converTo3DRay(const Point3d &window_coord, Point3d } ///////////////////////////////////////////////////////////////////////////////////////////// -void cv::viz::Viz3d::VizImpl::resetCameraViewpoint (const std::string &id) +void cv::viz::Viz3d::VizImpl::resetCameraViewpoint (const String &id) { vtkSmartPointer camera_pose; static WidgetActorMap::iterator it = widget_actor_map_->find (id); if (it != widget_actor_map_->end ()) { vtkProp3D *actor = vtkProp3D::SafeDownCast(it->second); + CV_Assert("Widget is not 3D." && actor); camera_pose = actor->GetUserMatrix(); } else return; // Prevent a segfault - if (!camera_pose) - return; + if (!camera_pose) return; vtkSmartPointer cam = renderer_->GetActiveCamera (); cam->SetPosition (camera_pose->GetElement (0, 3), @@ -455,6 +455,12 @@ void cv::viz::Viz3d::VizImpl::resetCameraViewpoint (const std::string &id) renderer_->Render (); } +/////////////////////////////////////////////////////////////////////////////////// +void cv::viz::Viz3d::VizImpl::resetCamera() +{ + renderer_->ResetCamera(); +} + /////////////////////////////////////////////////////////////////////////////////// void cv::viz::Viz3d::VizImpl::setRepresentationToSurface() { diff --git a/modules/viz/src/viz3d_impl.hpp b/modules/viz/src/viz3d_impl.hpp index b2339c40c8..0eab85bc5b 100644 --- a/modules/viz/src/viz3d_impl.hpp +++ b/modules/viz/src/viz3d_impl.hpp @@ -49,18 +49,14 @@ public: void setRepresentationToSurface(); void setRepresentationToPoints(); void setRepresentationToWireframe(); - - - // //////////////////////////////////////////////////////////////////////////////////// - // All camera methods to refactor into set/getViewwerPose, setCamera() - // and 'Camera' class itself with various constructors/fields void setCamera(const Camera &camera); Camera getCamera() const; /** \brief Reset the camera direction from {0, 0, 0} to the center_{x, y, z} of a given dataset. * \param[in] id the point cloud object id (default: cloud) */ - void resetCameraViewpoint (const String& id = "cloud"); + void resetCameraViewpoint(const String& id); + void resetCamera(); void setViewerPose(const Affine3f &pose); Affine3f getViewerPose(); From 2705113bc4c82c17c984da77e2d2921747ae3489 Mon Sep 17 00:00:00 2001 From: ozantonkal Date: Sat, 31 Aug 2013 12:39:41 +0200 Subject: [PATCH 21/29] remove common.cpp, remove commented code in common.h --- modules/viz/src/common.cpp | 265 ------------------------------------- modules/viz/src/common.h | 14 -- 2 files changed, 279 deletions(-) delete mode 100644 modules/viz/src/common.cpp diff --git a/modules/viz/src/common.cpp b/modules/viz/src/common.cpp deleted file mode 100644 index 3c40a00f50..0000000000 --- a/modules/viz/src/common.cpp +++ /dev/null @@ -1,265 +0,0 @@ -#include -#include -#include -#include "viz3d_impl.hpp" - - -/////////////////////////////////////////////////////////////////////////////////////////////// -//Eigen::Vector2i cv::viz::worldToView (const Eigen::Vector4d &world_pt, const Eigen::Matrix4d &view_projection_matrix, int width, int height) -//{ -// // Transform world to clipping coordinates -// Eigen::Vector4d world (view_projection_matrix * world_pt); -// // Normalize w-component -// world /= world.w (); - -// // X/Y screen space coordinate -// int screen_x = int (floor (double (((world.x () + 1) / 2.0) * width) + 0.5)); -// int screen_y = int (floor (double (((world.y () + 1) / 2.0) * height) + 0.5)); - -// // Calculate -world_pt.y () because the screen Y axis is oriented top->down, ie 0 is top-left -// //int winY = (int) floor ( (double) (((1 - world_pt.y ()) / 2.0) * height) + 0.5); // top left - -// return (Eigen::Vector2i (screen_x, screen_y)); -//} - -///////////////////////////////////////////////////////////////////////////////////////////// -//void cv::viz::getViewFrustum (const Eigen::Matrix4d &view_projection_matrix, double planes[24]) -//{ -// // Set up the normals -// Eigen::Vector4d normals[6]; -// for (int i=0; i < 6; i++) -// { -// normals[i] = Eigen::Vector4d (0.0, 0.0, 0.0, 1.0); - -// // if i is even set to -1, if odd set to +1 -// normals[i] (i/2) = 1 - (i%2)*2; -// } - -// // Transpose the matrix for use with normals -// Eigen::Matrix4d view_matrix = view_projection_matrix.transpose (); - -// // Transform the normals to world coordinates -// for (int i=0; i < 6; i++) -// { -// normals[i] = view_matrix * normals[i]; - -// double f = 1.0/sqrt (normals[i].x () * normals[i].x () + -// normals[i].y () * normals[i].y () + -// normals[i].z () * normals[i].z ()); - -// planes[4*i + 0] = normals[i].x ()*f; -// planes[4*i + 1] = normals[i].y ()*f; -// planes[4*i + 2] = normals[i].z ()*f; -// planes[4*i + 3] = normals[i].w ()*f; -// } -//} - -//int cv::viz::cullFrustum (double frustum[24], const Eigen::Vector3d &min_bb, const Eigen::Vector3d &max_bb) -//{ -// int result = PCL_INSIDE_FRUSTUM; - -// for(int i =0; i < 6; i++){ -// double a = frustum[(i*4)]; -// double b = frustum[(i*4)+1]; -// double c = frustum[(i*4)+2]; -// double d = frustum[(i*4)+3]; - -// //cout << i << ": " << a << "x + " << b << "y + " << c << "z + " << d << endl; - -// // Basic VFC algorithm -// Eigen::Vector3d center ((max_bb.x () - min_bb.x ()) / 2 + min_bb.x (), -// (max_bb.y () - min_bb.y ()) / 2 + min_bb.y (), -// (max_bb.z () - min_bb.z ()) / 2 + min_bb.z ()); - -// Eigen::Vector3d radius (fabs (static_cast (max_bb.x () - center.x ())), -// fabs (static_cast (max_bb.y () - center.y ())), -// fabs (static_cast (max_bb.z () - center.z ()))); - -// double m = (center.x () * a) + (center.y () * b) + (center.z () * c) + d; -// double n = (radius.x () * fabs(a)) + (radius.y () * fabs(b)) + (radius.z () * fabs(c)); - -// if (m + n < 0){ -// result = PCL_OUTSIDE_FRUSTUM; -// break; -// } - -// if (m - n < 0) -// { -// result = PCL_INTERSECT_FRUSTUM; -// } -// } - -// return result; -//} - -//void -//cv::viz::getModelViewPosition (Eigen::Matrix4d model_view_matrix, Eigen::Vector3d &position) -//{ -// //Compute eye or position from model view matrix -// Eigen::Matrix4d inverse_model_view_matrix = model_view_matrix.inverse(); -// for (int i=0; i < 3; i++) -// { -// position(i) = inverse_model_view_matrix(i, 3); -// } -//} - -// Lookup table of max 6 bounding box vertices, followed by number of vertices, ie {v0, v1, v2, v3, v4, v5, nv} -// -// 3--------2 -// /| /| Y 0 = xmin, ymin, zmin -// / | / | | 6 = xmax, ymax. zmax -// 7--------6 | | -// | | | | | -// | 0-----|--1 +------X -// | / | / / -// |/ |/ / -// 4--------5 Z - -int hull_vertex_table[43][7] = { - { 0, 0, 0, 0, 0, 0, 0 }, // inside - { 0, 4, 7, 3, 0, 0, 4 }, // left - { 1, 2, 6, 5, 0, 0, 4 }, // right - { 0, 0, 0, 0, 0, 0, 0 }, - { 0, 1, 5, 4, 0, 0, 4 }, // bottom - { 0, 1, 5, 4, 7, 3, 6 }, // bottom, left - { 0, 1, 2, 6, 5, 4, 6 }, // bottom, right - { 0, 0, 0, 0, 0, 0, 0 }, - { 2, 3, 7, 6, 0, 0, 4 }, // top - { 4, 7, 6, 2, 3, 0, 6 }, // top, left - { 2, 3, 7, 6, 5, 1, 6 }, // top, right - { 0, 0, 0, 0, 0, 0, 0 }, - { 0, 0, 0, 0, 0, 0, 0 }, - { 0, 0, 0, 0, 0, 0, 0 }, - { 0, 0, 0, 0, 0, 0, 0 }, - { 0, 0, 0, 0, 0, 0, 0 }, - { 0, 3, 2, 1, 0, 0, 4 }, // front - { 0, 4, 7, 3, 2, 1, 6 }, // front, left - { 0, 3, 2, 6, 5, 1, 6 }, // front, right - { 0, 0, 0, 0, 0, 0, 0 }, - { 0, 3, 2, 1, 5, 4, 6 }, // front, bottom - { 2, 1, 5, 4, 7, 3, 6 }, // front, bottom, left - { 0, 3, 2, 6, 5, 4, 6 }, - { 0, 0, 0, 0, 0, 0, 0 }, - { 0, 3, 7, 6, 2, 1, 6 }, // front, top - { 0, 4, 7, 6, 2, 1, 6 }, // front, top, left - { 0, 3, 7, 6, 5, 1, 6 }, // front, top, right - { 0, 0, 0, 0, 0, 0, 0 }, - { 0, 0, 0, 0, 0, 0, 0 }, - { 0, 0, 0, 0, 0, 0, 0 }, - { 0, 0, 0, 0, 0, 0, 0 }, - { 0, 0, 0, 0, 0, 0, 0 }, - { 4, 5, 6, 7, 0, 0, 4 }, // back - { 4, 5, 6, 7, 3, 0, 6 }, // back, left - { 1, 2, 6, 7, 4, 5, 6 }, // back, right - { 0, 0, 0, 0, 0, 0, 0 }, - { 0, 1, 5, 6, 7, 4, 6 }, // back, bottom - { 0, 1, 5, 6, 7, 3, 6 }, // back, bottom, left - { 0, 1, 2, 6, 7, 4, 6 }, // back, bottom, right - { 0, 0, 0, 0, 0, 0, 0 }, - { 2, 3, 7, 4, 5, 6, 6 }, // back, top - { 0, 4, 5, 6, 2, 3, 6 }, // back, top, left - { 1, 2, 3, 7, 4, 5, 6 } // back, top, right -}; - -///////////////////////////////////////////////////////////////////////////////////////////// -//float -//cv::viz::viewScreenArea ( -// const Eigen::Vector3d &eye, -// const Eigen::Vector3d &min_bb, const Eigen::Vector3d &max_bb, -// const Eigen::Matrix4d &view_projection_matrix, int width, int height) -//{ -// Eigen::Vector4d bounding_box[8]; -// bounding_box[0] = Eigen::Vector4d(min_bb.x (), min_bb.y (), min_bb.z (), 1.0); -// bounding_box[1] = Eigen::Vector4d(max_bb.x (), min_bb.y (), min_bb.z (), 1.0); -// bounding_box[2] = Eigen::Vector4d(max_bb.x (), max_bb.y (), min_bb.z (), 1.0); -// bounding_box[3] = Eigen::Vector4d(min_bb.x (), max_bb.y (), min_bb.z (), 1.0); -// bounding_box[4] = Eigen::Vector4d(min_bb.x (), min_bb.y (), max_bb.z (), 1.0); -// bounding_box[5] = Eigen::Vector4d(max_bb.x (), min_bb.y (), max_bb.z (), 1.0); -// bounding_box[6] = Eigen::Vector4d(max_bb.x (), max_bb.y (), max_bb.z (), 1.0); -// bounding_box[7] = Eigen::Vector4d(min_bb.x (), max_bb.y (), max_bb.z (), 1.0); - -// // Compute 6-bit code to classify eye with respect to the 6 defining planes -// int pos = ((eye.x () < bounding_box[0].x ()) ) // 1 = left -// + ((eye.x () > bounding_box[6].x ()) << 1) // 2 = right -// + ((eye.y () < bounding_box[0].y ()) << 2) // 4 = bottom -// + ((eye.y () > bounding_box[6].y ()) << 3) // 8 = top -// + ((eye.z () < bounding_box[0].z ()) << 4) // 16 = front -// + ((eye.z () > bounding_box[6].z ()) << 5); // 32 = back - -// // Look up number of vertices -// int num = hull_vertex_table[pos][6]; -// if (num == 0) -// { -// return (float (width * height)); -// } -// //return 0.0; - - -// // cout << "eye: " << eye.x() << " " << eye.y() << " " << eye.z() << endl; -// // cout << "min: " << bounding_box[0].x() << " " << bounding_box[0].y() << " " << bounding_box[0].z() << endl; -// // -// // cout << "pos: " << pos << " "; -// // switch(pos){ -// // case 0: cout << "inside" << endl; break; -// // case 1: cout << "left" << endl; break; -// // case 2: cout << "right" << endl; break; -// // case 3: -// // case 4: cout << "bottom" << endl; break; -// // case 5: cout << "bottom, left" << endl; break; -// // case 6: cout << "bottom, right" << endl; break; -// // case 7: -// // case 8: cout << "top" << endl; break; -// // case 9: cout << "top, left" << endl; break; -// // case 10: cout << "top, right" << endl; break; -// // case 11: -// // case 12: -// // case 13: -// // case 14: -// // case 15: -// // case 16: cout << "front" << endl; break; -// // case 17: cout << "front, left" << endl; break; -// // case 18: cout << "front, right" << endl; break; -// // case 19: -// // case 20: cout << "front, bottom" << endl; break; -// // case 21: cout << "front, bottom, left" << endl; break; -// // case 22: -// // case 23: -// // case 24: cout << "front, top" << endl; break; -// // case 25: cout << "front, top, left" << endl; break; -// // case 26: cout << "front, top, right" << endl; break; -// // case 27: -// // case 28: -// // case 29: -// // case 30: -// // case 31: -// // case 32: cout << "back" << endl; break; -// // case 33: cout << "back, left" << endl; break; -// // case 34: cout << "back, right" << endl; break; -// // case 35: -// // case 36: cout << "back, bottom" << endl; break; -// // case 37: cout << "back, bottom, left" << endl; break; -// // case 38: cout << "back, bottom, right" << endl; break; -// // case 39: -// // case 40: cout << "back, top" << endl; break; -// // case 41: cout << "back, top, left" << endl; break; -// // case 42: cout << "back, top, right" << endl; break; -// // } - -// //return -1 if inside -// Eigen::Vector2d dst[8]; -// for (int i = 0; i < num; i++) -// { -// Eigen::Vector4d world_pt = bounding_box[hull_vertex_table[pos][i]]; -// Eigen::Vector2i screen_pt = cv::viz::worldToView(world_pt, view_projection_matrix, width, height); -// // cout << "point[" << i << "]: " << screen_pt.x() << " " << screen_pt.y() << endl; -// dst[i] = Eigen::Vector2d(screen_pt.x (), screen_pt.y ()); -// } - -// double sum = 0.0; -// for (int i = 0; i < num; ++i) -// { -// sum += (dst[i].x () - dst[(i+1) % num].x ()) * (dst[i].y () + dst[(i+1) % num].y ()); -// } - -// return (fabsf (float (sum * 0.5f))); -//} diff --git a/modules/viz/src/common.h b/modules/viz/src/common.h index ea89334178..7e13b0fee3 100644 --- a/modules/viz/src/common.h +++ b/modules/viz/src/common.h @@ -8,20 +8,6 @@ namespace cv { namespace viz { - //CV_EXPORTS Eigen::Matrix4d vtkToEigen (vtkMatrix4x4* vtk_matrix); - //CV_EXPORTS Eigen::Vector2i worldToView (const Eigen::Vector4d &world_pt, const Eigen::Matrix4d &view_projection_matrix, int width, int height); - //CV_EXPORTS void getViewFrustum (const Eigen::Matrix4d &view_projection_matrix, double planes[24]); - - // enum FrustumCull - // { - // PCL_INSIDE_FRUSTUM, - // PCL_INTERSECT_FRUSTUM, - // PCL_OUTSIDE_FRUSTUM - // }; - - //CV_EXPORTS int cullFrustum (double planes[24], const Eigen::Vector3d &min_bb, const Eigen::Vector3d &max_bb); - //CV_EXPORTS float viewScreenArea (const Eigen::Vector3d &eye, const Eigen::Vector3d &min_bb, const Eigen::Vector3d &max_bb, const Eigen::Matrix4d &view_projection_matrix, int width, int height); - enum RenderingProperties { VIZ_POINT_SIZE, From 21be9796ae3a0705124c9dc4971f6351eb839fcc Mon Sep 17 00:00:00 2001 From: Ozan Tonkal Date: Sun, 1 Sep 2013 12:29:01 +0200 Subject: [PATCH 22/29] comments on widgets where constructors might be confusing --- modules/viz/include/opencv2/viz.hpp | 9 +++++--- modules/viz/include/opencv2/viz/types.hpp | 11 +++------- modules/viz/include/opencv2/viz/widgets.hpp | 23 ++++++++++++++++++--- 3 files changed, 29 insertions(+), 14 deletions(-) diff --git a/modules/viz/include/opencv2/viz.hpp b/modules/viz/include/opencv2/viz.hpp index 0a82a9ebb7..7f7cc7d2fe 100644 --- a/modules/viz/include/opencv2/viz.hpp +++ b/modules/viz/include/opencv2/viz.hpp @@ -65,9 +65,10 @@ namespace cv //! takes coordiante frame data and builds transfrom to global coordinate frame CV_EXPORTS Affine3f makeTransformToGlobal(const Vec3f& axis_x, const Vec3f& axis_y, const Vec3f& axis_z, const Vec3f& origin = Vec3f::all(0)); - //! constructs camera pose from position, focal_point and up_vector (see gluLookAt() for more infromation + //! constructs camera pose from position, focal_point and up_vector (see gluLookAt() for more infromation) CV_EXPORTS Affine3f makeCameraPose(const Vec3f& position, const Vec3f& focal_point, const Vec3f& y_dir); + //! retrieves a window by its name CV_EXPORTS Viz3d get(const String &window_name); //! checks float value for Nan @@ -92,6 +93,7 @@ namespace cv template inline bool isNan(const Point3_<_Tp>& p) { return isNan(p.x) || isNan(p.y) || isNan(p.z); } + //! helper class that provides access by name infrastructure class CV_EXPORTS VizAccessor { public: @@ -102,6 +104,7 @@ namespace cv void add(Viz3d window); void remove(const String &window_name); + //! window names automatically have Viz - prefix even though not provided by the users static void generateWindowName(const String &window_name, String &output); private: @@ -112,8 +115,8 @@ namespace cv static bool is_instantiated_; static VizMap viz_map_; }; - } -} + } /* namespace viz */ +} /* namespace cv */ #endif /* __OPENCV_VIZ_HPP__ */ diff --git a/modules/viz/include/opencv2/viz/types.hpp b/modules/viz/include/opencv2/viz/types.hpp index f41b5fa0f4..26aa204406 100644 --- a/modules/viz/include/opencv2/viz/types.hpp +++ b/modules/viz/include/opencv2/viz/types.hpp @@ -39,6 +39,7 @@ namespace cv Mat cloud, colors; Mat polygons; + //! Loads mesh from a given ply file static cv::viz::Mesh3d loadMesh(const String& file); private: @@ -52,14 +53,8 @@ namespace cv static const unsigned int Ctrl = 2; static const unsigned int Shift = 4; - /** \brief Constructor - * \param[in] action true for key was pressed, false for released - * \param[in] key_sym the key-name that caused the action - * \param[in] key the key code that caused the action - * \param[in] alt whether the alt key was pressed at the time where this event was triggered - * \param[in] ctrl whether the ctrl was pressed at the time where this event was triggered - * \param[in] shift whether the shift was pressed at the time where this event was triggered - */ + //! Create a keyboard event + //! - Note that action is true if key is pressed, false if released KeyboardEvent (bool action, const std::string& key_sym, unsigned char key, bool alt, bool ctrl, bool shift); bool isAltPressed () const; diff --git a/modules/viz/include/opencv2/viz/widgets.hpp b/modules/viz/include/opencv2/viz/widgets.hpp index 9f1d14f13c..fb2d6ca349 100644 --- a/modules/viz/include/opencv2/viz/widgets.hpp +++ b/modules/viz/include/opencv2/viz/widgets.hpp @@ -18,11 +18,14 @@ namespace cv Widget& operator=(const Widget& other); ~Widget(); + //! Create a widget directly from ply file static Widget fromPlyFile(const String &file_name); + //! Rendering properties of this particular widget void setRenderingProperty(int property, double value); double getRenderingProperty(int property) const; + //! Casting between widgets template _W cast(); private: class Impl; @@ -120,7 +123,9 @@ namespace cv class CV_EXPORTS GridWidget : public Widget3D { public: + //! Creates grid at the origin GridWidget(const Vec2i &dimensions, const Vec2d &spacing, const Color &color = Color::white()); + //! Creates grid based on the plane equation GridWidget(const Vec4f &coeffs, const Vec2i &dimensions, const Vec2d &spacing, const Color &color = Color::white()); private: @@ -157,7 +162,9 @@ namespace cv class CV_EXPORTS Image3DWidget : public Widget3D { public: + //! Creates 3D image at the origin Image3DWidget(const Mat &image, const Size &size); + //! Creates 3D image at a given position, pointing in the direction of the normal, and having the up_vector orientation Image3DWidget(const Vec3f &position, const Vec3f &normal, const Vec3f &up_vector, const Mat &image, const Size &size); void setImage(const Mat &image); @@ -166,11 +173,14 @@ namespace cv class CV_EXPORTS CameraPositionWidget : public Widget3D { public: + //! Creates camera coordinate frame (axes) at the origin CameraPositionWidget(double scale = 1.0); + //! Creates frustum based on the intrinsic marix K at the origin CameraPositionWidget(const Matx33f &K, double scale = 1.0, const Color &color = Color::white()); + //! Creates frustum based on the field of view at the origin CameraPositionWidget(const Vec2f &fov, double scale = 1.0, const Color &color = Color::white()); + //! Creates frustum and display given image at the far plane CameraPositionWidget(const Matx33f &K, const Mat &img, double scale = 1.0, const Color &color = Color::white()); - }; class CV_EXPORTS TrajectoryWidget : public Widget3D @@ -178,9 +188,12 @@ namespace cv public: enum {DISPLAY_FRAMES = 1, DISPLAY_PATH = 2}; + //! Displays trajectory of the given path either by coordinate frames or polyline TrajectoryWidget(const std::vector &path, int display_mode = TrajectoryWidget::DISPLAY_PATH, const Color &color = Color::white(), double scale = 1.0); - TrajectoryWidget(const std::vector &path, const Matx33f &K, double scale = 1.0, const Color &color = Color::white()); // Camera frustums - TrajectoryWidget(const std::vector &path, const Vec2f &fov, double scale = 1.0, const Color &color = Color::white()); // Camera frustums + //! Displays trajectory of the given path by frustums + TrajectoryWidget(const std::vector &path, const Matx33f &K, double scale = 1.0, const Color &color = Color::white()); + //! Displays trajectory of the given path by frustums + TrajectoryWidget(const std::vector &path, const Vec2f &fov, double scale = 1.0, const Color &color = Color::white()); private: struct ApplyPath; @@ -196,7 +209,9 @@ namespace cv class CV_EXPORTS CloudWidget : public Widget3D { public: + //! Each point in cloud is mapped to a color in colors CloudWidget(InputArray cloud, InputArray colors); + //! All points in cloud have the same color CloudWidget(InputArray cloud, const Color &color = Color::white()); private: @@ -208,7 +223,9 @@ namespace cv public: CloudCollectionWidget(); + //! Each point in cloud is mapped to a color in colors void addCloud(InputArray cloud, InputArray colors, const Affine3f &pose = Affine3f::Identity()); + //! All points in cloud have the same color void addCloud(InputArray cloud, const Color &color = Color::white(), const Affine3f &pose = Affine3f::Identity()); private: From 9d4fe6984b694596003e809d84808a7c646f1d6c Mon Sep 17 00:00:00 2001 From: Ozan Tonkal Date: Sun, 1 Sep 2013 14:59:14 +0200 Subject: [PATCH 23/29] remove setWindowName method to avoid complications --- modules/viz/include/opencv2/viz/viz3d.hpp | 1 - modules/viz/src/viz3d.cpp | 1 - modules/viz/src/viz3d_impl.cpp | 6 ------ modules/viz/src/viz3d_impl.hpp | 1 - 4 files changed, 9 deletions(-) diff --git a/modules/viz/include/opencv2/viz/viz3d.hpp b/modules/viz/include/opencv2/viz/viz3d.hpp index a54493611d..988f7ed5f2 100644 --- a/modules/viz/include/opencv2/viz/viz3d.hpp +++ b/modules/viz/include/opencv2/viz/viz3d.hpp @@ -50,7 +50,6 @@ namespace cv void saveScreenshot (const String &file); void setWindowPosition (int x, int y); void setFullScreen (bool mode); - void setWindowName (const String &name); void setBackgroundColor(const Color& color = Color::black()); void spin(); diff --git a/modules/viz/src/viz3d.cpp b/modules/viz/src/viz3d.cpp index 61911ca42c..1b45f3a56a 100644 --- a/modules/viz/src/viz3d.cpp +++ b/modules/viz/src/viz3d.cpp @@ -79,7 +79,6 @@ cv::String cv::viz::Viz3d::getWindowName() const { return impl_->getWindowName() void cv::viz::Viz3d::saveScreenshot (const String &file) { impl_->saveScreenshot(file); } void cv::viz::Viz3d::setWindowPosition (int x, int y) { impl_->setWindowPosition(x,y); } void cv::viz::Viz3d::setFullScreen (bool mode) { impl_->setFullScreen(mode); } -void cv::viz::Viz3d::setWindowName (const String &name) { impl_->setWindowName(name); } void cv::viz::Viz3d::setBackgroundColor(const Color& color) { impl_->setBackgroundColor(color); } void cv::viz::Viz3d::setRenderingProperty(int property, double value, const String &id) { getWidget(id).setRenderingProperty(property, value); } diff --git a/modules/viz/src/viz3d_impl.cpp b/modules/viz/src/viz3d_impl.cpp index 00a5cae787..f99fd8e1f9 100644 --- a/modules/viz/src/viz3d_impl.cpp +++ b/modules/viz/src/viz3d_impl.cpp @@ -542,12 +542,6 @@ void cv::viz::Viz3d::VizImpl::setFullScreen (bool mode) } ////////////////////////////////////////////////////////////////////////////////////////////// -void cv::viz::Viz3d::VizImpl::setWindowName (const std::string &name) -{ - if (window_) - window_->SetWindowName (name.c_str ()); -} - cv::String cv::viz::Viz3d::VizImpl::getWindowName() const { return (window_ ? window_->GetWindowName() : ""); diff --git a/modules/viz/src/viz3d_impl.hpp b/modules/viz/src/viz3d_impl.hpp index 0eab85bc5b..7e31501ed0 100644 --- a/modules/viz/src/viz3d_impl.hpp +++ b/modules/viz/src/viz3d_impl.hpp @@ -69,7 +69,6 @@ public: Size getWindowSize() const; void setWindowSize (int xw, int yw); void setFullScreen (bool mode); - void setWindowName (const String &name); String getWindowName() const; void setBackgroundColor (const Color& color); From 2822845ba6ba8c3637b30e86fa345f6de5178f24 Mon Sep 17 00:00:00 2001 From: Ozan Tonkal Date: Sun, 1 Sep 2013 15:46:46 +0200 Subject: [PATCH 24/29] set get RenderingProperty id comes first --- modules/viz/include/opencv2/viz/viz3d.hpp | 4 ++-- modules/viz/src/viz3d.cpp | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/modules/viz/include/opencv2/viz/viz3d.hpp b/modules/viz/include/opencv2/viz/viz3d.hpp index 988f7ed5f2..4c6015d7d8 100644 --- a/modules/viz/include/opencv2/viz/viz3d.hpp +++ b/modules/viz/include/opencv2/viz/viz3d.hpp @@ -59,8 +59,8 @@ namespace cv void registerKeyboardCallback(KeyboardCallback callback, void* cookie = 0); void registerMouseCallback(MouseCallback callback, void* cookie = 0); - void setRenderingProperty(int property, double value, const String &id); - double getRenderingProperty(int property, const String &id); + void setRenderingProperty(const String &id, int property, double value); + double getRenderingProperty(const String &id, int property); void setDesiredUpdateRate(double time); double getDesiredUpdateRate(); diff --git a/modules/viz/src/viz3d.cpp b/modules/viz/src/viz3d.cpp index 1b45f3a56a..068d9b1b7a 100644 --- a/modules/viz/src/viz3d.cpp +++ b/modules/viz/src/viz3d.cpp @@ -81,8 +81,8 @@ void cv::viz::Viz3d::setWindowPosition (int x, int y) { impl_->setWindowPosition void cv::viz::Viz3d::setFullScreen (bool mode) { impl_->setFullScreen(mode); } void cv::viz::Viz3d::setBackgroundColor(const Color& color) { impl_->setBackgroundColor(color); } -void cv::viz::Viz3d::setRenderingProperty(int property, double value, const String &id) { getWidget(id).setRenderingProperty(property, value); } -double cv::viz::Viz3d::getRenderingProperty(int property, const String &id) { return getWidget(id).getRenderingProperty(property); } +void cv::viz::Viz3d::setRenderingProperty(const String &id, int property, double value) { getWidget(id).setRenderingProperty(property, value); } +double cv::viz::Viz3d::getRenderingProperty(const String &id, int property) { return getWidget(id).getRenderingProperty(property); } void cv::viz::Viz3d::setDesiredUpdateRate(double time) { impl_->setDesiredUpdateRate(time); } double cv::viz::Viz3d::getDesiredUpdateRate() { return impl_->getDesiredUpdateRate(); } From a5b75769a3150d723026c40fe41e588c7f6e144c Mon Sep 17 00:00:00 2001 From: Ozan Tonkal Date: Sun, 1 Sep 2013 19:34:17 +0200 Subject: [PATCH 25/29] initial documentation --- modules/viz/doc/viz.rst | 11 + modules/viz/doc/viz3d.rst | 556 +++++++++++++++++++++++++ modules/viz/doc/widget.rst | 811 +++++++++++++++++++++++++++++++++++++ 3 files changed, 1378 insertions(+) create mode 100644 modules/viz/doc/viz.rst create mode 100644 modules/viz/doc/viz3d.rst create mode 100644 modules/viz/doc/widget.rst diff --git a/modules/viz/doc/viz.rst b/modules/viz/doc/viz.rst new file mode 100644 index 0000000000..f51a151e09 --- /dev/null +++ b/modules/viz/doc/viz.rst @@ -0,0 +1,11 @@ +*********************** +viz. 3D Visualizer +*********************** + +.. toctree:: + :maxdepth: 2 + + viz3d.rst + widget.rst + types.rst + widget_accessor.rst diff --git a/modules/viz/doc/viz3d.rst b/modules/viz/doc/viz3d.rst new file mode 100644 index 0000000000..e7dcc358c4 --- /dev/null +++ b/modules/viz/doc/viz3d.rst @@ -0,0 +1,556 @@ +Viz3d +===== + +.. highlight:: cpp + +Viz3d +----- +.. ocv:class:: Viz3d + +The Viz3d class represents a 3D visualizer window. This class is implicitly shared. :: + + class CV_EXPORTS Viz3d + { + public: + typedef cv::Ptr Ptr; + typedef void (*KeyboardCallback)(const KeyboardEvent&, void*); + typedef void (*MouseCallback)(const MouseEvent&, void*); + + Viz3d(const String& window_name = String()); + Viz3d(const Viz3d&); + Viz3d& operator=(const Viz3d&); + ~Viz3d(); + + void showWidget(const String &id, const Widget &widget, const Affine3f &pose = Affine3f::Identity()); + void removeWidget(const String &id); + Widget getWidget(const String &id) const; + void removeAllWidgets(); + + void setWidgetPose(const String &id, const Affine3f &pose); + void updateWidgetPose(const String &id, const Affine3f &pose); + Affine3f getWidgetPose(const String &id) const; + + void setCamera(const Camera &camera); + Camera getCamera() const; + Affine3f getViewerPose(); + void setViewerPose(const Affine3f &pose); + + void resetCameraViewpoint (const String &id); + void resetCamera(); + + void convertToWindowCoordinates(const Point3d &pt, Point3d &window_coord); + void converTo3DRay(const Point3d &window_coord, Point3d &origin, Vec3d &direction); + + Size getWindowSize() const; + void setWindowSize(const Size &window_size); + String getWindowName() const; + void saveScreenshot (const String &file); + void setWindowPosition (int x, int y); + void setFullScreen (bool mode); + void setBackgroundColor(const Color& color = Color::black()); + + void spin(); + void spinOnce(int time = 1, bool force_redraw = false); + bool wasStopped() const; + + void registerKeyboardCallback(KeyboardCallback callback, void* cookie = 0); + void registerMouseCallback(MouseCallback callback, void* cookie = 0); + + void setRenderingProperty(const String &id, int property, double value); + double getRenderingProperty(const String &id, int property); + + void setDesiredUpdateRate(double rate); + double getDesiredUpdateRate(); + + void setRepresentationToSurface(); + void setRepresentationToWireframe(); + void setRepresentationToPoints(); + private: + /* hidden */ + }; + +Viz3d::Viz3d +------------ +The constructors. + +.. ocv:function:: Viz3d::Viz3d(const String& window_name = String()) + + :param window_name: Name of the window. + +Viz3d::showWidget +----------------- +Shows a widget in the window. + +.. ocv:function:: void Viz3d::showWidget(const String &id, const Widget &widget, const Affine3f &pose = Affine3f::Identity()) + + :param id: A unique id for the widget. + :param widget: The widget to be rendered in the window. + :param pose: Pose of the widget. + +Viz3d::removeWidget +------------------- +Removes a widget from the window. + +.. ocv:function:: void removeWidget(const String &id) + + :param id: The id of the widget that will be removed. + +Viz3d::getWidget +---------------- +Retrieves a widget from the window. A widget is implicitly shared; +that is, if the returned widget is modified, the changes will be +immediately visible in the window. + +.. ocv:function:: Widget getWidget(const String &id) const + + :param id: The id of the widget that will be returned. + +Viz3d::removeAllWidgets +----------------------- +Removes all widgets from the window. + +.. ocv:function:: void removeAllWidgets() + +Viz3d::setWidgetPose +-------------------- +Sets pose of a widget in the window. + +.. ocv:function:: void setWidgetPose(const String &id, const Affine3f &pose) + + :param id: The id of the widget whose pose will be set. + :param pose: The new pose of the widget. + +Viz3d::updateWidgetPose +----------------------- +Updates pose of a widget in the window by pre-multiplying its current pose. + +.. ocv:function:: void updateWidgetPose(const String &id, const Affine3f &pose) + + :param id: The id of the widget whose pose will be updated. + :param pose: The pose that the current pose of the widget will be pre-multiplied by. + +Viz3d::getWidgetPose +-------------------- +Returns the current pose of a widget in the window. + +.. ocv:function:: Affine3f getWidgetPose(const String &id) const + + :param id: The id of the widget whose pose will be returned. + +Viz3d::setCamera +---------------- +Sets the intrinsic parameters of the viewer using Camera. + +.. ocv:function:: void setCamera(const Camera &camera) + + :param camera: Camera object wrapping intrinsinc parameters. + +Viz3d::getCamera +---------------- +Returns a camera object that contains intrinsic parameters of the current viewer. + +.. ocv:function:: Camera getCamera() const + +Viz3d::getViewerPose +-------------------- +Returns the current pose of the viewer. + +..ocv:function:: Affine3f getViewerPose() + +Viz3d::setViewerPose +-------------------- +Sets pose of the viewer. + +.. ocv:function:: void setViewerPose(const Affine3f &pose) + + :param pose: The new pose of the viewer. + +Viz3d::resetCameraViewpoint +--------------------------- +Resets camera viewpoint to a 3D widget in the scene. + +.. ocv:function:: void resetCameraViewpoint (const String &id) + + :param pose: Id of a 3D widget. + +Viz3d::resetCamera +------------------ +Resets camera. + +.. ocv:function:: void resetCamera() + +Viz3d::convertToWindowCoordinates +--------------------------------- +Transforms a point in world coordinate system to window coordinate system. + +.. ocv:function:: void convertToWindowCoordinates(const Point3d &pt, Point3d &window_coord) + + :param pt: Point in world coordinate system. + :param window_coord: Output point in window coordinate system. + +Viz3d::converTo3DRay +-------------------- +Transforms a point in window coordinate system to a 3D ray in world coordinate system. + +.. ocv:function:: void converTo3DRay(const Point3d &window_coord, Point3d &origin, Vec3d &direction) + + :param window_coord: Point in window coordinate system. + :param origin: Output origin of the ray. + :param direction: Output direction of the ray. + +Viz3d::getWindowSize +-------------------- +Returns the current size of the window. + +.. ocv:function:: Size getWindowSize() const + +Viz3d::setWindowSize +-------------------- +Sets the size of the window. + +.. ocv:function:: void setWindowSize(const Size &window_size) + + :param window_size: New size of the window. + +Viz3d::getWindowName +-------------------- +Returns the name of the window which has been set in the constructor. + +.. ocv:function:: String getWindowName() const + +Viz3d::saveScreenshot +--------------------- +Saves screenshot of the current scene. + +.. ocv:function:: void saveScreenshot(const String &file) + + :param file: Name of the file. + +Viz3d::setWindowPosition +------------------------ +Sets the position of the window in the screen. + +.. ocv:function:: void setWindowPosition(int x, int y) + + :param x: x coordinate of the window + :param y: y coordinate of the window + +Viz3d::setFullScreen +-------------------- +Sets or unsets full-screen rendering mode. + +.. ocv:function:: void setFullScreen(bool mode) + + :param mode: If true, window will use full-screen mode. + +Viz3d::setBackgroundColor +------------------------- +Sets background color. + +.. ocv:function:: void setBackgroundColor(const Color& color = Color::black()) + +Viz3d::spin +----------- +The window renders and starts the event loop. + +.. ocv:function:: void spin() + +Viz3d::spinOnce +--------------- +Starts the event loop for a given time. + +.. ocv:function:: void spinOnce(int time = 1, bool force_redraw = false) + + :param time: Amount of time in milliseconds for the event loop to keep running. + :param force_draw: If true, window renders. + +Viz3d::wasStopped +----------------- +Returns whether the event loop has been stopped. + +.. ocv:function:: bool wasStopped() + +Viz3d::registerKeyboardCallback +------------------------------- +Sets keyboard handler. + +.. ocv:function:: void registerKeyboardCallback(KeyboardCallback callback, void* cookie = 0) + + :param callback: Keyboard callback. + :param cookie: The optional parameter passed to the callback. + +Viz3d::registerMouseCallback +---------------------------- +Sets mouse handler. + +.. ocv:function:: void registerMouseCallback(MouseCallback callback, void* cookie = 0) + + :param callback: Mouse callback. + :param cookie: The optional parameter passed to the callback. + +Viz3d::setRenderingProperty +--------------------------- +Sets rendering property of a widget. + +.. ocv:function:: void setRenderingProperty(const String &id, int property, double value) + + :param id: Id of the widget. + :param property: Property that will be modified. + :param value: The new value of the property. + +Viz3d::getRenderingProperty +--------------------------- +Returns rendering property of a widget. + +.. ocv:function:: double getRenderingProperty(const String &id, int property) + + :param id: Id of the widget. + :param property: Property. + +Viz3d::setDesiredUpdateRate +--------------------------- +Sets desired update rate of the window. + +.. ocv:function:: void setDesiredUpdateRate(double rate) + + :param rate: Desired update rate. The default is 30. + +Viz3d::getDesiredUpdateRate +--------------------------- +Returns desired update rate of the window. + +.. ocv:function:: double getDesiredUpdateRate() + +Viz3d::setRepresentationToSurface +--------------------------------- +Sets geometry representation of the widgets to surface. + +.. ocv:function:: void setRepresentationToSurface() + +Viz3d::setRepresentationToWireframe +----------------------------------- +Sets geometry representation of the widgets to wireframe. + +.. ocv:function:: void setRepresentationToWireframe() + +Viz3d::setRepresentationToPoints +-------------------------------- +Sets geometry representation of the widgets to points. + +.. ocv:function:: void setRepresentationToPoints() + +Color +----- +.. ocv:class:: Color + +This class a represents BGR color. :: + + class CV_EXPORTS Color : public Scalar + { + public: + Color(); + Color(double gray); + Color(double blue, double green, double red); + + Color(const Scalar& color); + + static Color black(); + static Color blue(); + static Color green(); + static Color cyan(); + + static Color red(); + static Color magenta(); + static Color yellow(); + static Color white(); + + static Color gray(); + }; + +Mesh3d +------ +.. ocv:class:: Mesh3d + +This class wraps mesh attributes, and it can load a mesh from a ``ply`` file. :: + + class CV_EXPORTS Mesh3d + { + public: + + Mat cloud, colors; + Mat polygons; + + //! Loads mesh from a given ply file + static Mesh3d loadMesh(const String& file); + + private: + /* hidden */ + }; + +Mesh3d::loadMesh +---------------- +Loads a mesh from a ``ply`` file. + +.. ocv:function:: static Mesh3d loadMesh(const String& file) + + :param file: File name. + + +KeyboardEvent +------------- +.. ocv:class:: KeyboardEvent + +This class represents a keyboard event. :: + + class CV_EXPORTS KeyboardEvent + { + public: + static const unsigned int Alt = 1; + static const unsigned int Ctrl = 2; + static const unsigned int Shift = 4; + + //! Create a keyboard event + //! - Note that action is true if key is pressed, false if released + KeyboardEvent (bool action, const std::string& key_sym, unsigned char key, bool alt, bool ctrl, bool shift); + + bool isAltPressed () const; + bool isCtrlPressed () const; + bool isShiftPressed () const; + + unsigned char getKeyCode () const; + + const String& getKeySym () const; + bool keyDown () const; + bool keyUp () const; + + protected: + /* hidden */ + }; + +KeyboardEvent::KeyboardEvent +---------------------------- +Constructs a KeyboardEvent. + +.. ocv:function:: KeyboardEvent (bool action, const std::string& key_sym, unsigned char key, bool alt, bool ctrl, bool shift) + + :param action: If true, key is pressed. If false, key is released. + :param key_sym: Name of the key. + :param key: Code of the key. + :param alt: If true, ``alt`` is pressed. + :param ctrl: If true, ``ctrl`` is pressed. + :param shift: If true, ``shift`` is pressed. + +MouseEvent +---------- +.. ocv:class:: MouseEvent + +This class represents a mouse event. :: + + class CV_EXPORTS MouseEvent + { + public: + enum Type { MouseMove = 1, MouseButtonPress, MouseButtonRelease, MouseScrollDown, MouseScrollUp, MouseDblClick } ; + enum MouseButton { NoButton = 0, LeftButton, MiddleButton, RightButton, VScroll } ; + + MouseEvent (const Type& type, const MouseButton& button, const Point& p, bool alt, bool ctrl, bool shift); + + Type type; + MouseButton button; + Point pointer; + unsigned int key_state; + }; + +MouseEvent::MouseEvent +---------------------- +Constructs a MouseEvent. + +.. ocv:function:: MouseEvent (const Type& type, const MouseButton& button, const Point& p, bool alt, bool ctrl, bool shift) + + :param type: Type of the event. This can be **MouseMove**, **MouseButtonPress**, **MouseButtonRelease**, **MouseScrollDown**, **MouseScrollUp**, **MouseDblClick**. + :param button: Mouse button. This can be **NoButton**, **LeftButton**, **MiddleButton**, **RightButton**, **VScroll**. + :param p: Position of the event. + :param alt: If true, ``alt`` is pressed. + :param ctrl: If true, ``ctrl`` is pressed. + :param shift: If true, ``shift`` is pressed. + +Camera +------ +.. ocv:class:: Camera + +This class wraps intrinsic parameters of a camera. It provides several constructors +that can extract the intrinsic parameters from ``field of view``, ``intrinsic matrix`` and +``projection matrix``. :: + + class CV_EXPORTS Camera + { + public: + Camera(float f_x, float f_y, float c_x, float c_y, const Size &window_size); + Camera(const Vec2f &fov, const Size &window_size); + Camera(const cv::Matx33f &K, const Size &window_size); + Camera(const cv::Matx44f &proj, const Size &window_size); + + inline const Vec2d & getClip() const { return clip_; } + inline void setClip(const Vec2d &clip) { clip_ = clip; } + + inline const Size & getWindowSize() const { return window_size_; } + void setWindowSize(const Size &window_size); + + inline const Vec2f & getFov() const { return fov_; } + inline void setFov(const Vec2f & fov) { fov_ = fov; } + + inline const Vec2f & getPrincipalPoint() const { return principal_point_; } + inline const Vec2f & getFocalLength() const { return focal_; } + + void computeProjectionMatrix(Matx44f &proj) const; + + static Camera KinectCamera(const Size &window_size); + + private: + /* hidden */ + }; + +Camera::Camera +-------------- +Constructs a Camera. + +.. ocv:function:: Camera(float f_x, float f_y, float c_x, float c_y, const Size &window_size) + + :param f_x: Horizontal focal length. + :param f_y: Vertical focal length. + :param c_x: x coordinate of the principal point. + :param c_y: y coordinate of the principal point. + :param window_size: Size of the window. This together with focal length and principal point determines the field of view. + +.. ocv:function:: Camera(const Vec2f &fov, const Size &window_size) + + :param fov: Field of view (horizontal, vertical) + :param window_size: Size of the window. + + Principal point is at the center of the window by default. + +.. ocv:function:: Camera(const cv::Matx33f &K, const Size &window_size) + + :param K: Intrinsic matrix of the camera. + :param window_size: Size of the window. This together with intrinsic matrix determines the field of view. + +.. ocv:function:: Camera(const cv::Matx44f &proj, const Size &window_size) + + :param proj: Projection matrix of the camera. + :param window_size: Size of the window. This together with projection matrix determines the field of view. + +Camera::computeProjectionMatrix +------------------------------- +Computes projection matrix using intrinsic parameters of the camera. + +.. ocv:function:: void computeProjectionMatrix(Matx44f &proj) const + + :param proj: Output projection matrix. + +Camera::KinectCamera +-------------------- +Creates a Kinect Camera. + +.. ocv:function:: static Camera KinectCamera(const Size &window_size) + + :param window_size: Size of the window. This together with intrinsic matrix of a Kinect Camera determines the field of view. + diff --git a/modules/viz/doc/widget.rst b/modules/viz/doc/widget.rst new file mode 100644 index 0000000000..d4199fdc42 --- /dev/null +++ b/modules/viz/doc/widget.rst @@ -0,0 +1,811 @@ +Widget +====== + +.. highlight:: cpp + +In this section, the built-in widgets are presented. + +Widget +------ +.. ocv:class:: Widget + +Base class of all widgets. Widget is implicitly shared.:: + + class CV_EXPORTS Widget + { + public: + Widget(); + Widget(const Widget& other); + Widget& operator=(const Widget& other); + ~Widget(); + + //! Create a widget directly from ply file + static Widget fromPlyFile(const String &file_name); + + //! Rendering properties of this particular widget + void setRenderingProperty(int property, double value); + double getRenderingProperty(int property) const; + + //! Casting between widgets + template _W cast(); + private: + /* hidden */ + }; + +Widget::fromPlyFile +------------------- +Creates a widget from ply file. + +.. ocv:function:: static Widget fromPlyFile(const String &file_name) + + :param file_name: Ply file name. + +Widget::setRenderingProperty +---------------------------- +Sets rendering property of the widget. + +.. ocv:function:: void setRenderingProperty(int property, double value) + + :param property: Property that will be modified. + :param value: The new value of the property. + +Widget::getRenderingProperty +---------------------------- +Returns rendering property of the widget. + +.. ocv:function:: double getRenderingProperty(int property) const + + :param property: Property. + +Widget::cast +------------ +Casts a widget to another. + +.. ocv:function:: template _W cast() + +Widget3D +-------- +.. ocv:class:: Widget3D + +Base class of all 3D widgets. :: + + class CV_EXPORTS Widget3D : public Widget + { + public: + Widget3D() {} + + void setPose(const Affine3f &pose); + void updatePose(const Affine3f &pose); + Affine3f getPose() const; + + void setColor(const Color &color); + private: + /* hidden */ + }; + +Widget3D::setPose +----------------- +Sets pose of the widget. + +.. ocv:function:: void setPose(const Affine3f &pose) + + :param pose: The new pose of the widget. + +Widget3D::updateWidgetPose +-------------------------- +Updates pose of the widget by pre-multiplying its current pose. + +.. ocv:function:: void updateWidgetPose(const Affine3f &pose) + + :param pose: The pose that the current pose of the widget will be pre-multiplied by. + +Widget3D::getPose +----------------- +Returns the current pose of the widget. + +.. ocv:function:: Affine3f getWidgetPose() const + +Widget3D::setColor +------------------ +Sets the color of the widget. + +.. ocv:function:: void setColor(const Color &color) + + :param color: Color + +Widget2D +-------- +.. ocv:class:: Widget2D + +Base class of all 2D widgets. :: + + class CV_EXPORTS Widget2D : public Widget + { + public: + Widget2D() {} + + void setColor(const Color &color); + }; + +Widget2D::setColor +------------------ +Sets the color of the widget. + +.. ocv:function:: void setColor(const Color &color) + + :param color: Color + +LineWidget +---------- +.. ocv:class:: LineWidget + +This 3D Widget defines a finite line. :: + + class CV_EXPORTS LineWidget : public Widget3D + { + public: + LineWidget(const Point3f &pt1, const Point3f &pt2, const Color &color = Color::white()); + }; + +LineWidget::LineWidget +---------------------- +Constructs a LineWidget. + +.. ocv:function:: LineWidget(const Point3f &pt1, const Point3f &pt2, const Color &color = Color::white()) + + :param pt1: Start point of the line. + :param pt2: End point of the line. + :param color: Color of the line. + +PlaneWidget +----------- +.. ocv:class:: PlaneWidget + +This 3D Widget defines a finite plane. :: + + class CV_EXPORTS PlaneWidget : public Widget3D + { + public: + PlaneWidget(const Vec4f& coefs, double size = 1.0, const Color &color = Color::white()); + PlaneWidget(const Vec4f& coefs, const Point3f& pt, double size = 1.0, const Color &color = Color::white()); + private: + /* hidden */ + }; + +PlaneWidget::PlaneWidget +------------------------ +Constructs a PlaneWidget. + +.. ocv:function:: PlaneWidget(const Vec4f& coefs, double size = 1.0, const Color &color = Color::white()) + + :param coefs: Plane coefficients as in (A,B,C,D) where Ax + By + Cz + D = 0. + :param size: Size of the plane. + :param color: Color of the plane. + +.. ocv:function:: PlaneWidget(const Vec4f& coefs, const Point3f& pt, double size = 1.0, const Color &color = Color::white()) + + :param coefs: Plane coefficients as in (A,B,C,D) where Ax + By + Cz + D = 0. + :param pt: Position of the plane. + :param color: Color of the plane. + +SphereWidget +------------ +.. ocv:class:: SphereWidget + +This 3D Widget defines a sphere. :: + + class CV_EXPORTS SphereWidget : public Widget3D + { + public: + SphereWidget(const cv::Point3f ¢er, float radius, int sphere_resolution = 10, const Color &color = Color::white()) + }; + +SphereWidget::SphereWidget +-------------------------- +Constructs a SphereWidget. + +.. ocv:function:: SphereWidget(const cv::Point3f ¢er, float radius, int sphere_resolution = 10, const Color &color = Color::white()) + + :param center: Center of the sphere. + :param radius: Radius of the sphere. + :param sphere_resolution: Resolution of the sphere. + :param color: Color of the sphere. + +ArrowWidget +----------- +.. ocv:class:: ArrowWidget + +This 3D Widget defines an arrow. :: + + class CV_EXPORTS ArrowWidget : public Widget3D + { + public: + ArrowWidget(const Point3f& pt1, const Point3f& pt2, double thickness = 0.03, const Color &color = Color::white()); + }; + +ArrowWidget::ArrowWidget +------------------------ +Constructs an ArrowWidget. + +.. ocv:function:: ArrowWidget(const Point3f& pt1, const Point3f& pt2, double thickness = 0.03, const Color &color = Color::white()) + + :param pt1: Start point of the arrow. + :param pt2: End point of the arrow. + :param thickness: Thickness of the arrow. Thickness of arrow head is also adjusted accordingly. + :param color: Color of the arrow. + +Arrow head is located at the end point of the arrow. + +CircleWidget +------------ +.. ocv:class:: CircleWidget + +This 3D Widget defines a circle. :: + + class CV_EXPORTS CircleWidget : public Widget3D + { + public: + CircleWidget(const Point3f& pt, double radius, double thickness = 0.01, const Color &color = Color::white()); + }; + +CircleWidget::CircleWidget +-------------------------- +Constructs a CircleWidget. + +.. ocv:function:: CircleWidget(const Point3f& pt, double radius, double thickness = 0.01, const Color &color = Color::white()) + + :param pt: Center of the circle. + :param radius: Radius of the circle. + :param thickness: Thickness of the circle. + :param color: Color of the circle. + +CylinderWidget +-------------- +.. ocv:class:: CylinderWidget + +This 3D Widget defines a cylinder. :: + + class CV_EXPORTS CylinderWidget : public Widget3D + { + public: + CylinderWidget(const Point3f& pt_on_axis, const Point3f& axis_direction, double radius, int numsides = 30, const Color &color = Color::white()); + }; + +CylinderWidget::CylinderWidget +------------------------------ +Constructs a CylinderWidget. + +.. ocv:function:: CylinderWidget(const Point3f& pt_on_axis, const Point3f& axis_direction, double radius, int numsides = 30, const Color &color = Color::white()) + + :param pt_on_axis: A point on the axis of the cylinder. + :param axis_direction: Direction of the axis of the cylinder. + :param radius: Radius of the cylinder. + :param numsides: Resolution of the cylinder. + :param color: Color of the cylinder. + +CubeWidget +---------- +.. ocv:class:: CubeWidget + +This 3D Widget defines a cube. :: + + class CV_EXPORTS CubeWidget : public Widget3D + { + public: + CubeWidget(const Point3f& pt_min, const Point3f& pt_max, bool wire_frame = true, const Color &color = Color::white()); + }; + +CubeWidget::CubeWidget +---------------------- +Constructs a CudeWidget. + +.. ocv:function:: CubeWidget(const Point3f& pt_min, const Point3f& pt_max, bool wire_frame = true, const Color &color = Color::white()) + + :param pt_min: Specifies minimum point of the bounding box. + :param pt_max: Specifies maximum point of the bounding box. + :param wire_frame: If true, cube is represented as wireframe. + :param color: Color of the cube. + +CoordinateSystemWidget +---------------------- +.. ocv:class:: CoordinateSystemWidget + +This 3D Widget represents a coordinate system. :: + + class CV_EXPORTS CoordinateSystemWidget : public Widget3D + { + public: + CoordinateSystemWidget(double scale = 1.0); + }; + +CoordinateSystemWidget::CoordinateSystemWidget +---------------------------------------------- +Constructs a CoordinateSystemWidget. + +.. ocv:function:: CoordinateSystemWidget(double scale = 1.0) + + :param scale: Determines the size of the axes. + +PolyLineWidget +-------------- +.. ocv:class:: PolyLineWidget + +This 3D Widget defines a poly line. :: + + class CV_EXPORTS PolyLineWidget : public Widget3D + { + public: + PolyLineWidget(InputArray points, const Color &color = Color::white()); + + private: + /* hidden */ + }; + +PolyLineWidget::PolyLineWidget +------------------------------ +Constructs a PolyLineWidget. + +.. ocv:function:: PolyLineWidget(InputArray points, const Color &color = Color::white()) + + :param points: Point set. + :param color: Color of the poly line. + +GridWidget +---------- +.. ocv:class:: GridWidget + +This 3D Widget defines a grid. :: + + class CV_EXPORTS GridWidget : public Widget3D + { + public: + //! Creates grid at the origin + GridWidget(const Vec2i &dimensions, const Vec2d &spacing, const Color &color = Color::white()); + //! Creates grid based on the plane equation + GridWidget(const Vec4f &coeffs, const Vec2i &dimensions, const Vec2d &spacing, const Color &color = Color::white()); + private: + /* hidden */ + }; + +GridWidget::GridWidget +---------------------- +Constructs a GridWidget. + +.. ocv:function:: GridWidget(const Vec2i &dimensions, const Vec2d &spacing, const Color &color = Color::white()) + + :param dimensions: Number of columns and rows, respectively. + :param spacing: Size of each column and row, respectively. + :param color: Color of the grid. + +.. ocv:function: GridWidget(const Vec4f &coeffs, const Vec2i &dimensions, const Vec2d &spacing, const Color &color = Color::white()) + + :param coeffs: Plane coefficients as in (A,B,C,D) where Ax + By + Cz + D = 0. + :param dimensions: Number of columns and rows, respectively. + :param spacing: Size of each column and row, respectively. + :param color: Color of the grid. + +Text3DWidget +------------ +.. ocv:class:: Text3DWidget + +This 3D Widget represents 3D text. The text always faces the camera. :: + + class CV_EXPORTS Text3DWidget : public Widget3D + { + public: + Text3DWidget(const String &text, const Point3f &position, double text_scale = 1.0, const Color &color = Color::white()); + + void setText(const String &text); + String getText() const; + }; + +Text3DWidget::Text3DWidget +-------------------------- +Constructs a Text3DWidget. + +.. ocv:function:: Text3DWidget(const String &text, const Point3f &position, double text_scale = 1.0, const Color &color = Color::white()) + + :param text: Text content of the widget. + :param position: Position of the text. + :param text_scale: Size of the text. + :param color: Color of the text. + +Text3DWidget::setText +--------------------- +Sets the text content of the widget. + +.. ocv:function:: void setText(const String &text) + + :param text: Text content of the widget. + +Text3DWidget::getText +--------------------- +Returns the current text content of the widget. + +.. ocv:function:: String getText() const + +TextWidget +---------- +.. ocv:class:: TextWidget + +This 2D Widget represents text overlay. :: + + class CV_EXPORTS TextWidget : public Widget2D + { + public: + TextWidget(const String &text, const Point2i &pos, int font_size = 10, const Color &color = Color::white()); + + void setText(const String &text); + String getText() const; + }; + +TextWidget::TextWidget +---------------------- +Constructs a TextWidget. + +.. ocv:function:: TextWidget(const String &text, const Point2i &pos, int font_size = 10, const Color &color = Color::white()) + + :param text: Text content of the widget. + :param pos: Position of the text. + :param font_size: Font size. + :param color: Color of the text. + +TextWidget::setText +--------------------- +Sets the text content of the widget. + +.. ocv:function:: void setText(const String &text) + + :param text: Text content of the widget. + +TextWidget::getText +--------------------- +Returns the current text content of the widget. + +.. ocv:function:: String getText() const + +ImageOverlayWidget +------------------ +.. ocv:class:: ImageOverlayWidget + +This 2D Widget represents an image overlay. :: + + class CV_EXPORTS ImageOverlayWidget : public Widget2D + { + public: + ImageOverlayWidget(const Mat &image, const Rect &rect); + + void setImage(const Mat &image); + }; + +ImageOverlayWidget::ImageOverlayWidget +-------------------------------------- +Constructs a ImageOverlayWidget. + +.. ocv:function:: ImageOverlayWidget(const Mat &image, const Rect &rect) + + :param image: BGR or Gray-Scale image. + :param rect: Image is scaled and positioned based on rect. + +ImageOverlayWidget::setImage +---------------------------- +Sets the image content of the widget. + +.. ocv:function:: void setImage(const Mat &image) + + :param image: BGR or Gray-Scale image. + +Image3DWidget +------------- +.. ocv:class:: Image3DWidget + +This 3D Widget represents 3D image. :: + + class CV_EXPORTS Image3DWidget : public Widget3D + { + public: + //! Creates 3D image at the origin + Image3DWidget(const Mat &image, const Size &size); + //! Creates 3D image at a given position, pointing in the direction of the normal, and having the up_vector orientation + Image3DWidget(const Vec3f &position, const Vec3f &normal, const Vec3f &up_vector, const Mat &image, const Size &size); + + void setImage(const Mat &image); + }; + +Image3DWidget::Image3DWidget +---------------------------- +Constructs a Image3DWidget. + +.. ocv:function:: Image3DWidget(const Mat &image, const Size &size) + + :param image: BGR or Gray-Scale image. + :param size: Size of the image. + +.. ocv:function:: Image3DWidget(const Vec3f &position, const Vec3f &normal, const Vec3f &up_vector, const Mat &image, const Size &size) + + :param position: Position of the image. + :param normal: Normal of the plane that represents the image. + :param up_vector: Determines orientation of the image. + :param image: BGR or Gray-Scale image. + :param size: Size of the image. + +Image3DWidget::setImage +----------------------- +Sets the image content of the widget. + +.. ocv:function:: void setImage(const Mat &image) + + :param image: BGR or Gray-Scale image. + +CameraPositionWidget +-------------------- +.. ocv:class:: CameraPositionWidget + +This 3D Widget represents camera position. :: + + class CV_EXPORTS CameraPositionWidget : public Widget3D + { + public: + //! Creates camera coordinate frame (axes) at the origin + CameraPositionWidget(double scale = 1.0); + //! Creates frustum based on the intrinsic marix K at the origin + CameraPositionWidget(const Matx33f &K, double scale = 1.0, const Color &color = Color::white()); + //! Creates frustum based on the field of view at the origin + CameraPositionWidget(const Vec2f &fov, double scale = 1.0, const Color &color = Color::white()); + //! Creates frustum and display given image at the far plane + CameraPositionWidget(const Matx33f &K, const Mat &img, double scale = 1.0, const Color &color = Color::white()); + }; + +CameraPositionWidget::CameraPositionWidget +------------------------------------------ +Constructs a CameraPositionWidget. + +.. ocv:function:: CameraPositionWidget(double scale = 1.0) + + Creates camera coordinate frame at the origin. + +.. ocv:function:: CameraPositionWidget(const Matx33f &K, double scale = 1.0, const Color &color = Color::white()) + + :param K: Intrinsic matrix of the camera. + :param scale: Scale of the frustum. + :param color: Color of the frustum. + + Creates viewing frustum of the camera based on its intrinsic matrix K. + +.. ocv:function:: CameraPositionWidget(const Vec2f &fov, double scale = 1.0, const Color &color = Color::white()) + + :param fov: Field of view of the camera (horizontal, vertical). + :param scale: Scale of the frustum. + :param color: Color of the frustum. + + Creates viewing frustum of the camera based on its field of view fov. + +.. ocv:function:: CameraPositionWidget(const Matx33f &K, const Mat &img, double scale = 1.0, const Color &color = Color::white()) + + :param K: Intrinsic matrix of the camera. + :param img: BGR or Gray-Scale image that is going to be displayed at the far plane of the frustum. + :param scale: Scale of the frustum and image. + :param color: Color of the frustum. + + Creates viewing frustum of the camera based on its intrinsic matrix K, and displays image on the far end plane. + +TrajectoryWidget +---------------- +.. ocv:class:: TrajectoryWidget + +This 3D Widget represents a trajectory. :: + + class CV_EXPORTS TrajectoryWidget : public Widget3D + { + public: + enum {DISPLAY_FRAMES = 1, DISPLAY_PATH = 2}; + + //! Displays trajectory of the given path either by coordinate frames or polyline + TrajectoryWidget(const std::vector &path, int display_mode = TrajectoryWidget::DISPLAY_PATH, const Color &color = Color::white(), double scale = 1.0); + //! Displays trajectory of the given path by frustums + TrajectoryWidget(const std::vector &path, const Matx33f &K, double scale = 1.0, const Color &color = Color::white()); + //! Displays trajectory of the given path by frustums + TrajectoryWidget(const std::vector &path, const Vec2f &fov, double scale = 1.0, const Color &color = Color::white()); + + private: + /* hidden */ + }; + +TrajectoryWidget::TrajectoryWidget +---------------------------------- +Constructs a TrajectoryWidget. + +.. ocv:function:: TrajectoryWidget(const std::vector &path, int display_mode = TrajectoryWidget::DISPLAY_PATH, const Color &color = Color::white(), double scale = 1.0) + + :param path: List of poses on a trajectory. + :param display_mode: Display mode. This can be DISPLAY_PATH, DISPLAY_FRAMES, DISPLAY_PATH & DISPLAY_FRAMES. + :param color: Color of the polyline that represents path. Frames are not affected. + :param scale: Scale of the frames. Polyline is not affected. + + Displays trajectory of the given path as follows: + + * DISPLAY_PATH : Displays a poly line that represents the path. + * DISPLAY_FRAMES : Displays coordinate frames at each pose. + * DISPLAY_PATH & DISPLAY_FRAMES : Displays both poly line and coordinate frames. + +.. ocv:function:: TrajectoryWidget(const std::vector &path, const Matx33f &K, double scale = 1.0, const Color &color = Color::white()) + + :param path: List of poses on a trajectory. + :param K: Intrinsic matrix of the camera. + :param scale: Scale of the frustums. + :param color: Color of the frustums. + + Displays frustums at each pose of the trajectory. + +.. ocv:function:: TrajectoryWidget(const std::vector &path, const Vec2f &fov, double scale = 1.0, const Color &color = Color::white()) + + :param path: List of poses on a trajectory. + :param fov: Field of view of the camera (horizontal, vertical). + :param scale: Scale of the frustums. + :param color: Color of the frustums. + + Displays frustums at each pose of the trajectory. + +SpheresTrajectoryWidget +----------------------- +.. ocv:class:: SpheresTrajectoryWidget + +This 3D Widget represents a trajectory using spheres and lines, where spheres represent the positions of the camera, and lines +represent the direction from previous position to the current. :: + + class CV_EXPORTS SpheresTrajectoryWidget : public Widget3D + { + public: + SpheresTrajectoryWidget(const std::vector &path, float line_length = 0.05f, + double init_sphere_radius = 0.021, sphere_radius = 0.007, + Color &line_color = Color::white(), const Color &sphere_color = Color::white()); + }; + +SpheresTrajectoryWidget::SpheresTrajectoryWidget +------------------------------------------------ +Constructs a SpheresTrajectoryWidget. + +.. ocv:function:: SpheresTrajectoryWidget(const std::vector &path, float line_length = 0.05f, double init_sphere_radius = 0.021, double sphere_radius = 0.007, const Color &line_color = Color::white(), const Color &sphere_color = Color::white()) + + :param path: List of poses on a trajectory. + :param line_length: Length of the lines. + :param init_sphere_radius: Radius of the first sphere which represents the initial position of the camera. + :param sphere_radius: Radius of the rest of the spheres. + :param line_color: Color of the lines. + :param sphere_color: Color of the spheres. + +CloudWidget +----------- +.. ocv:class:: CloudWidget + +This 3D Widget defines a point cloud. :: + + class CV_EXPORTS CloudWidget : public Widget3D + { + public: + //! Each point in cloud is mapped to a color in colors + CloudWidget(InputArray cloud, InputArray colors); + //! All points in cloud have the same color + CloudWidget(InputArray cloud, const Color &color = Color::white()); + + private: + /* hidden */ + }; + +CloudWidget::CloudWidget +------------------------ +Constructs a CloudWidget. + +.. ocv:function:: CloudWidget(InputArray cloud, InputArray colors) + + :param cloud: Point set which can be of type: CV_32FC3, CV_32FC4, CV_64FC3, CV_64FC4. + :param colors: Set of colors. It has to be of the same size with cloud. + + Points in the cloud belong to mask when they are set to (NaN, NaN, NaN). + +.. ocv:function:: CloudWidget(InputArray cloud, const Color &color = Color::white()) + + :param cloud: Point set which can be of type: CV_32FC3, CV_32FC4, CV_64FC3, CV_64FC4. + :param color: A single color for the whole cloud. + + Points in the cloud belong to mask when they are set to (NaN, NaN, NaN). + +CloudCollectionWidget +--------------------- +.. ocv:class:: CloudCollectionWidget + +This 3D Widget defines a collection of clouds. :: + + class CV_EXPORTS CloudCollectionWidget : public Widget3D + { + public: + CloudCollectionWidget(); + + //! Each point in cloud is mapped to a color in colors + void addCloud(InputArray cloud, InputArray colors, const Affine3f &pose = Affine3f::Identity()); + //! All points in cloud have the same color + void addCloud(InputArray cloud, const Color &color = Color::white(), Affine3f &pose = Affine3f::Identity()); + + private: + /* hidden */ + }; + +CloudCollectionWidget::CloudCollectionWidget +-------------------------------------------- +Constructs a CloudCollectionWidget. + +.. ocv:function:: CloudCollectionWidget() + +CloudCollectionWidget::addCloud +------------------------------- +Adds a cloud to the collection. + +.. ocv:function:: void addCloud(InputArray cloud, InputArray colors, const Affine3f &pose = Affine3f::Identity()) + + :param cloud: Point set which can be of type: CV_32FC3, CV_32FC4, CV_64FC3, CV_64FC4. + :param colors: Set of colors. It has to be of the same size with cloud. + :param pose: Pose of the cloud. + + Points in the cloud belong to mask when they are set to (NaN, NaN, NaN). + +.. ocv:function:: void addCloud(InputArray cloud, const Color &color = Color::white(), const Affine3f &pose = Affine3f::Identity()) + + :param cloud: Point set which can be of type: CV_32FC3, CV_32FC4, CV_64FC3, CV_64FC4. + :param colors: A single color for the whole cloud. + :param pose: Pose of the cloud. + + Points in the cloud belong to mask when they are set to (NaN, NaN, NaN). + +CloudNormalsWidget +------------------ +.. ocv:class:: CloudNormalsWidget + +This 3D Widget represents normals of a point cloud. :: + + class CV_EXPORTS CloudNormalsWidget : public Widget3D + { + public: + CloudNormalsWidget(InputArray cloud, InputArray normals, int level = 100, float scale = 0.02f, const Color &color = Color::white()); + + private: + /* hidden */ + }; + +CloudNormalsWidget::CloudNormalsWidget +-------------------------------------- +Constructs a CloudNormalsWidget. + +.. ocv:function:: CloudNormalsWidget(InputArray cloud, InputArray normals, int level = 100, float scale = 0.02f, const Color &color = Color::white()) + + :param cloud: Point set which can be of type: CV_32FC3, CV_32FC4, CV_64FC3, CV_64FC4. + :param normals: A set of normals that has to be of same type with cloud. + :param level: Display only every levelth normal. + :param scale: Scale of the arrows that represent normals. + :param color: Color of the arrows that represent normals. + +MeshWidget +---------- +.. ocv:class:: MeshWidget + +This 3D Widget defines a mesh. :: + + class CV_EXPORTS MeshWidget : public Widget3D + { + public: + MeshWidget(const Mesh3d &mesh); + + private: + /* hidden */ + }; + +MeshWidget::MeshWidget +---------------------- +Constructs a MeshWidget. + +.. ocv:function:: MeshWidget(const Mesh3d &mesh) + + :param mesh: Mesh object that will be displayed. + + + + From 31501ebf4f1d11b9b4b729b24543e5d59a9559d2 Mon Sep 17 00:00:00 2001 From: Ozan Tonkal Date: Sun, 1 Sep 2013 20:12:31 +0200 Subject: [PATCH 26/29] replace tabs by spaces --- modules/viz/doc/viz.rst | 2 - modules/viz/doc/viz3d.rst | 444 ++++++++++---------- modules/viz/doc/widget.rst | 802 +++++++++++++++++++------------------ 3 files changed, 629 insertions(+), 619 deletions(-) diff --git a/modules/viz/doc/viz.rst b/modules/viz/doc/viz.rst index f51a151e09..2f1bf04566 100644 --- a/modules/viz/doc/viz.rst +++ b/modules/viz/doc/viz.rst @@ -7,5 +7,3 @@ viz. 3D Visualizer viz3d.rst widget.rst - types.rst - widget_accessor.rst diff --git a/modules/viz/doc/viz3d.rst b/modules/viz/doc/viz3d.rst index e7dcc358c4..b2e2d49145 100644 --- a/modules/viz/doc/viz3d.rst +++ b/modules/viz/doc/viz3d.rst @@ -7,67 +7,67 @@ Viz3d ----- .. ocv:class:: Viz3d -The Viz3d class represents a 3D visualizer window. This class is implicitly shared. :: +The Viz3d class represents a 3D visualizer window. This class is implicitly shared. :: - class CV_EXPORTS Viz3d - { - public: - typedef cv::Ptr Ptr; - typedef void (*KeyboardCallback)(const KeyboardEvent&, void*); - typedef void (*MouseCallback)(const MouseEvent&, void*); + class CV_EXPORTS Viz3d + { + public: + typedef cv::Ptr Ptr; + typedef void (*KeyboardCallback)(const KeyboardEvent&, void*); + typedef void (*MouseCallback)(const MouseEvent&, void*); - Viz3d(const String& window_name = String()); - Viz3d(const Viz3d&); - Viz3d& operator=(const Viz3d&); - ~Viz3d(); + Viz3d(const String& window_name = String()); + Viz3d(const Viz3d&); + Viz3d& operator=(const Viz3d&); + ~Viz3d(); - void showWidget(const String &id, const Widget &widget, const Affine3f &pose = Affine3f::Identity()); - void removeWidget(const String &id); - Widget getWidget(const String &id) const; - void removeAllWidgets(); + void showWidget(const String &id, const Widget &widget, const Affine3f &pose = Affine3f::Identity()); + void removeWidget(const String &id); + Widget getWidget(const String &id) const; + void removeAllWidgets(); - void setWidgetPose(const String &id, const Affine3f &pose); - void updateWidgetPose(const String &id, const Affine3f &pose); - Affine3f getWidgetPose(const String &id) const; - - void setCamera(const Camera &camera); - Camera getCamera() const; - Affine3f getViewerPose(); - void setViewerPose(const Affine3f &pose); - - void resetCameraViewpoint (const String &id); - void resetCamera(); - - void convertToWindowCoordinates(const Point3d &pt, Point3d &window_coord); - void converTo3DRay(const Point3d &window_coord, Point3d &origin, Vec3d &direction); - - Size getWindowSize() const; - void setWindowSize(const Size &window_size); - String getWindowName() const; - void saveScreenshot (const String &file); - void setWindowPosition (int x, int y); - void setFullScreen (bool mode); - void setBackgroundColor(const Color& color = Color::black()); + void setWidgetPose(const String &id, const Affine3f &pose); + void updateWidgetPose(const String &id, const Affine3f &pose); + Affine3f getWidgetPose(const String &id) const; + + void setCamera(const Camera &camera); + Camera getCamera() const; + Affine3f getViewerPose(); + void setViewerPose(const Affine3f &pose); + + void resetCameraViewpoint (const String &id); + void resetCamera(); + + void convertToWindowCoordinates(const Point3d &pt, Point3d &window_coord); + void converTo3DRay(const Point3d &window_coord, Point3d &origin, Vec3d &direction); + + Size getWindowSize() const; + void setWindowSize(const Size &window_size); + String getWindowName() const; + void saveScreenshot (const String &file); + void setWindowPosition (int x, int y); + void setFullScreen (bool mode); + void setBackgroundColor(const Color& color = Color::black()); - void spin(); - void spinOnce(int time = 1, bool force_redraw = false); - bool wasStopped() const; + void spin(); + void spinOnce(int time = 1, bool force_redraw = false); + bool wasStopped() const; - void registerKeyboardCallback(KeyboardCallback callback, void* cookie = 0); - void registerMouseCallback(MouseCallback callback, void* cookie = 0); - - void setRenderingProperty(const String &id, int property, double value); - double getRenderingProperty(const String &id, int property); - - void setDesiredUpdateRate(double rate); - double getDesiredUpdateRate(); - - void setRepresentationToSurface(); - void setRepresentationToWireframe(); - void setRepresentationToPoints(); - private: - /* hidden */ - }; + void registerKeyboardCallback(KeyboardCallback callback, void* cookie = 0); + void registerMouseCallback(MouseCallback callback, void* cookie = 0); + + void setRenderingProperty(const String &id, int property, double value); + double getRenderingProperty(const String &id, int property); + + void setDesiredUpdateRate(double rate); + double getDesiredUpdateRate(); + + void setRepresentationToSurface(); + void setRepresentationToWireframe(); + void setRepresentationToPoints(); + private: + /* hidden */ + }; Viz3d::Viz3d ------------ @@ -75,7 +75,7 @@ The constructors. .. ocv:function:: Viz3d::Viz3d(const String& window_name = String()) - :param window_name: Name of the window. + :param window_name: Name of the window. Viz3d::showWidget ----------------- @@ -83,18 +83,18 @@ Shows a widget in the window. .. ocv:function:: void Viz3d::showWidget(const String &id, const Widget &widget, const Affine3f &pose = Affine3f::Identity()) - :param id: A unique id for the widget. - :param widget: The widget to be rendered in the window. - :param pose: Pose of the widget. - + :param id: A unique id for the widget. + :param widget: The widget to be rendered in the window. + :param pose: Pose of the widget. + Viz3d::removeWidget ------------------- Removes a widget from the window. .. ocv:function:: void removeWidget(const String &id) - :param id: The id of the widget that will be removed. - + :param id: The id of the widget that will be removed. + Viz3d::getWidget ---------------- Retrieves a widget from the window. A widget is implicitly shared; @@ -103,8 +103,8 @@ immediately visible in the window. .. ocv:function:: Widget getWidget(const String &id) const - :param id: The id of the widget that will be returned. - + :param id: The id of the widget that will be returned. + Viz3d::removeAllWidgets ----------------------- Removes all widgets from the window. @@ -117,8 +117,8 @@ Sets pose of a widget in the window. .. ocv:function:: void setWidgetPose(const String &id, const Affine3f &pose) - :param id: The id of the widget whose pose will be set. - :param pose: The new pose of the widget. + :param id: The id of the widget whose pose will be set. + :param pose: The new pose of the widget. Viz3d::updateWidgetPose ----------------------- @@ -126,8 +126,8 @@ Updates pose of a widget in the window by pre-multiplying its current pose. .. ocv:function:: void updateWidgetPose(const String &id, const Affine3f &pose) - :param id: The id of the widget whose pose will be updated. - :param pose: The pose that the current pose of the widget will be pre-multiplied by. + :param id: The id of the widget whose pose will be updated. + :param pose: The pose that the current pose of the widget will be pre-multiplied by. Viz3d::getWidgetPose -------------------- @@ -135,7 +135,7 @@ Returns the current pose of a widget in the window. .. ocv:function:: Affine3f getWidgetPose(const String &id) const - :param id: The id of the widget whose pose will be returned. + :param id: The id of the widget whose pose will be returned. Viz3d::setCamera ---------------- @@ -143,7 +143,7 @@ Sets the intrinsic parameters of the viewer using Camera. .. ocv:function:: void setCamera(const Camera &camera) - :param camera: Camera object wrapping intrinsinc parameters. + :param camera: Camera object wrapping intrinsinc parameters. Viz3d::getCamera ---------------- @@ -163,7 +163,7 @@ Sets pose of the viewer. .. ocv:function:: void setViewerPose(const Affine3f &pose) - :param pose: The new pose of the viewer. + :param pose: The new pose of the viewer. Viz3d::resetCameraViewpoint --------------------------- @@ -171,8 +171,8 @@ Resets camera viewpoint to a 3D widget in the scene. .. ocv:function:: void resetCameraViewpoint (const String &id) - :param pose: Id of a 3D widget. - + :param pose: Id of a 3D widget. + Viz3d::resetCamera ------------------ Resets camera. @@ -185,19 +185,19 @@ Transforms a point in world coordinate system to window coordinate system. .. ocv:function:: void convertToWindowCoordinates(const Point3d &pt, Point3d &window_coord) - :param pt: Point in world coordinate system. - :param window_coord: Output point in window coordinate system. - + :param pt: Point in world coordinate system. + :param window_coord: Output point in window coordinate system. + Viz3d::converTo3DRay -------------------- Transforms a point in window coordinate system to a 3D ray in world coordinate system. .. ocv:function:: void converTo3DRay(const Point3d &window_coord, Point3d &origin, Vec3d &direction) - :param window_coord: Point in window coordinate system. - :param origin: Output origin of the ray. - :param direction: Output direction of the ray. - + :param window_coord: Point in window coordinate system. + :param origin: Output origin of the ray. + :param direction: Output direction of the ray. + Viz3d::getWindowSize -------------------- Returns the current size of the window. @@ -210,8 +210,8 @@ Sets the size of the window. .. ocv:function:: void setWindowSize(const Size &window_size) - :param window_size: New size of the window. - + :param window_size: New size of the window. + Viz3d::getWindowName -------------------- Returns the name of the window which has been set in the constructor. @@ -224,25 +224,25 @@ Saves screenshot of the current scene. .. ocv:function:: void saveScreenshot(const String &file) - :param file: Name of the file. - + :param file: Name of the file. + Viz3d::setWindowPosition ------------------------ Sets the position of the window in the screen. .. ocv:function:: void setWindowPosition(int x, int y) - :param x: x coordinate of the window - :param y: y coordinate of the window - + :param x: x coordinate of the window + :param y: y coordinate of the window + Viz3d::setFullScreen -------------------- Sets or unsets full-screen rendering mode. .. ocv:function:: void setFullScreen(bool mode) - :param mode: If true, window will use full-screen mode. - + :param mode: If true, window will use full-screen mode. + Viz3d::setBackgroundColor ------------------------- Sets background color. @@ -261,8 +261,8 @@ Starts the event loop for a given time. .. ocv:function:: void spinOnce(int time = 1, bool force_redraw = false) - :param time: Amount of time in milliseconds for the event loop to keep running. - :param force_draw: If true, window renders. + :param time: Amount of time in milliseconds for the event loop to keep running. + :param force_draw: If true, window renders. Viz3d::wasStopped ----------------- @@ -276,17 +276,17 @@ Sets keyboard handler. .. ocv:function:: void registerKeyboardCallback(KeyboardCallback callback, void* cookie = 0) - :param callback: Keyboard callback. - :param cookie: The optional parameter passed to the callback. - + :param callback: Keyboard callback. + :param cookie: The optional parameter passed to the callback. + Viz3d::registerMouseCallback ---------------------------- Sets mouse handler. .. ocv:function:: void registerMouseCallback(MouseCallback callback, void* cookie = 0) - :param callback: Mouse callback. - :param cookie: The optional parameter passed to the callback. + :param callback: Mouse callback. + :param cookie: The optional parameter passed to the callback. Viz3d::setRenderingProperty --------------------------- @@ -294,18 +294,18 @@ Sets rendering property of a widget. .. ocv:function:: void setRenderingProperty(const String &id, int property, double value) - :param id: Id of the widget. - :param property: Property that will be modified. - :param value: The new value of the property. - + :param id: Id of the widget. + :param property: Property that will be modified. + :param value: The new value of the property. + Viz3d::getRenderingProperty --------------------------- Returns rendering property of a widget. .. ocv:function:: double getRenderingProperty(const String &id, int property) - :param id: Id of the widget. - :param property: Property. + :param id: Id of the widget. + :param property: Property. Viz3d::setDesiredUpdateRate --------------------------- @@ -313,8 +313,8 @@ Sets desired update rate of the window. .. ocv:function:: void setDesiredUpdateRate(double rate) - :param rate: Desired update rate. The default is 30. - + :param rate: Desired update rate. The default is 30. + Viz3d::getDesiredUpdateRate --------------------------- Returns desired update rate of the window. @@ -345,27 +345,27 @@ Color This class a represents BGR color. :: - class CV_EXPORTS Color : public Scalar - { - public: - Color(); - Color(double gray); - Color(double blue, double green, double red); + class CV_EXPORTS Color : public Scalar + { + public: + Color(); + Color(double gray); + Color(double blue, double green, double red); - Color(const Scalar& color); + Color(const Scalar& color); - static Color black(); - static Color blue(); - static Color green(); - static Color cyan(); + static Color black(); + static Color blue(); + static Color green(); + static Color cyan(); - static Color red(); - static Color magenta(); - static Color yellow(); - static Color white(); + static Color red(); + static Color magenta(); + static Color yellow(); + static Color white(); - static Color gray(); - }; + static Color gray(); + }; Mesh3d ------ @@ -373,27 +373,27 @@ Mesh3d This class wraps mesh attributes, and it can load a mesh from a ``ply`` file. :: - class CV_EXPORTS Mesh3d - { - public: + class CV_EXPORTS Mesh3d + { + public: - Mat cloud, colors; - Mat polygons; + Mat cloud, colors; + Mat polygons; - //! Loads mesh from a given ply file - static Mesh3d loadMesh(const String& file); - - private: - /* hidden */ - }; - + //! Loads mesh from a given ply file + static Mesh3d loadMesh(const String& file); + + private: + /* hidden */ + }; + Mesh3d::loadMesh ---------------- Loads a mesh from a ``ply`` file. .. ocv:function:: static Mesh3d loadMesh(const String& file) - :param file: File name. + :param file: File name. KeyboardEvent @@ -402,30 +402,30 @@ KeyboardEvent This class represents a keyboard event. :: - class CV_EXPORTS KeyboardEvent - { - public: - static const unsigned int Alt = 1; - static const unsigned int Ctrl = 2; - static const unsigned int Shift = 4; + class CV_EXPORTS KeyboardEvent + { + public: + static const unsigned int Alt = 1; + static const unsigned int Ctrl = 2; + static const unsigned int Shift = 4; - //! Create a keyboard event - //! - Note that action is true if key is pressed, false if released - KeyboardEvent (bool action, const std::string& key_sym, unsigned char key, bool alt, bool ctrl, bool shift); + //! Create a keyboard event + //! - Note that action is true if key is pressed, false if released + KeyboardEvent (bool action, const std::string& key_sym, unsigned char key, bool alt, bool ctrl, bool shift); - bool isAltPressed () const; - bool isCtrlPressed () const; - bool isShiftPressed () const; + bool isAltPressed () const; + bool isCtrlPressed () const; + bool isShiftPressed () const; - unsigned char getKeyCode () const; + unsigned char getKeyCode () const; - const String& getKeySym () const; - bool keyDown () const; - bool keyUp () const; + const String& getKeySym () const; + bool keyDown () const; + bool keyUp () const; - protected: - /* hidden */ - }; + protected: + /* hidden */ + }; KeyboardEvent::KeyboardEvent ---------------------------- @@ -433,46 +433,46 @@ Constructs a KeyboardEvent. .. ocv:function:: KeyboardEvent (bool action, const std::string& key_sym, unsigned char key, bool alt, bool ctrl, bool shift) - :param action: If true, key is pressed. If false, key is released. - :param key_sym: Name of the key. - :param key: Code of the key. - :param alt: If true, ``alt`` is pressed. - :param ctrl: If true, ``ctrl`` is pressed. - :param shift: If true, ``shift`` is pressed. - + :param action: If true, key is pressed. If false, key is released. + :param key_sym: Name of the key. + :param key: Code of the key. + :param alt: If true, ``alt`` is pressed. + :param ctrl: If true, ``ctrl`` is pressed. + :param shift: If true, ``shift`` is pressed. + MouseEvent ---------- .. ocv:class:: MouseEvent This class represents a mouse event. :: - class CV_EXPORTS MouseEvent - { - public: - enum Type { MouseMove = 1, MouseButtonPress, MouseButtonRelease, MouseScrollDown, MouseScrollUp, MouseDblClick } ; - enum MouseButton { NoButton = 0, LeftButton, MiddleButton, RightButton, VScroll } ; + class CV_EXPORTS MouseEvent + { + public: + enum Type { MouseMove = 1, MouseButtonPress, MouseButtonRelease, MouseScrollDown, MouseScrollUp, MouseDblClick } ; + enum MouseButton { NoButton = 0, LeftButton, MiddleButton, RightButton, VScroll } ; - MouseEvent (const Type& type, const MouseButton& button, const Point& p, bool alt, bool ctrl, bool shift); + MouseEvent (const Type& type, const MouseButton& button, const Point& p, bool alt, bool ctrl, bool shift); - Type type; - MouseButton button; - Point pointer; - unsigned int key_state; - }; - + Type type; + MouseButton button; + Point pointer; + unsigned int key_state; + }; + MouseEvent::MouseEvent ---------------------- Constructs a MouseEvent. .. ocv:function:: MouseEvent (const Type& type, const MouseButton& button, const Point& p, bool alt, bool ctrl, bool shift) - :param type: Type of the event. This can be **MouseMove**, **MouseButtonPress**, **MouseButtonRelease**, **MouseScrollDown**, **MouseScrollUp**, **MouseDblClick**. - :param button: Mouse button. This can be **NoButton**, **LeftButton**, **MiddleButton**, **RightButton**, **VScroll**. - :param p: Position of the event. - :param alt: If true, ``alt`` is pressed. - :param ctrl: If true, ``ctrl`` is pressed. - :param shift: If true, ``shift`` is pressed. - + :param type: Type of the event. This can be **MouseMove**, **MouseButtonPress**, **MouseButtonRelease**, **MouseScrollDown**, **MouseScrollUp**, **MouseDblClick**. + :param button: Mouse button. This can be **NoButton**, **LeftButton**, **MiddleButton**, **RightButton**, **VScroll**. + :param p: Position of the event. + :param alt: If true, ``alt`` is pressed. + :param ctrl: If true, ``ctrl`` is pressed. + :param shift: If true, ``shift`` is pressed. + Camera ------ .. ocv:class:: Camera @@ -481,33 +481,33 @@ This class wraps intrinsic parameters of a camera. It provides several construct that can extract the intrinsic parameters from ``field of view``, ``intrinsic matrix`` and ``projection matrix``. :: - class CV_EXPORTS Camera - { - public: - Camera(float f_x, float f_y, float c_x, float c_y, const Size &window_size); - Camera(const Vec2f &fov, const Size &window_size); - Camera(const cv::Matx33f &K, const Size &window_size); - Camera(const cv::Matx44f &proj, const Size &window_size); - - inline const Vec2d & getClip() const { return clip_; } - inline void setClip(const Vec2d &clip) { clip_ = clip; } - - inline const Size & getWindowSize() const { return window_size_; } - void setWindowSize(const Size &window_size); - - inline const Vec2f & getFov() const { return fov_; } - inline void setFov(const Vec2f & fov) { fov_ = fov; } - - inline const Vec2f & getPrincipalPoint() const { return principal_point_; } - inline const Vec2f & getFocalLength() const { return focal_; } - - void computeProjectionMatrix(Matx44f &proj) const; - - static Camera KinectCamera(const Size &window_size); - - private: - /* hidden */ - }; + class CV_EXPORTS Camera + { + public: + Camera(float f_x, float f_y, float c_x, float c_y, const Size &window_size); + Camera(const Vec2f &fov, const Size &window_size); + Camera(const cv::Matx33f &K, const Size &window_size); + Camera(const cv::Matx44f &proj, const Size &window_size); + + inline const Vec2d & getClip() const { return clip_; } + inline void setClip(const Vec2d &clip) { clip_ = clip; } + + inline const Size & getWindowSize() const { return window_size_; } + void setWindowSize(const Size &window_size); + + inline const Vec2f & getFov() const { return fov_; } + inline void setFov(const Vec2f & fov) { fov_ = fov; } + + inline const Vec2f & getPrincipalPoint() const { return principal_point_; } + inline const Vec2f & getFocalLength() const { return focal_; } + + void computeProjectionMatrix(Matx44f &proj) const; + + static Camera KinectCamera(const Size &window_size); + + private: + /* hidden */ + }; Camera::Camera -------------- @@ -515,28 +515,28 @@ Constructs a Camera. .. ocv:function:: Camera(float f_x, float f_y, float c_x, float c_y, const Size &window_size) - :param f_x: Horizontal focal length. - :param f_y: Vertical focal length. - :param c_x: x coordinate of the principal point. - :param c_y: y coordinate of the principal point. - :param window_size: Size of the window. This together with focal length and principal point determines the field of view. + :param f_x: Horizontal focal length. + :param f_y: Vertical focal length. + :param c_x: x coordinate of the principal point. + :param c_y: y coordinate of the principal point. + :param window_size: Size of the window. This together with focal length and principal point determines the field of view. .. ocv:function:: Camera(const Vec2f &fov, const Size &window_size) - :param fov: Field of view (horizontal, vertical) - :param window_size: Size of the window. + :param fov: Field of view (horizontal, vertical) + :param window_size: Size of the window. - Principal point is at the center of the window by default. - + Principal point is at the center of the window by default. + .. ocv:function:: Camera(const cv::Matx33f &K, const Size &window_size) - :param K: Intrinsic matrix of the camera. - :param window_size: Size of the window. This together with intrinsic matrix determines the field of view. + :param K: Intrinsic matrix of the camera. + :param window_size: Size of the window. This together with intrinsic matrix determines the field of view. .. ocv:function:: Camera(const cv::Matx44f &proj, const Size &window_size) - :param proj: Projection matrix of the camera. - :param window_size: Size of the window. This together with projection matrix determines the field of view. + :param proj: Projection matrix of the camera. + :param window_size: Size of the window. This together with projection matrix determines the field of view. Camera::computeProjectionMatrix ------------------------------- @@ -544,13 +544,13 @@ Computes projection matrix using intrinsic parameters of the camera. .. ocv:function:: void computeProjectionMatrix(Matx44f &proj) const - :param proj: Output projection matrix. - + :param proj: Output projection matrix. + Camera::KinectCamera -------------------- Creates a Kinect Camera. .. ocv:function:: static Camera KinectCamera(const Size &window_size) - :param window_size: Size of the window. This together with intrinsic matrix of a Kinect Camera determines the field of view. + :param window_size: Size of the window. This together with intrinsic matrix of a Kinect Camera determines the field of view. diff --git a/modules/viz/doc/widget.rst b/modules/viz/doc/widget.rst index d4199fdc42..bf724956db 100644 --- a/modules/viz/doc/widget.rst +++ b/modules/viz/doc/widget.rst @@ -1,6 +1,6 @@ Widget ====== - + .. highlight:: cpp In this section, the built-in widgets are presented. @@ -11,26 +11,26 @@ Widget Base class of all widgets. Widget is implicitly shared.:: - class CV_EXPORTS Widget - { - public: - Widget(); - Widget(const Widget& other); - Widget& operator=(const Widget& other); - ~Widget(); - - //! Create a widget directly from ply file - static Widget fromPlyFile(const String &file_name); - - //! Rendering properties of this particular widget - void setRenderingProperty(int property, double value); - double getRenderingProperty(int property) const; + class CV_EXPORTS Widget + { + public: + Widget(); + Widget(const Widget& other); + Widget& operator=(const Widget& other); + ~Widget(); + + //! Create a widget directly from ply file + static Widget fromPlyFile(const String &file_name); + + //! Rendering properties of this particular widget + void setRenderingProperty(int property, double value); + double getRenderingProperty(int property) const; - //! Casting between widgets - template _W cast(); - private: - /* hidden */ - }; + //! Casting between widgets + template _W cast(); + private: + /* hidden */ + }; Widget::fromPlyFile ------------------- @@ -38,50 +38,62 @@ Creates a widget from ply file. .. ocv:function:: static Widget fromPlyFile(const String &file_name) - :param file_name: Ply file name. - + :param file_name: Ply file name. + Widget::setRenderingProperty ---------------------------- Sets rendering property of the widget. .. ocv:function:: void setRenderingProperty(int property, double value) - :param property: Property that will be modified. - :param value: The new value of the property. - + :param property: Property that will be modified. + :param value: The new value of the property. + Widget::getRenderingProperty ---------------------------- Returns rendering property of the widget. .. ocv:function:: double getRenderingProperty(int property) const - :param property: Property. - + :param property: Property. + Widget::cast ------------ Casts a widget to another. .. ocv:function:: template _W cast() +WidgetAccessor +-------------- +.. ocv:class:: WidgetAccessor + +This class is for users who want to develop their own widgets using VTK library API. :: + + struct CV_EXPORTS WidgetAccessor + { + static vtkSmartPointer getProp(const Widget &widget); + static void setProp(Widget &widget, vtkSmartPointer prop); + }; + Widget3D -------- .. ocv:class:: Widget3D Base class of all 3D widgets. :: - class CV_EXPORTS Widget3D : public Widget - { - public: - Widget3D() {} + class CV_EXPORTS Widget3D : public Widget + { + public: + Widget3D() {} - void setPose(const Affine3f &pose); - void updatePose(const Affine3f &pose); - Affine3f getPose() const; + void setPose(const Affine3f &pose); + void updatePose(const Affine3f &pose); + Affine3f getPose() const; - void setColor(const Color &color); - private: - /* hidden */ - }; + void setColor(const Color &color); + private: + /* hidden */ + }; Widget3D::setPose ----------------- @@ -89,15 +101,15 @@ Sets pose of the widget. .. ocv:function:: void setPose(const Affine3f &pose) - :param pose: The new pose of the widget. - + :param pose: The new pose of the widget. + Widget3D::updateWidgetPose -------------------------- Updates pose of the widget by pre-multiplying its current pose. .. ocv:function:: void updateWidgetPose(const Affine3f &pose) - :param pose: The pose that the current pose of the widget will be pre-multiplied by. + :param pose: The pose that the current pose of the widget will be pre-multiplied by. Widget3D::getPose ----------------- @@ -111,29 +123,29 @@ Sets the color of the widget. .. ocv:function:: void setColor(const Color &color) - :param color: Color - + :param color: Color + Widget2D -------- .. ocv:class:: Widget2D Base class of all 2D widgets. :: - class CV_EXPORTS Widget2D : public Widget - { - public: - Widget2D() {} + class CV_EXPORTS Widget2D : public Widget + { + public: + Widget2D() {} - void setColor(const Color &color); - }; - + void setColor(const Color &color); + }; + Widget2D::setColor ------------------ Sets the color of the widget. .. ocv:function:: void setColor(const Color &color) - :param color: Color + :param color: Color LineWidget ---------- @@ -141,64 +153,64 @@ LineWidget This 3D Widget defines a finite line. :: - class CV_EXPORTS LineWidget : public Widget3D - { - public: - LineWidget(const Point3f &pt1, const Point3f &pt2, const Color &color = Color::white()); - }; - + class CV_EXPORTS LineWidget : public Widget3D + { + public: + LineWidget(const Point3f &pt1, const Point3f &pt2, const Color &color = Color::white()); + }; + LineWidget::LineWidget ---------------------- Constructs a LineWidget. .. ocv:function:: LineWidget(const Point3f &pt1, const Point3f &pt2, const Color &color = Color::white()) - :param pt1: Start point of the line. - :param pt2: End point of the line. - :param color: Color of the line. - + :param pt1: Start point of the line. + :param pt2: End point of the line. + :param color: Color of the line. + PlaneWidget ----------- .. ocv:class:: PlaneWidget This 3D Widget defines a finite plane. :: - class CV_EXPORTS PlaneWidget : public Widget3D - { - public: - PlaneWidget(const Vec4f& coefs, double size = 1.0, const Color &color = Color::white()); - PlaneWidget(const Vec4f& coefs, const Point3f& pt, double size = 1.0, const Color &color = Color::white()); - private: - /* hidden */ - }; - + class CV_EXPORTS PlaneWidget : public Widget3D + { + public: + PlaneWidget(const Vec4f& coefs, double size = 1.0, const Color &color = Color::white()); + PlaneWidget(const Vec4f& coefs, const Point3f& pt, double size = 1.0, const Color &color = Color::white()); + private: + /* hidden */ + }; + PlaneWidget::PlaneWidget ------------------------ Constructs a PlaneWidget. .. ocv:function:: PlaneWidget(const Vec4f& coefs, double size = 1.0, const Color &color = Color::white()) - - :param coefs: Plane coefficients as in (A,B,C,D) where Ax + By + Cz + D = 0. - :param size: Size of the plane. - :param color: Color of the plane. + + :param coefs: Plane coefficients as in (A,B,C,D) where Ax + By + Cz + D = 0. + :param size: Size of the plane. + :param color: Color of the plane. .. ocv:function:: PlaneWidget(const Vec4f& coefs, const Point3f& pt, double size = 1.0, const Color &color = Color::white()) - :param coefs: Plane coefficients as in (A,B,C,D) where Ax + By + Cz + D = 0. - :param pt: Position of the plane. - :param color: Color of the plane. - + :param coefs: Plane coefficients as in (A,B,C,D) where Ax + By + Cz + D = 0. + :param pt: Position of the plane. + :param color: Color of the plane. + SphereWidget ------------ .. ocv:class:: SphereWidget This 3D Widget defines a sphere. :: - class CV_EXPORTS SphereWidget : public Widget3D - { - public: - SphereWidget(const cv::Point3f ¢er, float radius, int sphere_resolution = 10, const Color &color = Color::white()) - }; + class CV_EXPORTS SphereWidget : public Widget3D + { + public: + SphereWidget(const cv::Point3f ¢er, float radius, int sphere_resolution = 10, const Color &color = Color::white()) + }; SphereWidget::SphereWidget -------------------------- @@ -206,10 +218,10 @@ Constructs a SphereWidget. .. ocv:function:: SphereWidget(const cv::Point3f ¢er, float radius, int sphere_resolution = 10, const Color &color = Color::white()) - :param center: Center of the sphere. - :param radius: Radius of the sphere. - :param sphere_resolution: Resolution of the sphere. - :param color: Color of the sphere. + :param center: Center of the sphere. + :param radius: Radius of the sphere. + :param sphere_resolution: Resolution of the sphere. + :param color: Color of the sphere. ArrowWidget ----------- @@ -217,59 +229,59 @@ ArrowWidget This 3D Widget defines an arrow. :: - class CV_EXPORTS ArrowWidget : public Widget3D - { - public: - ArrowWidget(const Point3f& pt1, const Point3f& pt2, double thickness = 0.03, const Color &color = Color::white()); - }; - + class CV_EXPORTS ArrowWidget : public Widget3D + { + public: + ArrowWidget(const Point3f& pt1, const Point3f& pt2, double thickness = 0.03, const Color &color = Color::white()); + }; + ArrowWidget::ArrowWidget ------------------------ Constructs an ArrowWidget. .. ocv:function:: ArrowWidget(const Point3f& pt1, const Point3f& pt2, double thickness = 0.03, const Color &color = Color::white()) - :param pt1: Start point of the arrow. - :param pt2: End point of the arrow. - :param thickness: Thickness of the arrow. Thickness of arrow head is also adjusted accordingly. - :param color: Color of the arrow. - + :param pt1: Start point of the arrow. + :param pt2: End point of the arrow. + :param thickness: Thickness of the arrow. Thickness of arrow head is also adjusted accordingly. + :param color: Color of the arrow. + Arrow head is located at the end point of the arrow. - + CircleWidget ------------ .. ocv:class:: CircleWidget This 3D Widget defines a circle. :: - class CV_EXPORTS CircleWidget : public Widget3D - { - public: - CircleWidget(const Point3f& pt, double radius, double thickness = 0.01, const Color &color = Color::white()); - }; - + class CV_EXPORTS CircleWidget : public Widget3D + { + public: + CircleWidget(const Point3f& pt, double radius, double thickness = 0.01, const Color &color = Color::white()); + }; + CircleWidget::CircleWidget -------------------------- Constructs a CircleWidget. .. ocv:function:: CircleWidget(const Point3f& pt, double radius, double thickness = 0.01, const Color &color = Color::white()) - :param pt: Center of the circle. - :param radius: Radius of the circle. - :param thickness: Thickness of the circle. - :param color: Color of the circle. - + :param pt: Center of the circle. + :param radius: Radius of the circle. + :param thickness: Thickness of the circle. + :param color: Color of the circle. + CylinderWidget -------------- .. ocv:class:: CylinderWidget This 3D Widget defines a cylinder. :: - class CV_EXPORTS CylinderWidget : public Widget3D - { - public: - CylinderWidget(const Point3f& pt_on_axis, const Point3f& axis_direction, double radius, int numsides = 30, const Color &color = Color::white()); - }; + class CV_EXPORTS CylinderWidget : public Widget3D + { + public: + CylinderWidget(const Point3f& pt_on_axis, const Point3f& axis_direction, double radius, int numsides = 30, const Color &color = Color::white()); + }; CylinderWidget::CylinderWidget ------------------------------ @@ -277,146 +289,146 @@ Constructs a CylinderWidget. .. ocv:function:: CylinderWidget(const Point3f& pt_on_axis, const Point3f& axis_direction, double radius, int numsides = 30, const Color &color = Color::white()) - :param pt_on_axis: A point on the axis of the cylinder. - :param axis_direction: Direction of the axis of the cylinder. - :param radius: Radius of the cylinder. - :param numsides: Resolution of the cylinder. - :param color: Color of the cylinder. - + :param pt_on_axis: A point on the axis of the cylinder. + :param axis_direction: Direction of the axis of the cylinder. + :param radius: Radius of the cylinder. + :param numsides: Resolution of the cylinder. + :param color: Color of the cylinder. + CubeWidget ---------- .. ocv:class:: CubeWidget This 3D Widget defines a cube. :: - class CV_EXPORTS CubeWidget : public Widget3D - { - public: - CubeWidget(const Point3f& pt_min, const Point3f& pt_max, bool wire_frame = true, const Color &color = Color::white()); - }; - + class CV_EXPORTS CubeWidget : public Widget3D + { + public: + CubeWidget(const Point3f& pt_min, const Point3f& pt_max, bool wire_frame = true, const Color &color = Color::white()); + }; + CubeWidget::CubeWidget ---------------------- Constructs a CudeWidget. .. ocv:function:: CubeWidget(const Point3f& pt_min, const Point3f& pt_max, bool wire_frame = true, const Color &color = Color::white()) - :param pt_min: Specifies minimum point of the bounding box. - :param pt_max: Specifies maximum point of the bounding box. - :param wire_frame: If true, cube is represented as wireframe. - :param color: Color of the cube. - + :param pt_min: Specifies minimum point of the bounding box. + :param pt_max: Specifies maximum point of the bounding box. + :param wire_frame: If true, cube is represented as wireframe. + :param color: Color of the cube. + CoordinateSystemWidget ---------------------- .. ocv:class:: CoordinateSystemWidget This 3D Widget represents a coordinate system. :: - class CV_EXPORTS CoordinateSystemWidget : public Widget3D - { - public: - CoordinateSystemWidget(double scale = 1.0); - }; - + class CV_EXPORTS CoordinateSystemWidget : public Widget3D + { + public: + CoordinateSystemWidget(double scale = 1.0); + }; + CoordinateSystemWidget::CoordinateSystemWidget ---------------------------------------------- Constructs a CoordinateSystemWidget. .. ocv:function:: CoordinateSystemWidget(double scale = 1.0) - :param scale: Determines the size of the axes. - + :param scale: Determines the size of the axes. + PolyLineWidget -------------- .. ocv:class:: PolyLineWidget This 3D Widget defines a poly line. :: - class CV_EXPORTS PolyLineWidget : public Widget3D - { - public: - PolyLineWidget(InputArray points, const Color &color = Color::white()); + class CV_EXPORTS PolyLineWidget : public Widget3D + { + public: + PolyLineWidget(InputArray points, const Color &color = Color::white()); - private: - /* hidden */ - }; + private: + /* hidden */ + }; PolyLineWidget::PolyLineWidget ------------------------------ Constructs a PolyLineWidget. .. ocv:function:: PolyLineWidget(InputArray points, const Color &color = Color::white()) - - :param points: Point set. - :param color: Color of the poly line. - + + :param points: Point set. + :param color: Color of the poly line. + GridWidget ---------- .. ocv:class:: GridWidget This 3D Widget defines a grid. :: - class CV_EXPORTS GridWidget : public Widget3D - { - public: - //! Creates grid at the origin - GridWidget(const Vec2i &dimensions, const Vec2d &spacing, const Color &color = Color::white()); - //! Creates grid based on the plane equation - GridWidget(const Vec4f &coeffs, const Vec2i &dimensions, const Vec2d &spacing, const Color &color = Color::white()); - private: - /* hidden */ - }; - + class CV_EXPORTS GridWidget : public Widget3D + { + public: + //! Creates grid at the origin + GridWidget(const Vec2i &dimensions, const Vec2d &spacing, const Color &color = Color::white()); + //! Creates grid based on the plane equation + GridWidget(const Vec4f &coeffs, const Vec2i &dimensions, const Vec2d &spacing, const Color &color = Color::white()); + private: + /* hidden */ + }; + GridWidget::GridWidget ---------------------- Constructs a GridWidget. .. ocv:function:: GridWidget(const Vec2i &dimensions, const Vec2d &spacing, const Color &color = Color::white()) - :param dimensions: Number of columns and rows, respectively. - :param spacing: Size of each column and row, respectively. - :param color: Color of the grid. - + :param dimensions: Number of columns and rows, respectively. + :param spacing: Size of each column and row, respectively. + :param color: Color of the grid. + .. ocv:function: GridWidget(const Vec4f &coeffs, const Vec2i &dimensions, const Vec2d &spacing, const Color &color = Color::white()) - - :param coeffs: Plane coefficients as in (A,B,C,D) where Ax + By + Cz + D = 0. - :param dimensions: Number of columns and rows, respectively. - :param spacing: Size of each column and row, respectively. - :param color: Color of the grid. - + + :param coeffs: Plane coefficients as in (A,B,C,D) where Ax + By + Cz + D = 0. + :param dimensions: Number of columns and rows, respectively. + :param spacing: Size of each column and row, respectively. + :param color: Color of the grid. + Text3DWidget ------------ .. ocv:class:: Text3DWidget This 3D Widget represents 3D text. The text always faces the camera. :: - class CV_EXPORTS Text3DWidget : public Widget3D - { - public: - Text3DWidget(const String &text, const Point3f &position, double text_scale = 1.0, const Color &color = Color::white()); + class CV_EXPORTS Text3DWidget : public Widget3D + { + public: + Text3DWidget(const String &text, const Point3f &position, double text_scale = 1.0, const Color &color = Color::white()); - void setText(const String &text); - String getText() const; - }; - + void setText(const String &text); + String getText() const; + }; + Text3DWidget::Text3DWidget -------------------------- Constructs a Text3DWidget. .. ocv:function:: Text3DWidget(const String &text, const Point3f &position, double text_scale = 1.0, const Color &color = Color::white()) - :param text: Text content of the widget. - :param position: Position of the text. - :param text_scale: Size of the text. - :param color: Color of the text. - + :param text: Text content of the widget. + :param position: Position of the text. + :param text_scale: Size of the text. + :param color: Color of the text. + Text3DWidget::setText --------------------- Sets the text content of the widget. .. ocv:function:: void setText(const String &text) - :param text: Text content of the widget. + :param text: Text content of the widget. Text3DWidget::getText --------------------- @@ -430,33 +442,33 @@ TextWidget This 2D Widget represents text overlay. :: - class CV_EXPORTS TextWidget : public Widget2D - { - public: - TextWidget(const String &text, const Point2i &pos, int font_size = 10, const Color &color = Color::white()); + class CV_EXPORTS TextWidget : public Widget2D + { + public: + TextWidget(const String &text, const Point2i &pos, int font_size = 10, const Color &color = Color::white()); - void setText(const String &text); - String getText() const; - }; - + void setText(const String &text); + String getText() const; + }; + TextWidget::TextWidget ---------------------- Constructs a TextWidget. .. ocv:function:: TextWidget(const String &text, const Point2i &pos, int font_size = 10, const Color &color = Color::white()) - :param text: Text content of the widget. - :param pos: Position of the text. - :param font_size: Font size. - :param color: Color of the text. - + :param text: Text content of the widget. + :param pos: Position of the text. + :param font_size: Font size. + :param color: Color of the text. + TextWidget::setText --------------------- Sets the text content of the widget. .. ocv:function:: void setText(const String &text) - :param text: Text content of the widget. + :param text: Text content of the widget. TextWidget::getText --------------------- @@ -470,181 +482,181 @@ ImageOverlayWidget This 2D Widget represents an image overlay. :: - class CV_EXPORTS ImageOverlayWidget : public Widget2D - { - public: - ImageOverlayWidget(const Mat &image, const Rect &rect); - - void setImage(const Mat &image); - }; - + class CV_EXPORTS ImageOverlayWidget : public Widget2D + { + public: + ImageOverlayWidget(const Mat &image, const Rect &rect); + + void setImage(const Mat &image); + }; + ImageOverlayWidget::ImageOverlayWidget -------------------------------------- Constructs a ImageOverlayWidget. .. ocv:function:: ImageOverlayWidget(const Mat &image, const Rect &rect) - :param image: BGR or Gray-Scale image. - :param rect: Image is scaled and positioned based on rect. - + :param image: BGR or Gray-Scale image. + :param rect: Image is scaled and positioned based on rect. + ImageOverlayWidget::setImage ---------------------------- Sets the image content of the widget. .. ocv:function:: void setImage(const Mat &image) - :param image: BGR or Gray-Scale image. - + :param image: BGR or Gray-Scale image. + Image3DWidget ------------- .. ocv:class:: Image3DWidget This 3D Widget represents 3D image. :: - class CV_EXPORTS Image3DWidget : public Widget3D - { - public: - //! Creates 3D image at the origin - Image3DWidget(const Mat &image, const Size &size); - //! Creates 3D image at a given position, pointing in the direction of the normal, and having the up_vector orientation - Image3DWidget(const Vec3f &position, const Vec3f &normal, const Vec3f &up_vector, const Mat &image, const Size &size); - - void setImage(const Mat &image); - }; + class CV_EXPORTS Image3DWidget : public Widget3D + { + public: + //! Creates 3D image at the origin + Image3DWidget(const Mat &image, const Size &size); + //! Creates 3D image at a given position, pointing in the direction of the normal, and having the up_vector orientation + Image3DWidget(const Vec3f &position, const Vec3f &normal, const Vec3f &up_vector, const Mat &image, const Size &size); + + void setImage(const Mat &image); + }; Image3DWidget::Image3DWidget ---------------------------- Constructs a Image3DWidget. .. ocv:function:: Image3DWidget(const Mat &image, const Size &size) - - :param image: BGR or Gray-Scale image. - :param size: Size of the image. - + + :param image: BGR or Gray-Scale image. + :param size: Size of the image. + .. ocv:function:: Image3DWidget(const Vec3f &position, const Vec3f &normal, const Vec3f &up_vector, const Mat &image, const Size &size) - :param position: Position of the image. - :param normal: Normal of the plane that represents the image. - :param up_vector: Determines orientation of the image. - :param image: BGR or Gray-Scale image. - :param size: Size of the image. - + :param position: Position of the image. + :param normal: Normal of the plane that represents the image. + :param up_vector: Determines orientation of the image. + :param image: BGR or Gray-Scale image. + :param size: Size of the image. + Image3DWidget::setImage ----------------------- Sets the image content of the widget. .. ocv:function:: void setImage(const Mat &image) - :param image: BGR or Gray-Scale image. - + :param image: BGR or Gray-Scale image. + CameraPositionWidget -------------------- .. ocv:class:: CameraPositionWidget This 3D Widget represents camera position. :: - class CV_EXPORTS CameraPositionWidget : public Widget3D - { - public: - //! Creates camera coordinate frame (axes) at the origin - CameraPositionWidget(double scale = 1.0); - //! Creates frustum based on the intrinsic marix K at the origin - CameraPositionWidget(const Matx33f &K, double scale = 1.0, const Color &color = Color::white()); - //! Creates frustum based on the field of view at the origin - CameraPositionWidget(const Vec2f &fov, double scale = 1.0, const Color &color = Color::white()); - //! Creates frustum and display given image at the far plane - CameraPositionWidget(const Matx33f &K, const Mat &img, double scale = 1.0, const Color &color = Color::white()); - }; - + class CV_EXPORTS CameraPositionWidget : public Widget3D + { + public: + //! Creates camera coordinate frame (axes) at the origin + CameraPositionWidget(double scale = 1.0); + //! Creates frustum based on the intrinsic marix K at the origin + CameraPositionWidget(const Matx33f &K, double scale = 1.0, const Color &color = Color::white()); + //! Creates frustum based on the field of view at the origin + CameraPositionWidget(const Vec2f &fov, double scale = 1.0, const Color &color = Color::white()); + //! Creates frustum and display given image at the far plane + CameraPositionWidget(const Matx33f &K, const Mat &img, double scale = 1.0, const Color &color = Color::white()); + }; + CameraPositionWidget::CameraPositionWidget ------------------------------------------ Constructs a CameraPositionWidget. .. ocv:function:: CameraPositionWidget(double scale = 1.0) - Creates camera coordinate frame at the origin. - + Creates camera coordinate frame at the origin. + .. ocv:function:: CameraPositionWidget(const Matx33f &K, double scale = 1.0, const Color &color = Color::white()) - :param K: Intrinsic matrix of the camera. - :param scale: Scale of the frustum. - :param color: Color of the frustum. - - Creates viewing frustum of the camera based on its intrinsic matrix K. - + :param K: Intrinsic matrix of the camera. + :param scale: Scale of the frustum. + :param color: Color of the frustum. + + Creates viewing frustum of the camera based on its intrinsic matrix K. + .. ocv:function:: CameraPositionWidget(const Vec2f &fov, double scale = 1.0, const Color &color = Color::white()) - :param fov: Field of view of the camera (horizontal, vertical). - :param scale: Scale of the frustum. - :param color: Color of the frustum. - - Creates viewing frustum of the camera based on its field of view fov. + :param fov: Field of view of the camera (horizontal, vertical). + :param scale: Scale of the frustum. + :param color: Color of the frustum. + + Creates viewing frustum of the camera based on its field of view fov. .. ocv:function:: CameraPositionWidget(const Matx33f &K, const Mat &img, double scale = 1.0, const Color &color = Color::white()) - :param K: Intrinsic matrix of the camera. - :param img: BGR or Gray-Scale image that is going to be displayed at the far plane of the frustum. - :param scale: Scale of the frustum and image. - :param color: Color of the frustum. - - Creates viewing frustum of the camera based on its intrinsic matrix K, and displays image on the far end plane. - + :param K: Intrinsic matrix of the camera. + :param img: BGR or Gray-Scale image that is going to be displayed at the far plane of the frustum. + :param scale: Scale of the frustum and image. + :param color: Color of the frustum. + + Creates viewing frustum of the camera based on its intrinsic matrix K, and displays image on the far end plane. + TrajectoryWidget ---------------- .. ocv:class:: TrajectoryWidget This 3D Widget represents a trajectory. :: - class CV_EXPORTS TrajectoryWidget : public Widget3D - { - public: - enum {DISPLAY_FRAMES = 1, DISPLAY_PATH = 2}; - - //! Displays trajectory of the given path either by coordinate frames or polyline - TrajectoryWidget(const std::vector &path, int display_mode = TrajectoryWidget::DISPLAY_PATH, const Color &color = Color::white(), double scale = 1.0); - //! Displays trajectory of the given path by frustums - TrajectoryWidget(const std::vector &path, const Matx33f &K, double scale = 1.0, const Color &color = Color::white()); - //! Displays trajectory of the given path by frustums - TrajectoryWidget(const std::vector &path, const Vec2f &fov, double scale = 1.0, const Color &color = Color::white()); - - private: - /* hidden */ - }; - + class CV_EXPORTS TrajectoryWidget : public Widget3D + { + public: + enum {DISPLAY_FRAMES = 1, DISPLAY_PATH = 2}; + + //! Displays trajectory of the given path either by coordinate frames or polyline + TrajectoryWidget(const std::vector &path, int display_mode = TrajectoryWidget::DISPLAY_PATH, const Color &color = Color::white(), double scale = 1.0); + //! Displays trajectory of the given path by frustums + TrajectoryWidget(const std::vector &path, const Matx33f &K, double scale = 1.0, const Color &color = Color::white()); + //! Displays trajectory of the given path by frustums + TrajectoryWidget(const std::vector &path, const Vec2f &fov, double scale = 1.0, const Color &color = Color::white()); + + private: + /* hidden */ + }; + TrajectoryWidget::TrajectoryWidget ---------------------------------- Constructs a TrajectoryWidget. .. ocv:function:: TrajectoryWidget(const std::vector &path, int display_mode = TrajectoryWidget::DISPLAY_PATH, const Color &color = Color::white(), double scale = 1.0) - :param path: List of poses on a trajectory. - :param display_mode: Display mode. This can be DISPLAY_PATH, DISPLAY_FRAMES, DISPLAY_PATH & DISPLAY_FRAMES. - :param color: Color of the polyline that represents path. Frames are not affected. - :param scale: Scale of the frames. Polyline is not affected. - - Displays trajectory of the given path as follows: - - * DISPLAY_PATH : Displays a poly line that represents the path. - * DISPLAY_FRAMES : Displays coordinate frames at each pose. - * DISPLAY_PATH & DISPLAY_FRAMES : Displays both poly line and coordinate frames. - + :param path: List of poses on a trajectory. + :param display_mode: Display mode. This can be DISPLAY_PATH, DISPLAY_FRAMES, DISPLAY_PATH & DISPLAY_FRAMES. + :param color: Color of the polyline that represents path. Frames are not affected. + :param scale: Scale of the frames. Polyline is not affected. + + Displays trajectory of the given path as follows: + + * DISPLAY_PATH : Displays a poly line that represents the path. + * DISPLAY_FRAMES : Displays coordinate frames at each pose. + * DISPLAY_PATH & DISPLAY_FRAMES : Displays both poly line and coordinate frames. + .. ocv:function:: TrajectoryWidget(const std::vector &path, const Matx33f &K, double scale = 1.0, const Color &color = Color::white()) - :param path: List of poses on a trajectory. - :param K: Intrinsic matrix of the camera. - :param scale: Scale of the frustums. - :param color: Color of the frustums. - - Displays frustums at each pose of the trajectory. - + :param path: List of poses on a trajectory. + :param K: Intrinsic matrix of the camera. + :param scale: Scale of the frustums. + :param color: Color of the frustums. + + Displays frustums at each pose of the trajectory. + .. ocv:function:: TrajectoryWidget(const std::vector &path, const Vec2f &fov, double scale = 1.0, const Color &color = Color::white()) - :param path: List of poses on a trajectory. - :param fov: Field of view of the camera (horizontal, vertical). - :param scale: Scale of the frustums. - :param color: Color of the frustums. - - Displays frustums at each pose of the trajectory. + :param path: List of poses on a trajectory. + :param fov: Field of view of the camera (horizontal, vertical). + :param scale: Scale of the frustums. + :param color: Color of the frustums. + + Displays frustums at each pose of the trajectory. SpheresTrajectoryWidget ----------------------- @@ -653,62 +665,62 @@ SpheresTrajectoryWidget This 3D Widget represents a trajectory using spheres and lines, where spheres represent the positions of the camera, and lines represent the direction from previous position to the current. :: - class CV_EXPORTS SpheresTrajectoryWidget : public Widget3D - { - public: - SpheresTrajectoryWidget(const std::vector &path, float line_length = 0.05f, - double init_sphere_radius = 0.021, sphere_radius = 0.007, - Color &line_color = Color::white(), const Color &sphere_color = Color::white()); - }; - + class CV_EXPORTS SpheresTrajectoryWidget : public Widget3D + { + public: + SpheresTrajectoryWidget(const std::vector &path, float line_length = 0.05f, + double init_sphere_radius = 0.021, sphere_radius = 0.007, + Color &line_color = Color::white(), const Color &sphere_color = Color::white()); + }; + SpheresTrajectoryWidget::SpheresTrajectoryWidget ------------------------------------------------ Constructs a SpheresTrajectoryWidget. .. ocv:function:: SpheresTrajectoryWidget(const std::vector &path, float line_length = 0.05f, double init_sphere_radius = 0.021, double sphere_radius = 0.007, const Color &line_color = Color::white(), const Color &sphere_color = Color::white()) - - :param path: List of poses on a trajectory. - :param line_length: Length of the lines. - :param init_sphere_radius: Radius of the first sphere which represents the initial position of the camera. - :param sphere_radius: Radius of the rest of the spheres. - :param line_color: Color of the lines. - :param sphere_color: Color of the spheres. - + + :param path: List of poses on a trajectory. + :param line_length: Length of the lines. + :param init_sphere_radius: Radius of the first sphere which represents the initial position of the camera. + :param sphere_radius: Radius of the rest of the spheres. + :param line_color: Color of the lines. + :param sphere_color: Color of the spheres. + CloudWidget ----------- .. ocv:class:: CloudWidget This 3D Widget defines a point cloud. :: - class CV_EXPORTS CloudWidget : public Widget3D - { - public: - //! Each point in cloud is mapped to a color in colors - CloudWidget(InputArray cloud, InputArray colors); - //! All points in cloud have the same color - CloudWidget(InputArray cloud, const Color &color = Color::white()); + class CV_EXPORTS CloudWidget : public Widget3D + { + public: + //! Each point in cloud is mapped to a color in colors + CloudWidget(InputArray cloud, InputArray colors); + //! All points in cloud have the same color + CloudWidget(InputArray cloud, const Color &color = Color::white()); - private: - /* hidden */ - }; - + private: + /* hidden */ + }; + CloudWidget::CloudWidget ------------------------ Constructs a CloudWidget. .. ocv:function:: CloudWidget(InputArray cloud, InputArray colors) - :param cloud: Point set which can be of type: CV_32FC3, CV_32FC4, CV_64FC3, CV_64FC4. - :param colors: Set of colors. It has to be of the same size with cloud. - - Points in the cloud belong to mask when they are set to (NaN, NaN, NaN). + :param cloud: Point set which can be of type: CV_32FC3, CV_32FC4, CV_64FC3, CV_64FC4. + :param colors: Set of colors. It has to be of the same size with cloud. + + Points in the cloud belong to mask when they are set to (NaN, NaN, NaN). .. ocv:function:: CloudWidget(InputArray cloud, const Color &color = Color::white()) - - :param cloud: Point set which can be of type: CV_32FC3, CV_32FC4, CV_64FC3, CV_64FC4. - :param color: A single color for the whole cloud. + + :param cloud: Point set which can be of type: CV_32FC3, CV_32FC4, CV_64FC3, CV_64FC4. + :param color: A single color for the whole cloud. - Points in the cloud belong to mask when they are set to (NaN, NaN, NaN). + Points in the cloud belong to mask when they are set to (NaN, NaN, NaN). CloudCollectionWidget --------------------- @@ -716,20 +728,20 @@ CloudCollectionWidget This 3D Widget defines a collection of clouds. :: - class CV_EXPORTS CloudCollectionWidget : public Widget3D - { - public: - CloudCollectionWidget(); - - //! Each point in cloud is mapped to a color in colors - void addCloud(InputArray cloud, InputArray colors, const Affine3f &pose = Affine3f::Identity()); - //! All points in cloud have the same color - void addCloud(InputArray cloud, const Color &color = Color::white(), Affine3f &pose = Affine3f::Identity()); - - private: - /* hidden */ - }; - + class CV_EXPORTS CloudCollectionWidget : public Widget3D + { + public: + CloudCollectionWidget(); + + //! Each point in cloud is mapped to a color in colors + void addCloud(InputArray cloud, InputArray colors, const Affine3f &pose = Affine3f::Identity()); + //! All points in cloud have the same color + void addCloud(InputArray cloud, const Color &color = Color::white(), Affine3f &pose = Affine3f::Identity()); + + private: + /* hidden */ + }; + CloudCollectionWidget::CloudCollectionWidget -------------------------------------------- Constructs a CloudCollectionWidget. @@ -742,69 +754,69 @@ Adds a cloud to the collection. .. ocv:function:: void addCloud(InputArray cloud, InputArray colors, const Affine3f &pose = Affine3f::Identity()) - :param cloud: Point set which can be of type: CV_32FC3, CV_32FC4, CV_64FC3, CV_64FC4. - :param colors: Set of colors. It has to be of the same size with cloud. - :param pose: Pose of the cloud. - - Points in the cloud belong to mask when they are set to (NaN, NaN, NaN). - + :param cloud: Point set which can be of type: CV_32FC3, CV_32FC4, CV_64FC3, CV_64FC4. + :param colors: Set of colors. It has to be of the same size with cloud. + :param pose: Pose of the cloud. + + Points in the cloud belong to mask when they are set to (NaN, NaN, NaN). + .. ocv:function:: void addCloud(InputArray cloud, const Color &color = Color::white(), const Affine3f &pose = Affine3f::Identity()) - :param cloud: Point set which can be of type: CV_32FC3, CV_32FC4, CV_64FC3, CV_64FC4. - :param colors: A single color for the whole cloud. - :param pose: Pose of the cloud. - - Points in the cloud belong to mask when they are set to (NaN, NaN, NaN). - + :param cloud: Point set which can be of type: CV_32FC3, CV_32FC4, CV_64FC3, CV_64FC4. + :param colors: A single color for the whole cloud. + :param pose: Pose of the cloud. + + Points in the cloud belong to mask when they are set to (NaN, NaN, NaN). + CloudNormalsWidget ------------------ .. ocv:class:: CloudNormalsWidget This 3D Widget represents normals of a point cloud. :: - class CV_EXPORTS CloudNormalsWidget : public Widget3D - { - public: - CloudNormalsWidget(InputArray cloud, InputArray normals, int level = 100, float scale = 0.02f, const Color &color = Color::white()); + class CV_EXPORTS CloudNormalsWidget : public Widget3D + { + public: + CloudNormalsWidget(InputArray cloud, InputArray normals, int level = 100, float scale = 0.02f, const Color &color = Color::white()); - private: - /* hidden */ - }; - + private: + /* hidden */ + }; + CloudNormalsWidget::CloudNormalsWidget -------------------------------------- Constructs a CloudNormalsWidget. .. ocv:function:: CloudNormalsWidget(InputArray cloud, InputArray normals, int level = 100, float scale = 0.02f, const Color &color = Color::white()) - - :param cloud: Point set which can be of type: CV_32FC3, CV_32FC4, CV_64FC3, CV_64FC4. - :param normals: A set of normals that has to be of same type with cloud. - :param level: Display only every levelth normal. - :param scale: Scale of the arrows that represent normals. - :param color: Color of the arrows that represent normals. - + + :param cloud: Point set which can be of type: CV_32FC3, CV_32FC4, CV_64FC3, CV_64FC4. + :param normals: A set of normals that has to be of same type with cloud. + :param level: Display only every levelth normal. + :param scale: Scale of the arrows that represent normals. + :param color: Color of the arrows that represent normals. + MeshWidget ---------- .. ocv:class:: MeshWidget This 3D Widget defines a mesh. :: - - class CV_EXPORTS MeshWidget : public Widget3D - { - public: - MeshWidget(const Mesh3d &mesh); - - private: - /* hidden */ - }; - + + class CV_EXPORTS MeshWidget : public Widget3D + { + public: + MeshWidget(const Mesh3d &mesh); + + private: + /* hidden */ + }; + MeshWidget::MeshWidget ---------------------- Constructs a MeshWidget. .. ocv:function:: MeshWidget(const Mesh3d &mesh) - :param mesh: Mesh object that will be displayed. + :param mesh: Mesh object that will be displayed. From b60894c1dd9fe0967f9bcc8481208267619189fe Mon Sep 17 00:00:00 2001 From: Ozan Tonkal Date: Sun, 1 Sep 2013 21:43:40 +0200 Subject: [PATCH 27/29] launching viz tutorial --- doc/tutorials/viz/images/window_demo.png | Bin 0 -> 7519 bytes doc/tutorials/viz/viz.rst | 118 ++++++++++++++++++ .../cpp/tutorial_code/viz/launching_viz.cpp | 53 ++++++++ 3 files changed, 171 insertions(+) create mode 100644 doc/tutorials/viz/images/window_demo.png create mode 100644 doc/tutorials/viz/viz.rst create mode 100644 samples/cpp/tutorial_code/viz/launching_viz.cpp diff --git a/doc/tutorials/viz/images/window_demo.png b/doc/tutorials/viz/images/window_demo.png new file mode 100644 index 0000000000000000000000000000000000000000..b853fe29da9b03ce7e606dae6aa743e3822df2df GIT binary patch literal 7519 zcmeHLi&v8A)~C~Sn@Z1|&eU`f&rGIsj<-@11(l{|GBR+o)GW~~l}y1DK@pXi>Eg_k z+IUR?sqw;i&l{$A8S_&^1xi9xKq^E6L{dUT0Y93v*7qNLYn`*!yz5=>yWaimXFb2Y zpZ)G<@83_~BK&uLyzgTG0I(Bw>gyl?;4cjTzy|8p%@&Cl=QP>!`Ura*c7Chn%GetH zqvd;V$~PBM&LzgCq(&vj08p4jbc{3hYH~~r274_rMYFNb4*)o@2>bf0^Jx^dn0P-H z^_6^4;;m^QcFFU%ea^BwW_P*p7UXaL`2OLMZChXNF24Q6S0hN*y2p37I&J##kju=^ z-ylOqldD3yzeuQgcR1DvDG_?F4GYDkcJ8I+k72;yxO8Pq zm&8x5&@Kyi^=iAh-ibIqsxiS|nsjm?>CON@d_AX0PU_L+Z3F=H*#gs2Q?*2c!eCsm zSZpbc7N}$8k=l?*BwKl-FmkOu5}rRljTct?aCI)bi^jO=es6W5YpjrJ4Mh{J|RVYP}L@ z?6%r3|BQrO$hxK6I*j#^m|U2^;Y5*m-T&2OB^ycqU2o2(^z4C#d@>F>jaN^y)zn)X*R>1R&^Nd7?5(zC|)To)`p+i!by zooQ<5^j`z^_P^+u9CPm?>T_VRi(n{}cKi12^ChIWH`OB}r?X4~$^Bi3$>yJ;0DxCB z9jTh$?$x7xl)=Hl^O~M{+i6hu>(JJ#!^>-HPb>;n%W5Glv~RBDTvKD?jAZyP0Dymc zTU(*hsO6wL5+(S&&DVsUaA74nHa>J(icB5nOw2ZDKx?h+g#O8SZtcZLeJDDiuO?|? zp}w~AG!;Qd1P9lsz-S@n-gdyTsbvlHJ|>^|S8{wa80`kkb1y}>QyKe@Oe)SR@L&aw z>F+yQi57;HFW)=Yr6hpPgXI%J;bfTA0_1_LnmlN8sr7~ks@6Qex&h#Y;2Y#rAx7Nwq$Wqmfb%@| z<_vk)M9MqL@p!zm)wn0GGH%=xUfYFGf`i4Zg{r6s-7h4z^FUm>$vpiTY@+yY_lBhJ z(|deOKWuNo%5%@q;nh5QxH}A)%2SL*O!TQ4nTB_thDQ4U=@M1L?b!AsoHQQ<{hYj8 z%i*#dpoihu*(6L4F3@lFMP7^t5Y;FNqzk=!uc3wYz)9N13Oj1&yvRE>Tbbxk*NN6# zudZ>MWE`UUctKaYN@QUU;biD~QyTkxV-4J(|&LZiv3xam7pW zT3kE&PCziw6giV$QqF^6I-Qy_2AM61DyQ8-)^#fkF=WQLh09`vv4%+|nW0C>8Ib~C z1|)~{YVLK0FL&C*adn*gzQ#FtAo!rrKHDv9nilKhqeOS5e<{Y74b$43 zHAZEFLYEH9XT-T3u)_9l3WPTaSU0>zQoua}4RK{T!e}=HQs8ZvElAe!1=WI5_I*!y z!E5F9^3^u2I}|keKVAhXU>w3*_I>B7GM=YS@hskU;9PJOCmC;>aV_gD%Yoi{<4OqB z)NiE8B35x^h0@M?rGJksyAKu6k`gnsB&Ts7z1A6)X28;>i1KyQFDmz%JC?uX(CFv@ zWG19;$6QwpNSL8lG<)pbxo7D&x!*yQYyCRVF1Uj>NTts)ZHZY~Z;u4~r4H_CZCa>2 z7u=dz9Gd*<_tVA2p{*@oR-3X?QX?q#3T#cj;l0JWAy)DHdU1(=*j_k~QBd#HF#GBe z->K=08;tr@lb=()U>M06UphQmSKy(jBxR!k-)TH5UZiQ=8(PEIN#%r*w`ODD{?Ov^VIoTqTpjiO{8Tamh2noIYV6`pH(^7yeQBH17d zjdm+Nuy`aq<;Cs2dBgjqq6{rt!61`*dX+jiqrh5*t;-wh#6qy~(}BGa3Fr3LJJ zlLV2o zIUiGiodf*d@u>ZpSTrPMdF-Kh&{&T)#@S2lSnxWYaXDD>Y}6Ke9oUQw=g2VY!x* z0?9l-;kVG`Z1ce7r(NW-%X{+2UG;F80ieb2+o?ubDLR2D@Q)dUPgVGNU6CO!`FjPjaZQH9>eutE>77 zn68M|PTxhGabt~tpR_wLBhAIA2$kP@QKzl03*ki*IfOR@$rnK|cg~ZA7}bgL`*Oc% zPjgCH${d1om9%om(5Z?jm6%KHO>srpJ#R~vy0)isJg*nbaNM=;_w?AKFvQF(1+pXh zan;qKPXWCr8sLcb;qG8qnZm=mtZsZq2@f$8=OCqMe^(P^SeIvHb6n~SR^335%JFhb zOk4+IN4D)3dJM=YexX&R2o%Z$;yJlEMSJXv1yiHl_9k{0l2-1i=5N(1rUedrbMAyq zw#49{hUPO$W22%zuXyog0n3i3s2{UzQA<}>dN#D6KC=mSvf?bGKBu*GIBTT=1Y(8G ztp79*%U1_J`^H)w9n(&Bckuy13T9VFwRz0CF`Fplm?g*D$qbJ!rzWVL{E9mF`lcbOcX>+X2G75Z^u{%^ z(}V>}Pc1%QVjKB&5fqxSbdP*6u@em6Oc1r&($rE#l=Q%}Em^Wdgnq6$!Vf|bV|BLX zE9L9En#L|Q!t%3#iE~UOH*CyAWrOnAhY^YAnTJql8@Ye^%Cm0W)%C&v+R|?nv8b5! zy$~bmsC5(E1H}fB8SvVK?t78J!G4QBIp(c4(3T3Zpkx~JwEH9)+>_GC^eM@dz6oD_I7lJB7|>3rro)pLChX8=wU{>6(1Y16 zoZGr))q;Coshy;ajk*$!jYpKE8s})Utrc0j)73*xs+CtB)}+BpOJ&2N2(q+prjWGG z3`Jp@iE9aOGH*C}zsW-_W8=w{(_W=@@Pf+JX>Y=f{Mk0+WTGi5YyO=WPbuEj#dc}| zov*RZ^j%NBx^yes?&e??nBSWr8zmOF2R<_{J1g4YwYsFxzWe&{PS=}gvFP2RwM{QaN`FHh`!0)?7q{bf{| zse_UIXD#H*_lMMXs(>I6J4 zhTw^qU?7n;)wR=h!OGR;Yrf-E^|21o?4L8e4q&=RCl+gXDsg^Z?^*!C%%v6?9K!SI zSs$)`8l2{mvdG?QQ52r-QG^C{xE@iVAa za;Pn3Hnlh7@Va6P?E!Xk1x0tyL7r2R`Gu=#VK9R`4Q6#IWo1=S%6501s*5wzv(|!B z9iL{vkbo@M;FER(O__pST+`cL*iVNe1+dt)F~106O1$g- zKzm+$QmvD-&E%vxjo*W@%382psyTs@b>D8)+GZu=*UPQ@9M(M*G0&L+NPAdyfem3O zz=iGI6Rp@qDwHtaOq>adS+67y4w{ExXL|<0k>*5bk*#-z&Gl3l$Zkk{9A08G`b(A{ zTX{Hp4#Cy?YQ~Mmf(|jg!fuyC6X9N8Z{Oh<+jH149(lQdx=v8?i~xy99;-On?aSzK3OQ(${ zQY$6Gd@!y{jKTEiik+OsP+)3xZP`m)0fOEe(8iguyNp-inVp6?GEbF~=Y>FWW4A$d zHC#)XaK>Kh0cRdTbO<44*@o6Fh5hdW3}n5eP+Lx1n$C=5LtL3I3hP++U({4=6KBF9 zqHIrw-l@97M|qnd)kK!r#bFGmW>&}=4!dXOq!WG*BYGHFertK_HiE0|D79B!!(D4P z^0f{zJkU(`61^F`F~O9r}{?SXbDf7653^v(;Jpi2xVdp>fw^o-DF?ns`c ze`#|5^g&Oq$fI>iAS)_*8C-N?baV={(NLc3Ir!T2O!& znHw(+m<&Vh>mXXM(L~TY^!*asNW zHG;85)5TEOCE0X*6FjJD;k;z}i)XQAC$dkLw!!!+l*&kT>3r$w-R3b?*)T3~dv+N- z*8lpG-bg2e88?*E5I?~eO7dSQ4!y# zxubCVTxfD^Dy0Eea1&0Ax9iKfgX~cy;C>f2=>#~@a)+sWu8BL3V0>#k9PCz?MU(!rFp=D;XFl(I}}Qq{3(#!>UZv< zAb7f#^AK36Zip1>mhawZq&>i`bO|bQcplUptJEFoJvoCLT8sVyuZFt;bFBB9%EK!@ z1$?(QFemv$wKZ07)+Q$7J+}Ghs!$7;lbK*~dE1{_=b+7SR4++|@${~q`sEmR`tSdy)U z=sXZi=Y3+qTL}Mvw;Mq(=yJTc0r2GofhD&Bs>sgPZ}A$96ae_HLYcyh{V+s6`oTVK zSqK2|vphfa|7?x_Fc={?)C2&0NezhDVDZTxqVj+1<30?R%PhY8d*bc} zSo*KafPV(ZJ9=qd^1l<_sH>tl?io&dnUL44hK{PGX~3r;>f A?*IS* literal 0 HcmV?d00001 diff --git a/doc/tutorials/viz/viz.rst b/doc/tutorials/viz/viz.rst new file mode 100644 index 0000000000..ceceaf1977 --- /dev/null +++ b/doc/tutorials/viz/viz.rst @@ -0,0 +1,118 @@ +.. _viz: + +Launching Viz +************* + +Goal +==== + +In this tutorial you will learn how to + +.. container:: enumeratevisibleitemswithsquare + + * Open a visualization window. + * Access a window by its name. + * Start event loop. + * Start event loop for a given amount of time. + +Code +==== + +You can download the code from `here <../../../../samples/cpp/tutorial_code/viz/launching_viz.cpp>`_. + +.. code-block:: cpp + + #include + #include + + using namespace cv; + using namespace std; + + /** + * @function main + */ + int main() + { + /// Create a window + viz::Viz3d myWindow("Viz Demo"); + + /// Start event loop + myWindow.spin(); + + /// Event loop is over when pressed q, Q, e, E + cout << "First event loop is over" << endl; + + /// Access window via its name + viz::Viz3d sameWindow = viz::get("Viz Demo"); + + /// Start event loop + sameWindow.spin(); + + /// Event loop is over when pressed q, Q, e, E + cout << "Second event loop is over" << endl; + + /// Event loop is over when pressed q, Q, e, E + /// Start event loop once for 1 millisecond + sameWindow.spinOnce(1, true); + while(!sameWindow.wasStopped()) + { + /// Interact with window + + /// Event loop for 1 millisecond + sameWindow.spinOnce(1, true); + } + + /// Once more event loop is stopped + cout << "Last event loop is over" << endl; + return 0; + } + +Explanation +=========== + +Here is the general structure of the program: + +* Create a window. + +.. code-block:: cpp + + /// Create a window + viz::Viz3d myWindow("Viz Demo"); + +* Start event loop. This event loop will run until user terminates it by pressing **e**, **E**, **q**, **Q**. + +.. code-block:: cpp + + /// Start event loop + myWindow.spin(); + +* Access same window via its name. Since windows are implicitly shared, **sameWindow** is exactly the same with **myWindow**. If the name does not exist, a new window is created. + +.. code-block:: cpp + + /// Access window via its name + viz::Viz3d sameWindow = viz::get("Viz Demo"); + +* Start a controlled event loop. Once it starts, **wasStopped** is set to false. Inside the while loop, in each iteration, **spinOnce** is called to prevent event loop from completely stopping. Inside the while loop, user can execute other statements including those which interact with the window. + +.. code-block:: cpp + + /// Event loop is over when pressed q, Q, e, E + /// Start event loop once for 1 millisecond + sameWindow.spinOnce(1, true); + while(!sameWindow.wasStopped()) + { + /// Interact with window + + /// Event loop for 1 millisecond + sameWindow.spinOnce(1, true); + } + +Results +======= + +Here is the result of the program. + +.. image:: images/window_demo.png + :alt: Launching Viz + :align: center diff --git a/samples/cpp/tutorial_code/viz/launching_viz.cpp b/samples/cpp/tutorial_code/viz/launching_viz.cpp new file mode 100644 index 0000000000..1827b33ea1 --- /dev/null +++ b/samples/cpp/tutorial_code/viz/launching_viz.cpp @@ -0,0 +1,53 @@ +#include +#include + +using namespace cv; +using namespace std; + +void help() +{ + cout + << "--------------------------------------------------------------------------" << endl + << "This program shows how to launch a 3D visualization window. You can stop event loop to continue executing. " + << "You can access the same window via its name. You can run event loop for a given period of time. " << endl + << "Usage:" << endl + << "./window_demo" << endl + << endl; +} + +int main() +{ + help(); + /// Create a window + viz::Viz3d myWindow("Viz Demo"); + + /// Start event loop + myWindow.spin(); + + /// Event loop is over when pressed q, Q, e, E + cout << "First event loop is over" << endl; + + /// Access window via its name + viz::Viz3d sameWindow = viz::get("Viz Demo"); + + /// Start event loop + sameWindow.spin(); + + /// Event loop is over when pressed q, Q, e, E + cout << "Second event loop is over" << endl; + + /// Event loop is over when pressed q, Q, e, E + /// Start event loop once for 1 millisecond + sameWindow.spinOnce(1, true); + while(!sameWindow.wasStopped()) + { + /// Interact with window + + /// Event loop for 1 millisecond + sameWindow.spinOnce(1, true); + } + + /// Once more event loop is stopped + cout << "Last event loop is over" << endl; + return 0; +} From f99e874704100bf9279a60611ff13b962c84fff7 Mon Sep 17 00:00:00 2001 From: Ozan Tonkal Date: Thu, 5 Sep 2013 20:53:57 +0200 Subject: [PATCH 28/29] tutorial: creating_widgets code --- .../tutorial_code/viz/creating_widgets.cpp | 106 ++++++++++++++++++ .../cpp/tutorial_code/viz/launching_viz.cpp | 23 +++- 2 files changed, 124 insertions(+), 5 deletions(-) create mode 100644 samples/cpp/tutorial_code/viz/creating_widgets.cpp diff --git a/samples/cpp/tutorial_code/viz/creating_widgets.cpp b/samples/cpp/tutorial_code/viz/creating_widgets.cpp new file mode 100644 index 0000000000..1c0f9a34ea --- /dev/null +++ b/samples/cpp/tutorial_code/viz/creating_widgets.cpp @@ -0,0 +1,106 @@ +/** + * @file creating_widgets.cpp + * @brief Creating custom widgets using VTK + * @author Ozan Cagri Tonkal + */ + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace cv; +using namespace std; + +/** + * @function help + * @brief Display instructions to use this tutorial program + */ +void help() +{ + cout + << "--------------------------------------------------------------------------" << endl + << "This program shows how to create a custom widget. You can create your own " + << "widgets by extending Widget2D/Widget3D, and with the help of WidgetAccessor." << endl + << "Usage:" << endl + << "./creating_widgets" << endl + << endl; +} + +/** + * @class TriangleWidget + * @brief Defining our own 3D Triangle widget + */ +class TriangleWidget : public viz::Widget3D +{ + public: + TriangleWidget(const Point3f &pt1, const Point3f &pt2, const Point3f &pt3, const viz::Color & color = viz::Color::white()); +}; + +/** + * @function TriangleWidget::TriangleWidget + * @brief Constructor + */ +TriangleWidget::TriangleWidget(const Point3f &pt1, const Point3f &pt2, const Point3f &pt3, const viz::Color & color) +{ + // Create a triangle + vtkSmartPointer points = vtkSmartPointer::New(); + points->InsertNextPoint(pt1.x, pt1.y, pt1.z); + points->InsertNextPoint(pt2.x, pt2.y, pt2.z); + points->InsertNextPoint(pt3.x, pt3.y, pt3.z); + + vtkSmartPointer triangle = vtkSmartPointer::New(); + triangle->GetPointIds()->SetId(0,0); + triangle->GetPointIds()->SetId(1,1); + triangle->GetPointIds()->SetId(2,2); + + vtkSmartPointer cells = vtkSmartPointer::New(); + cells->InsertNextCell(triangle); + + // Create a polydata object + vtkSmartPointer polyData = vtkSmartPointer::New(); + + // Add the geometry and topology to the polydata + polyData->SetPoints(points); + polyData->SetPolys(cells); + + // Create mapper and actor + vtkSmartPointer mapper = vtkSmartPointer::New(); + mapper->SetInput(polyData); + + vtkSmartPointer actor = vtkSmartPointer::New(); + actor->SetMapper(mapper); + + // Store this actor in the widget in order that visualizer can access it + viz::WidgetAccessor::setProp(*this, actor); +} + +/** + * @function main + */ +int main() +{ + help(); + + /// Create a window + viz::Viz3d myWindow("Creating Widgets"); + + /// Create a triangle widget + TriangleWidget tw(Point3f(0.0,0.0,0.0), Point3f(1.0,1.0,1.0), Point3f(0.0,1.0,0.0)); + + /// Show widget in the visualizer window + myWindow.showWidget("TRIANGLE", tw); + + /// Start event loop + myWindow.spin(); + + return 0; +} diff --git a/samples/cpp/tutorial_code/viz/launching_viz.cpp b/samples/cpp/tutorial_code/viz/launching_viz.cpp index 1827b33ea1..8dc9a617f0 100644 --- a/samples/cpp/tutorial_code/viz/launching_viz.cpp +++ b/samples/cpp/tutorial_code/viz/launching_viz.cpp @@ -1,9 +1,19 @@ +/** + * @file launching_viz.cpp + * @brief Launching visualization window + * @author Ozan Cagri Tonkal + */ + #include #include using namespace cv; using namespace std; +/** + * @function help + * @brief Display instructions to use this tutorial program + */ void help() { cout @@ -11,10 +21,13 @@ void help() << "This program shows how to launch a 3D visualization window. You can stop event loop to continue executing. " << "You can access the same window via its name. You can run event loop for a given period of time. " << endl << "Usage:" << endl - << "./window_demo" << endl + << "./launching_viz" << endl << endl; } +/** + * @function main + */ int main() { help(); @@ -41,10 +54,10 @@ int main() sameWindow.spinOnce(1, true); while(!sameWindow.wasStopped()) { - /// Interact with window - - /// Event loop for 1 millisecond - sameWindow.spinOnce(1, true); + /// Interact with window + + /// Event loop for 1 millisecond + sameWindow.spinOnce(1, true); } /// Once more event loop is stopped From 5eed0d6beff098f01d90500f3d430be9c75d3195 Mon Sep 17 00:00:00 2001 From: Ozan Tonkal Date: Thu, 5 Sep 2013 20:54:41 +0200 Subject: [PATCH 29/29] remove common.h include from widgets.hpp --- modules/viz/include/opencv2/viz/widgets.hpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/modules/viz/include/opencv2/viz/widgets.hpp b/modules/viz/include/opencv2/viz/widgets.hpp index fb2d6ca349..f96d0e6102 100644 --- a/modules/viz/include/opencv2/viz/widgets.hpp +++ b/modules/viz/include/opencv2/viz/widgets.hpp @@ -1,8 +1,6 @@ #pragma once #include -#include - namespace cv {