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);
96 //Get image spacing, size and mix and max values
97 gridImage->GetSpacing(spc);
98 gridImage->GetDimensions(dims);
102 gridImage->GetScalarRange(minMaxValue);
103 minValue = minMaxValue[0];
104 maxValue = minMaxValue[1];
106 //Grid spacing in voxels
107 spcVoxelX = spcX / spc[0];
108 spcVoxelY = spcY / spc[1];
109 spcVoxelZ = spcZ / spc[2];
111 std::cout << "spcVoxelX:" << spcVoxelX << ", spcVoxelY:" << spcVoxelY << ", spcVoxelZ:" << spcVoxelZ <<std::endl;
112 std::cout << "minValue:" << minValue << ", maxValue:" << maxValue << std::endl;
113 std::cout << "sizeX:" << sizeX << ", sizeY:" << sizeY << ", sizeZ:" << sizeZ <<std::endl;
115 for(int px = 0; px < sizeX; px++)
117 for(int py = 0; py < sizeY; py++)
119 for(int pz = 0; pz < sizeZ; pz++)
121 if(px % spcVoxelX == 0 || py % spcVoxelY == 0 || pz % spcVoxelZ == 0)
123 //std::cout << "In" ;
124 unsigned char* pointer = (unsigned char*) gridImage->GetScalarPointer(px, py, pz);
125 if( (*pointer - minValue) < (maxValue - *pointer) )