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 // 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 )
88 px = bbGetInputlstPointX()[i]*spc[0];
89 if (bbGetInputlstPointY().size() == bbGetInputlstPointX().size() )
91 py = bbGetInputlstPointY()[i]*spc[1];
93 if (bbGetInputlstPointZ().size() == bbGetInputlstPointX().size() )
95 pz = bbGetInputlstPointZ()[i]*spc[2];
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() )
101 radio = bbGetInputlstRadio()[i];
105 if (bbGetInputlstRadio().size()>=1)
107 radio = bbGetInputlstRadio()[ bbGetInputlstRadio().size() - 1 ];
116 vtkSphereSource * newSphere = vtkSphereSource::New();
118 newSphere -> SetThetaResolution(20);
119 newSphere -> SetPhiResolution(20);
120 newSphere -> SetRadius(radio);
122 vtkPolyDataMapper * newMapper = vtkPolyDataMapper::New();
123 newMapper -> SetInput( newSphere -> GetOutput() );
125 vtkActor * newActor = vtkActor::New();
126 sphereActor.push_back(newActor);
127 newActor -> SetMapper(newMapper);
128 newActor -> SetOrigin(0, 0, 0);
130 unsigned int j = 3*i +2;
131 if (j < bbGetInputColour().size() )
133 newActor -> GetProperty() -> SetColor( bbGetInputColour()[3*i] , bbGetInputColour()[3*i + 1] , bbGetInputColour()[3*i + 2] );
134 last_valid_color_index = 3*i;
137 newActor -> GetProperty() -> SetColor( bbGetInputColour()[last_valid_color_index] , bbGetInputColour()[last_valid_color_index + 1] , bbGetInputColour()[last_valid_color_index + 2] );
139 newActor -> GetProperty() -> SetOpacity( bbGetInputOpacity() );
140 newActor -> SetPosition( px,py,pz );
142 if ( bbGetInputTransform()!=NULL )
144 newActor->SetUserTransform( bbGetInputTransform() );
148 if (bbGetInputRenderer()!=NULL)
150 bbGetInputRenderer() -> AddActor( newActor );
155 if (sphereActor.size() != 0)
158 bbSetOutputActorList(sphereActor);
161 } // if (bbGetInputRenderer()!=NULL)
163 } // if (sphereActor.size() != 0)
166 void SphereList::bbUserSetDefaultValues()
169 bbSetInputRenderer(NULL);
170 bbSetInputTransform(NULL);
172 // Sets default radio to 1.
173 std::vector<double> radio;
174 radio.push_back(1.0);
175 bbSetInputlstRadio(radio);
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);
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);
191 bbSetInputOpacity(1.0);
195 void SphereList::bbUserInitializeProcessing()
200 void SphereList::bbUserFinalizeProcessing()
205 // EO namespace bbvtk