提交 8d327fa4 编写于 作者: A Anatoly Baksheev

updated for compatibility with VTK6.0

上级 e472d45d
......@@ -2,7 +2,7 @@ if(NOT WITH_VTK OR ANDROID OR IOS)
return()
endif()
find_package(VTK 6.0 QUIET COMPONENTS vtkRenderingCore vtkInteractionWidgets vtkInteractionStyle vtkIOLegacy vtkIOPLY vtkRenderingFreeType vtkRenderingLOD vtkFiltersTexture NO_MODULE)
find_package(VTK 6.0 QUIET COMPONENTS vtkRenderingCore vtkInteractionWidgets vtkInteractionStyle vtkIOLegacy vtkIOPLY vtkRenderingFreeType vtkRenderingLOD vtkFiltersTexture vtkIOExport NO_MODULE)
if(NOT DEFINED VTK_FOUND OR NOT VTK_FOUND)
find_package(VTK 5.10 QUIET COMPONENTS vtkCommon vtkFiltering vtkRendering vtkWidgets vtkImaging NO_MODULE)
......@@ -18,4 +18,4 @@ if(VTK_FOUND)
else()
set(HAVE_VTK OFF)
message(STATUS "VTK is not found. Please set -DVTK_DIR in CMake to VTK build directory, or set $VTK_DIR enviroment variable to VTK install subdirectory with VTKConfig.cmake file (for windows)")
endif()
\ No newline at end of file
endif()
......@@ -230,8 +230,8 @@ void cv::viz::WCloudCollection::addCloud(InputArray cloud, InputArray colors, co
CV_Assert("Cloud Widget without data" && currdata);
vtkSmartPointer<vtkAppendPolyData> append_filter = vtkSmartPointer<vtkAppendPolyData>::New();
append_filter->AddInputConnection(currdata->GetProducerPort());
append_filter->AddInputConnection(polydata->GetProducerPort());
VtkUtils::AddInputData(append_filter, currdata);
VtkUtils::AddInputData(append_filter, polydata);
append_filter->Update();
VtkUtils::SetInputData(mapper, append_filter->GetOutput());
......
......@@ -230,6 +230,25 @@ namespace cv
filter->SetInputData(polydata);
#endif
}
template<class Filter>
static void SetSourceData(vtkSmartPointer<Filter> filter, vtkPolyData* polydata)
{
#if VTK_MAJOR_VERSION <= 5
filter->SetSource(polydata);
#else
filter->SetSourceData(polydata);
#endif
}
template<class Filter>
static void SetInputData(vtkSmartPointer<Filter> filter, vtkImageData* polydata)
{
#if VTK_MAJOR_VERSION <= 5
filter->SetInput(polydata);
#else
filter->SetInputData(polydata);
#endif
}
template<class Filter>
static void AddInputData(vtkSmartPointer<Filter> filter, vtkPolyData *polydata)
......@@ -285,7 +304,14 @@ namespace cv
static vtkSmartPointer<vtkPolyData> TransformPolydata(vtkSmartPointer<vtkPolyData> polydata, const Affine3d& pose)
{
return TransformPolydata(polydata->GetProducerPort(), pose);
vtkSmartPointer<vtkTransform> transform = vtkSmartPointer<vtkTransform>::New();
transform->SetMatrix(vtkmatrix(pose.matrix));
vtkSmartPointer<vtkTransformPolyDataFilter> transform_filter = vtkSmartPointer<vtkTransformPolyDataFilter>::New();
VtkUtils::SetInputData(transform_filter, polydata);
transform_filter->SetTransform(transform);
transform_filter->Update();
return transform_filter->GetOutput();
}
};
}
......
......@@ -355,7 +355,7 @@ cv::viz::WCoordinateSystem::WCoordinateSystem(double scale)
polydata->GetPointData()->SetScalars(colors);
vtkSmartPointer<vtkTubeFilter> tube_filter = vtkSmartPointer<vtkTubeFilter>::New();
tube_filter->SetInputConnection(polydata->GetProducerPort());
VtkUtils::SetInputData(tube_filter, polydata);
tube_filter->SetRadius(axes->GetScaleFactor() / 50.0);
tube_filter->SetNumberOfSides(6);
tube_filter->Update();
......@@ -447,7 +447,7 @@ cv::viz::WGrid::WGrid(const Vec2i &cells, const Vec2d &cells_spacing, const Colo
// Extract the edges so we have the grid
vtkSmartPointer<vtkExtractEdges> extract_edges = vtkSmartPointer<vtkExtractEdges>::New();
extract_edges->SetInputConnection(grid_data->GetProducerPort());
VtkUtils::SetInputData(extract_edges, grid_data);
extract_edges->Update();
vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
......@@ -854,13 +854,13 @@ cv::viz::WCameraPosition::WCameraPosition(const Matx33d &K, InputArray _image, d
// Frustum needs to be textured or else it can't be combined with image
vtkSmartPointer<vtkTextureMapToPlane> frustum_texture = vtkSmartPointer<vtkTextureMapToPlane>::New();
frustum_texture->SetInputConnection(frustum->GetProducerPort());
VtkUtils::SetInputData(frustum_texture, frustum);
frustum_texture->SetSRange(0.0, 0.0); // Texture mapping with only one pixel
frustum_texture->SetTRange(0.0, 0.0); // from the image to have constant color
vtkSmartPointer<vtkAppendPolyData> append_filter = vtkSmartPointer<vtkAppendPolyData>::New();
append_filter->AddInputConnection(frustum_texture->GetOutputPort());
append_filter->AddInputConnection(plane->GetProducerPort());
VtkUtils::AddInputData(append_filter, plane);
vtkSmartPointer<vtkActor> actor = getActor(image_widget);
actor->GetMapper()->SetInputConnection(append_filter->GetOutputPort());
......@@ -886,13 +886,13 @@ cv::viz::WCameraPosition::WCameraPosition(const Vec2d &fov, InputArray _image, d
// Frustum needs to be textured or else it can't be combined with image
vtkSmartPointer<vtkTextureMapToPlane> frustum_texture = vtkSmartPointer<vtkTextureMapToPlane>::New();
frustum_texture->SetInputConnection(frustum->GetProducerPort());
VtkUtils::SetInputData(frustum_texture, frustum);
frustum_texture->SetSRange(0.0, 0.0); // Texture mapping with only one pixel
frustum_texture->SetTRange(0.0, 0.0); // from the image to have constant color
vtkSmartPointer<vtkAppendPolyData> append_filter = vtkSmartPointer<vtkAppendPolyData>::New();
append_filter->AddInputConnection(frustum_texture->GetOutputPort());
append_filter->AddInputConnection(plane->GetProducerPort());
VtkUtils::AddInputData(append_filter, plane);
vtkSmartPointer<vtkActor> actor = getActor(image_widget);
actor->GetMapper()->SetInputConnection(append_filter->GetOutputPort());
......@@ -917,7 +917,7 @@ cv::viz::WTrajectory::WTrajectory(InputArray _path, int display_mode, double sca
{
Mat points = vtkTrajectorySource::ExtractPoints(_path);
vtkSmartPointer<vtkPolyData> polydata = getPolyData(WPolyLine(points, color));
append_filter->AddInputConnection(polydata->GetProducerPort());
VtkUtils::AddInputData(append_filter, polydata);
}
if (display_mode & WTrajectory::FRAMES)
......@@ -929,7 +929,7 @@ cv::viz::WTrajectory::WTrajectory(InputArray _path, int display_mode, double sca
vtkSmartPointer<vtkTensorGlyph> tensor_glyph = vtkSmartPointer<vtkTensorGlyph>::New();
tensor_glyph->SetInputConnection(source->GetOutputPort());
tensor_glyph->SetSourceConnection(glyph->GetProducerPort());
VtkUtils::SetSourceData(tensor_glyph, glyph);
tensor_glyph->ExtractEigenvaluesOff(); // Treat as a rotation matrix, not as something with eigenvalues
tensor_glyph->ThreeGlyphsOff();
tensor_glyph->SymmetricOff();
......@@ -968,7 +968,7 @@ cv::viz::WTrajectoryFrustums::WTrajectoryFrustums(InputArray _path, const Matx33
vtkSmartPointer<vtkTensorGlyph> tensor_glyph = vtkSmartPointer<vtkTensorGlyph>::New();
tensor_glyph->SetInputConnection(source->GetOutputPort());
tensor_glyph->SetSourceConnection(glyph->GetProducerPort());
VtkUtils::SetSourceData(tensor_glyph, glyph);
tensor_glyph->ExtractEigenvaluesOff(); // Treat as a rotation matrix, not as something with eigenvalues
tensor_glyph->ThreeGlyphsOff();
tensor_glyph->SymmetricOff();
......@@ -994,7 +994,7 @@ cv::viz::WTrajectoryFrustums::WTrajectoryFrustums(InputArray _path, const Vec2d
vtkSmartPointer<vtkTensorGlyph> tensor_glyph = vtkSmartPointer<vtkTensorGlyph>::New();
tensor_glyph->SetInputConnection(source->GetOutputPort());
tensor_glyph->SetSourceConnection(glyph->GetProducerPort());
VtkUtils::SetSourceData(tensor_glyph, glyph);
tensor_glyph->ExtractEigenvaluesOff(); // Treat as a rotation matrix, not as something with eigenvalues
tensor_glyph->ThreeGlyphsOff();
tensor_glyph->SymmetricOff();
......@@ -1046,7 +1046,7 @@ cv::viz::WTrajectorySpheres::WTrajectorySpheres(InputArray _path, double line_le
vtkSmartPointer<vtkPolyData> polydata = sphere_source->GetOutput();
polydata->GetCellData()->SetScalars(VtkUtils::FillScalars(polydata->GetNumberOfCells(), c));
append_filter->AddInputConnection(polydata->GetProducerPort());
VtkUtils::AddInputData(append_filter, polydata);
if (i > 0)
{
......@@ -1064,7 +1064,7 @@ cv::viz::WTrajectorySpheres::WTrajectorySpheres(InputArray _path, double line_le
line_source->Update();
vtkSmartPointer<vtkPolyData> polydata = line_source->GetOutput();
polydata->GetCellData()->SetScalars(VtkUtils::FillScalars(polydata->GetNumberOfCells(), c));
append_filter->AddInputConnection(polydata->GetProducerPort());
VtkUtils::AddInputData(append_filter, polydata);
}
}
append_filter->Update();
......
......@@ -276,6 +276,7 @@ void cv::viz::Widget3D::applyTransform(const Affine3d &transform)
vtkSmartPointer<vtkPolyDataMapper> mapper = vtkPolyDataMapper::SafeDownCast(actor->GetMapper());
CV_Assert("Widget doesn't have a polydata mapper" && mapper);
mapper->Update();
VtkUtils::SetInputData(mapper, VtkUtils::TransformPolydata(mapper->GetInput(), transform));
}
......
......@@ -113,7 +113,7 @@ TEST(Viz, show_painted_clouds)
viz.setBackgroundMeshLab();
viz.showWidget("coosys", WCoordinateSystem());
viz.showWidget("cloud1", WPaintedCloud(cloud), Affine3d(Vec3d(0.0, -CV_PI/2, 0.0), Vec3d(-1.5, 0.0, 0.0)));
viz.showWidget("cloud2", WPaintedCloud(cloud, Vec3d(0.0, 0.0, -1.0), Vec3d(0.0, 0.0, 1.0)), Affine3d(Vec3d(0.0, CV_PI/2, 0.0), Vec3d(1.5, 0.0, 0.0)));
viz.showWidget("cloud2", WPaintedCloud(cloud, Vec3d(0.0, -0.75, -1.0), Vec3d(0.0, 0.75, 0.0)), Affine3d(Vec3d(0.0, CV_PI/2, 0.0), Vec3d(1.5, 0.0, 0.0)));
viz.showWidget("cloud3", WPaintedCloud(cloud, Vec3d(0.0, 0.0, -1.0), Vec3d(0.0, 0.0, 1.0), Color::blue(), Color::red()));
viz.showWidget("arrow", WArrow(Vec3d(0.0, 1.0, -1.0), Vec3d(0.0, 1.0, 1.0), 0.009, Color::raspberry()));
viz.spin();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册