2 # ---------------------------------------------------------------------
4 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
6 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
7 # Previous Authors : Laurent Guigues, Jean-Pierre Roux
8 # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
10 # This software is governed by the CeCILL-B license under French law and
11 # abiding by the rules of distribution of free software. You can use,
12 # modify and/ or redistribute the software under the terms of the CeCILL-B
13 # license as circulated by CEA, CNRS and INRIA at the following URL
14 # http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
15 # or in the file LICENSE.txt.
17 # As a counterpart to the access to the source code and rights to copy,
18 # modify and redistribute granted by the license, users are provided only
19 # with a limited warranty and the software's author, the holder of the
20 # economic rights, and the successive licensors have only limited
23 # The fact that you are presently reading this means that you have had
24 # knowledge of the CeCILL-B license and that you accept its terms.
25 # ------------------------------------------------------------------------ */
27 //----------------------------------------------------------------------------
28 // Class definition include
29 //----------------------------------------------------------------------------
31 #include "MyGridOnImageGenerator.h"
33 //----------------------------------------------------------------------------
34 // Class implementation
35 //----------------------------------------------------------------------------
36 //----------------------------------------------------------------------------
38 //----------------------------------------------------------------------------
40 MyGridOnImageGenerator::MyGridOnImageGenerator( vtkImageData* nImage, double nScpX, double nScpY, double nScpZ)
48 //----------------------------------------------------------------------------
50 //----------------------------------------------------------------------------
52 MyGridOnImageGenerator::~MyGridOnImageGenerator( )
56 //----------------------------------------------------------------------------
58 //----------------------------------------------------------------------------
61 void MyGridOnImageGenerator::setScpX(double nScpX)
66 void MyGridOnImageGenerator::setScpY(double nScpY)
71 void MyGridOnImageGenerator::setScpZ(double nScpZ)
77 void MyGridOnImageGenerator::setImage(vtkImageData* nImage)
82 vtkImageData* MyGridOnImageGenerator::getGridOnImage( )
87 int sizeX = 0, sizeY = 0, sizeZ = 0;
88 double minMaxValue[2];
89 double minValue = 0, maxValue = 0;
90 int spcVoxelX = 0, spcVoxelY = 0, spcVoxelZ = 0;
92 vtkImageData* gridImage = vtkImageData::New();
93 gridImage->ShallowCopy(image);
94 //EED 2017-01-01 Migration VTK7
95 #if VTK_MAJOR_VERSION <= 5
98 gridImage->Modified();
101 //Get image spacing, size and mix and max values
102 gridImage->GetSpacing(spc);
103 gridImage->GetDimensions(dims);
107 gridImage->GetScalarRange(minMaxValue);
108 minValue = minMaxValue[0];
109 maxValue = minMaxValue[1];
111 //Grid spacing in voxels
112 spcVoxelX = spcX / spc[0];
113 spcVoxelY = spcY / spc[1];
114 spcVoxelZ = spcZ / spc[2];
116 std::cout << "spcVoxelX:" << spcVoxelX << ", spcVoxelY:" << spcVoxelY << ", spcVoxelZ:" << spcVoxelZ <<std::endl;
117 std::cout << "minValue:" << minValue << ", maxValue:" << maxValue << std::endl;
118 std::cout << "sizeX:" << sizeX << ", sizeY:" << sizeY << ", sizeZ:" << sizeZ <<std::endl;
120 for(int px = 0; px < sizeX; px++)
122 for(int py = 0; py < sizeY; py++)
124 for(int pz = 0; pz < sizeZ; pz++)
126 if(px % spcVoxelX == 0 || py % spcVoxelY == 0 || pz % spcVoxelZ == 0)
128 //std::cout << "In" ;
129 unsigned char* pointer = (unsigned char*) gridImage->GetScalarPointer(px, py, pz);
130 if( (*pointer - minValue) < (maxValue - *pointer) )