1 #include "bbmaracasvisuAnimationSphere.h"
2 #include "bbcreaMaracasVisuPackage.h"
5 #include <vtkPolyDataMapper.h>
6 #include <vtkProperty.h>
7 #include <vtkRenderWindow.h>
8 #include <vtkWindowToImageFilter.h>
9 #include <vtkPNGWriter.h>
13 namespace bbcreaMaracasVisu
16 BBTK_ADD_BLACK_BOX_TO_PACKAGE(creaMaracasVisu,AnimationSphere)
17 BBTK_BLACK_BOX_IMPLEMENTATION(AnimationSphere,bbtk::AtomicBlackBox);
20 void AnimationSphere::Process()
29 if (sphereActor==NULL)
32 vtksphere = vtkSphereSource::New();
33 vtksphere->SetThetaResolution (20);
34 vtksphere->SetPhiResolution (20);
35 vtksphere->SetRadius( 1 );
37 vtkPolyDataMapper *sphereMapper = vtkPolyDataMapper::New();
38 sphereMapper->SetInput( vtksphere->GetOutput() );
40 sphereActor = vtkActor::New();
41 sphereActor->SetMapper(sphereMapper);
42 sphereActor->SetOrigin(0, 0, 0);
43 sphereActor->GetProperty()->SetColor( bbGetInputColour()[0] , bbGetInputColour()[1] , bbGetInputColour()[2] );
44 sphereActor->GetProperty()->SetOpacity( bbGetInputOpacity() );
46 bbGetInputRenderer()->RemoveActor( sphereActor );
50 if (bbGetInputRenderer()!=NULL)
52 bbGetInputRenderer()->AddActor( sphereActor );
56 if (bbGetInputRenderer()!=NULL)
58 spc[0]=spc[1]=spc[2]=1;
61 if ( (bbGetInputIndex()==0) ){
63 iMax=bbGetInputlstPointX().size();
65 else if ( bbGetInputIndex()<=(int)(bbGetInputlstIndexs().size()) )
69 size = bbGetInputIndex();
72 iMax = iMax + bbGetInputlstIndexs()[i];
74 iMin = iMin + bbGetInputlstIndexs()[i-1];
84 std::string newFileName;
87 for ( i=iMin ; i<iMax ; i=i+1 )
89 px = bbGetInputlstPointX()[i]*spc[0];
90 py = bbGetInputlstPointY()[i]*spc[1];
91 pz = bbGetInputlstPointZ()[i]*spc[2];
92 radio = bbGetInputlstRadio()[i];
93 sphereActor->SetPosition( px,py,pz );
94 vtksphere->SetRadius( radio );
95 if ( bbGetInputTransform()!=NULL )
97 sphereActor->SetUserTransform( bbGetInputTransform() );
101 bbGetInputRenderer()->Render();
102 bbGetInputRenderer()->GetRenderWindow()->Render();
104 if (i%bbGetInputStep()==0)
107 std::stringstream strId;
109 std::string strtmp1 =strId.str();
110 std::string strtmp2 = "00000";
111 for (int iStr = 0; iStr<(int)(strtmp1.length()) ; iStr++ )
113 strtmp2[ strtmp2.length()-1-iStr ] = strtmp1[ strtmp1.length()-1-iStr ];
115 newFileName = "c:/temp/image"+strtmp2+".png";
117 vtkWindowToImageFilter *w2i;
119 w2i = vtkWindowToImageFilter::New();
120 png = vtkPNGWriter::New();
121 w2i->SetInput( bbGetInputRenderer()->GetRenderWindow() );
122 png->SetInput( w2i->GetOutput() );
123 png->SetFileName( newFileName.c_str() );
129 } // if (bbGetInputRenderer()
133 void AnimationSphere::bbUserSetDefaultValues()
137 bbSetInputRenderer(NULL);
139 std::vector<double> colour;
140 colour.push_back(1.0);
141 colour.push_back(0.0);
142 colour.push_back(0.0);
143 bbSetInputColour(colour);
145 bbSetInputOpacity(1);
147 std::vector<int> lstInd;
149 std::vector<double> lstX;
150 std::vector<double> lstY;
151 std::vector<double> lstZ;
152 std::vector<double> lstR;
154 bbSetInputTransform(NULL);
160 //-----------------------------------------------------------------
161 void AnimationSphere::bbUserInitializeProcessing()
165 //-----------------------------------------------------------------
166 void AnimationSphere::bbUserFinalizeProcessing()
170 //-----------------------------------------------------------------
173 // EO namespace bbcreaMaracasVisu