From 56f9168ac12855763d0d07c4f51c4c586c1904f0 Mon Sep 17 00:00:00 2001 From: Ozan Tonkal Date: Sun, 8 Sep 2013 18:55:41 +0200 Subject: [PATCH] support VTK 6.0.0: cmakelist.txt might need to be refactored --- doc/tutorials/viz/creating_widgets.rst | 4 + modules/viz/CMakeLists.txt | 9 +- modules/viz/src/cloud_widgets.cpp | 34 ++++- modules/viz/src/shape_widgets.cpp | 122 ++++++++++++++---- modules/viz/src/viz3d_impl.cpp | 4 + modules/viz/src/viz3d_impl.hpp | 4 + modules/viz/src/widget.cpp | 16 ++- .../tutorial_code/viz/creating_widgets.cpp | 4 + 8 files changed, 168 insertions(+), 29 deletions(-) diff --git a/doc/tutorials/viz/creating_widgets.rst b/doc/tutorials/viz/creating_widgets.rst index a0e9da36cc..59f1fdc4bc 100644 --- a/doc/tutorials/viz/creating_widgets.rst +++ b/doc/tutorials/viz/creating_widgets.rst @@ -74,7 +74,11 @@ You can download the code from `here <../../../../samples/cpp/tutorial_code/viz/ // Create mapper and actor vtkSmartPointer mapper = vtkSmartPointer::New(); + #if VTK_MAJOR_VERSION <= 5 mapper->SetInput(polyData); + #else + mapper->SetInputData(polyData); + #endif vtkSmartPointer actor = vtkSmartPointer::New(); actor->SetMapper(mapper); diff --git a/modules/viz/CMakeLists.txt b/modules/viz/CMakeLists.txt index 84981f6a01..9a486fb821 100644 --- a/modules/viz/CMakeLists.txt +++ b/modules/viz/CMakeLists.txt @@ -13,6 +13,9 @@ endmacro() macro(find_vtk) find_package(VTK 5.10.0 REQUIRED) + if(NOT VTK_FOUND) + find_package(VTK 6.0.0 REQUIRED) + endif() if(VTK_FOUND) if (BUILD_SHARED_LIBS OR (NOT BUILD_SHARED_LIBS AND NOT VTK_BUILD_SHARED_LIBS)) find_qvtk() @@ -43,7 +46,11 @@ include_directories(src) ocv_define_module(viz opencv_core) if(DEFINED BUILD_opencv_viz AND BUILD_opencv_viz AND DEFINED HAVE_VTK AND HAVE_VTK) - target_link_libraries(opencv_viz vtkCommon vtkWidgets vtkFiltering vtkRendering) + if (${VTK_VERSION_MAJOR} EQUAL 5) + target_link_libraries(opencv_viz vtkCommon vtkWidgets vtkFiltering vtkRendering) + else() + target_link_libraries(opencv_viz vtkViewsCore vtkRenderingLOD vtkIOPLY vtkRenderingFreeTypeOpenGL vtkRenderingVolumeOpenGL vtkFiltersTexture) + endif() if(APPLE) target_link_libraries(opencv_viz "-framework Cocoa") endif() diff --git a/modules/viz/src/cloud_widgets.cpp b/modules/viz/src/cloud_widgets.cpp index b4ba5b3fe1..ec6c203565 100644 --- a/modules/viz/src/cloud_widgets.cpp +++ b/modules/viz/src/cloud_widgets.cpp @@ -175,7 +175,11 @@ cv::viz::CloudWidget::CloudWidget(InputArray _cloud, InputArray _colors) polydata->GetPointData()->SetScalars(scalars); vtkSmartPointer mapper = vtkSmartPointer::New(); +#if VTK_MAJOR_VERSION <= 5 mapper->SetInput(polydata); +#else + mapper->SetInputData(polydata); +#endif Vec3d minmax(scalars->GetRange()); mapper->SetScalarRange(minmax.val); @@ -206,7 +210,11 @@ cv::viz::CloudWidget::CloudWidget(InputArray _cloud, const Color &color) vtkSmartPointer polydata = CreateCloudWidget::create(cloud, nr_points); vtkSmartPointer mapper = vtkSmartPointer::New(); +#if VTK_MAJOR_VERSION <= 5 mapper->SetInput(polydata); +#else + mapper->SetInputData(polydata); +#endif bool interpolation = (polydata && polydata->GetNumberOfCells() != polydata->GetNumberOfVerts()); @@ -327,7 +335,11 @@ struct cv::viz::CloudCollectionWidget::CreateCloudWidget { // This is the first cloud vtkSmartPointer mapper_new = vtkSmartPointer::New(); +#if VTK_MAJOR_VERSION <= 5 mapper_new->SetInputConnection(poly_data->GetProducerPort()); +#else + mapper_new->SetInputData(poly_data); +#endif mapper_new->SetScalarRange(minmax.val); mapper_new->SetScalarModeToUsePointData(); @@ -349,8 +361,13 @@ struct cv::viz::CloudCollectionWidget::CreateCloudWidget CV_Assert("Cloud Widget without data" && data); vtkSmartPointer appendFilter = vtkSmartPointer::New(); +#if VTK_MAJOR_VERSION <= 5 appendFilter->AddInputConnection(mapper->GetInput()->GetProducerPort()); appendFilter->AddInputConnection(poly_data->GetProducerPort()); +#else + appendFilter->AddInputData(data); + appendFilter->AddInputData(poly_data); +#endif mapper->SetInputConnection(appendFilter->GetOutputPort()); // Update the number of cloud points @@ -401,7 +418,11 @@ void cv::viz::CloudCollectionWidget::addCloud(InputArray _cloud, InputArray _col vtkSmartPointer transform_filter = vtkSmartPointer::New(); transform_filter->SetTransform(transform); +#if VTK_MAJOR_VERSION <= 5 transform_filter->SetInputConnection(polydata->GetProducerPort()); +#else + transform_filter->SetInputData(polydata); +#endif transform_filter->Update(); vtkLODActor *actor = vtkLODActor::SafeDownCast(WidgetAccessor::getProp(*this)); @@ -436,7 +457,11 @@ void cv::viz::CloudCollectionWidget::addCloud(InputArray _cloud, const Color &co vtkSmartPointer transform_filter = vtkSmartPointer::New(); transform_filter->SetTransform(transform); +#if VTK_MAJOR_VERSION <= 5 transform_filter->SetInputConnection(polydata->GetProducerPort()); +#else + transform_filter->SetInputData(polydata); +#endif transform_filter->Update(); vtkLODActor *actor = vtkLODActor::SafeDownCast(WidgetAccessor::getProp(*this)); @@ -571,7 +596,11 @@ cv::viz::CloudNormalsWidget::CloudNormalsWidget(InputArray _cloud, InputArray _n polyData->SetLines(lines); vtkSmartPointer mapper = vtkSmartPointer::New(); +#if VTK_MAJOR_VERSION <= 5 mapper->SetInput(polyData); +#else + mapper->SetInputData(polyData); +#endif mapper->SetColorModeToMapScalars(); mapper->SetScalarModeToUsePointData(); @@ -707,7 +736,6 @@ cv::viz::MeshWidget::MeshWidget(const Mesh3d &mesh) poly_grid->Allocate(1, 1); poly_grid->InsertNextCell(polygon->GetCellType(), polygon->GetPointIds()); poly_grid->SetPoints(points); - poly_grid->Update(); if (scalars) poly_grid->GetPointData()->SetScalars(scalars); @@ -724,7 +752,11 @@ cv::viz::MeshWidget::MeshWidget(const Mesh3d &mesh) actor->GetProperty()->ShadingOff(); vtkSmartPointer mapper = vtkSmartPointer::New(); +#if VTK_MAJOR_VERSION <= 5 mapper->SetInput(data); +#else + mapper->SetInputData(data); +#endif mapper->ImmediateModeRenderingOff(); vtkIdType numberOfCloudPoints = nr_points * 0.1; diff --git a/modules/viz/src/shape_widgets.cpp b/modules/viz/src/shape_widgets.cpp index 8443477175..45a653de55 100644 --- a/modules/viz/src/shape_widgets.cpp +++ b/modules/viz/src/shape_widgets.cpp @@ -66,7 +66,7 @@ cv::viz::LineWidget::LineWidget(const Point3f &pt1, const Point3f &pt2, const Co line->Update(); vtkSmartPointer mapper = vtkSmartPointer::New(); - mapper->SetInput(line->GetOutput()); + mapper->SetInputConnection(line->GetOutputPort()); vtkSmartPointer actor = vtkSmartPointer::New(); actor->SetMapper(mapper); @@ -87,7 +87,7 @@ template<> cv::viz::LineWidget cv::viz::Widget::cast() struct cv::viz::PlaneWidget::SetSizeImpl { template - static vtkSmartPointer setSize(const Vec<_Tp, 3> ¢er, vtkSmartPointer poly_data, double size) + static vtkSmartPointer setSize(const Vec<_Tp, 3> ¢er, vtkSmartPointer poly_data_port, double size) { vtkSmartPointer transform = vtkSmartPointer::New(); transform->PreMultiply(); @@ -96,11 +96,11 @@ struct cv::viz::PlaneWidget::SetSizeImpl transform->Translate(-center[0], -center[1], -center[2]); vtkSmartPointer transform_filter = vtkSmartPointer::New(); - transform_filter->SetInput(poly_data); + transform_filter->SetInputConnection(poly_data_port); transform_filter->SetTransform(transform); transform_filter->Update(); - return transform_filter->GetOutput(); + return transform_filter; } }; @@ -115,7 +115,7 @@ cv::viz::PlaneWidget::PlaneWidget(const Vec4f& coefs, double size, const Color & plane->GetOrigin(p_center.val); vtkSmartPointer mapper = vtkSmartPointer::New(); - mapper->SetInput(SetSizeImpl::setSize(p_center, plane->GetOutput(), size)); + mapper->SetInputConnection(SetSizeImpl::setSize(p_center, plane->GetOutputPort(), size)->GetOutputPort()); vtkSmartPointer actor = vtkSmartPointer::New(); actor->SetMapper(mapper); @@ -136,7 +136,7 @@ cv::viz::PlaneWidget::PlaneWidget(const Vec4f& coefs, const Point3f& pt, double plane->SetCenter(p_center[0], p_center[1], p_center[2]); vtkSmartPointer mapper = vtkSmartPointer::New(); - mapper->SetInput(SetSizeImpl::setSize(p_center, plane->GetOutput(), size)); + mapper->SetInputConnection(SetSizeImpl::setSize(p_center, plane->GetOutputPort(), size)->GetOutputPort()); vtkSmartPointer actor = vtkSmartPointer::New(); actor->SetMapper(mapper); @@ -165,7 +165,7 @@ cv::viz::SphereWidget::SphereWidget(const Point3f ¢er, float radius, int sph sphere->Update(); vtkSmartPointer mapper = vtkSmartPointer::New(); - mapper->SetInput(sphere->GetOutput()); + mapper->SetInputConnection(sphere->GetOutputPort()); vtkSmartPointer actor = vtkSmartPointer::New(); actor->SetMapper(mapper); @@ -238,7 +238,7 @@ cv::viz::ArrowWidget::ArrowWidget(const Point3f& pt1, const Point3f& pt2, double transformPD->SetInputConnection(arrowSource->GetOutputPort()); vtkSmartPointer mapper = vtkSmartPointer::New(); - mapper->SetInput(transformPD->GetOutput()); + mapper->SetInputConnection(transformPD->GetOutputPort()); vtkSmartPointer actor = vtkSmartPointer::New(); actor->SetMapper(mapper); @@ -274,7 +274,7 @@ cv::viz::CircleWidget::CircleWidget(const Point3f& pt, double radius, double thi tf->SetInputConnection(disk->GetOutputPort()); vtkSmartPointer mapper = vtkSmartPointer::New(); - mapper->SetInput(tf->GetOutput()); + mapper->SetInputConnection(tf->GetOutputPort()); vtkSmartPointer actor = vtkSmartPointer::New(); actor->SetMapper(mapper); @@ -305,7 +305,7 @@ cv::viz::CylinderWidget::CylinderWidget(const Point3f& pt_on_axis, const Point3f tuber->SetNumberOfSides(numsides); vtkSmartPointer mapper = vtkSmartPointer::New(); - mapper->SetInput(tuber->GetOutput()); + mapper->SetInputConnection(tuber->GetOutputPort()); vtkSmartPointer actor = vtkSmartPointer::New(); actor->SetMapper(mapper); @@ -330,13 +330,13 @@ cv::viz::CubeWidget::CubeWidget(const Point3f& pt_min, const Point3f& pt_max, bo { 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->SetInput(cube->GetOutput()); + mapper->SetInputConnection(cube->GetOutputPort()); } 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->SetInput(cube->GetOutput()); + mapper->SetInputConnection(cube->GetOutputPort()); } vtkSmartPointer actor = vtkSmartPointer::New(); @@ -371,17 +371,25 @@ cv::viz::CoordinateSystemWidget::CoordinateSystemWidget(double scale) axes_colors->InsertNextValue(1.0); vtkSmartPointer axes_data = axes->GetOutput(); +#if VTK_MAJOR_VERSION <= 5 axes_data->Update(); +#else + axes->Update(); +#endif axes_data->GetPointData()->SetScalars(axes_colors); vtkSmartPointer axes_tubes = vtkSmartPointer::New(); +#if VTK_MAJOR_VERSION <= 5 axes_tubes->SetInput(axes_data); +#else + axes_tubes->SetInputData(axes_data); +#endif axes_tubes->SetRadius(axes->GetScaleFactor() / 50.0); axes_tubes->SetNumberOfSides(6); vtkSmartPointer mapper = vtkSmartPointer::New(); mapper->SetScalarModeToUsePointData(); - mapper->SetInput(axes_tubes->GetOutput()); + mapper->SetInputConnection(axes_tubes->GetOutputPort()); vtkSmartPointer actor = vtkSmartPointer::New(); actor->SetMapper(mapper); @@ -456,7 +464,11 @@ cv::viz::PolyLineWidget::PolyLineWidget(InputArray _pointData, const Color &colo polyData->SetLines(cells); vtkSmartPointer mapper = vtkSmartPointer::New(); +#if VTK_MAJOR_VERSION <= 5 mapper->SetInput(polyData); +#else + mapper->SetInputData(polyData); +#endif vtkSmartPointer actor = vtkSmartPointer::New(); actor->SetMapper(mapper); @@ -491,7 +503,11 @@ struct cv::viz::GridWidget::GridImpl // Extract the edges so we have the grid vtkSmartPointer filter = vtkSmartPointer::New(); +#if VTK_MAJOR_VERSION <= 5 filter->SetInputConnection(grid->GetProducerPort()); +#else + filter->SetInputData(grid); +#endif filter->Update(); return filter->GetOutput(); } @@ -502,7 +518,11 @@ cv::viz::GridWidget::GridWidget(const Vec2i &dimensions, const Vec2d &spacing, c vtkSmartPointer grid = GridImpl::createGrid(dimensions, spacing); vtkSmartPointer mapper = vtkSmartPointer::New(); +#if VTK_MAJOR_VERSION <= 5 mapper->SetInputConnection(grid->GetProducerPort()); +#else + mapper->SetInputData(grid); +#endif vtkSmartPointer actor = vtkSmartPointer::New(); actor->SetMapper(mapper); @@ -547,7 +567,11 @@ cv::viz::GridWidget::GridWidget(const Vec4f &coefs, const Vec2i &dimensions, con 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(); @@ -685,7 +709,11 @@ cv::viz::ImageOverlayWidget::ImageOverlayWidget(const Mat &image, const Rect &re // 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 @@ -728,7 +756,11 @@ void cv::viz::ImageOverlayWidget::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()); @@ -754,7 +786,11 @@ cv::viz::Image3DWidget::Image3DWidget(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); @@ -802,7 +838,11 @@ cv::viz::Image3DWidget::Image3DWidget(const Vec3f &position, const Vec3f &normal // 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(); @@ -875,7 +915,11 @@ void cv::viz::Image3DWidget::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 @@ -915,7 +959,11 @@ struct cv::viz::CameraPositionWidget::ProjectImage // 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); @@ -962,7 +1010,7 @@ struct cv::viz::CameraPositionWidget::ProjectImage frustumSource->Update(); vtkSmartPointer filter = vtkSmartPointer::New(); - filter->SetInput(frustumSource->GetOutput()); + filter->SetInputConnection(frustumSource->GetOutputPort()); filter->Update(); // Frustum needs to be textured or else it can't be combined with image @@ -1000,17 +1048,25 @@ cv::viz::CameraPositionWidget::CameraPositionWidget(double scale) axes_colors->InsertNextValue(1.0); vtkSmartPointer axes_data = axes->GetOutput(); +#if VTK_MAJOR_VERSION <= 5 axes_data->Update(); +#else + axes->Update(); +#endif axes_data->GetPointData()->SetScalars(axes_colors); vtkSmartPointer axes_tubes = vtkSmartPointer::New(); +#if VTK_MAJOR_VERSION <= 5 axes_tubes->SetInput(axes_data); +#else + axes_tubes->SetInputData(axes_data); +#endif axes_tubes->SetRadius(axes->GetScaleFactor() / 50.0); axes_tubes->SetNumberOfSides(6); vtkSmartPointer mapper = vtkSmartPointer::New(); mapper->SetScalarModeToUsePointData(); - mapper->SetInput(axes_tubes->GetOutput()); + mapper->SetInputConnection(axes_tubes->GetOutputPort()); vtkSmartPointer actor = vtkSmartPointer::New(); actor->SetMapper(mapper); @@ -1046,11 +1102,11 @@ cv::viz::CameraPositionWidget::CameraPositionWidget(const Matx33f &K, double sca frustumSource->Update(); vtkSmartPointer filter = vtkSmartPointer::New(); - filter->SetInput(frustumSource->GetOutput()); + filter->SetInputConnection(frustumSource->GetOutputPort()); filter->Update(); vtkSmartPointer mapper = vtkSmartPointer::New(); - mapper->SetInput(filter->GetOutput()); + mapper->SetInputConnection(filter->GetOutputPort()); vtkSmartPointer actor = vtkSmartPointer::New(); actor->SetMapper(mapper); @@ -1085,11 +1141,11 @@ cv::viz::CameraPositionWidget::CameraPositionWidget(const Vec2f &fov, double sca // Extract the edges so we have the grid vtkSmartPointer filter = vtkSmartPointer::New(); - filter->SetInput(frustumSource->GetOutput()); + filter->SetInputConnection(frustumSource->GetOutputPort()); filter->Update(); vtkSmartPointer mapper = vtkSmartPointer::New(); - mapper->SetInput(filter->GetOutput()); + mapper->SetInputConnection(filter->GetOutputPort()); vtkSmartPointer actor = vtkSmartPointer::New(); actor->SetMapper(mapper); @@ -1151,7 +1207,11 @@ struct cv::viz::TrajectoryWidget::ApplyPath transform->SetMatrix(mat_trans); vtkSmartPointer filter = vtkSmartPointer::New(); +#if VTK_MAJOR_VERSION <= 5 filter->SetInput(new_data); +#else + filter->SetInputData(new_data); +#endif filter->SetTransform(transform); filter->Update(); @@ -1202,7 +1262,11 @@ cv::viz::TrajectoryWidget::TrajectoryWidget(const std::vector &path, i colors->FillComponent(2, color[0]); polyData->GetPointData()->SetScalars(colors); +#if VTK_MAJOR_VERSION <= 5 appendFilter->AddInputConnection(polyData->GetProducerPort()); +#else + appendFilter->AddInputData(polyData); +#endif } if ((~display_mode & 3) ^ TrajectoryWidget::DISPLAY_FRAMES) @@ -1222,11 +1286,19 @@ cv::viz::TrajectoryWidget::TrajectoryWidget(const std::vector &path, i axes_colors->InsertNextTuple3(0,0,255); vtkSmartPointer axes_data = axes->GetOutput(); +#if VTK_MAJOR_VERSION <= 5 axes_data->Update(); +#else + axes->Update(); +#endif axes_data->GetPointData()->SetScalars(axes_colors); vtkSmartPointer axes_tubes = vtkSmartPointer::New(); +#if VTK_MAJOR_VERSION <= 5 axes_tubes->SetInput(axes_data); +#else + axes_tubes->SetInputData(axes_data); +#endif axes_tubes->SetRadius(axes->GetScaleFactor() / 50.0); axes_tubes->SetNumberOfSides(6); axes_tubes->Update(); @@ -1236,7 +1308,7 @@ cv::viz::TrajectoryWidget::TrajectoryWidget(const std::vector &path, i vtkSmartPointer mapper = vtkSmartPointer::New(); mapper->SetScalarModeToUsePointData(); - mapper->SetInput(appendFilter->GetOutput()); + mapper->SetInputConnection(appendFilter->GetOutputPort()); vtkSmartPointer actor = vtkSmartPointer::New(); actor->SetMapper(mapper); @@ -1272,14 +1344,14 @@ cv::viz::TrajectoryWidget::TrajectoryWidget(const std::vector &path, c // Extract the edges vtkSmartPointer filter = vtkSmartPointer::New(); - filter->SetInput(frustumSource->GetOutput()); + filter->SetInputConnection(frustumSource->GetOutputPort()); filter->Update(); vtkSmartPointer appendFilter = vtkSmartPointer::New(); ApplyPath::applyPath(filter->GetOutput(), appendFilter, path); vtkSmartPointer mapper = vtkSmartPointer::New(); - mapper->SetInput(appendFilter->GetOutput()); + mapper->SetInputConnection(appendFilter->GetOutputPort()); vtkSmartPointer actor = vtkSmartPointer::New(); actor->SetMapper(mapper); @@ -1312,14 +1384,14 @@ cv::viz::TrajectoryWidget::TrajectoryWidget(const std::vector &path, c // Extract the edges vtkSmartPointer filter = vtkSmartPointer::New(); - filter->SetInput(frustumSource->GetOutput()); + filter->SetInputConnection(frustumSource->GetOutputPort()); filter->Update(); vtkSmartPointer appendFilter = vtkSmartPointer::New(); ApplyPath::applyPath(filter->GetOutput(), appendFilter, path); vtkSmartPointer mapper = vtkSmartPointer::New(); - mapper->SetInput(appendFilter->GetOutput()); + mapper->SetInputConnection(appendFilter->GetOutputPort()); vtkSmartPointer actor = vtkSmartPointer::New(); actor->SetMapper(mapper); @@ -1410,7 +1482,7 @@ cv::viz::SpheresTrajectoryWidget::SpheresTrajectoryWidget(const std::vector mapper = vtkSmartPointer::New(); mapper->SetScalarModeToUseCellData(); - mapper->SetInput(appendFilter->GetOutput()); + mapper->SetInputConnection(appendFilter->GetOutputPort()); vtkSmartPointer actor = vtkSmartPointer::New(); actor->SetMapper(mapper); diff --git a/modules/viz/src/viz3d_impl.cpp b/modules/viz/src/viz3d_impl.cpp index 52c6a45aa9..1f01461c7e 100644 --- a/modules/viz/src/viz3d_impl.cpp +++ b/modules/viz/src/viz3d_impl.cpp @@ -325,7 +325,11 @@ void cv::viz::Viz3d::VizImpl::createActorFromVTKDataSet(const vtkSmartPointer::New(); vtkSmartPointer mapper = vtkSmartPointer::New(); +#if VTK_MAJOR_VERSION <= 5 mapper->SetInput(data); +#else + mapper->SetInputData(data); +#endif if (use_scalars) { diff --git a/modules/viz/src/viz3d_impl.hpp b/modules/viz/src/viz3d_impl.hpp index a6d5bd9ca0..7b1ddae6bd 100644 --- a/modules/viz/src/viz3d_impl.hpp +++ b/modules/viz/src/viz3d_impl.hpp @@ -369,9 +369,13 @@ namespace cv { // Create the vtk image output->SetDimensions(image.cols, image.rows, 1); +#if VTK_MAJOR_VERSION <= 5 output->SetNumberOfScalarComponents(image.channels()); output->SetScalarTypeToUnsignedChar(); output->AllocateScalars(); +#else + output->AllocateScalars(VTK_UNSIGNED_CHAR, image.channels()); +#endif int i_chs = image.channels(); if (i_chs > 1) diff --git a/modules/viz/src/widget.cpp b/modules/viz/src/widget.cpp index cdcae8792d..1742e854e3 100644 --- a/modules/viz/src/widget.cpp +++ b/modules/viz/src/widget.cpp @@ -93,7 +93,11 @@ cv::viz::Widget cv::viz::Widget::fromPlyFile(const String &file_name) vtkSmartPointer actor = vtkSmartPointer::New(); vtkSmartPointer mapper = vtkSmartPointer::New(); +#if VTK_MAJOR_VERSION <= 5 mapper->SetInput(data); +#else + mapper->SetInputData(data); +#endif vtkSmartPointer scalars = data->GetPointData()->GetScalars(); if (scalars) @@ -183,9 +187,13 @@ void cv::viz::Widget::setRenderingProperty(int property, double value) if (!actor->GetMapper()->GetInput()->GetPointData()->GetNormals()) { vtkSmartPointer normals = vtkSmartPointer::New(); +#if VTK_MAJOR_VERSION <= 5 normals->SetInput(actor->GetMapper()->GetInput()); +#else + normals->SetInputData(actor->GetMapper()->GetInput()); +#endif normals->Update(); - vtkDataSetMapper::SafeDownCast(actor->GetMapper())->SetInput(normals->GetOutput()); + vtkDataSetMapper::SafeDownCast(actor->GetMapper())->SetInputConnection(normals->GetOutputPort()); } actor->GetProperty()->SetInterpolationToGouraud(); break; @@ -195,9 +203,13 @@ void cv::viz::Widget::setRenderingProperty(int property, double value) if (!actor->GetMapper()->GetInput()->GetPointData()->GetNormals()) { vtkSmartPointer normals = vtkSmartPointer::New(); +#if VTK_MAJOR_VERSION <= 5 normals->SetInput(actor->GetMapper()->GetInput()); +#else + normals->SetInputData(actor->GetMapper()->GetInput()); +#endif normals->Update(); - vtkDataSetMapper::SafeDownCast(actor->GetMapper())->SetInput(normals->GetOutput()); + vtkDataSetMapper::SafeDownCast(actor->GetMapper())->SetInputConnection(normals->GetOutputPort()); } actor->GetProperty()->SetInterpolationToPhong(); break; diff --git a/samples/cpp/tutorial_code/viz/creating_widgets.cpp b/samples/cpp/tutorial_code/viz/creating_widgets.cpp index 9d2b5a3130..f5fdd92dd0 100644 --- a/samples/cpp/tutorial_code/viz/creating_widgets.cpp +++ b/samples/cpp/tutorial_code/viz/creating_widgets.cpp @@ -74,7 +74,11 @@ TriangleWidget::TriangleWidget(const Point3f &pt1, const Point3f &pt2, const Poi // Create mapper and actor vtkSmartPointer mapper = vtkSmartPointer::New(); +#if VTK_MAJOR_VERSION <= 5 mapper->SetInput(polyData); +#else + mapper->SetInputData(polyData); +#endif vtkSmartPointer actor = vtkSmartPointer::New(); actor->SetMapper(mapper);