From 94a6229aed777e2270a361e3d1721a14daa50d25 Mon Sep 17 00:00:00 2001 From: Eduardo DAVILA Date: Thu, 3 Aug 2017 16:04:05 +0200 Subject: [PATCH] #3109 creaMaracasVisu Bug New Normal - branch vtk7itk4 compilation with vtk7 --- .../surfacerenderingimagestencilexport.cxx | 125 +++++++++++++----- .../surfacerenderingimagestencilexport.h | 30 ++++- .../wxWindows/widgets/vtkClosePolyData.cxx | 3 - .../wxWindows/widgets/vtkClosePolyData.h | 9 +- 4 files changed, 122 insertions(+), 45 deletions(-) diff --git a/lib/Kernel/VTKObjects/SurfaceRenderer/surfacerenderingimagestencilexport.cxx b/lib/Kernel/VTKObjects/SurfaceRenderer/surfacerenderingimagestencilexport.cxx index 15d7bdb..0042474 100644 --- a/lib/Kernel/VTKObjects/SurfaceRenderer/surfacerenderingimagestencilexport.cxx +++ b/lib/Kernel/VTKObjects/SurfaceRenderer/surfacerenderingimagestencilexport.cxx @@ -25,11 +25,11 @@ #include "surfacerenderingimagestencilexport.h" -#include "vtkObjectFactory.h" #include "vtkMetaImageWriter.h" #include "math.h" + vtkStandardNewMacro(SurfaceRenderingImageStencilExport) SurfaceRenderingImageStencilExport::SurfaceRenderingImageStencilExport() @@ -37,78 +37,143 @@ SurfaceRenderingImageStencilExport::SurfaceRenderingImageStencilExport() ImageOutput = 0; } -SurfaceRenderingImageStencilExport::~SurfaceRenderingImageStencilExport(){ +SurfaceRenderingImageStencilExport::~SurfaceRenderingImageStencilExport() +{ - if(ImageOutput){ + if(ImageOutput) + { ImageOutput->Delete(); } } -void SurfaceRenderingImageStencilExport::Update(){ - this->Execute(0); -} -void SurfaceRenderingImageStencilExport::Execute(vtkImageData *data){ - - vtkSmartPointer polytostencil = vtkSmartPointer::New(); //EED 2017-01-01 Migration VTK7 #if VTK_MAJOR_VERSION <= 5 + + void SurfaceRenderingImageStencilExport::Update(){ + this->Execute(0); + } + + + // This method is much too long, and has to be broken up! + // Furthermore we are loosing the normals !!! + void SurfaceRenderingImageStencilExport::Execute(vtkImageData *data){ + { + + vtkSmartPointer polytostencil = vtkSmartPointer::New(); + vtkPolyData* polydata = (vtkPolyData*)this->GetInput(); polytostencil->SetInput(polydata); -#else - vtkPolyData* polydata = (vtkPolyData*)this->GetInput(); - polytostencil->SetInputData(polydata); -#endif polytostencil->Update(); double *bounds = polydata->GetBounds(); vtkSmartPointer imagein = vtkSmartPointer::New(); imagein->SetExtent(bounds[0] - 1, bounds[1] + 1, bounds[2] - 1, bounds[3] + 1, bounds[4] - 1, bounds[5] + 1); -//EED 2017-01-01 Migration VTK7 -#if VTK_MAJOR_VERSION <= 5 imagein->SetScalarTypeToUnsignedShort(); imagein->AllocateScalars(); -#else - imagein->AllocateScalars(VTK_UNSIGNED_SHORT,1); -#endif - int* extent = imagein->GetExtent(); - for (int x = extent[0]; x <= extent[1]; x++){ - for (int y = extent[2]; y <= extent[3]; y++){ - for (int z =extent[4]; z <= extent[5]; z++){ + int x, y, z; + for (x = extent[0]; x <= extent[1]; x++){ + for (y = extent[2]; y <= extent[3]; y++){ + for (z =extent[4]; z <= extent[5]; z++){ unsigned short* pixel = static_cast(imagein->GetScalarPointer(x,y,z)); *pixel = 0; - } - } - } + } // for x + } // for y + } // for z vtkSmartPointer stencil = vtkSmartPointer::New(); -//EED 2017-01-01 Migration VTK7 -#if VTK_MAJOR_VERSION <= 5 stencil->SetInput(imagein); stencil->SetStencil(polytostencil->GetOutput()); + + stencil->ReverseStencilOn(); + stencil->SetBackgroundValue(128); + stencil->Update(); + + if(ImageOutput) + { + ImageOutput->Delete(); + } + ImageOutput = vtkImageData::New(); + ImageOutput->DeepCopy(stencil->GetOutput()); + + } + #else + +int SurfaceRenderingImageStencilExport::RequestData( vtkInformation *vtkNotUsed(request), vtkInformationVector **inputVector, vtkInformationVector *outputVector) +{ + + // get the info objects + vtkInformation *inInfo = inputVector[0]->GetInformationObject(0); + vtkInformation *outInfo = outputVector->GetInformationObject(0); + + // get the input and output + vtkPolyData *input = vtkPolyData::SafeDownCast( inInfo->Get(vtkDataObject::DATA_OBJECT())); + vtkPolyData *output = vtkPolyData::SafeDownCast( outInfo->Get(vtkDataObject::DATA_OBJECT())); + + + vtkSmartPointer polytostencil = vtkSmartPointer::New(); + +// vtkPolyData* polydata = (vtkPolyData*)this->GetInput(); + vtkPolyData* polydata = input; + polytostencil->SetInputData(polydata); + polytostencil->Update(); + + double *bounds = polydata->GetBounds(); + vtkSmartPointer imagein = vtkSmartPointer::New(); + + imagein->SetExtent(bounds[0] - 1, bounds[1] + 1, bounds[2] - 1, bounds[3] + 1, bounds[4] - 1, bounds[5] + 1); + imagein->AllocateScalars(VTK_UNSIGNED_SHORT,1); + + + int* extent = imagein->GetExtent(); + + int x,y,z; + for (x = extent[0]; x <= extent[1]; x++){ + for (y = extent[2]; y <= extent[3]; y++){ + for (z =extent[4]; z <= extent[5]; z++){ + unsigned short* pixel = static_cast(imagein->GetScalarPointer(x,y,z)); + *pixel = 0; + } // for z + } // for y + } // for z + + vtkSmartPointer stencil = vtkSmartPointer::New(); + stencil->SetInputData(imagein); stencil->SetStencilData(polytostencil->GetOutput()); -#endif stencil->ReverseStencilOn(); stencil->SetBackgroundValue(128); stencil->Update(); - if(ImageOutput){ + if(ImageOutput) + { ImageOutput->Delete(); } ImageOutput = vtkImageData::New(); ImageOutput->DeepCopy(stencil->GetOutput()); + return 1; } -vtkImageData* SurfaceRenderingImageStencilExport::GetOutput(){ +#endif + + + + + + + +//------------------------------------------------------------------------------------------- + +vtkImageData* SurfaceRenderingImageStencilExport::GetOutputData() +{ return ImageOutput; } diff --git a/lib/Kernel/VTKObjects/SurfaceRenderer/surfacerenderingimagestencilexport.h b/lib/Kernel/VTKObjects/SurfaceRenderer/surfacerenderingimagestencilexport.h index 86d4f7d..5548f52 100644 --- a/lib/Kernel/VTKObjects/SurfaceRenderer/surfacerenderingimagestencilexport.h +++ b/lib/Kernel/VTKObjects/SurfaceRenderer/surfacerenderingimagestencilexport.h @@ -26,32 +26,54 @@ #ifndef SURFACERENDERINGIMAGESTENCILEXPORT_H #define SURFACERENDERINGIMAGESTENCILEXPORT_H +#include "vtkObjectFactory.h" -#include //EED 2017-01-01 Migration VTK7 #if VTK_MAJOR_VERSION <= 5 #include #else - // .. + #include "vtkPolyDataAlgorithm.h" + #include "vtkDataObject.h" + #include "vtkInformation.h" + #include "vtkDemandDrivenPipeline.h" + #include "vtkInformationVector.h" #endif #include #include #include +#include #include +//EED 2017-01-01 Migration VTK7 +#if VTK_MAJOR_VERSION <= 5 class SurfaceRenderingImageStencilExport : public vtkDataSetToImageFilter +#else +class SurfaceRenderingImageStencilExport : public vtkPolyDataAlgorithm +#endif { public: static SurfaceRenderingImageStencilExport *New(); - vtkTypeMacro(SurfaceRenderingImageStencilExport,vtkDataSetToImageFilter) + vtkTypeMacro(SurfaceRenderingImageStencilExport,vtkPolyDataAlgorithm) +#if VTK_MAJOR_VERSION <= 5 virtual void Update(); - vtkImageData* GetOutput(); +#else + // .. +#endif + + + virtual vtkImageData* GetOutputData(); protected: +//EED 2017-01-01 Migration VTK7 +#if VTK_MAJOR_VERSION <= 5 + // Usual data generation method virtual void Execute(vtkImageData *data); +#else + virtual int RequestData( vtkInformation *vtkNotUsed(request), vtkInformationVector **inputVector, vtkInformationVector *outputVector); +#endif private: diff --git a/lib/maracasVisuLib/src/interface/wxWindows/widgets/vtkClosePolyData.cxx b/lib/maracasVisuLib/src/interface/wxWindows/widgets/vtkClosePolyData.cxx index 1ed82f0..bb24468 100644 --- a/lib/maracasVisuLib/src/interface/wxWindows/widgets/vtkClosePolyData.cxx +++ b/lib/maracasVisuLib/src/interface/wxWindows/widgets/vtkClosePolyData.cxx @@ -197,9 +197,6 @@ int vtkClosePolyData::RequestData( vtkInformation *vtkNotUsed(request), vtkInf return 1; } - - - #endif //---------------------------------------------------------------------------- diff --git a/lib/maracasVisuLib/src/interface/wxWindows/widgets/vtkClosePolyData.h b/lib/maracasVisuLib/src/interface/wxWindows/widgets/vtkClosePolyData.h index a11f8b8..37f8cde 100644 --- a/lib/maracasVisuLib/src/interface/wxWindows/widgets/vtkClosePolyData.h +++ b/lib/maracasVisuLib/src/interface/wxWindows/widgets/vtkClosePolyData.h @@ -93,14 +93,7 @@ protected: // Usual data generation method void Execute(); #else -/* - int ProcessRequest( vtkInformation *request, - vtkInformationVector **inputVector, - vtkInformationVector *outputVector); -*/ -int RequestData( vtkInformation *vtkNotUsed(request), vtkInformationVector **inputVector, vtkInformationVector *outputVector); - - + int RequestData( vtkInformation *vtkNotUsed(request), vtkInformationVector **inputVector, vtkInformationVector *outputVector); #endif -- 2.47.1