1 /*# ---------------------------------------------------------------------
3 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
5 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
6 # Previous Authors : Laurent Guigues, Jean-Pierre Roux
7 # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
9 # This software is governed by the CeCILL-B license under French law and
10 # abiding by the rules of distribution of free software. You can use,
11 # modify and/ or redistribute the software under the terms of the CeCILL-B
12 # license as circulated by CEA, CNRS and INRIA at the following URL
13 # http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
14 # or in the file LICENSE.txt.
16 # As a counterpart to the access to the source code and rights to copy,
17 # modify and redistribute granted by the license, users are provided only
18 # with a limited warranty and the software's author, the holder of the
19 # economic rights, and the successive licensors have only limited
22 # The fact that you are presently reading this means that you have had
23 # knowledge of the CeCILL-B license and that you accept its terms.
24 # ------------------------------------------------------------------------ */
26 #include "bbmaracasvisuAnimationSphere.h"
27 #include "bbcreaMaracasVisuPackage.h"
30 #include <vtkPolyDataMapper.h>
31 #include <vtkProperty.h>
32 #include <vtkRenderWindow.h>
33 #include <vtkWindowToImageFilter.h>
34 #include <vtkPNGWriter.h>
38 namespace bbcreaMaracasVisu
41 BBTK_ADD_BLACK_BOX_TO_PACKAGE(creaMaracasVisu,AnimationSphere)
42 BBTK_BLACK_BOX_IMPLEMENTATION(AnimationSphere,bbtk::AtomicBlackBox);
45 void AnimationSphere::Process()
54 if (sphereActor==NULL)
57 vtksphere = vtkSphereSource::New();
58 vtksphere->SetThetaResolution (20);
59 vtksphere->SetPhiResolution (20);
60 vtksphere->SetRadius( 1 );
62 vtkPolyDataMapper *sphereMapper = vtkPolyDataMapper::New();
63 //EED 2017-01-01 Migration VTK7
64 #if VTK_MAJOR_VERSION <= 5
65 sphereMapper->SetInput( vtksphere->GetOutput() );
67 sphereMapper->SetInputData( vtksphere->GetOutput() );
70 sphereActor = vtkActor::New();
71 sphereActor->SetMapper(sphereMapper);
72 sphereActor->SetOrigin(0, 0, 0);
73 sphereActor->GetProperty()->SetColor( bbGetInputColour()[0] , bbGetInputColour()[1] , bbGetInputColour()[2] );
74 sphereActor->GetProperty()->SetOpacity( bbGetInputOpacity() );
76 bbGetInputRenderer()->RemoveActor( sphereActor );
80 if (bbGetInputRenderer()!=NULL)
82 bbGetInputRenderer()->AddActor( sphereActor );
86 if (bbGetInputRenderer()!=NULL)
88 spc[0]=spc[1]=spc[2]=1;
91 if ( (bbGetInputIndex()==0) ){
93 iMax=bbGetInputlstPointX().size();
95 else if ( bbGetInputIndex()<=(int)(bbGetInputlstIndexs().size()) )
99 size = bbGetInputIndex();
100 for (i=0;i<size; i++)
102 iMax = iMax + bbGetInputlstIndexs()[i];
104 iMin = iMin + bbGetInputlstIndexs()[i-1];
114 std::string newFileName;
117 for ( i=iMin ; i<iMax ; i=i+1 )
119 px = bbGetInputlstPointX()[i]*spc[0];
120 py = bbGetInputlstPointY()[i]*spc[1];
121 pz = bbGetInputlstPointZ()[i]*spc[2];
122 radio = bbGetInputlstRadio()[i];
123 sphereActor->SetPosition( px,py,pz );
124 vtksphere->SetRadius( radio );
125 if ( bbGetInputTransform()!=NULL )
127 sphereActor->SetUserTransform( bbGetInputTransform() );
131 bbGetInputRenderer()->Render();
132 bbGetInputRenderer()->GetRenderWindow()->Render();
134 if (i%bbGetInputStep()==0)
137 std::stringstream strId;
139 std::string strtmp1 =strId.str();
140 std::string strtmp2 = "00000";
141 for (int iStr = 0; iStr<(int)(strtmp1.length()) ; iStr++ )
143 strtmp2[ strtmp2.length()-1-iStr ] = strtmp1[ strtmp1.length()-1-iStr ];
145 newFileName = "c:/temp/image"+strtmp2+".png";
147 vtkWindowToImageFilter *w2i;
149 w2i = vtkWindowToImageFilter::New();
150 png = vtkPNGWriter::New();
151 w2i->SetInput( bbGetInputRenderer()->GetRenderWindow() );
153 //EED 2017-01-01 Migration VTK7
154 #if VTK_MAJOR_VERSION <= 5
155 png->SetInput( w2i->GetOutput() );
157 png->SetInputData( w2i->GetOutput() );
160 png->SetFileName( newFileName.c_str() );
166 } // if (bbGetInputRenderer()
170 void AnimationSphere::bbUserSetDefaultValues()
174 bbSetInputRenderer(NULL);
176 std::vector<double> colour;
177 colour.push_back(1.0);
178 colour.push_back(0.0);
179 colour.push_back(0.0);
180 bbSetInputColour(colour);
182 bbSetInputOpacity(1);
184 std::vector<int> lstInd;
186 std::vector<double> lstX;
187 std::vector<double> lstY;
188 std::vector<double> lstZ;
189 std::vector<double> lstR;
191 bbSetInputTransform(NULL);
197 //-----------------------------------------------------------------
198 void AnimationSphere::bbUserInitializeProcessing()
202 //-----------------------------------------------------------------
203 void AnimationSphere::bbUserFinalizeProcessing()
207 //-----------------------------------------------------------------
210 // EO namespace bbcreaMaracasVisu