Skip to content

Commit

Permalink
VTK6 code fixes. VTK5 backward compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
fran6co committed May 25, 2014
1 parent e256f92 commit 4d1ee47
Show file tree
Hide file tree
Showing 52 changed files with 443 additions and 83 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,6 @@ namespace pcl
filter_scale->Update ();

vtkSmartPointer<vtkPolyData> mapper = filter_scale->GetOutput ();
mapper->Update ();

//generate views
pcl::apps::RenderViewsTesselatedSphere render_views;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@ namespace pcl
}

vtkSmartPointer<vtkPolyData> poly = mapper->GetInput ();
poly->Update ();

uniform_sampling (poly, n_samples, cloud_out);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,18 +54,24 @@ pcl::cloud_composer::RectangularFrustumSelector::OnLeftButtonUp ()
vtkMapper* mapper = act->actor->GetMapper ();
vtkDataSet* data = mapper->GetInput ();
vtkPolyData* poly_data = vtkPolyData::SafeDownCast (data);
#if VTK_MAJOR_VERSION > 5
id_filter->SetInputData (poly_data);
#else
id_filter->SetInput (poly_data);
#endif
//extract_geometry->SetInput (poly_data);

vtkSmartPointer<vtkPolyData> selected = vtkSmartPointer<vtkPolyData>::New ();
glyph_filter->SetOutput (selected);
glyph_filter->Update ();
#if VTK_MAJOR_VERSION < 6
selected->SetSource (0);
#endif
if (selected->GetNumberOfPoints() > 0)
{
qDebug () << "Selected " << selected->GetNumberOfPoints () << " points.";
id_selected_data_map.insert ( QString::fromStdString ((*it).first), selected);
#if VTK_MAJOR_VERSION <= 5
#if VTK_MAJOR_VERSION < 6
append->AddInput (selected);
#else // VTK 6
append->AddInputData (selected);
Expand All @@ -77,9 +83,12 @@ pcl::cloud_composer::RectangularFrustumSelector::OnLeftButtonUp ()
append->Update ();
vtkSmartPointer<vtkPolyData> all_points = append->GetOutput ();
qDebug () << "Allpoints = " <<all_points->GetNumberOfPoints ();

selected_mapper->SetInput (all_points);

#if VTK_MAJOR_VERSION < 6
selected_mapper->SetInput (all_points);
#else
selected_mapper->SetInputData (all_points);
#endif
selected_mapper->ScalarVisibilityOff ();

vtkIdTypeArray* ids = vtkIdTypeArray::SafeDownCast (all_points->GetPointData ()->GetArray ("OriginalIds"));
Expand Down
6 changes: 4 additions & 2 deletions apps/modeler/src/normals_actor_item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,11 @@ pcl::modeler::NormalsActorItem::initImpl()
createNormalLines();

vtkSmartPointer<vtkDataSetMapper> mapper = vtkSmartPointer<vtkDataSetMapper>::New();
#if VTK_MAJOR_VERSION < 6
mapper->SetInput(poly_data_);
#else
mapper->SetInputData (poly_data_);
#endif

vtkSmartPointer<vtkDataArray> scalars;
cloud_mesh_->getColorScalarsFromField(scalars, color_scheme_);
Expand Down Expand Up @@ -166,8 +170,6 @@ pcl::modeler::NormalsActorItem::updateImpl()
scalars->GetRange(minmax);
actor_->GetMapper()->SetScalarRange(minmax);

poly_data_->Update();

return;
}

Expand Down
7 changes: 2 additions & 5 deletions apps/modeler/src/points_actor_item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,12 @@ void
pcl::modeler::PointsActorItem::initImpl()
{
poly_data_->SetPoints(cloud_mesh_->getVtkPoints());
poly_data_->Update();

vtkSmartPointer<vtkVertexGlyphFilter> vertex_glyph_filter = vtkSmartPointer<vtkVertexGlyphFilter>::New();
#if VTK_MAJOR_VERSION <= 5
#if VTK_MAJOR_VERSION < 6
vertex_glyph_filter->AddInput(poly_data_);
#else
vertex_glyph_filter->AddInputData(polydata);
vertex_glyph_filter->AddInputData (poly_data_);
#endif
vertex_glyph_filter->Update();

Expand Down Expand Up @@ -109,8 +108,6 @@ pcl::modeler::PointsActorItem::updateImpl()
scalars->GetRange(minmax);
actor_->GetMapper()->SetScalarRange(minmax);

poly_data_->Update();

return;
}

Expand Down
7 changes: 4 additions & 3 deletions apps/modeler/src/surface_actor_item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,13 @@ pcl::modeler::SurfaceActorItem::initImpl()
vtkSmartPointer<vtkDataArray> scalars;
cloud_mesh_->getColorScalarsFromField(scalars, color_scheme_);
poly_data_->GetPointData ()->SetScalars (scalars);
poly_data_->Update();

