]> Creatis software - creaMaracasVisu.git/blob - bbtk/src/bbmaracasvisuAnimationSphere.cxx
#3109 creaMaracasVisu Bug New Normal - branch vtk7itk4 compilation with vtk7
[creaMaracasVisu.git] / bbtk / src / bbmaracasvisuAnimationSphere.cxx
1 /*# ---------------------------------------------------------------------
2 #
3 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
4 #                        pour la Sant�)
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
8 #
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.
15 #
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
20 #  liability.
21 #
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 # ------------------------------------------------------------------------ */
25
26 #include "bbmaracasvisuAnimationSphere.h"
27 #include "bbcreaMaracasVisuPackage.h"
28
29
30 #include <vtkPolyDataMapper.h>
31 #include <vtkProperty.h>
32 #include <vtkRenderWindow.h>
33 #include <vtkWindowToImageFilter.h>
34 #include <vtkPNGWriter.h>
35
36
37
38 namespace bbcreaMaracasVisu
39 {
40
41 BBTK_ADD_BLACK_BOX_TO_PACKAGE(creaMaracasVisu,AnimationSphere)
42 BBTK_BLACK_BOX_IMPLEMENTATION(AnimationSphere,bbtk::AtomicBlackBox);
43
44
45 void AnimationSphere::Process()
46 {
47         int iMin,iMax;
48         double px;
49         double py;
50         double pz;
51         double radio;
52         double spc[3];
53   
54         if (sphereActor==NULL)
55         {
56                 // Sphere
57                 vtksphere               = vtkSphereSource::New();
58                         vtksphere->SetThetaResolution (20);
59                         vtksphere->SetPhiResolution (20);
60                         vtksphere->SetRadius( 1  ); 
61
62                 vtkPolyDataMapper       *sphereMapper   = vtkPolyDataMapper::New();
63 //EED 2017-01-01 Migration VTK7
64 #if VTK_MAJOR_VERSION <= 5
65                         sphereMapper->SetInput( vtksphere->GetOutput() );
66 #else
67                         sphereMapper->SetInputData( vtksphere->GetOutput() );
68 #endif
69
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() );
75         } else {
76                 bbGetInputRenderer()->RemoveActor( sphereActor );
77         }// if (sphereActor
78
79
80         if (bbGetInputRenderer()!=NULL)
81         {
82                 bbGetInputRenderer()->AddActor( sphereActor );
83         } // if
84
85
86         if (bbGetInputRenderer()!=NULL)
87         {
88                 spc[0]=spc[1]=spc[2]=1;
89                 int i,size;
90
91                 if ( (bbGetInputIndex()==0) ){
92                         iMin=0;
93                         iMax=bbGetInputlstPointX().size();
94                 }  
95                 else if ( bbGetInputIndex()<=(int)(bbGetInputlstIndexs().size()) ) 
96                 {
97                         iMin = 0;
98                         iMax = 0;
99                         size = bbGetInputIndex();
100                         for (i=0;i<size; i++)
101                         {
102                                 iMax = iMax + bbGetInputlstIndexs()[i];
103                                 if (i-1>=0){
104                                         iMin = iMin + bbGetInputlstIndexs()[i-1];
105                                 }
106                         }
107                 } else {
108                         iMin=0;
109                         iMax=-1;
110                 }
111
112                 bbSetInputIndex(0);
113
114                 std::string newFileName;
115
116
117                 for ( i=iMin ; i<iMax ; i=i+1 )
118                 {
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 )
126                         {
127                                 sphereActor->SetUserTransform( bbGetInputTransform() );
128                         }
129
130
131                         bbGetInputRenderer()->Render();
132                         bbGetInputRenderer()->GetRenderWindow()->Render();
133
134                         if (i%bbGetInputStep()==0)
135                         {
136                                 //writing file
137                                 std::stringstream strId;
138                                 strId << i;
139                                 std::string strtmp1 =strId.str();
140                                 std::string strtmp2 = "00000";
141                                 for (int iStr = 0; iStr<(int)(strtmp1.length()) ; iStr++  )
142                                 {
143                                         strtmp2[ strtmp2.length()-1-iStr ] = strtmp1[ strtmp1.length()-1-iStr ];
144                                 }
145                                 newFileName = "c:/temp/image"+strtmp2+".png";
146
147                                 vtkWindowToImageFilter  *w2i;
148                                 vtkPNGWriter                    *png;
149                                 w2i = vtkWindowToImageFilter::New();
150                                 png = vtkPNGWriter::New();
151                                 w2i->SetInput( bbGetInputRenderer()->GetRenderWindow() );
152
153 //EED 2017-01-01 Migration VTK7
154 #if VTK_MAJOR_VERSION <= 5
155                                 png->SetInput( w2i->GetOutput() );     
156 #else
157                                 png->SetInputData( w2i->GetOutput() );     
158 #endif
159
160                                 png->SetFileName( newFileName.c_str() );
161                                 png->Write();
162                                 png->Delete();
163                                 w2i->Delete();
164                         } // if i%10
165                 } // for
166         } //    if (bbGetInputRenderer()
167 }
168
169
170 void AnimationSphere::bbUserSetDefaultValues()
171 {
172      sphereActor=NULL;
173
174         bbSetInputRenderer(NULL);
175
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);
181
182         bbSetInputOpacity(1);
183
184         std::vector<int> lstInd;
185         lstInd.push_back(0);
186         std::vector<double> lstX;
187         std::vector<double> lstY;
188         std::vector<double> lstZ;
189         std::vector<double> lstR;
190
191         bbSetInputTransform(NULL);
192         bbSetInputIndex(0);
193         bbSetInputStep(1);
194 }
195
196         
197         //-----------------------------------------------------------------     
198         void AnimationSphere::bbUserInitializeProcessing()
199         {
200         }
201         
202         //-----------------------------------------------------------------     
203         void AnimationSphere::bbUserFinalizeProcessing()
204         {
205         }
206         
207         //-----------------------------------------------------------------     
208
209 }
210 // EO namespace bbcreaMaracasVisu
211
212