]> Creatis software - creaMaracasVisu.git/blob - bbtk/src/bbmaracasvisuAnimationSphere.cxx
e3555c2366abe9f8bd3ba8500b3c491cef6b8a45
[creaMaracasVisu.git] / bbtk / src / bbmaracasvisuAnimationSphere.cxx
1 #include "bbmaracasvisuAnimationSphere.h"
2 #include "bbcreaMaracasVisuPackage.h"
3
4
5 #include <vtkPolyDataMapper.h>
6 #include <vtkProperty.h>
7 #include <vtkRenderWindow.h>
8 #include <vtkWindowToImageFilter.h>
9 #include <vtkPNGWriter.h>
10
11
12
13 namespace bbcreaMaracasVisu
14 {
15
16 BBTK_ADD_BLACK_BOX_TO_PACKAGE(creaMaracasVisu,AnimationSphere)
17 BBTK_BLACK_BOX_IMPLEMENTATION(AnimationSphere,bbtk::AtomicBlackBox);
18
19
20 void AnimationSphere::Process()
21 {
22         int iMin,iMax;
23         double px;
24         double py;
25         double pz;
26         double radio;
27         double spc[3];
28   
29         if (sphereActor==NULL)
30         {
31                 // Sphere
32                 vtksphere               = vtkSphereSource::New();
33                         vtksphere->SetThetaResolution (20);
34                         vtksphere->SetPhiResolution (20);
35                         vtksphere->SetRadius( 1  ); 
36
37                 vtkPolyDataMapper       *sphereMapper   = vtkPolyDataMapper::New();
38                         sphereMapper->SetInput( vtksphere->GetOutput() );
39
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() );
45         } else {
46                 bbGetInputRenderer()->RemoveActor( sphereActor );
47         }// if (sphereActor
48
49
50         if (bbGetInputRenderer()!=NULL)
51         {
52                 bbGetInputRenderer()->AddActor( sphereActor );
53         } // if
54
55
56         if (bbGetInputRenderer()!=NULL)
57         {
58                 spc[0]=spc[1]=spc[2]=1;
59                 int i,size;
60
61                 if ( (bbGetInputIndex()==0) ){
62                         iMin=0;
63                         iMax=bbGetInputlstPointX().size();
64                 }  
65                 else if ( bbGetInputIndex()<=(int)(bbGetInputlstIndexs().size()) ) 
66                 {
67                         iMin = 0;
68                         iMax = 0;
69                         size = bbGetInputIndex();
70                         for (i=0;i<size; i++)
71                         {
72                                 iMax = iMax + bbGetInputlstIndexs()[i];
73                                 if (i-1>=0){
74                                         iMin = iMin + bbGetInputlstIndexs()[i-1];
75                                 }
76                         }
77                 } else {
78                         iMin=0;
79                         iMax=-1;
80                 }
81
82                 bbSetInputIndex(0);
83
84                 std::string newFileName;
85
86
87                 for ( i=iMin ; i<iMax ; i=i+1 )
88                 {
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 )
96                         {
97                                 sphereActor->SetUserTransform( bbGetInputTransform() );
98                         }
99
100
101                         bbGetInputRenderer()->Render();
102                         bbGetInputRenderer()->GetRenderWindow()->Render();
103
104                         if (i%bbGetInputStep()==0)
105                         {
106                                 //writing file
107                                 std::stringstream strId;
108                                 strId << i;
109                                 std::string strtmp1 =strId.str();
110                                 std::string strtmp2 = "00000";
111                                 for (int iStr = 0; iStr<(int)(strtmp1.length()) ; iStr++  )
112                                 {
113                                         strtmp2[ strtmp2.length()-1-iStr ] = strtmp1[ strtmp1.length()-1-iStr ];
114                                 }
115                                 newFileName = "c:/temp/image"+strtmp2+".png";
116
117                                 vtkWindowToImageFilter  *w2i;
118                                 vtkPNGWriter                    *png;
119                                 w2i = vtkWindowToImageFilter::New();
120                                 png = vtkPNGWriter::New();
121                                 w2i->SetInput( bbGetInputRenderer()->GetRenderWindow() );
122                                 png->SetInput( w2i->GetOutput() );     
123                                 png->SetFileName( newFileName.c_str() );
124                                 png->Write();
125                                 png->Delete();
126                                 w2i->Delete();
127                         } // if i%10
128                 } // for
129         } //    if (bbGetInputRenderer()
130 }
131
132
133 void AnimationSphere::bbUserSetDefaultValues()
134 {
135      sphereActor=NULL;
136
137         bbSetInputRenderer(NULL);
138
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);
144
145         bbSetInputOpacity(1);
146
147         std::vector<int> lstInd;
148         lstInd.push_back(0);
149         std::vector<double> lstX;
150         std::vector<double> lstY;
151         std::vector<double> lstZ;
152         std::vector<double> lstR;
153
154         bbSetInputTransform(NULL);
155         bbSetInputIndex(0);
156         bbSetInputStep(1);
157 }
158
159         
160         //-----------------------------------------------------------------     
161         void AnimationSphere::bbUserInitializeProcessing()
162         {
163         }
164         
165         //-----------------------------------------------------------------     
166         void AnimationSphere::bbUserFinalizeProcessing()
167         {
168         }
169         
170         //-----------------------------------------------------------------     
171
172 }
173 // EO namespace bbcreaMaracasVisu
174
175