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];
83 void SphereList::GetColor(int i, double &cr,double &cg,double &cb)
85 unsigned int j = 3*i +2;
86 if (j < bbGetInputColour().size() )
88 cr=bbGetInputColour()[3*i+0];
89 cg=bbGetInputColour()[3*i+1];
90 cb=bbGetInputColour()[3*i+2];
93 int lastValidColorIndex = (bbGetInputColour().size()-1)/3;
94 lastValidColorIndex = lastValidColorIndex*3;
95 cr=bbGetInputColour()[ lastValidColorIndex+0 ];
96 cg=bbGetInputColour()[ lastValidColorIndex+1 ];
97 cb=bbGetInputColour()[ lastValidColorIndex+2 ];
101 void SphereList::Process()
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 newMapper -> SetInputData( newSphere -> GetOutput() );
146 vtkActor * newActor = vtkActor::New();
147 sphereActor.push_back(newActor);
148 newActor -> SetMapper(newMapper);
149 newActor -> SetOrigin(0, 0, 0);
150 if ( bbGetInputTransform()!=NULL )
152 newActor->SetUserTransform( bbGetInputTransform() );
154 bbGetInputRenderer()->AddActor( newActor );
159 for (int i = 0; i < sphereActor.size() ; i++)
167 GetPoint(i, px,py,pz);
168 GetColor(i, cr,cg,cb);
169 sphereActor[i] ->SetPosition( px,py,pz );
170 sphereActor[i] -> GetProperty() -> SetOpacity( bbGetInputOpacity() );
171 sphereActor[i] -> GetProperty() -> SetColor( cr,cg,cb );
172 vtkspheresourceLst[i] -> SetRadius( GetRadio(i) );
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 //====================================================================
193 void SphereList::bbUserSetDefaultValues()
196 bbSetInputRenderer(NULL);
197 bbSetInputTransform(NULL);
199 // Sets default radio to 1.
200 std::vector<double> radio;
201 radio.push_back(1.0);
202 bbSetInputlstRadio(radio);
204 // Sets default colour to red.
205 std::vector<double> colour;
206 colour.push_back(1.0);
207 colour.push_back(0.0);
208 colour.push_back(0.0);
209 bbSetInputColour(colour);
211 // Sets default spacing.
212 std::vector<double> spacing;
213 spacing.push_back(1.0);
214 spacing.push_back(1.0);
215 spacing.push_back(1.0);
216 bbSetInputSpacing(spacing);
218 bbSetInputOpacity(1.0);
222 void SphereList::bbUserInitializeProcessing()
227 void SphereList::bbUserFinalizeProcessing()
232 // EO namespace bbvtk