]> Creatis software - creaMaracasVisu.git/blob - bbtk/src/bbmaracasvisuAxeVolume.cxx
1a72bb5e4a55e8daf80b77784cd5c8f716081092
[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 //EED 2017-01-01 Migration VTK7
95 #if VTK_MAJOR_VERSION <= 5
96         mimage->SetScalarType( outputformat );
97         mimage->AllocateScalars();
98 #else
99         mimage->AllocateScalars( outputformat , 1);
100 #endif
101
102     int sizeLstPointR   = bbGetInputlstPointR().size();
103         int iAxe,sizeAxe        = bbGetInputlstPointX().size();
104         int ii;
105         int sizeImage           = sizeX*sizeY*sizeZ;
106         unsigned short *p;
107
108         // Clean image
109         p = (unsigned short*)mimage->GetScalarPointer (0, 0, 0);
110         for ( ii=0 ; ii<sizeImage ; ii++)
111         {
112                 *p = 0;
113                 p++;
114         }
115
116
117 #pragma omp parallel for 
118         for (iAxe=0 ; iAxe<sizeAxe; iAxe++)
119          {
120                 int i,j,k;
121                 double rx,ry,rz;
122                 double r,rr;
123                 double px,py,pz;
124                 double px1,py1,pz1;
125                 double px2,py2,pz2;
126                 printf("AxeVolume %d/%d\n ",iAxe,sizeAxe);
127                 if (iAxe<sizeLstPointR)
128                 {
129                         r = bbGetInputlstPointR()[ iAxe ]* invSpc[0];
130                 } else {
131                         if (bbGetInputlstPointR().size()>=1)
132                         {
133                                 r = bbGetInputlstPointR()[ bbGetInputlstPointR().size()-1 ]    * invSpc[0];
134                         } else {
135                                 r = 1;
136                         }
137                 }
138                 px = bbGetInputlstPointX()[iAxe] * invSpc[0];
139                 py = bbGetInputlstPointY()[iAxe] * invSpc[1];
140                 pz = bbGetInputlstPointZ()[iAxe] * invSpc[2];
141                 px1 = px - r;
142                 py1 = py - r;
143                 pz1 = pz - r;
144                 px2 = px + r;
145                 py2 = py + r;
146                 pz2 = pz + r;
147                 rr=r*r;
148
149                 for ( i=px1 ; i<=px2 ; i++ )
150                 {
151                         rx      =       i - px;
152                         rx      =       rx*rx;
153                         for ( j=py1 ; j<py2 ; j++ )
154                         {
155                                 ry      =       j - py;
156                                 ry      =       ry*ry;
157                                 for ( k=pz1 ; k<pz2 ; k++ )
158                                 {
159                                         if ( (i>=0) && (i<sizeX) && (j>=0) && (j<sizeY) &&(k>=0) && (k<sizeZ) )
160                                         {
161 //                                              p = (unsigned short*)mimage->GetScalarPointer (i, j, k);
162 //                                              if (*p==0)
163                                                 if ( mimage->GetScalarComponentAsDouble(i,j,k,0)==0 )
164                                                 {
165                                                         rz      =       k - pz;
166                                                         rz      =       rz*rz;
167                                                         if ( rx + ry + rz <= rr )
168                                                         {
169 //                                                              *p=255;
170                                                                 mimage->SetScalarComponentFromDouble (i,j,k,0, bbGetInputValue() );
171                                                         }
172                                                 } // *p==0
173                                         } // if inside point
174                                 } //for k
175                         } //for j
176                 } //for i
177         } // for iAxe
178     bbSetOutputOut( mimage );
179 }
180
181
182         //-----------------------------------------------------------------
183         void AxeVolume::bbUserSetDefaultValues()
184         {
185                 mimage=NULL;
186                 bbSetInputOutputFormat("SAME");
187                 bbSetInputValue(255);
188         }
189
190         //-----------------------------------------------------------------
191         void AxeVolume::bbUserInitializeProcessing()
192         {
193         }
194
195         //-----------------------------------------------------------------
196         void AxeVolume::bbUserFinalizeProcessing()
197         {
198         }
199
200         //-----------------------------------------------------------------
201
202 }
203 // EO namespace bbcreaMaracasVisu
204
205