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 sphereMapper->SetInput( vtksphere->GetOutput() );
65 sphereActor = vtkActor::New();
66 sphereActor->SetMapper(sphereMapper);
67 sphereActor->SetOrigin(0, 0, 0);
68 sphereActor->GetProperty()->SetColor( bbGetInputColour()[0] , bbGetInputColour()[1] , bbGetInputColour()[2] );
69 sphereActor->GetProperty()->SetOpacity( bbGetInputOpacity() );
71 bbGetInputRenderer()->RemoveActor( sphereActor );
75 if (bbGetInputRenderer()!=NULL)
77 bbGetInputRenderer()->AddActor( sphereActor );
81 if (bbGetInputRenderer()!=NULL)
83 spc[0]=spc[1]=spc[2]=1;
86 if ( (bbGetInputIndex()==0) ){
88 iMax=bbGetInputlstPointX().size();
90 else if ( bbGetInputIndex()<=(int)(bbGetInputlstIndexs().size()) )
94 size = bbGetInputIndex();
97 iMax = iMax + bbGetInputlstIndexs()[i];
99 iMin = iMin + bbGetInputlstIndexs()[i-1];
109 std::string newFileName;
112 for ( i=iMin ; i<iMax ; i=i+1 )
114 px = bbGetInputlstPointX()[i]*spc[0];
115 py = bbGetInputlstPointY()[i]*spc[1];
116 pz = bbGetInputlstPointZ()[i]*spc[2];
117 radio = bbGetInputlstRadio()[i];
118 sphereActor->SetPosition( px,py,pz );
119 vtksphere->SetRadius( radio );
120 if ( bbGetInputTransform()!=NULL )
122 sphereActor->SetUserTransform( bbGetInputTransform() );
126 bbGetInputRenderer()->Render();
127 bbGetInputRenderer()->GetRenderWindow()->Render();
129 if (i%bbGetInputStep()==0)
132 std::stringstream strId;
134 std::string strtmp1 =strId.str();
135 std::string strtmp2 = "00000";
136 for (int iStr = 0; iStr<(int)(strtmp1.length()) ; iStr++ )
138 strtmp2[ strtmp2.length()-1-iStr ] = strtmp1[ strtmp1.length()-1-iStr ];
140 newFileName = "c:/temp/image"+strtmp2+".png";
142 vtkWindowToImageFilter *w2i;
144 w2i = vtkWindowToImageFilter::New();
145 png = vtkPNGWriter::New();
146 w2i->SetInput( bbGetInputRenderer()->GetRenderWindow() );
147 png->SetInput( w2i->GetOutput() );
148 png->SetFileName( newFileName.c_str() );
154 } // if (bbGetInputRenderer()
158 void AnimationSphere::bbUserSetDefaultValues()
162 bbSetInputRenderer(NULL);
164 std::vector<double> colour;
165 colour.push_back(1.0);
166 colour.push_back(0.0);
167 colour.push_back(0.0);
168 bbSetInputColour(colour);
170 bbSetInputOpacity(1);
172 std::vector<int> lstInd;
174 std::vector<double> lstX;
175 std::vector<double> lstY;
176 std::vector<double> lstZ;
177 std::vector<double> lstR;
179 bbSetInputTransform(NULL);
185 //-----------------------------------------------------------------
186 void AnimationSphere::bbUserInitializeProcessing()
190 //-----------------------------------------------------------------
191 void AnimationSphere::bbUserFinalizeProcessing()
195 //-----------------------------------------------------------------
198 // EO namespace bbcreaMaracasVisu