vtkSmartPointer<vtkDataSetMapper> mapper = vtkSmartPointer<vtkDataSetMapper>::New();
#if VTK_MAJOR_VERSION < 6
mapper->SetInput(poly_data_);
#else
mapper->SetInputData (poly_data_);
#endif

double minmax[2];
scalars->GetRange(minmax);
Expand Down Expand Up @@ -108,8 +111,6 @@ pcl::modeler::SurfaceActorItem::updateImpl()
scalars->GetRange(minmax);
actor_->GetMapper()->SetScalarRange(minmax);

poly_data_->Update();

return;
}

Expand Down
5 changes: 4 additions & 1 deletion apps/src/render_views_tesselated_sphere.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,11 @@ pcl::apps::RenderViewsTesselatedSphere::generateViews() {

vtkSmartPointer<vtkTransformFilter> trans_filter_center = vtkSmartPointer<vtkTransformFilter>::New ();
trans_filter_center->SetTransform (trans_center);
#if VTK_MAJOR_VERSION < 6
trans_filter_center->SetInput (polydata_);
#else
trans_filter_center->SetInputData (polydata_);
#endif
trans_filter_center->Update ();

vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New ();
Expand Down Expand Up @@ -116,7 +120,6 @@ pcl::apps::RenderViewsTesselatedSphere::generateViews() {

// Get camera positions
vtkPolyData *sphere = subdivide->GetOutput ();
sphere->Update ();

std::vector<Eigen::Vector3f> cam_positions;
if (!use_vertices_)
Expand Down
3 changes: 2 additions & 1 deletion io/include/pcl/io/impl/vtk_lib_io.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
#ifdef __GNUC__
#pragma GCC system_header
#endif
#include <vtkVersion.h>
#include <vtkFloatArray.h>
#include <vtkPointData.h>
#include <vtkPoints.h>
Expand Down Expand Up @@ -377,7 +378,7 @@ pcl::io::pointCloudTovtkPolyData (const pcl::PointCloud<PointT>& cloud, vtkPolyD

// Add 0D topology to every point
vtkSmartPointer<vtkVertexGlyphFilter> vertex_glyph_filter = vtkSmartPointer<vtkVertexGlyphFilter>::New ();
#if VTK_MAJOR_VERSION <= 5
#if VTK_MAJOR_VERSION < 6
vertex_glyph_filter->AddInputConnection (temp_polydata->GetProducerPort ());
#else
vertex_glyph_filter->SetInputData (temp_polydata);
Expand Down
1 change: 1 addition & 0 deletions io/include/pcl/io/vtk_lib_io.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
#ifdef __GNUC__
#pragma GCC system_header
#endif
#include <vtkVersion.h>
#include <vtkSmartPointer.h>
#include <vtkStructuredGrid.h>
#include <vtkPoints.h>
Expand Down
22 changes: 21 additions & 1 deletion io/src/vtk_lib_io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#include <pcl/io/vtk_lib_io.h>
#include <pcl/io/impl/vtk_lib_io.hpp>
#include <pcl/PCLPointCloud2.h>
#include <vtkVersion.h>
#include <vtkCellArray.h>
#include <vtkCellData.h>
#include <vtkDoubleArray.h>
Expand Down Expand Up @@ -178,7 +179,11 @@ pcl::io::savePolygonFileVTK (const std::string &file_name, const pcl::PolygonMes
pcl::io::mesh2vtk (mesh, poly_data);

vtkSmartPointer<vtkPolyDataWriter> poly_writer = vtkSmartPointer<vtkPolyDataWriter>::New ();
#if VTK_MAJOR_VERSION < 6
poly_writer->SetInput (poly_data);
#else
poly_writer->SetInputData (poly_data);
#endif
poly_writer->SetFileName (file_name.c_str ());
poly_writer->Write ();

Expand All @@ -194,7 +199,11 @@ pcl::io::savePolygonFilePLY (const std::string &file_name, const pcl::PolygonMes
pcl::io::mesh2vtk (mesh, poly_data);

vtkSmartPointer<vtkPLYWriter> poly_writer = vtkSmartPointer<vtkPLYWriter>::New ();
#if VTK_MAJOR_VERSION < 6
poly_writer->SetInput (poly_data);
#else
poly_writer->SetInputData (poly_data);
#endif
poly_writer->SetFileName (file_name.c_str ());
poly_writer->SetArrayName ("Colors");
poly_writer->Write ();
Expand All @@ -209,9 +218,12 @@ pcl::io::savePolygonFileSTL (const std::string &file_name, const pcl::PolygonMes
vtkSmartPointer<vtkPolyData> poly_data = vtkSmartPointer<vtkPolyData>::New ();

pcl::io::mesh2vtk (mesh, poly_data);
poly_data->Update ();
vtkSmartPointer<vtkSTLWriter> poly_writer = vtkSmartPointer<vtkSTLWriter>::New ();
#if VTK_MAJOR_VERSION < 6
poly_writer->SetInput (poly_data);
#else
poly_writer->SetInputData (poly_data);
#endif
poly_writer->SetFileName (file_name.c_str ());
poly_writer->Write ();

Expand Down Expand Up @@ -483,9 +495,13 @@ pcl::io::saveRangeImagePlanarFilePNG (
{
vtkSmartPointer<vtkImageData> image = vtkSmartPointer<vtkImageData>::New();
image->SetDimensions(range_image.width, range_image.height, 1);
#if VTK_MAJOR_VERSION < 6
image->SetNumberOfScalarComponents(1);
image->SetScalarTypeToFloat();
image->AllocateScalars();
#else
image->AllocateScalars (VTK_FLOAT, 1);
#endif

int* dims = image->GetDimensions();

Expand All @@ -504,7 +520,11 @@ pcl::io::saveRangeImagePlanarFilePNG (

vtkSmartPointer<vtkImageShiftScale> shiftScaleFilter = vtkSmartPointer<vtkImageShiftScale>::New();
shiftScaleFilter->SetOutputScalarTypeToUnsignedChar();
#if VTK_MAJOR_VERSION < 6
shiftScaleFilter->SetInputConnection(image->GetProducerPort());
#else
shiftScaleFilter->SetInputData (image);
#endif
shiftScaleFilter->SetShift(-1.0f * image->GetScalarRange()[0]); // brings the lower bound to 0
shiftScaleFilter->SetScale(newRange/oldRange);
shiftScaleFilter->Update();
Expand Down
11 changes: 10 additions & 1 deletion outofcore/include/pcl/outofcore/visualization/axes.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "object.h"

// VTK
#include <vtkVersion.h>
#include <vtkActor.h>
#include <vtkTubeFilter.h>
#include <vtkAxes.h>
Expand All @@ -31,6 +32,7 @@ class Axes : public Object
axes_ = vtkSmartPointer<vtkAxes>::New ();
axes_->SetOrigin (0, 0, 0);
axes_->SetScaleFactor (size);
axes_->Update ();

vtkSmartPointer<vtkFloatArray> axes_colors = vtkSmartPointer<vtkFloatArray>::New ();
axes_colors->Allocate (6);
Expand All @@ -42,17 +44,24 @@ class Axes : public Object
axes_colors->InsertNextValue (1.0);

vtkSmartPointer<vtkPolyData> axes_data = axes_->GetOutput ();
axes_data->Update ();
axes_data->GetPointData ()->SetScalars (axes_colors);

vtkSmartPointer<vtkTubeFilter> axes_tubes = vtkSmartPointer<vtkTubeFilter>::New ();
#if VTK_MAJOR_VERSION < 6
axes_tubes->SetInput (axes_data);
#else
axes_tubes->SetInputData (axes_data);
#endif
axes_tubes->SetRadius (axes_->GetScaleFactor () / 100.0);
axes_tubes->SetNumberOfSides (6);

vtkSmartPointer<vtkPolyDataMapper> axes_mapper = vtkSmartPointer<vtkPolyDataMapper>::New ();
axes_mapper->SetScalarModeToUsePointData ();
#if VTK_MAJOR_VERSION < 6
axes_mapper->SetInput (axes_tubes->GetOutput ());
#else
axes_mapper->SetInputData (axes_tubes->GetOutput ());
#endif

axes_actor_ = vtkSmartPointer<vtkActor>::New ();
axes_actor_->GetProperty ()->SetLighting (false);
Expand Down
2 changes: 1 addition & 1 deletion outofcore/src/visualization/camera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ Camera::computeFrustum ()
//
// vtkSmartPointer<vtkPolyDataMapper> hull_mapper = static_cast<vtkPolyDataMapper*> (hull_actor_->GetMapper ());
//
//#if VTK_MAJOR_VERSION <= 5
//#if VTK_MAJOR_VERSION < 6
// hull_mapper->SetInput (hullData);
//#else
// hull_mapper->SetInputData(hullData);
Expand Down
3 changes: 2 additions & 1 deletion outofcore/src/visualization/grid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <pcl/outofcore/visualization/grid.h>

// VTK
#include <vtkVersion.h>
#include <vtkActor.h>
#include <vtkRectilinearGrid.h>
#include <vtkDoubleArray.h>
Expand Down Expand Up @@ -36,7 +37,7 @@ Grid::Grid (std::string name, int size/*=10*/, double spacing/*=1.0*/) :
grid_->SetYCoordinates (y_array);
grid_->SetZCoordinates (xz_array);

#if VTK_MAJOR_VERSION <= 5
#if VTK_MAJOR_VERSION < 6
grid_mapper->SetInputConnection (grid_->GetProducerPort ());
#else
grid_mapper->SetInputData(grid_);
Expand Down
9 changes: 9 additions & 0 deletions outofcore/src/visualization/outofcore_cloud.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <pcl/visualization/vtk/vtkVertexBufferObjectMapper.h>

// VTK
#include <vtkVersion.h>
#include <vtkActor.h>
#include <vtkPolyData.h>
#include <vtkProperty.h>
Expand Down Expand Up @@ -159,10 +160,18 @@ OutofcoreCloud::updateVoxelData ()
double y = voxel_centers[i].y;
double z = voxel_centers[i].z;

#if VTK_MAJOR_VERSION < 6
voxel_data->AddInput (getVtkCube (x - s, x + s, y - s, y + s, z - s, z + s));
#else
voxel_data->AddInputData (getVtkCube (x - s, x + s, y - s, y + s, z - s, z + s));
#endif
}

#if VTK_MAJOR_VERSION < 6
voxel_mapper->SetInput (voxel_data->GetOutput ());
#else
voxel_mapper->SetInputData (voxel_data->GetOutput ());
#endif

voxel_actor_->SetMapper (voxel_mapper);
voxel_actor_->GetProperty ()->SetRepresentationToWireframe ();
Expand Down
5 changes: 5 additions & 0 deletions surface/src/vtk_smoothing/vtk_mesh_quadric_decimation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#include <pcl/surface/vtk_smoothing/vtk_mesh_quadric_decimation.h>
#include <pcl/surface/vtk_smoothing/vtk_utils.h>

#include <vtkVersion.h>
#include <vtkQuadricDecimation.h>

//////////////////////////////////////////////////////////////////////////////////////////////
Expand All @@ -59,7 +60,11 @@ pcl::MeshQuadricDecimationVTK::performProcessing (pcl::PolygonMesh &output)
// Apply the VTK algorithm
vtkSmartPointer<vtkQuadricDecimation> vtk_quadric_decimation_filter = vtkSmartPointer<vtkQuadricDecimation>::New();
vtk_quadric_decimation_filter->SetTargetReduction (target_reduction_factor_);
#if VTK_MAJOR_VERSION < 6
vtk_quadric_decimation_filter->SetInput (vtk_polygons_);
#else
vtk_quadric_decimation_filter->SetInputData (vtk_polygons_);
#endif
vtk_quadric_decimation_filter->Update ();

vtk_polygons_ = vtk_quadric_decimation_filter->GetOutput ();
Expand Down
5 changes: 5 additions & 0 deletions surface/src/vtk_smoothing/vtk_mesh_smoothing_laplacian.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#include <pcl/surface/vtk_smoothing/vtk_mesh_smoothing_laplacian.h>
#include <pcl/surface/vtk_smoothing/vtk_utils.h>

#include <vtkVersion.h>
#include <vtkSmoothPolyDataFilter.h>


Expand All @@ -51,7 +52,11 @@ pcl::MeshSmoothingLaplacianVTK::performProcessing (pcl::PolygonMesh &output)

// Apply the VTK algorithm
vtkSmartPointer<vtkSmoothPolyDataFilter> vtk_smoother = vtkSmoothPolyDataFilter::New ();
#if VTK_MAJOR_VERSION < 6
vtk_smoother->SetInput (vtk_polygons_);
#else
vtk_smoother->SetInputData (vtk_polygons_);
#endif
vtk_smoother->SetNumberOfIterations (num_iter_);
if (convergence_ != 0.0f)
vtk_smoother->SetConvergence (convergence_);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#include <pcl/surface/vtk_smoothing/vtk_mesh_smoothing_windowed_sinc.h>
#include <pcl/surface/vtk_smoothing/vtk_utils.h>

#include <vtkVersion.h>
#include <vtkWindowedSincPolyDataFilter.h>


Expand All @@ -51,7 +52,11 @@ pcl::MeshSmoothingWindowedSincVTK::performProcessing (pcl::PolygonMesh &output)

// Apply the VTK algorithm
vtkSmartPointer<vtkWindowedSincPolyDataFilter> vtk_smoother = vtkWindowedSincPolyDataFilter::New ();
#if VTK_MAJOR_VERSION < 6
vtk_smoother->SetInput (vtk_polygons_);
#else
vtk_smoother->SetInputData (vtk_polygons_);
#endif
vtk_smoother->SetNumberOfIterations (num_iter_);
vtk_smoother->SetPassBand (pass_band_);
vtk_smoother->SetNormalizeCoordinates (normalize_coordinates_);
Expand Down
Loading

0 comments on commit 4d1ee47

Please sign in to comment.