1 /*# ---------------------------------------------------------------------
3 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
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
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.
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
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 # ------------------------------------------------------------------------ */
26 #include "bbmaracasvisuAxeVolume.h"
27 #include "bbcreaMaracasVisuPackage.h"
29 namespace bbcreaMaracasVisu
33 BBTK_ADD_BLACK_BOX_TO_PACKAGE(creaMaracasVisu,AxeVolume)
34 BBTK_BLACK_BOX_IMPLEMENTATION(AxeVolume,bbtk::AtomicBlackBox);
36 int AxeVolume::GetTypeFormat( std::string formatStr , vtkImageData* image )
38 int outputformat = VTK_UNSIGNED_CHAR;
39 if (formatStr=="SAME")
41 if (image!=NULL) outputformat = image->GetScalarType();
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
67 void AxeVolume::Process()
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;
81 bbGetInputIn()->GetSpacing(spc);
87 int outputformat = GetTypeFormat( bbGetInputOutputFormat() , bbGetInputIn() );
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();
99 mimage->AllocateScalars( outputformat , 1);
102 int sizeLstPointR = bbGetInputlstPointR().size();
103 int iAxe,sizeAxe = bbGetInputlstPointX().size();
105 int sizeImage = sizeX*sizeY*sizeZ;
109 p = (unsigned short*)mimage->GetScalarPointer (0, 0, 0);
110 for ( ii=0 ; ii<sizeImage ; ii++)
117 #pragma omp parallel for
118 for (iAxe=0 ; iAxe<sizeAxe; iAxe++)
126 printf("AxeVolume %d/%d\n ",iAxe,sizeAxe);
127 if (iAxe<sizeLstPointR)
129 r = bbGetInputlstPointR()[ iAxe ]* invSpc[0];
131 if (bbGetInputlstPointR().size()>=1)
133 r = bbGetInputlstPointR()[ bbGetInputlstPointR().size()-1 ] * invSpc[0];
138 px = bbGetInputlstPointX()[iAxe] * invSpc[0];
139 py = bbGetInputlstPointY()[iAxe] * invSpc[1];
140 pz = bbGetInputlstPointZ()[iAxe] * invSpc[2];
149 for ( i=px1 ; i<=px2 ; i++ )
153 for ( j=py1 ; j<py2 ; j++ )
157 for ( k=pz1 ; k<pz2 ; k++ )
159 if ( (i>=0) && (i<sizeX) && (j>=0) && (j<sizeY) &&(k>=0) && (k<sizeZ) )
161 // p = (unsigned short*)mimage->GetScalarPointer (i, j, k);
163 if ( mimage->GetScalarComponentAsDouble(i,j,k,0)==0 )
167 if ( rx + ry + rz <= rr )
170 mimage->SetScalarComponentFromDouble (i,j,k,0, bbGetInputValue() );
178 bbSetOutputOut( mimage );
182 //-----------------------------------------------------------------
183 void AxeVolume::bbUserSetDefaultValues()
186 bbSetInputOutputFormat("SAME");
187 bbSetInputValue(255);
190 //-----------------------------------------------------------------
191 void AxeVolume::bbUserInitializeProcessing()
195 //-----------------------------------------------------------------
196 void AxeVolume::bbUserFinalizeProcessing()
200 //-----------------------------------------------------------------
203 // EO namespace bbcreaMaracasVisu