From 0d702b83f4bbcdcaed1f3463e21c7bbe89445dee Mon Sep 17 00:00:00 2001 From: Anatoly Baksheev Date: Wed, 8 Jan 2014 17:16:25 +0400 Subject: [PATCH] updated code to use mapper->SetInput instead of SetInputConnection. All widgets except plane, images ans texts --- modules/core/include/opencv2/core/affine.hpp | 8 +++ modules/viz/include/opencv2/viz.hpp | 3 - modules/viz/src/clouds.cpp | 40 ++++--------- modules/viz/src/interactor_style.cpp | 2 - modules/viz/src/shapes.cpp | 89 +++++++++++----------------- 5 files changed, 54 insertions(+), 88 deletions(-) diff --git a/modules/core/include/opencv2/core/affine.hpp b/modules/core/include/opencv2/core/affine.hpp index 62720b5..0ee6fab 100644 --- a/modules/core/include/opencv2/core/affine.hpp +++ b/modules/core/include/opencv2/core/affine.hpp @@ -113,6 +113,8 @@ namespace cv template operator Affine3() const; + template Affine3 cast() const; + Mat4 matrix; #if defined EIGEN_WORLD_VERSION && defined EIGEN_GEOMETRY_MODULE_H @@ -421,6 +423,12 @@ cv::Affine3::operator Affine3() const return Affine3(matrix); } +template template inline +cv::Affine3 cv::Affine3::cast() const +{ + return Affine3(matrix); +} + template inline cv::Affine3 cv::operator*(const cv::Affine3& affine1, const cv::Affine3& affine2) { diff --git a/modules/viz/include/opencv2/viz.hpp b/modules/viz/include/opencv2/viz.hpp index b281635..9ceed08 100644 --- a/modules/viz/include/opencv2/viz.hpp +++ b/modules/viz/include/opencv2/viz.hpp @@ -41,9 +41,6 @@ // * Ozan Tonkal, ozantonkal@gmail.com // * Anatoly Baksheev, Itseez Inc. myname.mysurname <> mycompany.com // -// OpenCV Viz module is complete rewrite of -// PCL visualization module (www.pointclouds.org) -// //M*/ #ifndef __OPENCV_VIZ_HPP__ diff --git a/modules/viz/src/clouds.cpp b/modules/viz/src/clouds.cpp index 15e9d4a..4b4010e 100644 --- a/modules/viz/src/clouds.cpp +++ b/modules/viz/src/clouds.cpp @@ -54,9 +54,10 @@ cv::viz::WCloud::WCloud(InputArray cloud, InputArray colors) vtkSmartPointer cloud_source = vtkSmartPointer::New(); cloud_source->SetColorCloud(cloud, colors); + cloud_source->Update(); vtkSmartPointer mapper = vtkSmartPointer::New(); - mapper->SetInputConnection(cloud_source->GetOutputPort()); + VtkUtils::SetInputData(mapper, cloud_source->GetOutput()); mapper->SetScalarModeToUsePointData(); mapper->ImmediateModeRenderingOff(); mapper->SetScalarRange(0, 255); @@ -74,9 +75,10 @@ cv::viz::WCloud::WCloud(InputArray cloud, const Color &color) { vtkSmartPointer cloud_source = vtkSmartPointer::New(); cloud_source->SetCloud(cloud); + cloud_source->Update(); vtkSmartPointer mapper = vtkSmartPointer::New(); - mapper->SetInputConnection(cloud_source->GetOutputPort()); + VtkUtils::SetInputData(mapper, cloud_source->GetOutput()); mapper->ImmediateModeRenderingOff(); mapper->ScalarVisibilityOff(); @@ -127,15 +129,11 @@ void cv::viz::WCloudCollection::addCloud(InputArray cloud, InputArray colors, co { // This is the first cloud mapper = vtkSmartPointer::New(); -#if VTK_MAJOR_VERSION <= 5 - mapper->SetInput(polydata); -#else - mapper->SetInputData(polydata); -#endif mapper->SetScalarRange(0, 255); mapper->SetScalarModeToUsePointData(); mapper->ScalarVisibilityOn(); mapper->ImmediateModeRenderingOff(); + VtkUtils::SetInputData(mapper, polydata); actor->SetNumberOfCloudPoints(std::max(1, polydata->GetNumberOfPoints()/10)); actor->GetProperty()->SetInterpolationToFlat(); @@ -147,16 +145,12 @@ void cv::viz::WCloudCollection::addCloud(InputArray cloud, InputArray colors, co vtkPolyData *currdata = vtkPolyData::SafeDownCast(mapper->GetInput()); CV_Assert("Cloud Widget without data" && currdata); - vtkSmartPointer appendFilter = vtkSmartPointer::New(); -#if VTK_MAJOR_VERSION <= 5 - appendFilter->AddInput(currdata); - appendFilter->AddInput(polydata); - mapper->SetInput(appendFilter->GetOutput()); -#else - appendFilter->AddInputData(currdata); - appendFilter->AddInputData(polydata); - mapper->SetInputData(appendFilter->GetOutput()); -#endif + vtkSmartPointer append_filter = vtkSmartPointer::New(); + append_filter->AddInputConnection(currdata->GetProducerPort()); + append_filter->AddInputConnection(polydata->GetProducerPort()); + append_filter->Update(); + + VtkUtils::SetInputData(mapper, append_filter->GetOutput()); actor->SetNumberOfCloudPoints(std::max(1, actor->GetNumberOfCloudPoints() + polydata->GetNumberOfPoints()/10)); } @@ -245,11 +239,7 @@ cv::viz::WCloudNormals::WCloudNormals(InputArray _cloud, InputArray _normals, in vtkSmartPointer mapper = vtkSmartPointer::New(); mapper->SetColorModeToMapScalars(); mapper->SetScalarModeToUsePointData(); -#if VTK_MAJOR_VERSION <= 5 - mapper->SetInput(polyData); -#else - mapper->SetInputData(polyData); -#endif + VtkUtils::SetInputData(mapper, polyData); vtkSmartPointer actor = vtkSmartPointer::New(); actor->SetMapper(mapper); @@ -326,11 +316,7 @@ cv::viz::WMesh::WMesh(const Mesh3d &mesh) vtkSmartPointer mapper = vtkSmartPointer::New(); mapper->SetScalarModeToUsePointData(); mapper->ImmediateModeRenderingOff(); -#if VTK_MAJOR_VERSION <= 5 - mapper->SetInput(polydata); -#else - mapper->SetInputData(polydata); -#endif + VtkUtils::SetInputData(mapper, polydata); vtkSmartPointer actor = vtkSmartPointer::New(); //actor->SetNumberOfCloudPoints(std::max(1, polydata->GetNumberOfPoints() / 10)); diff --git a/modules/viz/src/interactor_style.cpp b/modules/viz/src/interactor_style.cpp index 19a3476..2e948e6 100644 --- a/modules/viz/src/interactor_style.cpp +++ b/modules/viz/src/interactor_style.cpp @@ -564,7 +564,6 @@ void cv::viz::InteractorStyle::OnLeftButtonUp() void cv::viz::InteractorStyle::OnMiddleButtonDown() { Vec2i p(Interactor->GetEventPosition()); - MouseEvent::Type type = (Interactor->GetRepeatCount() == 0) ? MouseEvent::MouseButtonPress : MouseEvent::MouseDblClick; MouseEvent event(type, MouseEvent::MiddleButton, p, getModifiers()); if (mouseCallback_) @@ -586,7 +585,6 @@ void cv::viz::InteractorStyle::OnMiddleButtonUp() void cv::viz::InteractorStyle::OnRightButtonDown() { Vec2i p(Interactor->GetEventPosition()); - MouseEvent::Type type = (Interactor->GetRepeatCount() == 0) ? MouseEvent::MouseButtonPress : MouseEvent::MouseDblClick; MouseEvent event(type, MouseEvent::RightButton, p, getModifiers()); if (mouseCallback_) diff --git a/modules/viz/src/shapes.cpp b/modules/viz/src/shapes.cpp index 347a58b..cc674dc 100644 --- a/modules/viz/src/shapes.cpp +++ b/modules/viz/src/shapes.cpp @@ -52,9 +52,10 @@ cv::viz::WLine::WLine(const Point3d &pt1, const Point3d &pt2, const Color &color vtkSmartPointer line = vtkSmartPointer::New(); line->SetPoint1(pt1.x, pt1.y, pt1.z); line->SetPoint2(pt2.x, pt2.y, pt2.z); + line->Update(); vtkSmartPointer mapper = vtkSmartPointer::New(); - mapper->SetInputConnection(line->GetOutputPort()); + VtkUtils::SetInputData(mapper, line->GetOutput()); vtkSmartPointer actor = vtkSmartPointer::New(); actor->SetMapper(mapper); @@ -153,9 +154,10 @@ cv::viz::WSphere::WSphere(const Point3d ¢er, double radius, int sphere_resol sphere->SetPhiResolution(sphere_resolution); sphere->SetThetaResolution(sphere_resolution); sphere->LatLongTessellationOff(); + sphere->Update(); vtkSmartPointer mapper = vtkSmartPointer::New(); - mapper->SetInputConnection(sphere->GetOutputPort()); + VtkUtils::SetInputData(mapper, sphere->GetOutput()); vtkSmartPointer actor = vtkSmartPointer::New(); actor->SetMapper(mapper); @@ -203,9 +205,10 @@ cv::viz::WArrow::WArrow(const Point3d& pt1, const Point3d& pt2, double thickness vtkSmartPointer transformPD = vtkSmartPointer::New(); transformPD->SetTransform(transform); transformPD->SetInputConnection(arrowSource->GetOutputPort()); + transformPD->Update(); vtkSmartPointer mapper = vtkSmartPointer::New(); - mapper->SetInputConnection(transformPD->GetOutputPort()); + VtkUtils::SetInputData(mapper, transformPD->GetOutput()); vtkSmartPointer actor = vtkSmartPointer::New(); actor->SetMapper(mapper); @@ -239,9 +242,10 @@ cv::viz::WCircle::WCircle(const Point3d& pt, double radius, double thickness, co vtkSmartPointer tf = vtkSmartPointer::New(); tf->SetTransform(t); tf->SetInputConnection(disk->GetOutputPort()); + tf->Update(); vtkSmartPointer mapper = vtkSmartPointer::New(); - mapper->SetInputConnection(tf->GetOutputPort()); + VtkUtils::SetInputData(mapper, tf->GetOutput()); vtkSmartPointer actor = vtkSmartPointer::New(); actor->SetMapper(mapper); @@ -270,9 +274,10 @@ cv::viz::WCylinder::WCylinder(const Point3d& pt_on_axis, const Point3d& axis_dir tuber->SetInputConnection(line->GetOutputPort()); tuber->SetRadius(radius); tuber->SetNumberOfSides(numsides); + tuber->Update(); vtkSmartPointer mapper = vtkSmartPointer::New(); - mapper->SetInputConnection(tuber->GetOutputPort()); + VtkUtils::SetInputData(mapper, tuber->GetOutput()); vtkSmartPointer actor = vtkSmartPointer::New(); actor->SetMapper(mapper); @@ -292,19 +297,21 @@ template<> cv::viz::WCylinder cv::viz::Widget::cast() cv::viz::WCube::WCube(const Point3d& pt_min, const Point3d& pt_max, bool wire_frame, const Color &color) { - vtkSmartPointer mapper = vtkSmartPointer::New(); + vtkSmartPointer cube; if (wire_frame) { - vtkSmartPointer cube = vtkSmartPointer::New(); - cube->SetBounds(pt_min.x, pt_max.x, pt_min.y, pt_max.y, pt_min.z, pt_max.z); - mapper->SetInputConnection(cube->GetOutputPort()); + cube = vtkSmartPointer::New(); + vtkOutlineSource::SafeDownCast(cube)->SetBounds(pt_min.x, pt_max.x, pt_min.y, pt_max.y, pt_min.z, pt_max.z); } else { - vtkSmartPointer cube = vtkSmartPointer::New(); - cube->SetBounds(pt_min.x, pt_max.x, pt_min.y, pt_max.y, pt_min.z, pt_max.z); - mapper->SetInputConnection(cube->GetOutputPort()); + cube = vtkSmartPointer::New(); + vtkCubeSource::SafeDownCast(cube)->SetBounds(pt_min.x, pt_max.x, pt_min.y, pt_max.y, pt_min.z, pt_max.z); } + cube->Update(); + + vtkSmartPointer mapper = vtkSmartPointer::New(); + VtkUtils::SetInputData(mapper, cube->GetOutput()); vtkSmartPointer actor = vtkSmartPointer::New(); actor->SetMapper(mapper); @@ -345,6 +352,7 @@ cv::viz::WCoordinateSystem::WCoordinateSystem(double scale) tube_filter->SetInputConnection(polydata->GetProducerPort()); tube_filter->SetRadius(axes->GetScaleFactor() / 50.0); tube_filter->SetNumberOfSides(6); + tube_filter->Update(); vtkSmartPointer mapper = vtkSmartPointer::New(); mapper->SetScalarModeToUsePointData(); @@ -400,7 +408,7 @@ cv::viz::WPolyLine::WPolyLine(InputArray _points, const Color &color) polydata->GetPointData()->SetScalars(scalars); vtkSmartPointer mapper = vtkSmartPointer::New(); - mapper->SetInputConnection(polydata->GetProducerPort()); + VtkUtils::SetInputData(mapper, polydata); mapper->SetScalarRange(0, 255); vtkSmartPointer actor = vtkSmartPointer::New(); @@ -449,7 +457,7 @@ cv::viz::WGrid::WGrid(const Vec2i &dimensions, const Vec2d &spacing, const Color vtkSmartPointer grid = GridUtils::createGrid(dimensions, spacing); vtkSmartPointer mapper = vtkSmartPointer::New(); - mapper->SetInputConnection(grid->GetProducerPort()); + VtkUtils::SetInputData(mapper, grid); vtkSmartPointer actor = vtkSmartPointer::New(); actor->SetMapper(mapper); @@ -478,15 +486,11 @@ cv::viz::WGrid::WGrid(const Vec4d &coefs, const Vec2i &dimensions, const Vec2d & vtkSmartPointer transform_filter = vtkSmartPointer::New(); transform_filter->SetTransform(transform); -#if VTK_MAJOR_VERSION <= 5 transform_filter->SetInputConnection(grid->GetProducerPort()); -#else - transform_filter->SetInputData(grid); -#endif transform_filter->Update(); vtkSmartPointer mapper = vtkSmartPointer::New(); - mapper->SetInputConnection(transform_filter->GetOutputPort()); + VtkUtils::SetInputData(mapper, transform_filter->GetOutput()); vtkSmartPointer actor = vtkSmartPointer::New(); actor->SetMapper(mapper); @@ -544,6 +548,7 @@ void cv::viz::WText3D::setText(const String &text) CV_Assert("This widget does not support text." && textSource); textSource->SetText(text.c_str()); + textSource->Modified(); textSource->Update(); } @@ -620,11 +625,7 @@ cv::viz::WImageOverlay::WImageOverlay(const Mat &image, const Rect &rect) // Need to flip the image as the coordinates are different in OpenCV and VTK vtkSmartPointer flipFilter = vtkSmartPointer::New(); flipFilter->SetFilteredAxis(1); // Vertical flip -#if VTK_MAJOR_VERSION <= 5 flipFilter->SetInputConnection(vtk_image->GetProducerPort()); -#else - flipFilter->SetInputData(vtk_image); -#endif flipFilter->Update(); // Scale the image based on the Rect @@ -667,11 +668,7 @@ void cv::viz::WImageOverlay::setImage(const Mat &image) // Need to flip the image as the coordinates are different in OpenCV and VTK vtkSmartPointer flipFilter = vtkSmartPointer::New(); flipFilter->SetFilteredAxis(1); // Vertical flip -#if VTK_MAJOR_VERSION <= 5 flipFilter->SetInputConnection(vtk_image->GetProducerPort()); -#else - flipFilter->SetInputData(vtk_image); -#endif flipFilter->Update(); mapper->SetInputConnection(flipFilter->GetOutputPort()); @@ -697,11 +694,7 @@ cv::viz::WImage3D::WImage3D(const Mat &image, const Size &size) // Need to flip the image as the coordinates are different in OpenCV and VTK vtkSmartPointer flipFilter = vtkSmartPointer::New(); flipFilter->SetFilteredAxis(1); // Vertical flip -#if VTK_MAJOR_VERSION <= 5 flipFilter->SetInputConnection(vtk_image->GetProducerPort()); -#else - flipFilter->SetInputData(vtk_image); -#endif flipFilter->Update(); Vec3d plane_center(size.width * 0.5, size.height * 0.5, 0.0); @@ -749,11 +742,7 @@ cv::viz::WImage3D::WImage3D(const Vec3d &position, const Vec3d &normal, const Ve // Need to flip the image as the coordinates are different in OpenCV and VTK vtkSmartPointer flipFilter = vtkSmartPointer::New(); flipFilter->SetFilteredAxis(1); // Vertical flip -#if VTK_MAJOR_VERSION <= 5 flipFilter->SetInputConnection(vtk_image->GetProducerPort()); -#else - flipFilter->SetInputData(vtk_image); -#endif flipFilter->Update(); vtkSmartPointer plane = vtkSmartPointer::New(); @@ -809,11 +798,7 @@ void cv::viz::WImage3D::setImage(const Mat &image) // Need to flip the image as the coordinates are different in OpenCV and VTK vtkSmartPointer flipFilter = vtkSmartPointer::New(); flipFilter->SetFilteredAxis(1); // Vertical flip -#if VTK_MAJOR_VERSION <= 5 flipFilter->SetInputConnection(vtk_image->GetProducerPort()); -#else - flipFilter->SetInputData(vtk_image); -#endif flipFilter->Update(); // Apply the texture @@ -855,11 +840,7 @@ namespace cv { namespace viz { namespace // Need to flip the image as the coordinates are different in OpenCV and VTK vtkSmartPointer flipFilter = vtkSmartPointer::New(); flipFilter->SetFilteredAxis(1); // Vertical flip -#if VTK_MAJOR_VERSION <= 5 flipFilter->SetInputConnection(vtk_image->GetProducerPort()); -#else - flipFilter->SetInputData(vtk_image); -#endif flipFilter->Update(); Vec3d plane_center(0.0, 0.0, scale); @@ -958,7 +939,6 @@ namespace cv { namespace viz { namespace cv::viz::WCameraPosition::WCameraPosition(double scale) { vtkSmartPointer mapper = vtkSmartPointer::New(); - VtkUtils::SetInputData(mapper, getPolyData(WCoordinateSystem(scale))); mapper->SetScalarModeToUsePointData(); @@ -979,7 +959,7 @@ cv::viz::WCameraPosition::WCameraPosition(const Matx33d &K, double scale, const vtkSmartPointer polydata = CameraPositionUtils::createFrustrum(aspect_ratio, fovy, scale); vtkSmartPointer mapper = vtkSmartPointer::New(); - mapper->SetInputConnection(polydata->GetProducerPort()); + VtkUtils::SetInputData(mapper, polydata); vtkSmartPointer actor = vtkSmartPointer::New(); actor->SetMapper(mapper); @@ -996,7 +976,7 @@ cv::viz::WCameraPosition::WCameraPosition(const Vec2d &fov, double scale, const vtkSmartPointer polydata = CameraPositionUtils::createFrustrum(aspect_ratio, fovy, scale); vtkSmartPointer mapper = vtkSmartPointer::New(); - mapper->SetInputConnection(polydata->GetProducerPort()); + VtkUtils::SetInputData(mapper, polydata); vtkSmartPointer actor = vtkSmartPointer::New(); actor->SetMapper(mapper); @@ -1042,14 +1022,14 @@ template<> cv::viz::WCameraPosition cv::viz::Widget::cast appendFilter = vtkSmartPointer::New(); + vtkSmartPointer append_filter = vtkSmartPointer::New(); // Bitwise and with 3 in order to limit the domain to 2 bits if (display_mode & WTrajectory::PATH) { Mat points = vtkTrajectorySource::ExtractPoints(_path); vtkSmartPointer polydata = getPolyData(WPolyLine(points, color)); - appendFilter->AddInputConnection(polydata->GetProducerPort()); + append_filter->AddInputConnection(polydata->GetProducerPort()); } if (display_mode & WTrajectory::FRAMES) @@ -1067,11 +1047,12 @@ cv::viz::WTrajectory::WTrajectory(InputArray _path, int display_mode, double sca tensor_glyph->SymmetricOff(); tensor_glyph->ColorGlyphsOff(); - appendFilter->AddInputConnection(tensor_glyph->GetOutputPort()); + append_filter->AddInputConnection(tensor_glyph->GetOutputPort()); } + append_filter->Update(); vtkSmartPointer mapper = vtkSmartPointer::New(); - VtkUtils::SetInputData(mapper, appendFilter->GetOutput()); + VtkUtils::SetInputData(mapper, append_filter->GetOutput()); mapper->SetScalarModeToUsePointData(); mapper->SetScalarRange(0, 255); @@ -1106,10 +1087,8 @@ cv::viz::WTrajectoryFrustums::WTrajectoryFrustums(InputArray _path, const Matx33 tensor_glyph->ColorGlyphsOff(); tensor_glyph->Update(); - vtkSmartPointer polydata = tensor_glyph->GetOutput(); - vtkSmartPointer mapper = vtkSmartPointer::New(); - mapper->SetInputConnection(polydata->GetProducerPort()); + VtkUtils::SetInputData(mapper, tensor_glyph->GetOutput()); vtkSmartPointer actor = vtkSmartPointer::New(); actor->SetMapper(mapper); @@ -1134,10 +1113,8 @@ cv::viz::WTrajectoryFrustums::WTrajectoryFrustums(InputArray _path, const Vec2d tensor_glyph->ColorGlyphsOff(); tensor_glyph->Update(); - vtkSmartPointer polydata = tensor_glyph->GetOutput(); - vtkSmartPointer mapper = vtkSmartPointer::New(); - mapper->SetInputConnection(polydata->GetProducerPort()); + VtkUtils::SetInputData(mapper, tensor_glyph->GetOutput()); vtkSmartPointer actor = vtkSmartPointer::New(); actor->SetMapper(mapper); -- 2.7.4