]> Creatis software - creaMaracasVisu.git/blob - bbtk/src/bbmaracasvisuAnimationSphere.cxx
#3262 creaMaracasVisu Feature New Normal - Export LookupTable fron ColorLayerImageV...
[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                         sphereMapper->SetInput( vtksphere->GetOutput() );
64
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() );
70         } else {
71                 bbGetInputRenderer()->RemoveActor( sphereActor );
72         }// if (sphereActor
73
74
75         if (bbGetInputRenderer()!=NULL)
76         {
77                 bbGetInputRenderer()->AddActor( sphereActor );
78         } // if
79
80
81         if (bbGetInputRenderer()!=NULL)
82         {
83                 spc[0]=spc[1]=spc[2]=1;
84                 int i,size;
85
86                 if ( (bbGetInputIndex()==0) ){
87                         iMin=0;
88                         iMax=bbGetInputlstPointX().size();
89                 }  
90                 else if ( bbGetInputIndex()<=(int)(bbGetInputlstIndexs().size()) ) 
91                 {
92                         iMin = 0;
93                         iMax = 0;
94                         size = bbGetInputIndex();
95                         for (i=0;i<size; i++)
96                         {
97                                 iMax = iMax + bbGetInputlstIndexs()[i];
98                                 if (i-1>=0){
99                                         iMin = iMin + bbGetInputlstIndexs()[i-1];
100                                 }
101                         }
102                 } else {
103                         iMin=0;
104                         iMax=-1;
105                 }
106
107                 bbSetInputIndex(0);
108
109                 std::string newFileName;
110
111
112                 for ( i=iMin ; i<iMax ; i=i+1 )
113                 {
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 )
121                         {
122                                 sphereActor->SetUserTransform( bbGetInputTransform() );
123                         }
124
125
126                         bbGetInputRenderer()->Render();
127                         bbGetInputRenderer()->GetRenderWindow()->Render();
128
129                         if (i%bbGetInputStep()==0)
130                         {
131                                 //writing file
132                                 std::stringstream strId;
133                                 strId << i;
134                                 std::string strtmp1 =strId.str();
135                                 std::string strtmp2 = "00000";
136                                 for (int iStr = 0; iStr<(int)(strtmp1.length()) ; iStr++  )
137                                 {
138                                         strtmp2[ strtmp2.length()-1-iStr ] = strtmp1[ strtmp1.length()-1-iStr ];
139                                 }
140                                 newFileName = "c:/temp/image"+strtmp2+".png";
141
142                                 vtkWindowToImageFilter  *w2i;
143                                 vtkPNGWriter                    *png;
144                                 w2i = vtkWindowToImageFilter::New();
145                                 png = vtkPNGWriter::New();
146                                 w2i->SetInput( bbGetInputRenderer()->GetRenderWindow() );
147                                 png->SetInput( w2i->GetOutput() );     
148                                 png->SetFileName( newFileName.c_str() );
149                                 png->Write();
150                                 png->Delete();
151                                 w2i->Delete();
152                         } // if i%10
153                 } // for
154         } //    if (bbGetInputRenderer()
155 }
156
157
158 void AnimationSphere::bbUserSetDefaultValues()
159 {
160      sphereActor=NULL;
161
162         bbSetInputRenderer(NULL);
163
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);
169
170         bbSetInputOpacity(1);
171
172         std::vector<int> lstInd;
173         lstInd.push_back(0);
174         std::vector<double> lstX;
175         std::vector<double> lstY;
176         std::vector<double> lstZ;
177         std::vector<double> lstR;
178
179         bbSetInputTransform(NULL);
180         bbSetInputIndex(0);
181         bbSetInputStep(1);
182 }
183
184         
185         //-----------------------------------------------------------------     
186         void AnimationSphere::bbUserInitializeProcessing()
187         {
188         }
189         
190         //-----------------------------------------------------------------     
191         void AnimationSphere::bbUserFinalizeProcessing()
192         {
193         }
194         
195         //-----------------------------------------------------------------     
196
197 }
198 // EO namespace bbcreaMaracasVisu
199
200