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()
101 printf("EED SphereList::Process Start\n");
103 if (bbGetInputRenderer()!=NULL)
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))
111 if (sizeLstActors>sizeLstX)
114 int diff=sizeLstActors-sizeLstX;
117 bbGetInputRenderer()->RemoveActor( sphereActor[0] );
118 vtkspheresourceLst[0]->Delete();
119 sphereActor[0]->Delete();
120 vtkspheresourceLst.erase( vtkspheresourceLst.begin() );
121 sphereActor.erase( sphereActor.begin() );
125 if (sizeLstActors<sizeLstX)
128 int diff=sizeLstX-sizeLstActors;
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();
139 //EED 2017-01-01 Migration VTK7
140 #if VTK_MAJOR_VERSION <= 5
141 newMapper -> SetInput( newSphere -> GetOutput() );
143 newSphere -> Update();
144 newMapper -> SetInputData( newSphere -> GetOutput() );
147 vtkActor * newActor = vtkActor::New();
148 sphereActor.push_back(newActor);
149 newActor -> SetMapper(newMapper);
150 newActor -> SetOrigin(0, 0, 0);
151 if ( bbGetInputTransform()!=NULL )
153 newActor->SetUserTransform( bbGetInputTransform() );
155 bbGetInputRenderer()->AddActor( newActor );
160 for (int i = 0; i < sphereActor.size() ; i++)
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();
177 if (sphereActor.size() != 0)
180 bbSetOutputActorList(sphereActor);
184 printf("EED Warning! SphereList::Process Lst XYZ are not of the same size.\n");
187 printf("EED Warning! SphereList::Process Render not assigned.\n");
190 //====================================================================
195 void SphereList::bbUserSetDefaultValues()
198 bbSetInputRenderer(NULL);
199 bbSetInputTransform(NULL);
201 // Sets default radio to 1.
202 std::vector<double> radio;
203 radio.push_back(1.0);
204 bbSetInputlstRadio(radio);
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);
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);
220 bbSetInputOpacity(1.0);
224 void SphereList::bbUserInitializeProcessing()
229 void SphereList::bbUserFinalizeProcessing()
234 // EO namespace bbvtk