An update will be applied December 9th, between 12PM and 1:00PM EST (UTC -5:00). The site may be slow during that time.

Commit ea976db9 authored by lassoan's avatar lassoan
Browse files

COMP: Allow building with Qt4/VTK7

Code can still be compiled with VTK7, but then legacy filters are used instead of new, higher-performance filters of VTK9.

git-svn-id: http://svn.slicer.org/Slicer4/trunk@27163 3bd1e089-480b-0410-8dfb-8563597acbee
parent be786f7d
......@@ -36,7 +36,6 @@
#include <vtkActor2D.h>
#include <vtkAlgorithmOutput.h>
#include <vtkCallbackCommand.h>
#include <vtkCompositeDataGeometryFilter.h>
#include <vtkDataSetSurfaceFilter.h>
#include <vtkEventBroker.h>
#include <vtkLookupTable.h>
......@@ -57,7 +56,12 @@
#include <vtkVersion.h>
// VTK includes: customization
#if VTK_MAJOR_VERSION >= 9
#include <vtkCompositeDataGeometryFilter.h>
#include <vtkPlaneCutter.h>
#else
#include <vtkCutter.h>
#endif
#include <vtkSampleImplicitFunctionFilter.h>
// STD includes
......@@ -81,8 +85,12 @@ public:
vtkSmartPointer<vtkDataSetSurfaceFilter> SurfaceExtractor;
vtkSmartPointer<vtkTransformFilter> ModelWarper;
vtkSmartPointer<vtkPlane> Plane;
#if VTK_MAJOR_VERSION >= 9
vtkSmartPointer<vtkPlaneCutter> Cutter;
vtkSmartPointer<vtkCompositeDataGeometryFilter> GeometryFilter; // appends multiple cut pieces into a single polydata
#else
vtkSmartPointer<vtkCutter> Cutter;
#endif
vtkSmartPointer<vtkSampleImplicitFunctionFilter> SliceDistance;
vtkSmartPointer<vtkProp> Actor;
};
......@@ -340,8 +348,12 @@ void vtkMRMLModelSliceDisplayableManager::vtkInternal
// Create pipeline
Pipeline* pipeline = new Pipeline();
pipeline->Actor = actor.GetPointer();
#if VTK_MAJOR_VERSION >= 9
pipeline->Cutter = vtkSmartPointer<vtkPlaneCutter>::New();
pipeline->GeometryFilter = vtkSmartPointer<vtkCompositeDataGeometryFilter>::New();
#else
pipeline->Cutter = vtkSmartPointer<vtkCutter>::New();
#endif
pipeline->SliceDistance = vtkSmartPointer<vtkSampleImplicitFunctionFilter>::New();
pipeline->TransformToSlice = vtkSmartPointer<vtkTransform>::New();
pipeline->NodeToWorld = vtkSmartPointer<vtkGeneralTransform>::New();
......@@ -352,11 +364,18 @@ void vtkMRMLModelSliceDisplayableManager::vtkInternal
// Set up pipeline
pipeline->Transformer->SetTransform(pipeline->TransformToSlice);
#if VTK_MAJOR_VERSION >= 9
pipeline->Transformer->SetInputConnection(pipeline->GeometryFilter->GetOutputPort());
pipeline->Cutter->SetPlane(pipeline->Plane);
pipeline->Cutter->BuildTreeOff(); // the cutter crashes for complex geometries if build tree is enabled
pipeline->Cutter->SetInputConnection(pipeline->ModelWarper->GetOutputPort());
pipeline->GeometryFilter->SetInputConnection(pipeline->Cutter->GetOutputPort());
#else
pipeline->Transformer->SetInputConnection(pipeline->Cutter->GetOutputPort());
pipeline->Cutter->SetCutFunction(pipeline->Plane);
pipeline->Cutter->SetGenerateCutScalars(0);
pipeline->Cutter->SetInputConnection(pipeline->ModelWarper->GetOutputPort());
#endif
// Projection is created from outer surface of volumetric meshes (for polydata surface
// extraction is just shallow-copy)
pipeline->SurfaceExtractor->SetInputConnection(pipeline->ModelWarper->GetOutputPort());
......@@ -478,7 +497,22 @@ void vtkMRMLModelSliceDisplayableManager::vtkInternal
{
// show intersection in the slice view
// include clipper in the pipeline
#if VTK_MAJOR_VERSION >= 9
pipeline->Transformer->SetInputConnection(pipeline->GeometryFilter->GetOutputPort());
#else
pipeline->Transformer->SetInputConnection(pipeline->Cutter->GetOutputPort());
// optimization for slice to slice intersections which are 1 quad polydatas
// no need for 50^3 default locator divisons
if (pointSet->GetPoints() != NULL && pointSet->GetNumberOfPoints() <= 4)
{
vtkNew<vtkPointLocator> locator;
double *bounds = pointSet->GetBounds();
locator->SetDivisions(2, 2, 2);
locator->InitPointInsertion(pointSet->GetPoints(), bounds);
pipeline->Cutter->SetLocator(locator.GetPointer());
}
#endif
pipeline->Cutter->SetInputConnection(pipeline->ModelWarper->GetOutputPort());
// Set Poly Data Transform
......
......@@ -25,7 +25,11 @@
// VTK includes
#include <vtkDecimatePro.h>
#if VTK_MAJOR_VERSION >= 9
#include <vtkDiscreteFlyingEdges3D.h>
#else
#include <vtkDiscreteMarchingCubes.h>
#endif
#include <vtkImageChangeInformation.h>
#include <vtkImageConstantPad.h>
#include <vtkImageThreshold.h>
......@@ -163,13 +167,19 @@ bool vtkBinaryLabelmapToClosedSurfaceConversionRule::Convert(vtkDataObject* sour
double smoothingFactor = vtkVariant(this->ConversionParameters[GetSmoothingFactorParameterName()].first).ToDouble();
int computeSurfaceNormals = vtkVariant(this->ConversionParameters[GetComputeSurfaceNormalsParameterName()].first).ToInt();
// Run marching cubes
#if VTK_MAJOR_VERSION >= 9
// Normals computation in vtkDiscreteFlyingEdges3D is faster than computing normals in a subsequent
// vtkPolyDataNormals filter. However, if smoothing step is applied after vtkDiscreteFlyingEdges3D then
// computing normals after smoothing provides smoother surfaces.
bool marchingCubesComputesSurfaceNormals = (computeSurfaceNormals > 0) && (smoothingFactor <= 0);
// Run marching cubes
vtkSmartPointer<vtkDiscreteFlyingEdges3D> marchingCubes = vtkSmartPointer<vtkDiscreteFlyingEdges3D>::New();
#else
bool marchingCubesComputesSurfaceNormals = false;
vtkSmartPointer<vtkDiscreteMarchingCubes> marchingCubes = vtkSmartPointer<vtkDiscreteMarchingCubes>::New();
#endif
marchingCubes->SetInputData(binaryLabelmapWithIdentityGeometry);
const int labelmapFillValue = binaryLabelmapWithIdentityGeometry->GetScalarRange()[1]; // max value
marchingCubes->GenerateValues(1, labelmapFillValue, labelmapFillValue);
......
......@@ -25,7 +25,11 @@
#include <vtkObjectFactory.h>
#include <vtkPolyData.h>
#include <vtkVersion.h>
#if VTK_MAJOR_VERSION >= 9
#include <vtkFlyingEdges3D.h>
#else
#include <vtkMarchingCubes.h>
#endif
#include <vtkDecimatePro.h>
#include <vtkSmoothPolyDataFilter.h>
#include <vtkTransform.h>
......@@ -173,7 +177,11 @@ bool vtkFractionalLabelmapToClosedSurfaceConversionRule::Convert(vtkDataObject*
imageResize->InterpolateOn();
// Run marching cubes
#if VTK_MAJOR_VERSION >= 9
vtkSmartPointer<vtkFlyingEdges3D> marchingCubes = vtkSmartPointer<vtkFlyingEdges3D>::New();
#else
vtkSmartPointer<vtkMarchingCubes> marchingCubes = vtkSmartPointer<vtkMarchingCubes>::New();
#endif
marchingCubes->SetInputConnection(imageResize->GetOutputPort());
marchingCubes->SetNumberOfContours(1);
marchingCubes->SetValue(0, (fractionalThreshold * (maximumValue - minimumValue)) + minimumValue);
......
......@@ -15,7 +15,11 @@ Version: $Revision$
#include "GrayscaleModelMakerCLP.h"
#include "vtkITKArchetypeImageSeriesScalarReader.h"
#include "vtkImageData.h"
#include "vtkFlyingEdges3D.h"
#if VTK_MAJOR_VERSION >= 9
#include <vtkFlyingEdges3D.h>
#else
#include <vtkMarchingCubes.h>
#endif
#include "vtkWindowedSincPolyDataFilter.h"
#include "vtkTransform.h"
#include "vtkDecimatePro.h"
......@@ -68,7 +72,11 @@ int main(int argc, char * argv[])
vtkImageData * image;
vtkWindowedSincPolyDataFilter * smootherSinc = NULL;
vtkDecimatePro * decimator = NULL;
#if VTK_MAJOR_VERSION >= 9
vtkFlyingEdges3D * mcubes = NULL;
#else
vtkMarchingCubes * mcubes = NULL;
#endif
vtkTransform * transformIJKtoRAS = NULL;
vtkReverseSense * reverser = NULL;
vtkTransformPolyDataFilter * transformer = NULL;
......@@ -139,7 +147,11 @@ int main(int argc, char * argv[])
transformIJKtoRAS->GetMatrix()->Print(std::cout);
}
transformIJKtoRAS->Inverse();
#if VTK_MAJOR_VERSION >= 9
mcubes = vtkFlyingEdges3D::New();
#else
mcubes = vtkMarchingCubes::New();
#endif
vtkPluginFilterWatcher watchMCubes(mcubes,
"Marching Cubes",
CLPProcessInformation,
......
......@@ -32,8 +32,13 @@ Version: $Revision$
// VTK includes
#include <vtkDebugLeaks.h>
#include <vtkDecimatePro.h>
#if VTK_MAJOR_VERSION >= 9
#include <vtkDiscreteFlyingEdges3D.h>
#include <vtkFlyingEdges3D.h>
#else
#include <vtkDiscreteMarchingCubes.h>
#include <vtkMarchingCubes.h>
#endif
#include <vtkGeometryFilter.h>
#include <vtkImageAccumulate.h>
#include <vtkImageChangeInformation.h>
......@@ -272,7 +277,11 @@ int main(int argc, char * argv[])
// vtk and helper variables
vtkSmartPointer<vtkITKArchetypeImageSeriesReader> reader;
vtkImageData * image;
#if VTK_MAJOR_VERSION >= 9
vtkSmartPointer<vtkDiscreteFlyingEdges3D> cubes;
#else
vtkSmartPointer<vtkDiscreteMarchingCubes> cubes;
#endif
vtkSmartPointer<vtkWindowedSincPolyDataFilter> smoother;
bool makeMultiple = false;
bool useStartEnd = false;
......@@ -284,7 +293,12 @@ int main(int argc, char * argv[])
vtkSmartPointer<vtkImageConstantPad> padder;
vtkSmartPointer<vtkDecimatePro> decimator;
#if VTK_MAJOR_VERSION >= 9
vtkSmartPointer<vtkFlyingEdges3D> mcubes;
#else
vtkSmartPointer<vtkMarchingCubes> mcubes;
#endif
vtkSmartPointer<vtkImageThreshold> imageThreshold;
vtkSmartPointer<vtkThreshold> threshold;
vtkSmartPointer<vtkImageToStructuredPoints> imageToStructuredPoints;
......@@ -650,7 +664,12 @@ int main(int argc, char * argv[])
cubes->SetInputData(NULL);
cubes = NULL;
}
#if VTK_MAJOR_VERSION >= 9
cubes = vtkSmartPointer<vtkDiscreteFlyingEdges3D>::New();
#else
cubes = vtkSmartPointer<vtkDiscreteMarchingCubes>::New();
#endif
std::string comment1 = "Discrete Marching Cubes";
vtkPluginFilterWatcher watchDMCubes(cubes,
comment1.c_str(),
......@@ -1087,7 +1106,11 @@ int main(int argc, char * argv[])
mcubes->SetInputData(NULL);
mcubes = NULL;
}
#if VTK_MAJOR_VERSION >= 9
mcubes = vtkSmartPointer<vtkFlyingEdges3D>::New();
#else
mcubes = vtkSmartPointer<vtkMarchingCubes>::New();
#endif
std::string comment5 = "Marching Cubes " + labelName;
vtkPluginFilterWatcher watchThreshold(mcubes,
comment5.c_str(),
......
......@@ -280,12 +280,17 @@ If segments overlap, segment higher in the segments table will have priority. <b
ici.SetOutputOrigin(0, 0, 0)
# Convert labelmap to combined polydata
if vtk.VTK_MAJOR_VERSION >= 9:
convertToPolyData = vtk.vtkDiscreteFlyingEdges3D()
convertToPolyData.SetInputConnection(ici.GetOutputPort())
convertToPolyData.SetNumberOfContours(len(segmentLabelValues))
convertToPolyData.ComputeGradientsOff()
convertToPolyData.ComputeNormalsOff()
convertToPolyData.ComputeScalarsOff()
else:
convertToPolyData = vtk.vtkDiscreteMarchingCubes()
convertToPolyData.SetInputConnection(ici.GetOutputPort())
convertToPolyData.SetNumberOfContours(len(segmentLabelValues))
contourIndex = 0
for segmentId, labelValue in segmentLabelValues:
convertToPolyData.SetValue(contourIndex, labelValue)
......
......@@ -37,7 +37,12 @@
#include "vtkOrientedImageDataResample.h"
// VTK includes
#if VTK_MAJOR_VERSION >= 9
#include <vtkCompositeDataGeometryFilter.h>
#include <vtkPlaneCutter.h>
#else
#include <vtkCutter.h>
#endif
#include <vtkNew.h>
#include <vtkObjectFactory.h>
#include <vtkSmartPointer.h>
......@@ -55,7 +60,6 @@
#include <vtkGeneralTransform.h>
#include <vtkPointData.h>
#include <vtkDataSetAttributes.h>
#include <vtkPlaneCutter.h>
#include <vtkImageReslice.h>
#include <vtkImageMapper.h>
#include <vtkImageMapToRGBA.h>
......@@ -140,7 +144,11 @@ public:
// Create poly data pipeline
this->PolyDataOutlineActor = vtkSmartPointer<vtkActor2D>::New();
this->PolyDataFillActor = vtkSmartPointer<vtkActor2D>::New();
#if VTK_MAJOR_VERSION >= 9
this->Cutter = vtkSmartPointer<vtkPlaneCutter>::New();
#else
this->Cutter = vtkSmartPointer<vtkCutter>::New();
#endif
this->ModelWarper = vtkSmartPointer<vtkTransformPolyDataFilter>::New();
this->Plane = vtkSmartPointer<vtkPlane>::New();
this->Stripper = vtkSmartPointer<vtkStripper>::New();
......@@ -148,6 +156,7 @@ public:
this->TriangleFilter = vtkSmartPointer<vtkTriangleFilter>::New();
// Set up poly data outline pipeline
#if VTK_MAJOR_VERSION >= 9
this->Cutter->SetInputConnection(this->ModelWarper->GetOutputPort());
this->Cutter->SetPlane(this->Plane);
this->Cutter->BuildTreeOff(); // the cutter crashes for complex geometries if build tree is enabled
......@@ -155,6 +164,12 @@ public:
vtkNew<vtkCompositeDataGeometryFilter> geometryFilter; // merge multi-piece output of vtkPlaneCutter
geometryFilter->SetInputConnection(this->Cutter->GetOutputPort());
polyDataOutlineTransformer->SetInputConnection(geometryFilter->GetOutputPort());
#else
this->Cutter->SetCutFunction(this->Plane);
this->Cutter->SetGenerateCutScalars(0);
vtkSmartPointer<vtkTransformPolyDataFilter> polyDataOutlineTransformer = vtkSmartPointer<vtkTransformPolyDataFilter>::New();
polyDataOutlineTransformer->SetInputConnection(this->Cutter->GetOutputPort());
#endif
polyDataOutlineTransformer->SetTransform(this->WorldToSliceTransform);
vtkSmartPointer<vtkPolyDataMapper2D> polyDataOutlineMapper = vtkSmartPointer<vtkPolyDataMapper2D>::New();
polyDataOutlineMapper->SetInputConnection(polyDataOutlineTransformer->GetOutputPort());
......@@ -162,10 +177,14 @@ public:
this->PolyDataOutlineActor->SetVisibility(0);
// Set up poly data fill pipeline
#if VTK_MAJOR_VERSION >= 9
vtkNew<vtkCleanPolyData> pointMerger;
pointMerger->PointMergingOn();
pointMerger->SetInputConnection(geometryFilter->GetOutputPort());
this->Stripper->SetInputConnection(pointMerger->GetOutputPort());
#else
this->Stripper->SetInputConnection(this->Cutter->GetOutputPort());
#endif
this->Cleaner->SetInputConnection(NULL); // This will be modified in the UpdateDisplayNodePipeline function
this->TriangleFilter->SetInputConnection(this->Cleaner->GetOutputPort());
vtkSmartPointer<vtkTransformPolyDataFilter> polyDataFillTransformer = vtkSmartPointer<vtkTransformPolyDataFilter>::New();
......@@ -246,7 +265,11 @@ public:
vtkSmartPointer<vtkActor2D> PolyDataFillActor;
vtkSmartPointer<vtkTransformPolyDataFilter> ModelWarper;
vtkSmartPointer<vtkPlane> Plane;
#if VTK_MAJOR_VERSION >= 9
vtkSmartPointer<vtkPlaneCutter> Cutter;
#else
vtkSmartPointer<vtkCutter> Cutter;
#endif
vtkSmartPointer<vtkStripper> Stripper;
vtkSmartPointer<vtkCleanPolyData> Cleaner;
vtkSmartPointer<vtkTriangleFilter> TriangleFilter;
......
......@@ -545,7 +545,7 @@ void vtkMRMLVolumeRenderingDisplayableManager::vtkInternal::UpdatePipelineROIs(
}
vtkNew<vtkPlanes> planes;
displayNode->GetROINode()->GetTransformedPlanes(planes);
displayNode->GetROINode()->GetTransformedPlanes(planes.GetPointer());
//TODO: Workaround for bug that broke cropping: normals were inverted, need to invert them
// (the reason is not the use of SetUserMatrix instead of PokeMatrix when setting the transform to the mapper)
vtkDoubleArray* normals = vtkDoubleArray::SafeDownCast(planes->GetNormals());
......@@ -553,7 +553,7 @@ void vtkMRMLVolumeRenderingDisplayableManager::vtkInternal::UpdatePipelineROIs(
{
normals->SetValue(i, (-1.0)*normals->GetValue(i));
}
volumeMapper->SetClippingPlanes(planes);
volumeMapper->SetClippingPlanes(planes.GetPointer());
}
//---------------------------------------------------------------------------
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment