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 void SphereList::Process()
51 int last_valid_color_index = 0;
54 if (bbGetInputRenderer()!=NULL)
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)
59 for (int i = 0; i < sphereActor.size(); i++)
60 sphereActor[i] -> GetProperty() -> SetOpacity( bbGetInputOpacity() );
64 if (bbGetInputSpacing().size()==3)
66 spc[0]=bbGetInputSpacing()[0];
67 spc[1]=bbGetInputSpacing()[1];
68 spc[2]=bbGetInputSpacing()[2];
72 spc[0]=spc[1]=spc[2]=1;
76 iMax=bbGetInputlstPointX().size();
77 printf("EED SphereList::Process iMax=%d \n", iMax);
78 for (int i = 0; i < iMax; i++)
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;
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 )
87 px = bbGetInputlstPointX()[i]*spc[0];
88 if (bbGetInputlstPointY().size() == bbGetInputlstPointX().size() )
90 py = bbGetInputlstPointY()[i]*spc[1];
92 if (bbGetInputlstPointZ().size() == bbGetInputlstPointX().size() )
94 pz = bbGetInputlstPointZ()[i]*spc[2];
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() )
100 radio = bbGetInputlstRadio()[i];
104 if (bbGetInputlstRadio().size()>=1)
106 radio = bbGetInputlstRadio()[ bbGetInputlstRadio().size() - 1 ];
115 vtkSphereSource * newSphere = vtkSphereSource::New();
117 newSphere -> SetThetaResolution(20);
118 newSphere -> SetPhiResolution(20);
119 newSphere -> SetRadius(radio);
121 vtkPolyDataMapper * newMapper = vtkPolyDataMapper::New();
122 newMapper -> SetInput( newSphere -> GetOutput() );
124 vtkActor * newActor = vtkActor::New();
125 sphereActor.push_back(newActor);
126 newActor -> SetMapper(newMapper);
127 newActor -> SetOrigin(0, 0, 0);
129 unsigned int j = 3*i +2;
130 if (j < bbGetInputColour().size() )
132 newActor -> GetProperty() -> SetColor( bbGetInputColour()[3*i] , bbGetInputColour()[3*i + 1] , bbGetInputColour()[3*i + 2] );
133 last_valid_color_index = 3*i;
136 newActor -> GetProperty() -> SetColor( bbGetInputColour()[last_valid_color_index] , bbGetInputColour()[last_valid_color_index + 1] , bbGetInputColour()[last_valid_color_index + 2] );
138 newActor -> GetProperty() -> SetOpacity( bbGetInputOpacity() );
139 newActor -> SetPosition( px,py,pz );
141 if ( bbGetInputTransform()!=NULL )
143 newActor->SetUserTransform( bbGetInputTransform() );
147 if (bbGetInputRenderer()!=NULL)
149 bbGetInputRenderer() -> AddActor( newActor );
154 if (sphereActor.size() != 0)
157 bbSetOutputActorList(sphereActor);
160 } // if (bbGetInputRenderer()!=NULL)
162 } // if (sphereActor.size() != 0)
165 void SphereList::bbUserSetDefaultValues()
168 bbSetInputRenderer(NULL);
169 bbSetInputTransform(NULL);
171 // Sets default radio to 1.
172 std::vector<double> radio;
173 radio.push_back(1.0);
174 bbSetInputlstRadio(radio);
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);
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);
190 bbSetInputOpacity(1.0);
194 void SphereList::bbUserInitializeProcessing()
199 void SphereList::bbUserFinalizeProcessing()
204 // EO namespace bbvtk