]> Creatis software - creaMaracasVisu.git/blob - bbtk/src/bbmaracasvisuAxeVolume.cxx
#2982 creaMaracasVisu Feature New Normal - ShowNPoints_model
[creaMaracasVisu.git] / bbtk / src / bbmaracasvisuAxeVolume.cxx
1 /*# ---------------------------------------------------------------------
2 #
3 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
4 #                        pour la Sant�)
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
8 #
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.
15 #
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
20 #  liability.
21 #
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 # ------------------------------------------------------------------------ */
25
26 #include "bbmaracasvisuAxeVolume.h"
27 #include "bbcreaMaracasVisuPackage.h"
28
29 namespace bbcreaMaracasVisu
30 {
31
32
33 BBTK_ADD_BLACK_BOX_TO_PACKAGE(creaMaracasVisu,AxeVolume)
34 BBTK_BLACK_BOX_IMPLEMENTATION(AxeVolume,bbtk::AtomicBlackBox);
35
36 int AxeVolume::GetTypeFormat( std::string formatStr , vtkImageData* image )
37 {
38         int outputformat = VTK_UNSIGNED_CHAR;
39         if (formatStr=="SAME")
40         {                                               
41                 if (image!=NULL) outputformat = image->GetScalarType();
42         }
43         else if (formatStr=="VTK_BIT")                          outputformat = VTK_BIT;                         // 1
44         else if (formatStr=="VTK_CHAR")                         outputformat = VTK_CHAR;                        // 2
45         else if (formatStr=="VTK_SIGNED_CHAR")          outputformat = VTK_SIGNED_CHAR;         // 15
46         else if (formatStr=="VTK_UNSIGNED_CHAR")        outputformat = VTK_UNSIGNED_CHAR;       // 3
47         else if (formatStr=="VTK_SHORT")                        outputformat = VTK_SHORT;                       // 4
48         else if (formatStr=="VTK_UNSIGNED_SHORT")       outputformat = VTK_UNSIGNED_SHORT;      // 5
49         else if (formatStr=="VTK_INT")                          outputformat = VTK_INT;                 // 6
50         else if (formatStr=="VTK_UNSIGNED_INT")         outputformat = VTK_UNSIGNED_INT;        // 7
51         else if (formatStr=="VTK_LONG")                         outputformat = VTK_LONG;                // 8  
52         else if (formatStr=="VTK_UNSIGNED_LONG")        outputformat = VTK_UNSIGNED_LONG;       // 9
53         else if (formatStr=="VTK_FLOAT")                        outputformat = VTK_FLOAT;               // 10
54         else if (formatStr=="VTK_DOUBLE")                       outputformat = VTK_DOUBLE;              // 11 
55         else if (formatStr=="MET_CHAR")                         outputformat = VTK_CHAR;                        // 2
56         else if (formatStr=="MET_UCHAR")                        outputformat = VTK_UNSIGNED_CHAR;       // 3
57         else if (formatStr=="MET_SHORT")                        outputformat = VTK_SHORT;                       // 4
58         else if (formatStr=="MET_USHORT")                       outputformat = VTK_UNSIGNED_SHORT;      // 5
59         else if (formatStr=="MET_SHORT")                        outputformat = VTK_SHORT;               // 4
60         else if (formatStr=="MET_FLOAT")                        outputformat = VTK_FLOAT;               // 10
61         else if (formatStr=="MET_DOUBLE")                       outputformat = VTK_DOUBLE;              // 11  
62
63     return outputformat;
64 }
65
66
67 void AxeVolume::Process()
68 {
69         if ( mimage!=NULL )
70         {
71                 mimage->Delete();
72         }
73
74         int ext[6];
75         bbGetInputIn()->GetExtent(ext);
76         int sizeX=ext[1]-ext[0]+1;
77         int sizeY=ext[3]-ext[2]+1;
78         int sizeZ=ext[5]-ext[4]+1;
79
80     double spc[3];
81         bbGetInputIn()->GetSpacing(spc);
82     double invSpc[3];
83     invSpc[0] = 1/spc[0];
84     invSpc[1] = 1/spc[1];
85     invSpc[2] = 1/spc[2];
86
87         int outputformat = GetTypeFormat( bbGetInputOutputFormat() , bbGetInputIn() );
88
89         mimage = vtkImageData::New();
90         mimage->SetSpacing(bbGetInputIn()->GetSpacing());
91         mimage->SetDimensions(bbGetInputIn()->GetDimensions());
92         mimage->SetExtent(bbGetInputIn()->GetExtent());
93         mimage->SetOrigin(bbGetInputIn()->GetOrigin());
94         mimage->SetScalarType( outputformat );
95         mimage->AllocateScalars();
96         int i,j,k;
97     int sizeLstPointR   = bbGetInputlstPointR().size();
98         int iAxe,sizeAxe        = bbGetInputlstPointX().size();
99         double rx,ry,rz;
100         double r,rr;
101         unsigned short *p;
102         int sizeImage           = sizeX*sizeY*sizeZ;
103         double px,py,pz;
104         double px1,py1,pz1;
105         double px2,py2,pz2;
106         // Clean image
107         p = (unsigned short*)mimage->GetScalarPointer (0, 0, 0);
108         for ( i=0 ; i<sizeImage ; i++)
109         {
110                 *p = 0;
111                 p++;
112         }
113
114         for (iAxe=0 ; iAxe<sizeAxe; iAxe++)
115          {
116 printf("AxeVolume %d/%d\n ",iAxe,sizeAxe);
117                 if (iAxe<sizeLstPointR)
118                 {
119                         r = bbGetInputlstPointR()[ iAxe ]* invSpc[0];
120                 } else {
121                         if (bbGetInputlstPointR().size()>=1)
122                         {
123                                 r = bbGetInputlstPointR()[ bbGetInputlstPointR().size()-1 ]    * invSpc[0];
124                         } else {
125                                 r = 1;
126                         }
127                 }
128                 px = bbGetInputlstPointX()[iAxe] * invSpc[0];
129                 py = bbGetInputlstPointY()[iAxe] * invSpc[1];
130                 pz = bbGetInputlstPointZ()[iAxe] * invSpc[2];
131                 px1 = px - r;
132                 py1 = py - r;
133                 pz1 = pz - r;
134                 px2 = px + r;
135                 py2 = py + r;
136                 pz2 = pz + r;
137                 rr=r*r;
138
139                 for ( i=px1 ; i<=px2 ; i++ )
140                 {
141                         rx      =       i - px;
142                         rx      =       rx*rx;
143                         for ( j=py1 ; j<py2 ; j++ )
144                         {
145                                 ry      =       j - py;
146                                 ry      =       ry*ry;
147                                 for ( k=pz1 ; k<pz2 ; k++ )
148                                 {
149                                         if ( (i>=0) && (i<sizeX) && (j>=0) && (j<sizeY) &&(k>=0) && (k<sizeZ) )
150                                         {
151 //                                              p = (unsigned short*)mimage->GetScalarPointer (i, j, k);
152 //                                              if (*p==0)
153                                                 if ( mimage->GetScalarComponentAsDouble(i,j,k,0)==0 )
154                                                 {
155                                                         rz      =       k - pz;
156                                                         rz      =       rz*rz;
157                                                         if ( rx + ry + rz <= rr )
158                                                         {
159 //                                                              *p=255;
160                                                                 mimage->SetScalarComponentFromDouble (i,j,k,0, bbGetInputValue() );
161                                                         }
162                                                 } // *p==0
163                                         } // if inside point
164                                 } //for k
165                         } //for j
166                 } //for i
167         } // for iAxe
168     bbSetOutputOut( mimage );
169 }
170
171
172         //-----------------------------------------------------------------
173         void AxeVolume::bbUserSetDefaultValues()
174         {
175                 mimage=NULL;
176                 bbSetInputOutputFormat("SAME");
177                 bbSetInputValue(255);
178         }
179
180         //-----------------------------------------------------------------
181         void AxeVolume::bbUserInitializeProcessing()
182         {
183         }
184
185         //-----------------------------------------------------------------
186         void AxeVolume::bbUserFinalizeProcessing()
187         {
188         }
189
190         //-----------------------------------------------------------------
191
192 }
193 // EO namespace bbcreaMaracasVisu
194
195