support VTK 6.0.0: cmakelist.txt might need to be refactored

pull/1453/head
Ozan Tonkal 11 years ago
parent 26005a19bd
commit 56f9168ac1
  1. 4
      doc/tutorials/viz/creating_widgets.rst
  2. 7
      modules/viz/CMakeLists.txt
  3. 34
      modules/viz/src/cloud_widgets.cpp
  4. 122
      modules/viz/src/shape_widgets.cpp
  5. 4
      modules/viz/src/viz3d_impl.cpp
  6. 4
      modules/viz/src/viz3d_impl.hpp
  7. 16
      modules/viz/src/widget.cpp
  8. 4
      samples/cpp/tutorial_code/viz/creating_widgets.cpp

@ -74,7 +74,11 @@ You can download the code from `here <../../../../samples/cpp/tutorial_code/viz/
// Create mapper and actor
vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
#if VTK_MAJOR_VERSION <= 5
mapper->SetInput(polyData);
#else
mapper->SetInputData(polyData);
#endif
vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New();
actor->SetMapper(mapper);

@ -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)
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()

@ -175,7 +175,11 @@ cv::viz::CloudWidget::CloudWidget(InputArray _cloud, InputArray _colors)
polydata->GetPointData()->SetScalars(scalars);
vtkSmartPointer<vtkDataSetMapper> mapper = vtkSmartPointer<vtkDataSetMapper>::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<vtkPolyData> polydata = CreateCloudWidget::create(cloud, nr_points);
vtkSmartPointer<vtkDataSetMapper> mapper = vtkSmartPointer<vtkDataSetMapper>::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<vtkDataSetMapper> mapper_new = vtkSmartPointer<vtkDataSetMapper>::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<vtkAppendPolyData> appendFilter = vtkSmartPointer<vtkAppendPolyData>::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<vtkTransformPolyDataFilter> transform_filter = vtkSmartPointer<vtkTransformPolyDataFilter>::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<vtkTransformPolyDataFilter> transform_filter = vtkSmartPointer<vtkTransformPolyDataFilter>::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<vtkDataSetMapper> mapper = vtkSmartPointer<vtkDataSetMapper>::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<vtkDataSetMapper> mapper = vtkSmartPointer<vtkDataSetMapper>::New();
#if VTK_MAJOR_VERSION <= 5
mapper->SetInput(data);
#else
mapper->SetInputData(data);
#endif
mapper->ImmediateModeRenderingOff();
vtkIdType numberOfCloudPoints = nr_points * 0.1;

@ -66,7 +66,7 @@ cv::viz::LineWidget::LineWidget(const Point3f &pt1, const Point3f &pt2, const Co
line->Update();
vtkSmartPointer<vtkDataSetMapper> mapper = vtkSmartPointer<vtkDataSetMapper>::New();
mapper->SetInput(line->GetOutput());
mapper->SetInputConnection(line->GetOutputPort());
vtkSmartPointer<vtkLODActor> actor = vtkSmartPointer<vtkLODActor>::New();
actor->SetMapper(mapper);
@ -87,7 +87,7 @@ template<> cv::viz::LineWidget cv::viz::Widget::cast<cv::viz::LineWidget>()
struct cv::viz::PlaneWidget::SetSizeImpl
{
template<typename _Tp>
static vtkSmartPointer<vtkPolyData> setSize(const Vec<_Tp, 3> &center, vtkSmartPointer<vtkPolyData> poly_data, double size)
static vtkSmartPointer<vtkTransformPolyDataFilter> setSize(const Vec<_Tp, 3> &center, vtkSmartPointer<vtkAlgorithmOutput> poly_data_port, double size)
{
vtkSmartPointer<vtkTransform> transform = vtkSmartPointer<vtkTransform>::New();
transform->PreMultiply();
@ -96,11 +96,11 @@ struct cv::viz::PlaneWidget::SetSizeImpl
transform->Translate(-center[0], -center[1], -center[2]);
vtkSmartPointer<vtkTransformPolyDataFilter> transform_filter = vtkSmartPointer<vtkTransformPolyDataFilter>::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<vtkDataSetMapper> mapper = vtkSmartPointer<vtkDataSetMapper>::New();
mapper->SetInput(SetSizeImpl::setSize(p_center, plane->GetOutput(), size));
mapper->SetInputConnection(SetSizeImpl::setSize(p_center, plane->GetOutputPort(), size)->GetOutputPort());
vtkSmartPointer<vtkLODActor> actor = vtkSmartPointer<vtkLODActor>::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<vtkDataSetMapper> mapper = vtkSmartPointer<vtkDataSetMapper>::New();
mapper->SetInput(SetSizeImpl::setSize(p_center, plane->GetOutput(), size));
mapper->SetInputConnection(SetSizeImpl::setSize(p_center, plane->GetOutputPort(), size)->GetOutputPort());
vtkSmartPointer<vtkLODActor> actor = vtkSmartPointer<vtkLODActor>::New();
actor->SetMapper(mapper);
@ -165,7 +165,7 @@ cv::viz::SphereWidget::SphereWidget(const Point3f &center, float radius, int sph
sphere->Update();
vtkSmartPointer<vtkDataSetMapper> mapper = vtkSmartPointer<vtkDataSetMapper>::New();
mapper->SetInput(sphere->GetOutput());
mapper->SetInputConnection(sphere->GetOutputPort());
vtkSmartPointer<vtkLODActor> actor = vtkSmartPointer<vtkLODActor>::New();
actor->SetMapper(mapper);
@ -238,7 +238,7 @@ cv::viz::ArrowWidget::ArrowWidget(const Point3f& pt1, const Point3f& pt2, double
transformPD->SetInputConnection(arrowSource->GetOutputPort());
vtkSmartPointer<vtkDataSetMapper> mapper = vtkSmartPointer<vtkDataSetMapper>::New();
mapper->SetInput(transformPD->GetOutput());
mapper->SetInputConnection(transformPD->GetOutputPort());
vtkSmartPointer<vtkLODActor> actor = vtkSmartPointer<vtkLODActor>::New();
actor->SetMapper(mapper);
@ -274,7 +274,7 @@ cv::viz::CircleWidget::CircleWidget(const Point3f& pt, double radius, double thi
tf->SetInputConnection(disk->GetOutputPort());
vtkSmartPointer<vtkDataSetMapper> mapper = vtkSmartPointer<vtkDataSetMapper>::New();
mapper->SetInput(tf->GetOutput());
mapper->SetInputConnection(tf->GetOutputPort());
vtkSmartPointer<vtkLODActor> actor = vtkSmartPointer<vtkLODActor>::New();
actor->SetMapper(mapper);
@ -305,7 +305,7 @@ cv::viz::CylinderWidget::CylinderWidget(const Point3f& pt_on_axis, const Point3f
tuber->SetNumberOfSides(numsides);
vtkSmartPointer<vtkDataSetMapper> mapper = vtkSmartPointer<vtkDataSetMapper>::New();
mapper->SetInput(tuber->GetOutput());
mapper->SetInputConnection(tuber->GetOutputPort());
vtkSmartPointer<vtkLODActor> actor = vtkSmartPointer<vtkLODActor>::New();
actor->SetMapper(mapper);
@ -330,13 +330,13 @@ cv::viz::CubeWidget::CubeWidget(const Point3f& pt_min, const Point3f& pt_max, bo
{
vtkSmartPointer<vtkOutlineSource> cube = vtkSmartPointer<vtkOutlineSource>::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<vtkCubeSource> cube = vtkSmartPointer<vtkCubeSource>::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<vtkLODActor> actor = vtkSmartPointer<vtkLODActor>::New();
@ -371,17 +371,25 @@ cv::viz::CoordinateSystemWidget::CoordinateSystemWidget(double scale)
axes_colors->InsertNextValue(1.0);
vtkSmartPointer<vtkPolyData> axes_data = axes->GetOutput();
#if VTK_MAJOR_VERSION <= 5
axes_data->Update();
#else
axes->Update();
#endif
axes_data->GetPointData()->SetScalars(axes_colors);
vtkSmartPointer<vtkTubeFilter> axes_tubes = vtkSmartPointer<vtkTubeFilter>::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<vtkDataSetMapper> mapper = vtkSmartPointer<vtkDataSetMapper>::New();
mapper->SetScalarModeToUsePointData();
mapper->SetInput(axes_tubes->GetOutput());
mapper->SetInputConnection(axes_tubes->GetOutputPort());
vtkSmartPointer<vtkLODActor> actor = vtkSmartPointer<vtkLODActor>::New();
actor->SetMapper(mapper);
@ -456,7 +464,11 @@ cv::viz::PolyLineWidget::PolyLineWidget(InputArray _pointData, const Color &colo
polyData->SetLines(cells);
vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
#if VTK_MAJOR_VERSION <= 5
mapper->SetInput(polyData);
#else
mapper->SetInputData(polyData);
#endif
vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New();
actor->SetMapper(mapper);
@ -491,7 +503,11 @@ struct cv::viz::GridWidget::GridImpl
// Extract the edges so we have the grid
vtkSmartPointer<vtkExtractEdges> filter = vtkSmartPointer<vtkExtractEdges>::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<vtkPolyData> grid = GridImpl::createGrid(dimensions, spacing);
vtkSmartPointer<vtkDataSetMapper> mapper = vtkSmartPointer<vtkDataSetMapper>::New();
#if VTK_MAJOR_VERSION <= 5
mapper->SetInputConnection(grid->GetProducerPort());
#else
mapper->SetInputData(grid);
#endif
vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New();
actor->SetMapper(mapper);
@ -547,7 +567,11 @@ cv::viz::GridWidget::GridWidget(const Vec4f &coefs, const Vec2i &dimensions, con
vtkSmartPointer<vtkTransformPolyDataFilter> transform_filter = vtkSmartPointer<vtkTransformPolyDataFilter>::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<vtkDataSetMapper> mapper = vtkSmartPointer<vtkDataSetMapper>::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<vtkImageFlip> flipFilter = vtkSmartPointer<vtkImageFlip>::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<vtkImageFlip> flipFilter = vtkSmartPointer<vtkImageFlip>::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<vtkImageFlip> flipFilter = vtkSmartPointer<vtkImageFlip>::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<vtkImageFlip> flipFilter = vtkSmartPointer<vtkImageFlip>::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<vtkPlaneSource> plane = vtkSmartPointer<vtkPlaneSource>::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<vtkImageFlip> flipFilter = vtkSmartPointer<vtkImageFlip>::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<vtkImageFlip> flipFilter = vtkSmartPointer<vtkImageFlip>::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<vtkExtractEdges> filter = vtkSmartPointer<vtkExtractEdges>::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<vtkPolyData> axes_data = axes->GetOutput();
#if VTK_MAJOR_VERSION <= 5
axes_data->Update();
#else
axes->Update();
#endif
axes_data->GetPointData()->SetScalars(axes_colors);
vtkSmartPointer<vtkTubeFilter> axes_tubes = vtkSmartPointer<vtkTubeFilter>::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<vtkDataSetMapper> mapper = vtkSmartPointer<vtkDataSetMapper>::New();
mapper->SetScalarModeToUsePointData();
mapper->SetInput(axes_tubes->GetOutput());
mapper->SetInputConnection(axes_tubes->GetOutputPort());
vtkSmartPointer<vtkLODActor> actor = vtkSmartPointer<vtkLODActor>::New();
actor->SetMapper(mapper);
@ -1046,11 +1102,11 @@ cv::viz::CameraPositionWidget::CameraPositionWidget(const Matx33f &K, double sca
frustumSource->Update();
vtkSmartPointer<vtkExtractEdges> filter = vtkSmartPointer<vtkExtractEdges>::New();
filter->SetInput(frustumSource->GetOutput());
filter->SetInputConnection(frustumSource->GetOutputPort());
filter->Update();
vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
mapper->SetInput(filter->GetOutput());
mapper->SetInputConnection(filter->GetOutputPort());
vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::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<vtkExtractEdges> filter = vtkSmartPointer<vtkExtractEdges>::New();
filter->SetInput(frustumSource->GetOutput());
filter->SetInputConnection(frustumSource->GetOutputPort());
filter->Update();
vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
mapper->SetInput(filter->GetOutput());
mapper->SetInputConnection(filter->GetOutputPort());
vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New();
actor->SetMapper(mapper);
@ -1151,7 +1207,11 @@ struct cv::viz::TrajectoryWidget::ApplyPath
transform->SetMatrix(mat_trans);
vtkSmartPointer<vtkTransformPolyDataFilter> filter = vtkSmartPointer<vtkTransformPolyDataFilter>::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<Affine3f> &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<Affine3f> &path, i
axes_colors->InsertNextTuple3(0,0,255);
vtkSmartPointer<vtkPolyData> axes_data = axes->GetOutput();
#if VTK_MAJOR_VERSION <= 5
axes_data->Update();
#else
axes->Update();
#endif
axes_data->GetPointData()->SetScalars(axes_colors);
vtkSmartPointer<vtkTubeFilter> axes_tubes = vtkSmartPointer<vtkTubeFilter>::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<Affine3f> &path, i
vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
mapper->SetScalarModeToUsePointData();
mapper->SetInput(appendFilter->GetOutput());
mapper->SetInputConnection(appendFilter->GetOutputPort());
vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New();
actor->SetMapper(mapper);
@ -1272,14 +1344,14 @@ cv::viz::TrajectoryWidget::TrajectoryWidget(const std::vector<Affine3f> &path, c
// Extract the edges
vtkSmartPointer<vtkExtractEdges> filter = vtkSmartPointer<vtkExtractEdges>::New();
filter->SetInput(frustumSource->GetOutput());
filter->SetInputConnection(frustumSource->GetOutputPort());
filter->Update();
vtkSmartPointer<vtkAppendPolyData> appendFilter = vtkSmartPointer<vtkAppendPolyData>::New();
ApplyPath::applyPath(filter->GetOutput(), appendFilter, path);
vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
mapper->SetInput(appendFilter->GetOutput());
mapper->SetInputConnection(appendFilter->GetOutputPort());
vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New();
actor->SetMapper(mapper);
@ -1312,14 +1384,14 @@ cv::viz::TrajectoryWidget::TrajectoryWidget(const std::vector<Affine3f> &path, c
// Extract the edges
vtkSmartPointer<vtkExtractEdges> filter = vtkSmartPointer<vtkExtractEdges>::New();
filter->SetInput(frustumSource->GetOutput());
filter->SetInputConnection(frustumSource->GetOutputPort());
filter->Update();
vtkSmartPointer<vtkAppendPolyData> appendFilter = vtkSmartPointer<vtkAppendPolyData>::New();
ApplyPath::applyPath(filter->GetOutput(), appendFilter, path);
vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
mapper->SetInput(appendFilter->GetOutput());
mapper->SetInputConnection(appendFilter->GetOutputPort());
vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New();
actor->SetMapper(mapper);
@ -1410,7 +1482,7 @@ cv::viz::SpheresTrajectoryWidget::SpheresTrajectoryWidget(const std::vector<Affi
vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
mapper->SetScalarModeToUseCellData();
mapper->SetInput(appendFilter->GetOutput());
mapper->SetInputConnection(appendFilter->GetOutputPort());
vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New();
actor->SetMapper(mapper);

@ -325,7 +325,11 @@ void cv::viz::Viz3d::VizImpl::createActorFromVTKDataSet(const vtkSmartPointer<vt
actor = vtkSmartPointer<vtkLODActor>::New();
vtkSmartPointer<vtkDataSetMapper> mapper = vtkSmartPointer<vtkDataSetMapper>::New();
#if VTK_MAJOR_VERSION <= 5
mapper->SetInput(data);
#else
mapper->SetInputData(data);
#endif
if (use_scalars)
{

@ -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)

@ -93,7 +93,11 @@ cv::viz::Widget cv::viz::Widget::fromPlyFile(const String &file_name)
vtkSmartPointer<vtkLODActor> actor = vtkSmartPointer<vtkLODActor>::New();
vtkSmartPointer<vtkDataSetMapper> mapper = vtkSmartPointer<vtkDataSetMapper>::New();
#if VTK_MAJOR_VERSION <= 5
mapper->SetInput(data);
#else
mapper->SetInputData(data);
#endif
vtkSmartPointer<vtkDataArray> 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<vtkPolyDataNormals> normals = vtkSmartPointer<vtkPolyDataNormals>::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<vtkPolyDataNormals> normals = vtkSmartPointer<vtkPolyDataNormals>::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;

@ -74,7 +74,11 @@ TriangleWidget::TriangleWidget(const Point3f &pt1, const Point3f &pt2, const Poi
// Create mapper and actor
vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
#if VTK_MAJOR_VERSION <= 5
mapper->SetInput(polyData);
#else
mapper->SetInputData(polyData);
#endif
vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New();
actor->SetMapper(mapper);

Loading…
Cancel
Save