]> Creatis software - creaMaracasVisu.git/blob - bbtk/src/bbmaracasvisuAxeVolume.cxx
Support #1768 CREATIS Licence insertion
[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 namespace bbcreaMaracasVisu
29 {
30
31 BBTK_ADD_BLACK_BOX_TO_PACKAGE(creaMaracasVisu,AxeVolume)
32 BBTK_BLACK_BOX_IMPLEMENTATION(AxeVolume,bbtk::AtomicBlackBox);
33 void AxeVolume::Process()
34 {
35
36         printf("EED AxeVolume::Process start \n");
37
38         if ( mimage!=NULL )
39         {
40                 mimage->Delete();
41         }
42
43         int ext[6];
44         bbGetInputIn()->GetExtent(ext);
45         int sizeX=ext[1]-ext[0]+1;
46         int sizeY=ext[3]-ext[2]+1;
47         int sizeZ=ext[5]-ext[4]+1;
48
49     double spc[3];
50         bbGetInputIn()->GetSpacing(spc);
51     double invSpc[3];
52     invSpc[0] = 1/spc[0];
53     invSpc[1] = 1/spc[1];
54     invSpc[2] = 1/spc[2];
55
56         mimage = vtkImageData::New();
57         mimage->SetSpacing(bbGetInputIn()->GetSpacing());
58         mimage->SetDimensions(bbGetInputIn()->GetDimensions());
59         mimage->SetExtent(bbGetInputIn()->GetExtent());
60         mimage->SetOrigin(bbGetInputIn()->GetOrigin());
61         //mimage->SetDimensions(sizeX,sizeY,sizeZ);
62         //mimage->SetOrigin(0,0,0);
63         //mimage->SetExtent( 0 , sizeX-1 , 0 , sizeY-1 , 0, sizeZ-1 );
64         //mimage->SetWholeExtent( 0 , sizeX-1 , 0 , sizeY-1 , 0, sizeZ-1 );
65         mimage->SetScalarTypeToUnsignedShort();
66         //mimage->SetSpacing(spc);
67         mimage->AllocateScalars();
68
69
70
71         int i,j,k;
72     int sizeLstPointR = bbGetInputlstPointR().size();
73         int iAxe,sizeAxe=bbGetInputlstPointX().size();
74         double rx,ry,rz;
75         double r,rr;
76         unsigned short *p;
77         int sizeImage = sizeX*sizeY*sizeZ;
78         double px,py,pz,px1,py1,pz1,px2,py2,pz2;
79
80         // Clean image
81         p = (unsigned short*)mimage->GetScalarPointer (0, 0, 0);
82         for ( i=0 ; i<sizeImage ; i++)
83         {
84                 *p = 0;
85                 p++;
86         }
87
88         for (iAxe=0 ; iAxe<sizeAxe-1; iAxe++)
89          {
90                 if (sizeLstPointR<iAxe)
91                 {
92                         if (bbGetInputlstPointR().size()>=1)
93                         {
94                                 r = bbGetInputlstPointR()[ bbGetInputlstPointR().size()-1 ]    * invSpc[0];
95                         } else {
96                                 r = 1;
97                         }
98                 } else {
99                         r = bbGetInputlstPointR()[ iAxe ]* invSpc[0];
100                 }
101                 px = bbGetInputlstPointX()[iAxe] * invSpc[0];
102                 py = bbGetInputlstPointY()[iAxe] * invSpc[1];
103                 pz = bbGetInputlstPointZ()[iAxe] * invSpc[2];
104                 px1 = px - r;
105                 py1 = py - r;
106                 pz1 = pz - r;
107                 px2 = px + r;
108                 py2 = py + r;
109                 pz2 = pz + r;
110                 rr=r*r;
111
112                 for ( i=px1 ; i<=px2 ; i++ )
113                 {
114                         rx      =       i - px;
115                         rx      =       rx*rx;
116                         for ( j=py1 ; j<py2 ; j++ )
117                         {
118                                 ry      =       j - py;
119                                 ry      =       ry*ry;
120                                 for ( k=pz1 ; k<pz2 ; k++ )
121                                 {
122                                         if ( (i>=0) && (i<sizeX) && (j>=0) && (j<sizeY) &&(k>=0) && (k<sizeZ) ){
123                                                 p = (unsigned short*)mimage->GetScalarPointer (i, j, k);
124                                                 if (*p==0)
125                                                 {
126                                                         rz      =       k - pz;
127                                                         rz      =       rz*rz;
128                                                         if ( rx + ry + rz <= rr )
129                                                         {
130                                                                 *p=255;
131                                                         }
132                                                 } // *p==0
133                                         } // inside point
134                                 } //for k
135                         } //for j
136                 } //for i
137         } // for iAxe
138     bbSetOutputOut( mimage );
139
140         printf("EED AxeVolume::Process end \n");
141
142 }
143
144
145         //-----------------------------------------------------------------
146         void AxeVolume::bbUserSetDefaultValues()
147         {
148                 mimage=NULL;
149         }
150
151         //-----------------------------------------------------------------
152         void AxeVolume::bbUserInitializeProcessing()
153         {
154         }
155
156         //-----------------------------------------------------------------
157         void AxeVolume::bbUserFinalizeProcessing()
158         {
159         }
160
161         //-----------------------------------------------------------------
162
163 }
164 // EO namespace bbcreaMaracasVisu
165
166