1 /*# ---------------------------------------------------------------------
3 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
5 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
6 # Previous Authors : Laurent Guigues, Jean-Pierre Roux
7 # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
9 # This software is governed by the CeCILL-B license under French law and
10 # abiding by the rules of distribution of free software. You can use,
11 # modify and/ or redistribute the software under the terms of the CeCILL-B
12 # license as circulated by CEA, CNRS and INRIA at the following URL
13 # http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
14 # or in the file LICENSE.txt.
16 # As a counterpart to the access to the source code and rights to copy,
17 # modify and redistribute granted by the license, users are provided only
18 # with a limited warranty and the software's author, the holder of the
19 # economic rights, and the successive licensors have only limited
22 # The fact that you are presently reading this means that you have had
23 # knowledge of the CeCILL-B license and that you accept its terms.
24 # ------------------------------------------------------------------------ */
26 #include "surfacerenderingimagestencilexport.h"
28 #include "vtkMetaImageWriter.h"
33 vtkStandardNewMacro(SurfaceRenderingImageStencilExport)
35 SurfaceRenderingImageStencilExport::SurfaceRenderingImageStencilExport()
40 SurfaceRenderingImageStencilExport::~SurfaceRenderingImageStencilExport()
45 ImageOutput->Delete();
51 //EED 2017-01-01 Migration VTK7
52 #if VTK_MAJOR_VERSION <= 5
54 void SurfaceRenderingImageStencilExport::Update(){
59 // This method is much too long, and has to be broken up!
60 // Furthermore we are loosing the normals !!!
61 void SurfaceRenderingImageStencilExport::Execute(vtkImageData *data){
64 vtkSmartPointer<vtkPolyDataToImageStencil> polytostencil = vtkSmartPointer<vtkPolyDataToImageStencil>::New();
66 vtkPolyData* polydata = (vtkPolyData*)this->GetInput();
67 polytostencil->SetInput(polydata);
68 polytostencil->Update();
70 double *bounds = polydata->GetBounds();
71 vtkSmartPointer<vtkImageData> imagein = vtkSmartPointer<vtkImageData>::New();
73 imagein->SetExtent(bounds[0] - 1, bounds[1] + 1, bounds[2] - 1, bounds[3] + 1, bounds[4] - 1, bounds[5] + 1);
74 imagein->SetScalarTypeToUnsignedShort();
75 imagein->AllocateScalars();
77 int* extent = imagein->GetExtent();
80 for (x = extent[0]; x <= extent[1]; x++){
81 for (y = extent[2]; y <= extent[3]; y++){
82 for (z =extent[4]; z <= extent[5]; z++){
83 unsigned short* pixel = static_cast<unsigned short*>(imagein->GetScalarPointer(x,y,z));
89 vtkSmartPointer<vtkImageStencil> stencil = vtkSmartPointer<vtkImageStencil>::New();
91 stencil->SetInput(imagein);
92 stencil->SetStencil(polytostencil->GetOutput());
94 stencil->ReverseStencilOn();
95 stencil->SetBackgroundValue(128);
100 ImageOutput->Delete();
102 ImageOutput = vtkImageData::New();
103 ImageOutput->DeepCopy(stencil->GetOutput());
109 int SurfaceRenderingImageStencilExport::RequestData( vtkInformation *vtkNotUsed(request), vtkInformationVector **inputVector, vtkInformationVector *outputVector)
112 // get the info objects
113 vtkInformation *inInfo = inputVector[0]->GetInformationObject(0);
114 vtkInformation *outInfo = outputVector->GetInformationObject(0);
116 // get the input and output
117 vtkPolyData *input = vtkPolyData::SafeDownCast( inInfo->Get(vtkDataObject::DATA_OBJECT()));
118 vtkPolyData *output = vtkPolyData::SafeDownCast( outInfo->Get(vtkDataObject::DATA_OBJECT()));
121 vtkSmartPointer<vtkPolyDataToImageStencil> polytostencil = vtkSmartPointer<vtkPolyDataToImageStencil>::New();
123 // vtkPolyData* polydata = (vtkPolyData*)this->GetInput();
124 vtkPolyData* polydata = input;
125 polytostencil->SetInputData(polydata);
126 polytostencil->Update();
128 double *bounds = polydata->GetBounds();
129 vtkSmartPointer<vtkImageData> imagein = vtkSmartPointer<vtkImageData>::New();
131 imagein->SetExtent(bounds[0] - 1, bounds[1] + 1, bounds[2] - 1, bounds[3] + 1, bounds[4] - 1, bounds[5] + 1);
132 imagein->AllocateScalars(VTK_UNSIGNED_SHORT,1);
135 int* extent = imagein->GetExtent();
138 for (x = extent[0]; x <= extent[1]; x++){
139 for (y = extent[2]; y <= extent[3]; y++){
140 for (z =extent[4]; z <= extent[5]; z++){
141 unsigned short* pixel = static_cast<unsigned short*>(imagein->GetScalarPointer(x,y,z));
147 vtkSmartPointer<vtkImageStencil> stencil = vtkSmartPointer<vtkImageStencil>::New();
149 stencil->SetInputData(imagein);
150 stencil->SetStencilData(polytostencil->GetOutput());
152 stencil->ReverseStencilOn();
153 stencil->SetBackgroundValue(128);
158 // ImageOutput->Delete();
160 // ImageOutput = vtkImageData::New();
161 // ImageOutput->DeepCopy(stencil->GetOutput());
163 output->ShallowCopy( stencil->GetOutput() );
178 //-------------------------------------------------------------------------------------------
180 //EED 2017-01-01 Migration VTK7
181 #if VTK_MAJOR_VERSION <= 5
182 vtkImageData* SurfaceRenderingImageStencilExport::GetOutputData()