]> Creatis software - bbtk.git/blob - packages/vtk/src/bbvtkSphereList.cxx
Merge branch 'master' of ssh://git.creatis.insa-lyon.fr/bbtk
[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                     // Stops at iMax - 1 because of a bug of the box stdReadColumnsDouble creating an extra line at the end of the file.
86                     for ( int i=iMin ; i<iMax-1; i=i+1 )
87                     {
88                         px = bbGetInputlstPointX()[i]*spc[0];
89                         if (bbGetInputlstPointY().size() == bbGetInputlstPointX().size() )
90                         {
91                             py = bbGetInputlstPointY()[i]*spc[1];
92                         }
93                         if (bbGetInputlstPointZ().size() == bbGetInputlstPointX().size() )
94                         {                       
95                             pz = bbGetInputlstPointZ()[i]*spc[2];
96                         }
97
98                         // If the number of elements in the radio list is different from the number of X coordinates, the radio value is set to 1.
99                         if (bbGetInputlstRadio().size() == bbGetInputlstPointX().size() )
100                         {
101                             radio = bbGetInputlstRadio()[i];
102                         }
103                         else
104                         {
105                             if (bbGetInputlstRadio().size()>=1)
106                             {
107                                 radio = bbGetInputlstRadio()[ bbGetInputlstRadio().size() - 1 ];
108                             } 
109                             else 
110                             {
111                                 radio = 1.0;
112                             }
113                         }
114
115                         // Sphere
116                         vtkSphereSource * newSphere =  vtkSphereSource::New();
117
118                         newSphere -> SetThetaResolution(20);
119                         newSphere -> SetPhiResolution(20);
120                         newSphere -> SetRadius(radio); 
121
122                         vtkPolyDataMapper * newMapper = vtkPolyDataMapper::New();
123                         newMapper -> SetInput( newSphere -> GetOutput() );
124         
125                         vtkActor * newActor = vtkActor::New();
126                         sphereActor.push_back(newActor);
127                         newActor -> SetMapper(newMapper);
128                         newActor -> SetOrigin(0, 0, 0);
129                         
130                         unsigned int j = 3*i +2;
131                         if (j < bbGetInputColour().size() )
132                         {
133                             newActor -> GetProperty() -> SetColor( bbGetInputColour()[3*i] , bbGetInputColour()[3*i + 1] , bbGetInputColour()[3*i + 2] );
134                             last_valid_color_index = 3*i;
135                         }
136                         else
137                           newActor -> GetProperty() -> SetColor( bbGetInputColour()[last_valid_color_index] , bbGetInputColour()[last_valid_color_index + 1] , bbGetInputColour()[last_valid_color_index + 2] );
138
139                         newActor -> GetProperty() -> SetOpacity( bbGetInputOpacity() );
140                         newActor -> SetPosition( px,py,pz );
141         
142                         if ( bbGetInputTransform()!=NULL )
143                         {
144                                 newActor->SetUserTransform( bbGetInputTransform() );
145                         }
146         
147
148                         if (bbGetInputRenderer()!=NULL)
149                         {
150                             bbGetInputRenderer() -> AddActor( newActor );
151                         }
152
153                     } // for
154
155                     if (sphereActor.size() != 0)
156                     {
157                         // Sets the output.
158                         bbSetOutputActorList(sphereActor);
159                     }
160                     
161                 } // if (bbGetInputRenderer()!=NULL)
162
163         } // if (sphereActor.size() != 0)
164 }
165
166 void SphereList::bbUserSetDefaultValues()
167 {
168  
169   bbSetInputRenderer(NULL);
170   bbSetInputTransform(NULL);
171  
172   // Sets default radio to 1.
173   std::vector<double> radio;
174   radio.push_back(1.0);
175   bbSetInputlstRadio(radio);
176
177   // Sets default colour to red.
178   std::vector<double> colour;
179   colour.push_back(1.0);
180   colour.push_back(0.0);
181   colour.push_back(0.0);
182   bbSetInputColour(colour);
183         
184         // Sets default spacing.
185         std::vector<double> spacing;
186         spacing.push_back(1.0);
187         spacing.push_back(1.0);
188         spacing.push_back(1.0);
189         bbSetInputSpacing(spacing);
190         
191   bbSetInputOpacity(1.0);
192
193 }
194
195 void SphereList::bbUserInitializeProcessing()
196 {
197  
198 }
199
200 void SphereList::bbUserFinalizeProcessing()
201 {
202   
203 }
204 }
205 // EO namespace bbvtk
206
207