]> Creatis software - creaMaracasVisu.git/blob - bbtk/src/bbmaracasvisuAxeVolume.cxx
79e5ac0cf0fbfb4ccbed8ce1268a661ec33599f3
[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;
79         double px1,py1,pz1;
80         double px2,py2,pz2;
81
82         // Clean image
83         p = (unsigned short*)mimage->GetScalarPointer (0, 0, 0);
84         for ( i=0 ; i<sizeImage ; i++)
85         {
86                 *p = 0;
87                 p++;
88         }
89
90         for (iAxe=0 ; iAxe<sizeAxe; iAxe++)
91          {
92                 if (iAxe<sizeLstPointR)
93                 {
94                         r = bbGetInputlstPointR()[ iAxe ]* invSpc[0];
95                 } else {
96                         if (bbGetInputlstPointR().size()>=1)
97                         {
98                                 r = bbGetInputlstPointR()[ bbGetInputlstPointR().size()-1 ]    * invSpc[0];
99                         } else {
100                                 r = 1;
101                         }
102                 }
103                 px = bbGetInputlstPointX()[iAxe] * invSpc[0];
104                 py = bbGetInputlstPointY()[iAxe] * invSpc[1];
105                 pz = bbGetInputlstPointZ()[iAxe] * invSpc[2];
106                 px1 = px - r;
107                 py1 = py - r;
108                 pz1 = pz - r;
109                 px2 = px + r;
110                 py2 = py + r;
111                 pz2 = pz + r;
112                 rr=r*r;
113
114                 for ( i=px1 ; i<=px2 ; i++ )
115                 {
116                         rx      =       i - px;
117                         rx      =       rx*rx;
118                         for ( j=py1 ; j<py2 ; j++ )
119                         {
120                                 ry      =       j - py;
121                                 ry      =       ry*ry;
122                                 for ( k=pz1 ; k<pz2 ; k++ )
123                                 {
124                                         if ( (i>=0) && (i<sizeX) && (j>=0) && (j<sizeY) &&(k>=0) && (k<sizeZ) ){
125                                                 p = (unsigned short*)mimage->GetScalarPointer (i, j, k);
126                                                 if (*p==0)
127                                                 {
128                                                         rz      =       k - pz;
129                                                         rz      =       rz*rz;
130                                                         if ( rx + ry + rz <= rr )
131                                                         {
132                                                                 *p=255;
133                                                         }
134                                                 } // *p==0
135                                         } // inside point
136                                 } //for k
137                         } //for j
138                 } //for i
139         } // for iAxe
140     bbSetOutputOut( mimage );
141
142         printf("EED AxeVolume::Process end \n");
143
144 }
145
146
147         //-----------------------------------------------------------------
148         void AxeVolume::bbUserSetDefaultValues()
149         {
150                 mimage=NULL;
151         }
152
153         //-----------------------------------------------------------------
154         void AxeVolume::bbUserInitializeProcessing()
155         {
156         }
157
158         //-----------------------------------------------------------------
159         void AxeVolume::bbUserFinalizeProcessing()
160         {
161         }
162
163         //-----------------------------------------------------------------
164
165 }
166 // EO namespace bbcreaMaracasVisu
167
168