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 "vtkObjectFactory.h"
29 #include "vtkMetaImageWriter.h"
33 vtkStandardNewMacro(SurfaceRenderingImageStencilExport)
35 SurfaceRenderingImageStencilExport::SurfaceRenderingImageStencilExport()
40 SurfaceRenderingImageStencilExport::~SurfaceRenderingImageStencilExport(){
43 ImageOutput->Delete();
47 void SurfaceRenderingImageStencilExport::Update(){
51 void SurfaceRenderingImageStencilExport::Execute(vtkImageData *data){
53 vtkPolyData* polydata = (vtkPolyData*)this->GetInput();
55 vtkSmartPointer<vtkPolyDataToImageStencil> polytostencil = vtkSmartPointer<vtkPolyDataToImageStencil>::New();
56 polytostencil->SetInput(polydata);
57 polytostencil->Update();
59 double *bounds = polydata->GetBounds();
60 vtkSmartPointer<vtkImageData> imagein = vtkSmartPointer<vtkImageData>::New();
62 imagein->SetExtent(bounds[0] - 1, bounds[1] + 1, bounds[2] - 1, bounds[3] + 1, bounds[4] - 1, bounds[5] + 1);
63 imagein->SetScalarTypeToUnsignedShort();
64 imagein->AllocateScalars();
67 int* extent = imagein->GetExtent();
69 for (int x = extent[0]; x <= extent[1]; x++){
70 for (int y = extent[2]; y <= extent[3]; y++){
71 for (int z =extent[4]; z <= extent[5]; z++){
72 unsigned short* pixel = static_cast<unsigned short*>(imagein->GetScalarPointer(x,y,z));
78 vtkSmartPointer<vtkImageStencil> stencil = vtkSmartPointer<vtkImageStencil>::New();
79 stencil->SetInput(imagein);
80 stencil->SetStencil(polytostencil->GetOutput());
81 stencil->ReverseStencilOn();
82 stencil->SetBackgroundValue(128);
86 ImageOutput->Delete();
88 ImageOutput = vtkImageData::New();
89 ImageOutput->DeepCopy(stencil->GetOutput());
93 vtkImageData* SurfaceRenderingImageStencilExport::GetOutput(){