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 #include "creaVtk_MACROS.h"
31 namespace bbcreaMaracasVisu
35 BBTK_ADD_BLACK_BOX_TO_PACKAGE(creaMaracasVisu,AxeVolume)
36 BBTK_BLACK_BOX_IMPLEMENTATION(AxeVolume,bbtk::AtomicBlackBox);
38 int AxeVolume::GetTypeFormat( std::string formatStr , vtkImageData* image )
40 int outputformat = VTK_UNSIGNED_CHAR;
41 if (formatStr=="SAME")
43 if (image!=NULL) outputformat = image->GetScalarType();
45 else if (formatStr=="VTK_BIT") outputformat = VTK_BIT; // 1
46 else if (formatStr=="VTK_CHAR") outputformat = VTK_CHAR; // 2
47 else if (formatStr=="VTK_SIGNED_CHAR") outputformat = VTK_SIGNED_CHAR; // 15
48 else if (formatStr=="VTK_UNSIGNED_CHAR") outputformat = VTK_UNSIGNED_CHAR; // 3
49 else if (formatStr=="VTK_SHORT") outputformat = VTK_SHORT; // 4
50 else if (formatStr=="VTK_UNSIGNED_SHORT") outputformat = VTK_UNSIGNED_SHORT; // 5
51 else if (formatStr=="VTK_INT") outputformat = VTK_INT; // 6
52 else if (formatStr=="VTK_UNSIGNED_INT") outputformat = VTK_UNSIGNED_INT; // 7
53 else if (formatStr=="VTK_LONG") outputformat = VTK_LONG; // 8
54 else if (formatStr=="VTK_UNSIGNED_LONG") outputformat = VTK_UNSIGNED_LONG; // 9
55 else if (formatStr=="VTK_FLOAT") outputformat = VTK_FLOAT; // 10
56 else if (formatStr=="VTK_DOUBLE") outputformat = VTK_DOUBLE; // 11
57 else if (formatStr=="MET_CHAR") outputformat = VTK_CHAR; // 2
58 else if (formatStr=="MET_UCHAR") outputformat = VTK_UNSIGNED_CHAR; // 3
59 else if (formatStr=="MET_SHORT") outputformat = VTK_SHORT; // 4
60 else if (formatStr=="MET_USHORT") outputformat = VTK_UNSIGNED_SHORT; // 5
61 else if (formatStr=="MET_SHORT") outputformat = VTK_SHORT; // 4
62 else if (formatStr=="MET_FLOAT") outputformat = VTK_FLOAT; // 10
63 else if (formatStr=="MET_DOUBLE") outputformat = VTK_DOUBLE; // 11
69 void AxeVolume::Process()
71 if (bbGetInputIn()!=NULL)
79 bbGetInputIn()->GetExtent(ext);
80 int sizeX=ext[1]-ext[0]+1;
81 int sizeY=ext[3]-ext[2]+1;
82 int sizeZ=ext[5]-ext[4]+1;
85 bbGetInputIn()->GetSpacing(spc);
91 int outputformat = GetTypeFormat( bbGetInputOutputFormat() , bbGetInputIn() );
93 mimage = vtkImageData::New();
94 mimage->SetSpacing(bbGetInputIn()->GetSpacing());
95 mimage->SetDimensions(bbGetInputIn()->GetDimensions());
96 mimage->SetExtent(bbGetInputIn()->GetExtent());
97 mimage->SetOrigin(bbGetInputIn()->GetOrigin());
98 //EED 2017-01-01 Migration VTK7
99 #if VTK_MAJOR_VERSION <= 5
100 mimage->SetScalarType( outputformat );
101 mimage->AllocateScalars();
103 mimage->AllocateScalars( outputformat , 1);
106 int sizeLstPointR = bbGetInputlstPointR().size();
107 int iAxe,sizeAxe = bbGetInputlstPointX().size();
109 int sizeImage = sizeX*sizeY*sizeZ;
110 // unsigned short *p;
113 memset( (char*)mimage->GetScalarPointer(0,0,0) , 0, sizeImage*(mimage->GetScalarSize()) );
115 // p = (unsigned short*)mimage->GetScalarPointer (0, 0, 0);
116 // for ( ii=0 ; ii<sizeImage ; ii++)
123 DEF_POINTER_IMAGE_VTK_CREA(vI,ssI,pI,stI,mimage)
126 int k1omp=(double)(sizeAxe-1)*0.0;
127 int k2omp=(double)(sizeAxe-1)*0.2;
128 int k3omp=(double)(sizeAxe-1)*0.4;
129 int k4omp=(double)(sizeAxe-1)*0.6;
130 int k5omp=(double)(sizeAxe-1)*0.8;
131 int k6omp=(double)(sizeAxe-1)*1.0;
133 printf("EED AxeVolume::Process (with openmp)\n");
135 #pragma omp parallel for
136 for (iAxe=0 ; iAxe<sizeAxe; iAxe++)
138 if ( (k1omp==iAxe) || (k2omp==iAxe) || (k3omp==iAxe) ||
139 (k4omp==iAxe) || (k5omp==iAxe) || (k6omp==iAxe) ) { printf(" %d%\n", (int)(((double)iAxe/(double)(sizeAxe-1))*100 )); }
148 if (iAxe<sizeLstPointR)
150 r = bbGetInputlstPointR()[ iAxe ]* invSpc[0];
152 if (bbGetInputlstPointR().size()>=1)
154 r = bbGetInputlstPointR()[ bbGetInputlstPointR().size()-1 ] * invSpc[0];
158 } // if iAxe sizeLstPointR
159 px = bbGetInputlstPointX()[iAxe] * invSpc[0];
160 py = bbGetInputlstPointY()[iAxe] * invSpc[1];
161 pz = bbGetInputlstPointZ()[iAxe] * invSpc[2];
171 for ( i=px1 ; i<=px2 ; i++ )
175 for ( j=py1 ; j<py2 ; j++ )
179 for ( k=pz1 ; k<pz2 ; k++ )
181 if ( (i>=0) && (i<sizeX) && (j>=0) && (j<sizeY) &&(k>=0) && (k<sizeZ) )
183 // p = (unsigned short*)mimage->GetScalarPointer (i, j, k);
185 index=i+j*sizeX+k*sizeX*sizeY;
186 GETVALUE2_VTK_CREA(vItmpOMP,pI,stI,index)
187 // EED2020-04-25 if ( mimage->GetScalarComponentAsDouble(i,j,k,0)==0 )
192 if ( rx + ry + rz <= rr )
195 vItmpOMP=bbGetInputValue();
196 SETVALUE2_VTK_CREA(vItmpOMP,pI,stI,index)
197 // EED2020-04-25 mimage->SetScalarComponentFromDouble (i,j,k,0, bbGetInputValue() );
205 bbSetOutputOut( mimage );
208 printf("EED Warnning!! AxeVolume::Process The Input In is not set.\n");
210 }// if bbGetInputIn()
214 //-----------------------------------------------------------------
215 void AxeVolume::bbUserSetDefaultValues()
218 bbSetInputOutputFormat("SAME");
219 bbSetInputValue(255);
222 //-----------------------------------------------------------------
223 void AxeVolume::bbUserInitializeProcessing()
227 //-----------------------------------------------------------------
228 void AxeVolume::bbUserFinalizeProcessing()
232 //-----------------------------------------------------------------
235 // EO namespace bbcreaMaracasVisu