updated code to use mapper->SetInput instead of SetInputConnection. All widgets except plane, images ans texts

This commit is contained in:
Anatoly Baksheev 2014-01-08 17:16:25 +04:00
parent a3b1f29d23
commit 0d702b83f4
5 changed files with 54 additions and 88 deletions

View File

@ -113,6 +113,8 @@ namespace cv
template <typename Y> operator Affine3<Y>() const; template <typename Y> operator Affine3<Y>() const;
template <typename Y> Affine3<Y> cast() const;
Mat4 matrix; Mat4 matrix;
#if defined EIGEN_WORLD_VERSION && defined EIGEN_GEOMETRY_MODULE_H #if defined EIGEN_WORLD_VERSION && defined EIGEN_GEOMETRY_MODULE_H
@ -421,6 +423,12 @@ cv::Affine3<T>::operator Affine3<Y>() const
return Affine3<Y>(matrix); return Affine3<Y>(matrix);
} }
template<typename T> template <typename Y> inline
cv::Affine3<Y> cv::Affine3<T>::cast() const
{
return Affine3<Y>(matrix);
}
template<typename T> inline template<typename T> inline
cv::Affine3<T> cv::operator*(const cv::Affine3<T>& affine1, const cv::Affine3<T>& affine2) cv::Affine3<T> cv::operator*(const cv::Affine3<T>& affine1, const cv::Affine3<T>& affine2)
{ {

View File

@ -41,9 +41,6 @@
// * Ozan Tonkal, ozantonkal@gmail.com // * Ozan Tonkal, ozantonkal@gmail.com
// * Anatoly Baksheev, Itseez Inc. myname.mysurname <> mycompany.com // * Anatoly Baksheev, Itseez Inc. myname.mysurname <> mycompany.com
// //
// OpenCV Viz module is complete rewrite of
// PCL visualization module (www.pointclouds.org)
//
//M*/ //M*/
#ifndef __OPENCV_VIZ_HPP__ #ifndef __OPENCV_VIZ_HPP__

View File

@ -54,9 +54,10 @@ cv::viz::WCloud::WCloud(InputArray cloud, InputArray colors)
vtkSmartPointer<vtkCloudMatSource> cloud_source = vtkSmartPointer<vtkCloudMatSource>::New(); vtkSmartPointer<vtkCloudMatSource> cloud_source = vtkSmartPointer<vtkCloudMatSource>::New();
cloud_source->SetColorCloud(cloud, colors); cloud_source->SetColorCloud(cloud, colors);
cloud_source->Update();
vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New(); vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
mapper->SetInputConnection(cloud_source->GetOutputPort()); VtkUtils::SetInputData(mapper, cloud_source->GetOutput());
mapper->SetScalarModeToUsePointData(); mapper->SetScalarModeToUsePointData();
mapper->ImmediateModeRenderingOff(); mapper->ImmediateModeRenderingOff();
mapper->SetScalarRange(0, 255); mapper->SetScalarRange(0, 255);
@ -74,9 +75,10 @@ cv::viz::WCloud::WCloud(InputArray cloud, const Color &color)
{ {
vtkSmartPointer<vtkCloudMatSource> cloud_source = vtkSmartPointer<vtkCloudMatSource>::New(); vtkSmartPointer<vtkCloudMatSource> cloud_source = vtkSmartPointer<vtkCloudMatSource>::New();
cloud_source->SetCloud(cloud); cloud_source->SetCloud(cloud);
cloud_source->Update();
vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New(); vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
mapper->SetInputConnection(cloud_source->GetOutputPort()); VtkUtils::SetInputData(mapper, cloud_source->GetOutput());
mapper->ImmediateModeRenderingOff(); mapper->ImmediateModeRenderingOff();
mapper->ScalarVisibilityOff(); mapper->ScalarVisibilityOff();
@ -127,15 +129,11 @@ void cv::viz::WCloudCollection::addCloud(InputArray cloud, InputArray colors, co
{ {
// This is the first cloud // This is the first cloud
mapper = vtkSmartPointer<vtkPolyDataMapper>::New(); mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
#if VTK_MAJOR_VERSION <= 5
mapper->SetInput(polydata);
#else
mapper->SetInputData(polydata);
#endif
mapper->SetScalarRange(0, 255); mapper->SetScalarRange(0, 255);
mapper->SetScalarModeToUsePointData(); mapper->SetScalarModeToUsePointData();
mapper->ScalarVisibilityOn(); mapper->ScalarVisibilityOn();
mapper->ImmediateModeRenderingOff(); mapper->ImmediateModeRenderingOff();
VtkUtils::SetInputData(mapper, polydata);
actor->SetNumberOfCloudPoints(std::max(1, polydata->GetNumberOfPoints()/10)); actor->SetNumberOfCloudPoints(std::max(1, polydata->GetNumberOfPoints()/10));
actor->GetProperty()->SetInterpolationToFlat(); actor->GetProperty()->SetInterpolationToFlat();
@ -147,16 +145,12 @@ void cv::viz::WCloudCollection::addCloud(InputArray cloud, InputArray colors, co
vtkPolyData *currdata = vtkPolyData::SafeDownCast(mapper->GetInput()); vtkPolyData *currdata = vtkPolyData::SafeDownCast(mapper->GetInput());
CV_Assert("Cloud Widget without data" && currdata); CV_Assert("Cloud Widget without data" && currdata);
vtkSmartPointer<vtkAppendPolyData> appendFilter = vtkSmartPointer<vtkAppendPolyData>::New(); vtkSmartPointer<vtkAppendPolyData> append_filter = vtkSmartPointer<vtkAppendPolyData>::New();
#if VTK_MAJOR_VERSION <= 5 append_filter->AddInputConnection(currdata->GetProducerPort());
appendFilter->AddInput(currdata); append_filter->AddInputConnection(polydata->GetProducerPort());
appendFilter->AddInput(polydata); append_filter->Update();
mapper->SetInput(appendFilter->GetOutput());
#else VtkUtils::SetInputData(mapper, append_filter->GetOutput());
appendFilter->AddInputData(currdata);
appendFilter->AddInputData(polydata);
mapper->SetInputData(appendFilter->GetOutput());
#endif
actor->SetNumberOfCloudPoints(std::max(1, actor->GetNumberOfCloudPoints() + polydata->GetNumberOfPoints()/10)); actor->SetNumberOfCloudPoints(std::max(1, actor->GetNumberOfCloudPoints() + polydata->GetNumberOfPoints()/10));
} }
@ -245,11 +239,7 @@ cv::viz::WCloudNormals::WCloudNormals(InputArray _cloud, InputArray _normals, in
vtkSmartPointer<vtkDataSetMapper> mapper = vtkSmartPointer<vtkDataSetMapper>::New(); vtkSmartPointer<vtkDataSetMapper> mapper = vtkSmartPointer<vtkDataSetMapper>::New();
mapper->SetColorModeToMapScalars(); mapper->SetColorModeToMapScalars();
mapper->SetScalarModeToUsePointData(); mapper->SetScalarModeToUsePointData();
#if VTK_MAJOR_VERSION <= 5 VtkUtils::SetInputData(mapper, polyData);
mapper->SetInput(polyData);
#else
mapper->SetInputData(polyData);
#endif
vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New(); vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New();
actor->SetMapper(mapper); actor->SetMapper(mapper);
@ -326,11 +316,7 @@ cv::viz::WMesh::WMesh(const Mesh3d &mesh)
vtkSmartPointer<vtkDataSetMapper> mapper = vtkSmartPointer<vtkDataSetMapper>::New(); vtkSmartPointer<vtkDataSetMapper> mapper = vtkSmartPointer<vtkDataSetMapper>::New();
mapper->SetScalarModeToUsePointData(); mapper->SetScalarModeToUsePointData();
mapper->ImmediateModeRenderingOff(); mapper->ImmediateModeRenderingOff();
#if VTK_MAJOR_VERSION <= 5 VtkUtils::SetInputData(mapper, polydata);
mapper->SetInput(polydata);
#else
mapper->SetInputData(polydata);
#endif
vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New(); vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New();
//actor->SetNumberOfCloudPoints(std::max(1, polydata->GetNumberOfPoints() / 10)); //actor->SetNumberOfCloudPoints(std::max(1, polydata->GetNumberOfPoints() / 10));

View File

@ -564,7 +564,6 @@ void cv::viz::InteractorStyle::OnLeftButtonUp()
void cv::viz::InteractorStyle::OnMiddleButtonDown() void cv::viz::InteractorStyle::OnMiddleButtonDown()
{ {
Vec2i p(Interactor->GetEventPosition()); Vec2i p(Interactor->GetEventPosition());
MouseEvent::Type type = (Interactor->GetRepeatCount() == 0) ? MouseEvent::MouseButtonPress : MouseEvent::MouseDblClick; MouseEvent::Type type = (Interactor->GetRepeatCount() == 0) ? MouseEvent::MouseButtonPress : MouseEvent::MouseDblClick;
MouseEvent event(type, MouseEvent::MiddleButton, p, getModifiers()); MouseEvent event(type, MouseEvent::MiddleButton, p, getModifiers());
if (mouseCallback_) if (mouseCallback_)
@ -586,7 +585,6 @@ void cv::viz::InteractorStyle::OnMiddleButtonUp()
void cv::viz::InteractorStyle::OnRightButtonDown() void cv::viz::InteractorStyle::OnRightButtonDown()
{ {
Vec2i p(Interactor->GetEventPosition()); Vec2i p(Interactor->GetEventPosition());
MouseEvent::Type type = (Interactor->GetRepeatCount() == 0) ? MouseEvent::MouseButtonPress : MouseEvent::MouseDblClick; MouseEvent::Type type = (Interactor->GetRepeatCount() == 0) ? MouseEvent::MouseButtonPress : MouseEvent::MouseDblClick;
MouseEvent event(type, MouseEvent::RightButton, p, getModifiers()); MouseEvent event(type, MouseEvent::RightButton, p, getModifiers());
if (mouseCallback_) if (mouseCallback_)

View File

@ -52,9 +52,10 @@ cv::viz::WLine::WLine(const Point3d &pt1, const Point3d &pt2, const Color &color
vtkSmartPointer<vtkLineSource> line = vtkSmartPointer<vtkLineSource>::New(); vtkSmartPointer<vtkLineSource> line = vtkSmartPointer<vtkLineSource>::New();
line->SetPoint1(pt1.x, pt1.y, pt1.z); line->SetPoint1(pt1.x, pt1.y, pt1.z);
line->SetPoint2(pt2.x, pt2.y, pt2.z); line->SetPoint2(pt2.x, pt2.y, pt2.z);
line->Update();
vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New(); vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
mapper->SetInputConnection(line->GetOutputPort()); VtkUtils::SetInputData(mapper, line->GetOutput());
vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New(); vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New();
actor->SetMapper(mapper); actor->SetMapper(mapper);
@ -153,9 +154,10 @@ cv::viz::WSphere::WSphere(const Point3d &center, double radius, int sphere_resol
sphere->SetPhiResolution(sphere_resolution); sphere->SetPhiResolution(sphere_resolution);
sphere->SetThetaResolution(sphere_resolution); sphere->SetThetaResolution(sphere_resolution);
sphere->LatLongTessellationOff(); sphere->LatLongTessellationOff();
sphere->Update();
vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New(); vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
mapper->SetInputConnection(sphere->GetOutputPort()); VtkUtils::SetInputData(mapper, sphere->GetOutput());
vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New(); vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New();
actor->SetMapper(mapper); actor->SetMapper(mapper);
@ -203,9 +205,10 @@ cv::viz::WArrow::WArrow(const Point3d& pt1, const Point3d& pt2, double thickness
vtkSmartPointer<vtkTransformPolyDataFilter> transformPD = vtkSmartPointer<vtkTransformPolyDataFilter>::New(); vtkSmartPointer<vtkTransformPolyDataFilter> transformPD = vtkSmartPointer<vtkTransformPolyDataFilter>::New();
transformPD->SetTransform(transform); transformPD->SetTransform(transform);
transformPD->SetInputConnection(arrowSource->GetOutputPort()); transformPD->SetInputConnection(arrowSource->GetOutputPort());
transformPD->Update();
vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New(); vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
mapper->SetInputConnection(transformPD->GetOutputPort()); VtkUtils::SetInputData(mapper, transformPD->GetOutput());
vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New(); vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New();
actor->SetMapper(mapper); actor->SetMapper(mapper);
@ -239,9 +242,10 @@ cv::viz::WCircle::WCircle(const Point3d& pt, double radius, double thickness, co
vtkSmartPointer<vtkTransformPolyDataFilter> tf = vtkSmartPointer<vtkTransformPolyDataFilter>::New(); vtkSmartPointer<vtkTransformPolyDataFilter> tf = vtkSmartPointer<vtkTransformPolyDataFilter>::New();
tf->SetTransform(t); tf->SetTransform(t);
tf->SetInputConnection(disk->GetOutputPort()); tf->SetInputConnection(disk->GetOutputPort());
tf->Update();
vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New(); vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
mapper->SetInputConnection(tf->GetOutputPort()); VtkUtils::SetInputData(mapper, tf->GetOutput());
vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New(); vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New();
actor->SetMapper(mapper); 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->SetInputConnection(line->GetOutputPort());
tuber->SetRadius(radius); tuber->SetRadius(radius);
tuber->SetNumberOfSides(numsides); tuber->SetNumberOfSides(numsides);
tuber->Update();
vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New(); vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
mapper->SetInputConnection(tuber->GetOutputPort()); VtkUtils::SetInputData(mapper, tuber->GetOutput());
vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New(); vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New();
actor->SetMapper(mapper); actor->SetMapper(mapper);
@ -292,19 +297,21 @@ template<> cv::viz::WCylinder cv::viz::Widget::cast<cv::viz::WCylinder>()
cv::viz::WCube::WCube(const Point3d& pt_min, const Point3d& pt_max, bool wire_frame, const Color &color) cv::viz::WCube::WCube(const Point3d& pt_min, const Point3d& pt_max, bool wire_frame, const Color &color)
{ {
vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New(); vtkSmartPointer<vtkPolyDataAlgorithm> cube;
if (wire_frame) if (wire_frame)
{ {
vtkSmartPointer<vtkOutlineSource> cube = vtkSmartPointer<vtkOutlineSource>::New(); cube = vtkSmartPointer<vtkOutlineSource>::New();
cube->SetBounds(pt_min.x, pt_max.x, pt_min.y, pt_max.y, pt_min.z, pt_max.z); vtkOutlineSource::SafeDownCast(cube)->SetBounds(pt_min.x, pt_max.x, pt_min.y, pt_max.y, pt_min.z, pt_max.z);
mapper->SetInputConnection(cube->GetOutputPort());
} }
else else
{ {
vtkSmartPointer<vtkCubeSource> cube = vtkSmartPointer<vtkCubeSource>::New(); cube = vtkSmartPointer<vtkCubeSource>::New();
cube->SetBounds(pt_min.x, pt_max.x, pt_min.y, pt_max.y, pt_min.z, pt_max.z); vtkCubeSource::SafeDownCast(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->Update();
vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
VtkUtils::SetInputData(mapper, cube->GetOutput());
vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New(); vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New();
actor->SetMapper(mapper); actor->SetMapper(mapper);
@ -345,6 +352,7 @@ cv::viz::WCoordinateSystem::WCoordinateSystem(double scale)
tube_filter->SetInputConnection(polydata->GetProducerPort()); tube_filter->SetInputConnection(polydata->GetProducerPort());
tube_filter->SetRadius(axes->GetScaleFactor() / 50.0); tube_filter->SetRadius(axes->GetScaleFactor() / 50.0);
tube_filter->SetNumberOfSides(6); tube_filter->SetNumberOfSides(6);
tube_filter->Update();
vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New(); vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
mapper->SetScalarModeToUsePointData(); mapper->SetScalarModeToUsePointData();
@ -400,7 +408,7 @@ cv::viz::WPolyLine::WPolyLine(InputArray _points, const Color &color)
polydata->GetPointData()->SetScalars(scalars); polydata->GetPointData()->SetScalars(scalars);
vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New(); vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
mapper->SetInputConnection(polydata->GetProducerPort()); VtkUtils::SetInputData(mapper, polydata);
mapper->SetScalarRange(0, 255); mapper->SetScalarRange(0, 255);
vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New(); vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New();
@ -449,7 +457,7 @@ cv::viz::WGrid::WGrid(const Vec2i &dimensions, const Vec2d &spacing, const Color
vtkSmartPointer<vtkPolyData> grid = GridUtils::createGrid(dimensions, spacing); vtkSmartPointer<vtkPolyData> grid = GridUtils::createGrid(dimensions, spacing);
vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New(); vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
mapper->SetInputConnection(grid->GetProducerPort()); VtkUtils::SetInputData(mapper, grid);
vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New(); vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New();
actor->SetMapper(mapper); actor->SetMapper(mapper);
@ -478,15 +486,11 @@ cv::viz::WGrid::WGrid(const Vec4d &coefs, const Vec2i &dimensions, const Vec2d &
vtkSmartPointer<vtkTransformPolyDataFilter> transform_filter = vtkSmartPointer<vtkTransformPolyDataFilter>::New(); vtkSmartPointer<vtkTransformPolyDataFilter> transform_filter = vtkSmartPointer<vtkTransformPolyDataFilter>::New();
transform_filter->SetTransform(transform); transform_filter->SetTransform(transform);
#if VTK_MAJOR_VERSION <= 5
transform_filter->SetInputConnection(grid->GetProducerPort()); transform_filter->SetInputConnection(grid->GetProducerPort());
#else
transform_filter->SetInputData(grid);
#endif
transform_filter->Update(); transform_filter->Update();
vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New(); vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
mapper->SetInputConnection(transform_filter->GetOutputPort()); VtkUtils::SetInputData(mapper, transform_filter->GetOutput());
vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New(); vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New();
actor->SetMapper(mapper); actor->SetMapper(mapper);
@ -544,6 +548,7 @@ void cv::viz::WText3D::setText(const String &text)
CV_Assert("This widget does not support text." && textSource); CV_Assert("This widget does not support text." && textSource);
textSource->SetText(text.c_str()); textSource->SetText(text.c_str());
textSource->Modified();
textSource->Update(); 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 // Need to flip the image as the coordinates are different in OpenCV and VTK
vtkSmartPointer<vtkImageFlip> flipFilter = vtkSmartPointer<vtkImageFlip>::New(); vtkSmartPointer<vtkImageFlip> flipFilter = vtkSmartPointer<vtkImageFlip>::New();
flipFilter->SetFilteredAxis(1); // Vertical flip flipFilter->SetFilteredAxis(1); // Vertical flip
#if VTK_MAJOR_VERSION <= 5
flipFilter->SetInputConnection(vtk_image->GetProducerPort()); flipFilter->SetInputConnection(vtk_image->GetProducerPort());
#else
flipFilter->SetInputData(vtk_image);
#endif
flipFilter->Update(); flipFilter->Update();
// Scale the image based on the Rect // 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 // Need to flip the image as the coordinates are different in OpenCV and VTK
vtkSmartPointer<vtkImageFlip> flipFilter = vtkSmartPointer<vtkImageFlip>::New(); vtkSmartPointer<vtkImageFlip> flipFilter = vtkSmartPointer<vtkImageFlip>::New();
flipFilter->SetFilteredAxis(1); // Vertical flip flipFilter->SetFilteredAxis(1); // Vertical flip
#if VTK_MAJOR_VERSION <= 5
flipFilter->SetInputConnection(vtk_image->GetProducerPort()); flipFilter->SetInputConnection(vtk_image->GetProducerPort());
#else
flipFilter->SetInputData(vtk_image);
#endif
flipFilter->Update(); flipFilter->Update();
mapper->SetInputConnection(flipFilter->GetOutputPort()); 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 // Need to flip the image as the coordinates are different in OpenCV and VTK
vtkSmartPointer<vtkImageFlip> flipFilter = vtkSmartPointer<vtkImageFlip>::New(); vtkSmartPointer<vtkImageFlip> flipFilter = vtkSmartPointer<vtkImageFlip>::New();
flipFilter->SetFilteredAxis(1); // Vertical flip flipFilter->SetFilteredAxis(1); // Vertical flip
#if VTK_MAJOR_VERSION <= 5
flipFilter->SetInputConnection(vtk_image->GetProducerPort()); flipFilter->SetInputConnection(vtk_image->GetProducerPort());
#else
flipFilter->SetInputData(vtk_image);
#endif
flipFilter->Update(); flipFilter->Update();
Vec3d plane_center(size.width * 0.5, size.height * 0.5, 0.0); 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 // Need to flip the image as the coordinates are different in OpenCV and VTK
vtkSmartPointer<vtkImageFlip> flipFilter = vtkSmartPointer<vtkImageFlip>::New(); vtkSmartPointer<vtkImageFlip> flipFilter = vtkSmartPointer<vtkImageFlip>::New();
flipFilter->SetFilteredAxis(1); // Vertical flip flipFilter->SetFilteredAxis(1); // Vertical flip
#if VTK_MAJOR_VERSION <= 5
flipFilter->SetInputConnection(vtk_image->GetProducerPort()); flipFilter->SetInputConnection(vtk_image->GetProducerPort());
#else
flipFilter->SetInputData(vtk_image);
#endif
flipFilter->Update(); flipFilter->Update();
vtkSmartPointer<vtkPlaneSource> plane = vtkSmartPointer<vtkPlaneSource>::New(); vtkSmartPointer<vtkPlaneSource> plane = vtkSmartPointer<vtkPlaneSource>::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 // Need to flip the image as the coordinates are different in OpenCV and VTK
vtkSmartPointer<vtkImageFlip> flipFilter = vtkSmartPointer<vtkImageFlip>::New(); vtkSmartPointer<vtkImageFlip> flipFilter = vtkSmartPointer<vtkImageFlip>::New();
flipFilter->SetFilteredAxis(1); // Vertical flip flipFilter->SetFilteredAxis(1); // Vertical flip
#if VTK_MAJOR_VERSION <= 5
flipFilter->SetInputConnection(vtk_image->GetProducerPort()); flipFilter->SetInputConnection(vtk_image->GetProducerPort());
#else
flipFilter->SetInputData(vtk_image);
#endif
flipFilter->Update(); flipFilter->Update();
// Apply the texture // 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 // Need to flip the image as the coordinates are different in OpenCV and VTK
vtkSmartPointer<vtkImageFlip> flipFilter = vtkSmartPointer<vtkImageFlip>::New(); vtkSmartPointer<vtkImageFlip> flipFilter = vtkSmartPointer<vtkImageFlip>::New();
flipFilter->SetFilteredAxis(1); // Vertical flip flipFilter->SetFilteredAxis(1); // Vertical flip
#if VTK_MAJOR_VERSION <= 5
flipFilter->SetInputConnection(vtk_image->GetProducerPort()); flipFilter->SetInputConnection(vtk_image->GetProducerPort());
#else
flipFilter->SetInputData(vtk_image);
#endif
flipFilter->Update(); flipFilter->Update();
Vec3d plane_center(0.0, 0.0, scale); Vec3d plane_center(0.0, 0.0, scale);
@ -958,7 +939,6 @@ namespace cv { namespace viz { namespace
cv::viz::WCameraPosition::WCameraPosition(double scale) cv::viz::WCameraPosition::WCameraPosition(double scale)
{ {
vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New(); vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
VtkUtils::SetInputData(mapper, getPolyData(WCoordinateSystem(scale))); VtkUtils::SetInputData(mapper, getPolyData(WCoordinateSystem(scale)));
mapper->SetScalarModeToUsePointData(); mapper->SetScalarModeToUsePointData();
@ -979,7 +959,7 @@ cv::viz::WCameraPosition::WCameraPosition(const Matx33d &K, double scale, const
vtkSmartPointer<vtkPolyData> polydata = CameraPositionUtils::createFrustrum(aspect_ratio, fovy, scale); vtkSmartPointer<vtkPolyData> polydata = CameraPositionUtils::createFrustrum(aspect_ratio, fovy, scale);
vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New(); vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
mapper->SetInputConnection(polydata->GetProducerPort()); VtkUtils::SetInputData(mapper, polydata);
vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New(); vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New();
actor->SetMapper(mapper); actor->SetMapper(mapper);
@ -996,7 +976,7 @@ cv::viz::WCameraPosition::WCameraPosition(const Vec2d &fov, double scale, const
vtkSmartPointer<vtkPolyData> polydata = CameraPositionUtils::createFrustrum(aspect_ratio, fovy, scale); vtkSmartPointer<vtkPolyData> polydata = CameraPositionUtils::createFrustrum(aspect_ratio, fovy, scale);
vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New(); vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
mapper->SetInputConnection(polydata->GetProducerPort()); VtkUtils::SetInputData(mapper, polydata);
vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New(); vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New();
actor->SetMapper(mapper); actor->SetMapper(mapper);
@ -1042,14 +1022,14 @@ template<> cv::viz::WCameraPosition cv::viz::Widget::cast<cv::viz::WCameraPositi
cv::viz::WTrajectory::WTrajectory(InputArray _path, int display_mode, double scale, const Color &color) cv::viz::WTrajectory::WTrajectory(InputArray _path, int display_mode, double scale, const Color &color)
{ {
vtkSmartPointer<vtkAppendPolyData> appendFilter = vtkSmartPointer<vtkAppendPolyData>::New(); vtkSmartPointer<vtkAppendPolyData> append_filter = vtkSmartPointer<vtkAppendPolyData>::New();
// Bitwise and with 3 in order to limit the domain to 2 bits // Bitwise and with 3 in order to limit the domain to 2 bits
if (display_mode & WTrajectory::PATH) if (display_mode & WTrajectory::PATH)
{ {
Mat points = vtkTrajectorySource::ExtractPoints(_path); Mat points = vtkTrajectorySource::ExtractPoints(_path);
vtkSmartPointer<vtkPolyData> polydata = getPolyData(WPolyLine(points, color)); vtkSmartPointer<vtkPolyData> polydata = getPolyData(WPolyLine(points, color));
appendFilter->AddInputConnection(polydata->GetProducerPort()); append_filter->AddInputConnection(polydata->GetProducerPort());
} }
if (display_mode & WTrajectory::FRAMES) 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->SymmetricOff();
tensor_glyph->ColorGlyphsOff(); tensor_glyph->ColorGlyphsOff();
appendFilter->AddInputConnection(tensor_glyph->GetOutputPort()); append_filter->AddInputConnection(tensor_glyph->GetOutputPort());
} }
append_filter->Update();
vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New(); vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
VtkUtils::SetInputData(mapper, appendFilter->GetOutput()); VtkUtils::SetInputData(mapper, append_filter->GetOutput());
mapper->SetScalarModeToUsePointData(); mapper->SetScalarModeToUsePointData();
mapper->SetScalarRange(0, 255); mapper->SetScalarRange(0, 255);
@ -1106,10 +1087,8 @@ cv::viz::WTrajectoryFrustums::WTrajectoryFrustums(InputArray _path, const Matx33
tensor_glyph->ColorGlyphsOff(); tensor_glyph->ColorGlyphsOff();
tensor_glyph->Update(); tensor_glyph->Update();
vtkSmartPointer<vtkPolyData> polydata = tensor_glyph->GetOutput();
vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New(); vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
mapper->SetInputConnection(polydata->GetProducerPort()); VtkUtils::SetInputData(mapper, tensor_glyph->GetOutput());
vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New(); vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New();
actor->SetMapper(mapper); actor->SetMapper(mapper);
@ -1134,10 +1113,8 @@ cv::viz::WTrajectoryFrustums::WTrajectoryFrustums(InputArray _path, const Vec2d
tensor_glyph->ColorGlyphsOff(); tensor_glyph->ColorGlyphsOff();
tensor_glyph->Update(); tensor_glyph->Update();
vtkSmartPointer<vtkPolyData> polydata = tensor_glyph->GetOutput();
vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New(); vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
mapper->SetInputConnection(polydata->GetProducerPort()); VtkUtils::SetInputData(mapper, tensor_glyph->GetOutput());
vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New(); vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New();
actor->SetMapper(mapper); actor->SetMapper(mapper);