2 # ---------------------------------------------------------------------
4 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
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
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.
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
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 # ------------------------------------------------------------------------ */
28 #include "bbvtkSphereList.h"
29 #include "bbvtkPackage.h"
31 #include <vtkPolyDataMapper.h>
32 #include <vtkProperty.h>
33 #include <vtkRenderWindow.h>
38 BBTK_ADD_BLACK_BOX_TO_PACKAGE(vtk,SphereList)
39 BBTK_BLACK_BOX_IMPLEMENTATION(SphereList,bbtk::AtomicBlackBox);
41 double SphereList::GetRadio(int i)
44 if ( bbGetInputlstRadio().size()==0 )
47 } else if ( i<bbGetInputlstRadio().size() )
49 radio = bbGetInputlstRadio()[i];
51 radio = bbGetInputlstRadio()[ bbGetInputlstRadio().size() - 1 ];
57 void SphereList::GetPoint(int i, double &px,double &py,double &pz)
60 if (bbGetInputSpacing().size()==3)
62 spc[0]=bbGetInputSpacing()[0];
63 spc[1]=bbGetInputSpacing()[1];
64 spc[2]=bbGetInputSpacing()[2];
66 spc[0]=spc[1]=spc[2]=1;
69 px = bbGetInputlstPointX()[i]*spc[0];
70 if (bbGetInputlstPointY().size() == bbGetInputlstPointX().size() )
72 py = bbGetInputlstPointY()[i]*spc[1];
74 if (bbGetInputlstPointZ().size() == bbGetInputlstPointX().size() )
76 pz = bbGetInputlstPointZ()[i]*spc[2];
81 void SphereList::GetColor(int i, double &cr,double &cg,double &cb)
83 unsigned int j = 3*i +2;
84 if (j < bbGetInputColour().size() )
86 cr=bbGetInputColour()[3*i+0];
87 cg=bbGetInputColour()[3*i+1];
88 cb=bbGetInputColour()[3*i+2];
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 ];
99 void SphereList::Process()
102 if (bbGetInputRenderer()!=NULL)
104 int sizeLstX = bbGetInputlstPointX().size();
105 int sizeLstY = bbGetInputlstPointY().size();
106 int sizeLstZ = bbGetInputlstPointZ().size();
107 int sizeLstActors = sphereActor.size();
108 if ((sizeLstX==sizeLstY) &&(sizeLstX==sizeLstZ))
111 if (sizeLstActors>sizeLstX)
113 diff=sizeLstActors-sizeLstX;
116 bbGetInputRenderer()->RemoveActor( sphereActor[0] );
117 vtkspheresourceLst[0]->Delete();
118 sphereActor[0]->Delete();
119 vtkspheresourceLst.erase( vtkspheresourceLst.begin() );
120 sphereActor.erase( sphereActor.begin() );
124 if (sizeLstActors<sizeLstX)
126 diff=sizeLstX-sizeLstActors;
130 vtkSphereSource * newSphere = vtkSphereSource::New();
131 vtkspheresourceLst.push_back(newSphere);
132 newSphere -> SetThetaResolution(20);
133 newSphere -> SetPhiResolution(20);
134 newSphere -> SetRadius( 1 );
135 vtkPolyDataMapper * newMapper = vtkPolyDataMapper::New();
137 //EED 2017-01-01 Migration VTK7
138 #if VTK_MAJOR_VERSION <= 5
139 newMapper -> SetInput( newSphere -> GetOutput() );
141 newSphere -> Update();
142 newMapper -> SetInputData( newSphere -> GetOutput() );
145 vtkActor * newActor = vtkActor::New();
146 sphereActor.push_back(newActor);
147 newActor -> SetMapper(newMapper);
148 newActor -> SetOrigin(0, 0, 0);
149 if ( bbGetInputTransform()!=NULL )
151 newActor->SetUserTransform( bbGetInputTransform() );
153 bbGetInputRenderer()->AddActor( newActor );
158 for (i = 0; i < sphereActor.size() ; i++)
166 GetPoint(i, px,py,pz);
167 GetColor(i, cr,cg,cb);
168 sphereActor[i] ->SetPosition( px,py,pz );
169 sphereActor[i] -> GetProperty() -> SetOpacity( bbGetInputOpacity() );
170 sphereActor[i] -> GetProperty() -> SetColor( cr,cg,cb );
171 vtkspheresourceLst[i] -> SetRadius( GetRadio(i) );
172 vtkspheresourceLst[i] -> Update();
175 if (sphereActor.size() != 0)
178 bbSetOutputActorList(sphereActor);
182 printf("EED Warning! SphereList::Process Lst XYZ are not of the same size.\n");
185 printf("EED Warning! SphereList::Process Render not assigned.\n");
188 //====================================================================
191 if (bbGetInputRenderer()!=NULL)
193 int sizeLstX = bbGetInputlstPointX().size();
194 int sizeLstY = bbGetInputlstPointY().size();
195 int sizeLstZ = bbGetInputlstPointZ().size();
196 int sizeLstActors = sphereActor.size();
197 if ((sizeLstX==sizeLstY) &&(sizeLstX==sizeLstZ))
202 for ( i=0 ; i<sizeLstActors ; i++ )
204 bbGetInputRenderer()->RemoveActor( sphereActor[i] );
205 vtkspheresourceLst[i]->Delete();
206 vtkpolydatamaperLst[i]->Delete();
207 sphereActor[i]->Delete();
209 vtkspheresourceLst.clear();
210 vtkpolydatamaperLst.clear();
214 for (i=0;i<sizeLstX;i++)
217 vtkSphereSource * newSphere = vtkSphereSource::New();
218 vtkspheresourceLst.push_back(newSphere);
219 newSphere -> SetThetaResolution(20);
220 newSphere -> SetPhiResolution(20);
221 newSphere -> SetRadius( 1 );
222 vtkPolyDataMapper * newMapper = vtkPolyDataMapper::New();
223 vtkpolydatamaperLst.push_back(newMapper);
224 //EED 2017-01-01 Migration VTK7
225 #if VTK_MAJOR_VERSION <= 5
226 newMapper -> SetInput( newSphere -> GetOutput() );
228 newSphere -> Update();
229 newMapper -> SetInputData( newSphere -> GetOutput() );
232 vtkActor * newActor = vtkActor::New();
233 sphereActor.push_back(newActor);
234 newActor -> SetMapper(newMapper);
235 newActor -> SetOrigin(0, 0, 0);
236 if ( bbGetInputTransform()!=NULL )
238 newActor->SetUserTransform( bbGetInputTransform() );
240 bbGetInputRenderer()->AddActor( newActor );
245 for (i = 0; i < sphereActor.size() ; i++)
247 GetPoint(i, px,py,pz);
248 GetColor(i, cr,cg,cb);
249 sphereActor[i] ->SetPosition( px,py,pz );
250 sphereActor[i] -> GetProperty() -> SetOpacity( bbGetInputOpacity() );
251 sphereActor[i] -> GetProperty() -> SetColor( cr,cg,cb );
252 vtkspheresourceLst[i] -> SetRadius( GetRadio(i) );
253 vtkspheresourceLst[i] -> Update();
256 if (sphereActor.size() != 0)
259 bbSetOutputActorList(sphereActor);
262 } // sizeLstX sizeLstY sizeLstZ
267 void SphereList::bbUserSetDefaultValues()
270 bbSetInputRenderer(NULL);
271 bbSetInputTransform(NULL);
273 // Sets default radio to 1.
274 std::vector<double> radio;
275 radio.push_back(1.0);
276 bbSetInputlstRadio(radio);
278 // Sets default colour to red.
279 std::vector<double> colour;
280 colour.push_back(1.0);
281 colour.push_back(0.0);
282 colour.push_back(0.0);
283 bbSetInputColour(colour);
285 // Sets default spacing.
286 std::vector<double> spacing;
287 spacing.push_back(1.0);
288 spacing.push_back(1.0);
289 spacing.push_back(1.0);
290 bbSetInputSpacing(spacing);
292 bbSetInputOpacity(1.0);
296 void SphereList::bbUserInitializeProcessing()
301 void SphereList::bbUserFinalizeProcessing()
306 // EO namespace bbvtk