]> Creatis software - creaMaracasVisu.git/blobdiff - lib/Kernel/VTKObjects/SurfaceRenderer/surfacerenderingimagestencilexport.cxx
#3109 creaMaracasVisu Bug New Normal - branch vtk7itk4 compilation with vtk7
[creaMaracasVisu.git] / lib / Kernel / VTKObjects / SurfaceRenderer / surfacerenderingimagestencilexport.cxx
index 15d7bdb1cdbdda2840ffc356199232dcac428456..00424743978b101a25e85048f1b480c785268a42 100644 (file)
 
 #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<vtkPolyDataToImageStencil> polytostencil = vtkSmartPointer<vtkPolyDataToImageStencil>::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<vtkPolyDataToImageStencil> polytostencil = vtkSmartPointer<vtkPolyDataToImageStencil>::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<vtkImageData> imagein = vtkSmartPointer<vtkImageData>::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<unsigned short*>(imagein->GetScalarPointer(x,y,z));
                 *pixel = 0;
-            }
-        }
-    }
+            }  // for x
+        } // for y 
+    } // for z
 
     vtkSmartPointer<vtkImageStencil> stencil = vtkSmartPointer<vtkImageStencil>::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<vtkPolyDataToImageStencil> polytostencil = vtkSmartPointer<vtkPolyDataToImageStencil>::New();
+
+//    vtkPolyData* polydata = (vtkPolyData*)this->GetInput();
+    vtkPolyData* polydata = input;
+    polytostencil->SetInputData(polydata);
+    polytostencil->Update();
+
+    double *bounds = polydata->GetBounds();
+    vtkSmartPointer<vtkImageData> imagein = vtkSmartPointer<vtkImageData>::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<unsigned short*>(imagein->GetScalarPointer(x,y,z));
+                *pixel = 0;
+            } // for z
+        }  // for y
+    }  // for z
+
+    vtkSmartPointer<vtkImageStencil> stencil = vtkSmartPointer<vtkImageStencil>::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;
 }