From 8d327fa497123f2b2281bd0407253787be67bea1 Mon Sep 17 00:00:00 2001 From: Anatoly Baksheev Date: Mon, 13 Jan 2014 22:42:49 +0400 Subject: [PATCH] updated for compatibility with VTK6.0 --- cmake/OpenCVDetectVTK.cmake | 4 ++-- modules/viz/src/clouds.cpp | 4 ++-- modules/viz/src/precomp.hpp | 28 +++++++++++++++++++++++++++- modules/viz/src/shapes.cpp | 24 ++++++++++++------------ modules/viz/src/widget.cpp | 1 + modules/viz/test/tests_simple.cpp | 2 +- 6 files changed, 45 insertions(+), 18 deletions(-) diff --git a/cmake/OpenCVDetectVTK.cmake b/cmake/OpenCVDetectVTK.cmake index f0d28d5..ef9aa80 100644 --- a/cmake/OpenCVDetectVTK.cmake +++ b/cmake/OpenCVDetectVTK.cmake @@ -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() diff --git a/modules/viz/src/clouds.cpp b/modules/viz/src/clouds.cpp index ff81775..b8567dd 100644 --- a/modules/viz/src/clouds.cpp +++ b/modules/viz/src/clouds.cpp @@ -230,8 +230,8 @@ void cv::viz::WCloudCollection::addCloud(InputArray cloud, InputArray colors, co CV_Assert("Cloud Widget without data" && currdata); vtkSmartPointer append_filter = vtkSmartPointer::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()); diff --git a/modules/viz/src/precomp.hpp b/modules/viz/src/precomp.hpp index bf154e7..7440f1e 100644 --- a/modules/viz/src/precomp.hpp +++ b/modules/viz/src/precomp.hpp @@ -230,6 +230,25 @@ namespace cv filter->SetInputData(polydata); #endif } + template + static void SetSourceData(vtkSmartPointer filter, vtkPolyData* polydata) + { + #if VTK_MAJOR_VERSION <= 5 + filter->SetSource(polydata); + #else + filter->SetSourceData(polydata); + #endif + } + + template + static void SetInputData(vtkSmartPointer filter, vtkImageData* polydata) + { + #if VTK_MAJOR_VERSION <= 5 + filter->SetInput(polydata); + #else + filter->SetInputData(polydata); + #endif + } template static void AddInputData(vtkSmartPointer filter, vtkPolyData *polydata) @@ -285,7 +304,14 @@ namespace cv static vtkSmartPointer TransformPolydata(vtkSmartPointer polydata, const Affine3d& pose) { - return TransformPolydata(polydata->GetProducerPort(), pose); + vtkSmartPointer transform = vtkSmartPointer::New(); + transform->SetMatrix(vtkmatrix(pose.matrix)); + + vtkSmartPointer transform_filter = vtkSmartPointer::New(); + VtkUtils::SetInputData(transform_filter, polydata); + transform_filter->SetTransform(transform); + transform_filter->Update(); + return transform_filter->GetOutput(); } }; } diff --git a/modules/viz/src/shapes.cpp b/modules/viz/src/shapes.cpp index 92ab340..323482f 100644 --- a/modules/viz/src/shapes.cpp +++ b/modules/viz/src/shapes.cpp @@ -355,7 +355,7 @@ cv::viz::WCoordinateSystem::WCoordinateSystem(double scale) polydata->GetPointData()->SetScalars(colors); vtkSmartPointer tube_filter = vtkSmartPointer::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 extract_edges = vtkSmartPointer::New(); - extract_edges->SetInputConnection(grid_data->GetProducerPort()); + VtkUtils::SetInputData(extract_edges, grid_data); extract_edges->Update(); vtkSmartPointer mapper = vtkSmartPointer::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 frustum_texture = vtkSmartPointer::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 append_filter = vtkSmartPointer::New(); append_filter->AddInputConnection(frustum_texture->GetOutputPort()); - append_filter->AddInputConnection(plane->GetProducerPort()); + VtkUtils::AddInputData(append_filter, plane); vtkSmartPointer 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 frustum_texture = vtkSmartPointer::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 append_filter = vtkSmartPointer::New(); append_filter->AddInputConnection(frustum_texture->GetOutputPort()); - append_filter->AddInputConnection(plane->GetProducerPort()); + VtkUtils::AddInputData(append_filter, plane); vtkSmartPointer 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 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 tensor_glyph = vtkSmartPointer::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 tensor_glyph = vtkSmartPointer::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 tensor_glyph = vtkSmartPointer::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 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 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(); diff --git a/modules/viz/src/widget.cpp b/modules/viz/src/widget.cpp index 6c1463b..33b467e 100644 --- a/modules/viz/src/widget.cpp +++ b/modules/viz/src/widget.cpp @@ -276,6 +276,7 @@ void cv::viz::Widget3D::applyTransform(const Affine3d &transform) vtkSmartPointer 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)); } diff --git a/modules/viz/test/tests_simple.cpp b/modules/viz/test/tests_simple.cpp index 3e25399..7f91c89 100644 --- a/modules/viz/test/tests_simple.cpp +++ b/modules/viz/test/tests_simple.cpp @@ -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(); -- 2.7.4