]> Creatis software - bbtk.git/blob - packages/vtk/src/bbvtkSphereList.cxx
#3107 BBTK Bug New Normal - branch vtk7itk4 compilation with vtk7
[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 ( i<bbGetInputlstRadio().size() )
48         {
49                 radio = bbGetInputlstRadio()[i];
50         } else {
51         radio = bbGetInputlstRadio()[ bbGetInputlstRadio().size() - 1 ];
52     }  
53         return radio;
54 }
55
56
57 void SphereList::GetPoint(int i, double &px,double &py,double &pz)        
58  {
59       double spc[3];
60       if (bbGetInputSpacing().size()==3)
61       {
62                 spc[0]=bbGetInputSpacing()[0];
63                 spc[1]=bbGetInputSpacing()[1];
64                 spc[2]=bbGetInputSpacing()[2];
65       } else {
66                 spc[0]=spc[1]=spc[2]=1;
67        }
68
69        px = bbGetInputlstPointX()[i]*spc[0];
70        if (bbGetInputlstPointY().size() == bbGetInputlstPointX().size() )
71        {
72                 py = bbGetInputlstPointY()[i]*spc[1];
73         }
74                 if (bbGetInputlstPointZ().size() == bbGetInputlstPointX().size() )
75         {                       
76                 pz = bbGetInputlstPointZ()[i]*spc[2];
77         }
78 }  
79
80                         
81 void SphereList::GetColor(int i, double &cr,double &cg,double &cb)        
82  {
83         unsigned int j = 3*i +2;
84         if (j < bbGetInputColour().size() )
85         {
86                 cr=bbGetInputColour()[3*i+0];
87                 cg=bbGetInputColour()[3*i+1];
88                 cb=bbGetInputColour()[3*i+2];
89                 
90         } else {
91                 int lastValidColorIndex = (bbGetInputColour().size()-1)/3;
92                 lastValidColorIndex     = lastValidColorIndex*3;
93                 cr=bbGetInputColour()[ lastValidColorIndex+0 ];
94                 cg=bbGetInputColour()[ lastValidColorIndex+1 ];
95                 cb=bbGetInputColour()[ lastValidColorIndex+2 ];
96         }
97 }  
98
99 void SphereList::Process()
100 {
101 printf("EED SphereList::Process Start\n");
102
103         if (bbGetInputRenderer()!=NULL)
104         {
105                 int sizeLstX=bbGetInputlstPointX().size();      
106                 int sizeLstY=bbGetInputlstPointY().size();
107                 int sizeLstZ=bbGetInputlstPointZ().size();
108                 int sizeLstActors=sphereActor.size();
109                 if ((sizeLstX==sizeLstY) &&(sizeLstX==sizeLstZ))
110                 {
111                         if (sizeLstActors>sizeLstX)
112                         {
113                                 int i;
114                                 int diff=sizeLstActors-sizeLstX;
115                                 for (i=0;i<diff;i++)
116                                 {
117                                         bbGetInputRenderer()->RemoveActor( sphereActor[0] );
118                                         vtkspheresourceLst[0]->Delete();
119                                         sphereActor[0]->Delete();
120                                         vtkspheresourceLst.erase( vtkspheresourceLst.begin() );
121                                         sphereActor.erase( sphereActor.begin() );
122                                 } // for 
123                         } // if size
124
125                         if (sizeLstActors<sizeLstX)
126                         {
127                                 int i;
128                                 int diff=sizeLstX-sizeLstActors;
129                                 for (i=0;i<diff;i++)
130                                 {
131                                         // Sphere
132                                         vtkSphereSource * newSphere = vtkSphereSource::New();
133                                         vtkspheresourceLst.push_back(newSphere);
134                                         newSphere -> SetThetaResolution(20);
135                                         newSphere -> SetPhiResolution(20);
136                                         newSphere -> SetRadius( 1 ); 
137                                         vtkPolyDataMapper * newMapper = vtkPolyDataMapper::New();
138
139 //EED 2017-01-01 Migration VTK7
140 #if VTK_MAJOR_VERSION <= 5
141                                         newMapper -> SetInput( newSphere -> GetOutput() );      
142 #else
143                                         newSphere -> Update();
144                                         newMapper -> SetInputData( newSphere -> GetOutput() );  
145 #endif
146
147                                         vtkActor * newActor = vtkActor::New();
148                                         sphereActor.push_back(newActor);
149                                         newActor -> SetMapper(newMapper);
150                                         newActor -> SetOrigin(0, 0, 0);                         
151                                         if ( bbGetInputTransform()!=NULL )
152                                         {
153                                                 newActor->SetUserTransform( bbGetInputTransform() );
154                                         }
155                                         bbGetInputRenderer()->AddActor( newActor );
156                                 } // for
157                         } // if size
158
159                         // Refresh data
160                 for (int i = 0; i < sphereActor.size() ; i++)
161                 {
162                                 double px = 0.0;
163                                 double py = 0.0;
164                                 double pz = 0.0;
165                                 double cr = 0.0;
166                                 double cg = 0.0;
167                                 double cb = 0.0;
168                                 GetPoint(i, px,py,pz);
169                                 GetColor(i, cr,cg,cb);
170                                 sphereActor[i] ->SetPosition( px,py,pz );
171                 sphereActor[i] -> GetProperty() -> SetOpacity( bbGetInputOpacity() );
172                 sphereActor[i] -> GetProperty() -> SetColor( cr,cg,cb );
173                 vtkspheresourceLst[i] -> SetRadius( GetRadio(i) ); 
174                         vtkspheresourceLst[i] -> Update();
175                 } // for i
176
177                 if (sphereActor.size() != 0)
178             {
179                 // Sets the output.
180                 bbSetOutputActorList(sphereActor);
181                 }
182   
183                 } else {
184                         printf("EED Warning!  SphereList::Process Lst XYZ are not of the same size.\n");
185                 }// if sizeLst
186         } else {
187                         printf("EED Warning!  SphereList::Process Render not assigned.\n");             
188         }// if Renderer
189
190 //====================================================================
191
192 }
193
194
195 void SphereList::bbUserSetDefaultValues()
196 {
197  
198   bbSetInputRenderer(NULL);
199   bbSetInputTransform(NULL);
200  
201   // Sets default radio to 1.
202   std::vector<double> radio;
203   radio.push_back(1.0);
204   bbSetInputlstRadio(radio);
205
206   // Sets default colour to red.
207   std::vector<double> colour;
208   colour.push_back(1.0);
209   colour.push_back(0.0);
210   colour.push_back(0.0);
211   bbSetInputColour(colour);
212         
213         // Sets default spacing.
214         std::vector<double> spacing;
215         spacing.push_back(1.0);
216         spacing.push_back(1.0);
217         spacing.push_back(1.0);
218         bbSetInputSpacing(spacing);
219         
220   bbSetInputOpacity(1.0);
221
222 }
223
224 void SphereList::bbUserInitializeProcessing()
225 {
226  
227 }
228
229 void SphereList::bbUserFinalizeProcessing()
230 {
231   
232 }
233 }
234 // EO namespace bbvtk
235
236