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];
52 radio = bbGetInputlstRadio()[ bbGetInputlstRadio().size() - 1 ];
59 void SphereList::GetPoint(int i, double &px,double &py,double &pz)
62 if (bbGetInputSpacing().size()==3)
64 spc[0]=bbGetInputSpacing()[0];
65 spc[1]=bbGetInputSpacing()[1];
66 spc[2]=bbGetInputSpacing()[2];
68 spc[0]=spc[1]=spc[2]=1;
71 px = bbGetInputlstPointX()[i]*spc[0];
72 if (bbGetInputlstPointY().size() == bbGetInputlstPointX().size() )
74 py = bbGetInputlstPointY()[i]*spc[1];
76 if (bbGetInputlstPointZ().size() == bbGetInputlstPointX().size() )
78 pz = bbGetInputlstPointZ()[i]*spc[2];
80 printf("EED SphereList::GetPoint() %f %f %f\n",px,py,pz);
84 void SphereList::GetColor(int i, double &cr,double &cg,double &cb)
86 unsigned int j = 3*i +2;
87 if (j < bbGetInputColour().size() )
89 cr=bbGetInputColour()[3*i+0];
90 cg=bbGetInputColour()[3*i+1];
91 cb=bbGetInputColour()[3*i+2];
94 int lastValidColorIndex = (bbGetInputColour().size()-1)/3;
95 lastValidColorIndex = lastValidColorIndex*3;
96 cr=bbGetInputColour()[ lastValidColorIndex+0 ];
97 cg=bbGetInputColour()[ lastValidColorIndex+1 ];
98 cb=bbGetInputColour()[ lastValidColorIndex+2 ];
104 void SphereList::Process()
116 if (bbGetInputRenderer()!=NULL)
118 // 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.
119 if (sphereActor.size() != 0)
121 for (int i = 0; i < sphereActor.size(); i++)
123 GetPoint(i, px,py,pz);
124 GetColor(i, cr,cg,cb);
125 sphereActor[i] ->SetPosition( px,py,pz );
126 printf("EED SphereList::Process() %f %f %f\n",px,py,pz);
127 sphereActor[i] -> GetProperty() -> SetOpacity( bbGetInputOpacity() );
128 sphereActor[i] -> GetProperty() -> SetColor( cr,cg,cb );
129 vtkspheresourceLst[i] -> SetRadius( GetRadio(i) );
133 iMax=bbGetInputlstPointX().size();
134 // printf("EED SphereList::Process iMax=%d \n", iMax);
135 // for (int i = 0; i < iMax; i++)
137 // std::cout << "CM SphereList::Process i=" << i << " bbGetInputlstPointX()[i]=" << bbGetInputlstPointX()[i] << std::endl;
138 // std::cout << "CM SphereList::Process i=" << i << " bbGetInputlstPointY()[i]=" << bbGetInputlstPointY()[i] << std::endl;
139 // std::cout << "CM SphereList::Process i=" << i << " bbGetInputlstPointZ()[i]=" << bbGetInputlstPointZ()[i] << std::endl;
142 // 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.
143 for ( int i=iMin ; i<iMax; i=i+1 )
145 GetPoint(i, px,py,pz);
146 GetColor(i, cr,cg,cb);
148 vtkSphereSource * newSphere = vtkSphereSource::New();
149 vtkspheresourceLst.push_back(newSphere);
151 newSphere -> SetThetaResolution(20);
152 newSphere -> SetPhiResolution(20);
153 newSphere -> SetRadius( GetRadio(i) );
155 vtkPolyDataMapper * newMapper = vtkPolyDataMapper::New();
156 newMapper -> SetInput( newSphere -> GetOutput() );
158 vtkActor * newActor = vtkActor::New();
159 sphereActor.push_back(newActor);
160 newActor -> SetMapper(newMapper);
161 newActor -> SetOrigin(0, 0, 0);
162 newActor -> GetProperty() -> SetColor(cr,cg,cb);
163 newActor -> GetProperty() -> SetOpacity( bbGetInputOpacity() );
164 newActor -> SetPosition( px,py,pz );
166 if ( bbGetInputTransform()!=NULL )
168 newActor->SetUserTransform( bbGetInputTransform() );
171 if (bbGetInputRenderer()!=NULL)
173 bbGetInputRenderer() -> AddActor( newActor );
178 if (sphereActor.size() != 0)
181 bbSetOutputActorList(sphereActor);
184 } // if (sphereActor.size() != 0)
185 } // if (bbGetInputRenderer()!=NULL)
189 void SphereList::bbUserSetDefaultValues()
192 bbSetInputRenderer(NULL);
193 bbSetInputTransform(NULL);
195 // Sets default radio to 1.
196 std::vector<double> radio;
197 radio.push_back(1.0);
198 bbSetInputlstRadio(radio);
200 // Sets default colour to red.
201 std::vector<double> colour;
202 colour.push_back(1.0);
203 colour.push_back(0.0);
204 colour.push_back(0.0);
205 bbSetInputColour(colour);
207 // Sets default spacing.
208 std::vector<double> spacing;
209 spacing.push_back(1.0);
210 spacing.push_back(1.0);
211 spacing.push_back(1.0);
212 bbSetInputSpacing(spacing);
214 bbSetInputOpacity(1.0);
218 void SphereList::bbUserInitializeProcessing()
223 void SphereList::bbUserFinalizeProcessing()
228 // EO namespace bbvtk