]> Creatis software - bbtk.git/blob - packages/vtk/src/bbvtkSphereList.cxx
Merge remote-tracking branch 'origin/master'
[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 void SphereList::Process()
42 {
43
44         int iMin, iMax;
45         double px = 0.0;
46         double py = 0.0;
47         double pz = 0.0;
48         double radio;
49         double spc[3];
50  
51         int last_valid_color_index = 0;
52
53
54         if (bbGetInputRenderer()!=NULL)
55         {
56                 // 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. 
57                 if (sphereActor.size() != 0)
58                 {
59                   for (int i = 0; i < sphereActor.size(); i++)
60                     sphereActor[i] -> GetProperty() -> SetOpacity( bbGetInputOpacity() );
61                 }
62                 else
63                 {
64                     if (bbGetInputSpacing().size()==3)
65                     {
66                         spc[0]=bbGetInputSpacing()[0];
67                         spc[1]=bbGetInputSpacing()[1];
68                         spc[2]=bbGetInputSpacing()[2];
69                     }
70                     else
71                     {
72                         spc[0]=spc[1]=spc[2]=1;
73                     }
74
75                     iMin=0;
76                     iMax=bbGetInputlstPointX().size();
77                     printf("EED SphereList::Process   iMax=%d \n", iMax);
78                     for (int i = 0; i < iMax; i++)
79                       {
80                         std::cout << "CM SphereList::Process i=" <<  i  << " bbGetInputlstPointX()[i]=" << bbGetInputlstPointX()[i] << std::endl;
81                         std::cout << "CM SphereList::Process i=" <<  i  << " bbGetInputlstPointY()[i]=" << bbGetInputlstPointY()[i] << std::endl;
82                         std::cout << "CM SphereList::Process i=" <<  i  << " bbGetInputlstPointZ()[i]=" << bbGetInputlstPointZ()[i] << std::endl;
83                       }
84                     // 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.
85                     for ( int i=iMin ; i<iMax; i=i+1 )
86                     {
87                         px = bbGetInputlstPointX()[i]*spc[0];
88                         if (bbGetInputlstPointY().size() == bbGetInputlstPointX().size() )
89                         {
90                             py = bbGetInputlstPointY()[i]*spc[1];
91                         }
92                         if (bbGetInputlstPointZ().size() == bbGetInputlstPointX().size() )
93                         {                       
94                             pz = bbGetInputlstPointZ()[i]*spc[2];
95                         }
96
97                         // If the number of elements in the radio list is different from the number of X coordinates, the radio value is set to 1.
98                         if (bbGetInputlstRadio().size() == bbGetInputlstPointX().size() )
99                         {
100                             radio = bbGetInputlstRadio()[i];
101                         }
102                         else
103                         {
104                             if (bbGetInputlstRadio().size()>=1)
105                             {
106                                 radio = bbGetInputlstRadio()[ bbGetInputlstRadio().size() - 1 ];
107                             } 
108                             else 
109                             {
110                                 radio = 1.0;
111                             }
112                         }
113
114                         // Sphere
115                         vtkSphereSource * newSphere =  vtkSphereSource::New();
116
117                         newSphere -> SetThetaResolution(20);
118                         newSphere -> SetPhiResolution(20);
119                         newSphere -> SetRadius(radio); 
120
121                         vtkPolyDataMapper * newMapper = vtkPolyDataMapper::New();
122                         newMapper -> SetInput( newSphere -> GetOutput() );
123         
124                         vtkActor * newActor = vtkActor::New();
125                         sphereActor.push_back(newActor);
126                         newActor -> SetMapper(newMapper);
127                         newActor -> SetOrigin(0, 0, 0);
128                         
129                         unsigned int j = 3*i +2;
130                         if (j < bbGetInputColour().size() )
131                         {
132                             newActor -> GetProperty() -> SetColor( bbGetInputColour()[3*i] , bbGetInputColour()[3*i + 1] , bbGetInputColour()[3*i + 2] );
133                             last_valid_color_index = 3*i;
134                         }
135                         else
136                           newActor -> GetProperty() -> SetColor( bbGetInputColour()[last_valid_color_index] , bbGetInputColour()[last_valid_color_index + 1] , bbGetInputColour()[last_valid_color_index + 2] );
137
138                         newActor -> GetProperty() -> SetOpacity( bbGetInputOpacity() );
139                         newActor -> SetPosition( px,py,pz );
140         
141                         if ( bbGetInputTransform()!=NULL )
142                         {
143                                 newActor->SetUserTransform( bbGetInputTransform() );
144                         }
145         
146
147                         if (bbGetInputRenderer()!=NULL)
148                         {
149                             bbGetInputRenderer() -> AddActor( newActor );
150                         }
151
152                     } // for
153
154                     if (sphereActor.size() != 0)
155                     {
156                         // Sets the output.
157                         bbSetOutputActorList(sphereActor);
158                     }
159                     
160                 } // if (bbGetInputRenderer()!=NULL)
161
162         } // if (sphereActor.size() != 0)
163 }
164
165 void SphereList::bbUserSetDefaultValues()
166 {
167  
168   bbSetInputRenderer(NULL);
169   bbSetInputTransform(NULL);
170  
171   // Sets default radio to 1.
172   std::vector<double> radio;
173   radio.push_back(1.0);
174   bbSetInputlstRadio(radio);
175
176   // Sets default colour to red.
177   std::vector<double> colour;
178   colour.push_back(1.0);
179   colour.push_back(0.0);
180   colour.push_back(0.0);
181   bbSetInputColour(colour);
182         
183         // Sets default spacing.
184         std::vector<double> spacing;
185         spacing.push_back(1.0);
186         spacing.push_back(1.0);
187         spacing.push_back(1.0);
188         bbSetInputSpacing(spacing);
189         
190   bbSetInputOpacity(1.0);
191
192 }
193
194 void SphereList::bbUserInitializeProcessing()
195 {
196  
197 }
198
199 void SphereList::bbUserFinalizeProcessing()
200 {
201   
202 }
203 }
204 // EO namespace bbvtk
205
206