]> Creatis software - creaRigidRegistration.git/blob - lib/MyGridOnImageGenerator.cpp
Feature #1766 Add licence terms for all files.
[creaRigidRegistration.git] / lib / MyGridOnImageGenerator.cpp
1 /*
2 # ---------------------------------------------------------------------
3 #
4 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image 
5 #                        pour la Santé)
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
9 #
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.
16 #
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
21 #  liability. 
22 #
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 # ------------------------------------------------------------------------      */                                                                    
26
27 //----------------------------------------------------------------------------
28 // Class definition include
29 //----------------------------------------------------------------------------
30
31 #include "MyGridOnImageGenerator.h"
32
33 //----------------------------------------------------------------------------
34 // Class implementation
35 //----------------------------------------------------------------------------
36 //----------------------------------------------------------------------------
37 // Builder
38 //----------------------------------------------------------------------------
39
40 MyGridOnImageGenerator::MyGridOnImageGenerator( vtkImageData* nImage, double nScpX, double nScpY, double nScpZ)
41 {
42         spcX = nScpX;
43         spcY = nScpY;
44         spcZ = nScpZ;
45         image = nImage;
46 }
47
48 //----------------------------------------------------------------------------
49 // Destructor
50 //----------------------------------------------------------------------------
51
52 MyGridOnImageGenerator::~MyGridOnImageGenerator( )
53 {
54
55 }
56 //----------------------------------------------------------------------------
57 // Methods
58 //----------------------------------------------------------------------------
59
60
61 void MyGridOnImageGenerator::setScpX(double nScpX)
62 {
63         spcX = nScpX;
64 }
65
66 void MyGridOnImageGenerator::setScpY(double nScpY)
67 {
68         spcY = nScpY;
69 }
70
71 void MyGridOnImageGenerator::setScpZ(double nScpZ)
72 {
73         spcZ = nScpZ;
74 }
75
76
77 void MyGridOnImageGenerator::setImage(vtkImageData* nImage)
78 {
79         image = nImage;
80 }
81
82 vtkImageData* MyGridOnImageGenerator::getGridOnImage( )
83 {
84         //Variables
85         double spc[3];
86         int dims[3];
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;
91
92         vtkImageData* gridImage = vtkImageData::New();
93         gridImage->ShallowCopy(image);
94         gridImage->Update();
95
96         //Get image spacing, size and mix and max values
97         gridImage->GetSpacing(spc);
98         gridImage->GetDimensions(dims);
99         sizeX = dims[0];
100         sizeY = dims[1];
101         sizeZ = dims[2];
102         gridImage->GetScalarRange(minMaxValue);
103         minValue = minMaxValue[0];
104         maxValue = minMaxValue[1];
105
106         //Grid spacing in voxels
107         spcVoxelX = spcX / spc[0];
108         spcVoxelY = spcY / spc[1];
109         spcVoxelZ = spcZ / spc[2];
110
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;
114
115         for(int px = 0; px < sizeX; px++)
116         {
117                 for(int py = 0; py < sizeY; py++)
118                 {
119                         for(int pz = 0; pz < sizeZ; pz++)
120                         {
121                                 if(px % spcVoxelX == 0 || py % spcVoxelY == 0 || pz % spcVoxelZ == 0)
122                                 {
123                                         //std::cout << "In" ;
124                                         unsigned char* pointer = (unsigned char*) gridImage->GetScalarPointer(px, py, pz);
125                                         if( (*pointer - minValue) < (maxValue - *pointer) )
126                                                 *pointer = maxValue;
127                                         else
128                                                 *pointer = minValue;
129                                 }
130                         }
131                 }
132         }
133
134
135         return gridImage;
136 }
137