]> Creatis software - bbtk.git/blob - packages/vtk/src/bbvtkSphereList.cxx
2042 Feature bbpConfigurator
[bbtk.git] / packages / vtk / src / bbvtkSphereList.cxx
1 /*
2  # ---------------------------------------------------------------------
3  #
4  # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
5  #                        pour la SantÈ)
6  # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
7  # Previous Authors : Laurent Guigues, Jean-Pierre Roux
8  # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
9  #
10  #  This software is governed by the CeCILL-B license under French law and
11  #  abiding by the rules of distribution of free software. You can  use,
12  #  modify and/ or redistribute the software under the terms of the CeCILL-B
13  #  license as circulated by CEA, CNRS and INRIA at the following URL
14  #  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
15  #  or in the file LICENSE.txt.
16  #
17  #  As a counterpart to the access to the source code and  rights to copy,
18  #  modify and redistribute granted by the license, users are provided only
19  #  with a limited warranty  and the software's author,  the holder of the
20  #  economic rights,  and the successive licensors  have only  limited
21  #  liability.
22  #
23  #  The fact that you are presently reading this means that you have had
24  #  knowledge of the CeCILL-B license and that you accept its terms.
25  # ------------------------------------------------------------------------ */
26
27
28 #include "bbvtkSphereList.h"
29 #include "bbvtkPackage.h"
30
31 #include <vtkPolyDataMapper.h>
32 #include <vtkProperty.h>
33 #include <vtkRenderWindow.h>
34
35 namespace bbvtk
36 {
37
38 BBTK_ADD_BLACK_BOX_TO_PACKAGE(vtk,SphereList)
39 BBTK_BLACK_BOX_IMPLEMENTATION(SphereList,bbtk::AtomicBlackBox);
40
41 double SphereList::GetRadio(int i)
42 {
43     double radio;
44         if (bbGetInputlstRadio().size()==0)
45         {
46             radio = 1.0;
47         } else if (bbGetInputlstRadio().size() < i )
48         {
49             radio = bbGetInputlstRadio()[i];
50         } else  
51         {
52             radio = bbGetInputlstRadio()[ bbGetInputlstRadio().size() - 1 ];
53         }  
54
55        return radio;
56 }
57
58
59 void SphereList::GetPoint(int i, double &px,double &py,double &pz)        
60  {
61       double spc[3];
62       if (bbGetInputSpacing().size()==3)
63       {
64                 spc[0]=bbGetInputSpacing()[0];
65                 spc[1]=bbGetInputSpacing()[1];
66                 spc[2]=bbGetInputSpacing()[2];
67       } else {
68                 spc[0]=spc[1]=spc[2]=1;
69        }
70
71        px = bbGetInputlstPointX()[i]*spc[0];
72        if (bbGetInputlstPointY().size() == bbGetInputlstPointX().size() )
73        {
74                 py = bbGetInputlstPointY()[i]*spc[1];
75         }
76                 if (bbGetInputlstPointZ().size() == bbGetInputlstPointX().size() )
77         {                       
78                 pz = bbGetInputlstPointZ()[i]*spc[2];
79         }
80 }  
81
82                         
83
84 void SphereList::Process()
85 {
86
87         int iMin, iMax;
88         double px = 0.0;
89         double py = 0.0;
90         double pz = 0.0;
91         
92  
93         int last_valid_color_index = 0;
94
95
96         if (bbGetInputRenderer()!=NULL)
97         {
98                 // If it is not the first time Process is executed, the actors have already been created. The only thing to do is to update the opacity. 
99                 if (sphereActor.size() != 0)
100                 {
101                   for (int i = 0; i < sphereActor.size(); i++)
102                   {
103                         GetPoint(i, px,py,pz);
104                         sphereActor[i] ->SetPosition( px,py,pz );
105                         sphereActor[i] -> GetProperty() -> SetOpacity( bbGetInputOpacity() );
106                         vtkspheresourceLst[i] -> SetRadius( GetRadio(i) ); 
107                   } // for i
108                 } else {
109                    
110
111                     iMin=0;
112                     iMax=bbGetInputlstPointX().size();
113 //                    printf("EED SphereList::Process   iMax=%d \n", iMax);
114 //                    for (int i = 0; i < iMax; i++)
115 //                      {
116 //                        std::cout << "CM SphereList::Process i=" <<  i  << " bbGetInputlstPointX()[i]=" << bbGetInputlstPointX()[i] << std::endl;
117 //                        std::cout << "CM SphereList::Process i=" <<  i  << " bbGetInputlstPointY()[i]=" << bbGetInputlstPointY()[i] << std::endl;
118 //                        std::cout << "CM SphereList::Process i=" <<  i  << " bbGetInputlstPointZ()[i]=" << bbGetInputlstPointZ()[i] << std::endl;
119 //                      } // for i
120  
121                    // If the vector Y or respectively the vector Z has a different size from the vector X, the position value py or respectively pz is set to 0.
122                     for ( int i=iMin ; i<iMax; i=i+1 )
123                     {
124                          
125
126                         GetPoint(i, px,py,pz);
127
128                         
129
130                         // Sphere
131                         vtkSphereSource * newSphere =  vtkSphereSource::New();
132                         vtkspheresourceLst.push_back(newSphere);
133
134                         newSphere -> SetThetaResolution(20);
135                         newSphere -> SetPhiResolution(20);
136                         newSphere -> SetRadius( GetRadio(i) ); 
137
138                         vtkPolyDataMapper * newMapper = vtkPolyDataMapper::New();
139                         newMapper -> SetInput( newSphere -> GetOutput() );
140         
141                         vtkActor * newActor = vtkActor::New();
142                         sphereActor.push_back(newActor);
143                         newActor -> SetMapper(newMapper);
144                         newActor -> SetOrigin(0, 0, 0);
145                         
146                         unsigned int j = 3*i +2;
147                         if (j < bbGetInputColour().size() )
148                         {
149                             newActor -> GetProperty() -> SetColor( bbGetInputColour()[3*i] , bbGetInputColour()[3*i + 1] , bbGetInputColour()[3*i + 2] );
150                             last_valid_color_index = 3*i;
151                         }
152                         else
153                           newActor -> GetProperty() -> SetColor( bbGetInputColour()[last_valid_color_index] , bbGetInputColour()[last_valid_color_index + 1] , bbGetInputColour()[last_valid_color_index + 2] );
154
155                         newActor -> GetProperty() -> SetOpacity( bbGetInputOpacity() );
156                         newActor -> SetPosition( px,py,pz );
157         
158                         if ( bbGetInputTransform()!=NULL )
159                         {
160                                 newActor->SetUserTransform( bbGetInputTransform() );
161                         }
162         
163
164                         if (bbGetInputRenderer()!=NULL)
165                         {
166                             bbGetInputRenderer() -> AddActor( newActor );
167                         }
168
169                     } // for
170
171                     if (sphereActor.size() != 0)
172                     {
173                         // Sets the output.
174                         bbSetOutputActorList(sphereActor);
175                     }
176                     
177                 } // if (bbGetInputRenderer()!=NULL)
178
179         } // if (sphereActor.size() != 0)
180 }
181
182 void SphereList::bbUserSetDefaultValues()
183 {
184  
185   bbSetInputRenderer(NULL);
186   bbSetInputTransform(NULL);
187  
188   // Sets default radio to 1.
189   std::vector<double> radio;
190   radio.push_back(1.0);
191   bbSetInputlstRadio(radio);
192
193   // Sets default colour to red.
194   std::vector<double> colour;
195   colour.push_back(1.0);
196   colour.push_back(0.0);
197   colour.push_back(0.0);
198   bbSetInputColour(colour);
199         
200         // Sets default spacing.
201         std::vector<double> spacing;
202         spacing.push_back(1.0);
203         spacing.push_back(1.0);
204         spacing.push_back(1.0);
205         bbSetInputSpacing(spacing);
206         
207   bbSetInputOpacity(1.0);
208
209 }
210
211 void SphereList::bbUserInitializeProcessing()
212 {
213  
214 }
215
216 void SphereList::bbUserFinalizeProcessing()
217 {
218   
219 }
220 }
221 // EO namespace bbvtk
222
223