]> Creatis software - creaMaracasVisu.git/commitdiff
.
authorEduardo Davila <Eduardo.Davila@creatis.insa-lyon.fr>
Wed, 27 May 2009 13:39:37 +0000 (13:39 +0000)
committerEduardo Davila <Eduardo.Davila@creatis.insa-lyon.fr>
Wed, 27 May 2009 13:39:37 +0000 (13:39 +0000)
bbtk/src/bbmaracasvisuAnimationSphere.cxx [new file with mode: 0644]
bbtk/src/bbmaracasvisuAnimationSphere.h [new file with mode: 0644]

diff --git a/bbtk/src/bbmaracasvisuAnimationSphere.cxx b/bbtk/src/bbmaracasvisuAnimationSphere.cxx
new file mode 100644 (file)
index 0000000..e3555c2
--- /dev/null
@@ -0,0 +1,175 @@
+#include "bbmaracasvisuAnimationSphere.h"
+#include "bbcreaMaracasVisuPackage.h"
+
+
+#include <vtkPolyDataMapper.h>
+#include <vtkProperty.h>
+#include <vtkRenderWindow.h>
+#include <vtkWindowToImageFilter.h>
+#include <vtkPNGWriter.h>
+
+
+
+namespace bbcreaMaracasVisu
+{
+
+BBTK_ADD_BLACK_BOX_TO_PACKAGE(creaMaracasVisu,AnimationSphere)
+BBTK_BLACK_BOX_IMPLEMENTATION(AnimationSphere,bbtk::AtomicBlackBox);
+
+
+void AnimationSphere::Process()
+{
+       int iMin,iMax;
+       double px;
+       double py;
+       double pz;
+       double radio;
+       double spc[3];
+  
+       if (sphereActor==NULL)
+       {
+               // Sphere
+               vtksphere               = vtkSphereSource::New();
+                       vtksphere->SetThetaResolution (20);
+                       vtksphere->SetPhiResolution (20);
+                       vtksphere->SetRadius( 1  ); 
+
+               vtkPolyDataMapper       *sphereMapper   = vtkPolyDataMapper::New();
+                       sphereMapper->SetInput( vtksphere->GetOutput() );
+
+               sphereActor             = vtkActor::New();
+                       sphereActor->SetMapper(sphereMapper);
+                       sphereActor->SetOrigin(0, 0, 0);
+                       sphereActor->GetProperty()->SetColor( bbGetInputColour()[0] , bbGetInputColour()[1] , bbGetInputColour()[2] );
+                       sphereActor->GetProperty()->SetOpacity( bbGetInputOpacity() );
+       } else {
+               bbGetInputRenderer()->RemoveActor( sphereActor );
+       }// if (sphereActor
+
+
+       if (bbGetInputRenderer()!=NULL)
+       {
+               bbGetInputRenderer()->AddActor( sphereActor );
+       } // if
+
+
+       if (bbGetInputRenderer()!=NULL)
+       {
+               spc[0]=spc[1]=spc[2]=1;
+               int i,size;
+
+               if ( (bbGetInputIndex()==0) ){
+                       iMin=0;
+                       iMax=bbGetInputlstPointX().size();
+               }  
+               else if ( bbGetInputIndex()<=(int)(bbGetInputlstIndexs().size()) ) 
+               {
+                       iMin = 0;
+                       iMax = 0;
+                       size = bbGetInputIndex();
+                       for (i=0;i<size; i++)
+                       {
+                               iMax = iMax + bbGetInputlstIndexs()[i];
+                               if (i-1>=0){
+                                       iMin = iMin + bbGetInputlstIndexs()[i-1];
+                               }
+                       }
+               } else {
+                       iMin=0;
+                       iMax=-1;
+               }
+
+               bbSetInputIndex(0);
+
+               std::string newFileName;
+
+
+               for ( i=iMin ; i<iMax ; i=i+1 )
+               {
+                       px              = bbGetInputlstPointX()[i]*spc[0];
+                       py              = bbGetInputlstPointY()[i]*spc[1];
+                       pz              = bbGetInputlstPointZ()[i]*spc[2];
+                       radio   = bbGetInputlstRadio()[i];
+                       sphereActor->SetPosition( px,py,pz );
+                       vtksphere->SetRadius( radio  ); 
+                       if ( bbGetInputTransform()!=NULL )
+                       {
+                               sphereActor->SetUserTransform( bbGetInputTransform() );
+                       }
+
+
+                       bbGetInputRenderer()->Render();
+                       bbGetInputRenderer()->GetRenderWindow()->Render();
+
+                       if (i%bbGetInputStep()==0)
+                       {
+                               //writing file
+                               std::stringstream strId;
+                               strId << i;
+                               std::string strtmp1 =strId.str();
+                               std::string strtmp2 = "00000";
+                               for (int iStr = 0; iStr<(int)(strtmp1.length()) ; iStr++  )
+                               {
+                                       strtmp2[ strtmp2.length()-1-iStr ] = strtmp1[ strtmp1.length()-1-iStr ];
+                               }
+                               newFileName = "c:/temp/image"+strtmp2+".png";
+
+                               vtkWindowToImageFilter  *w2i;
+                               vtkPNGWriter                    *png;
+                               w2i = vtkWindowToImageFilter::New();
+                               png = vtkPNGWriter::New();
+                               w2i->SetInput( bbGetInputRenderer()->GetRenderWindow() );
+                               png->SetInput( w2i->GetOutput() );     
+                               png->SetFileName( newFileName.c_str() );
+                               png->Write();
+                               png->Delete();
+                               w2i->Delete();
+                       } // if i%10
+               } // for
+       } //    if (bbGetInputRenderer()
+}
+
+
+void AnimationSphere::bbUserSetDefaultValues()
+{
+     sphereActor=NULL;
+
+       bbSetInputRenderer(NULL);
+
+       std::vector<double> colour;
+       colour.push_back(1.0);
+       colour.push_back(0.0);
+       colour.push_back(0.0);
+       bbSetInputColour(colour);
+
+       bbSetInputOpacity(1);
+
+       std::vector<int> lstInd;
+       lstInd.push_back(0);
+       std::vector<double> lstX;
+       std::vector<double> lstY;
+       std::vector<double> lstZ;
+       std::vector<double> lstR;
+
+       bbSetInputTransform(NULL);
+       bbSetInputIndex(0);
+       bbSetInputStep(1);
+}
+
+       
+       //-----------------------------------------------------------------     
+       void AnimationSphere::bbUserInitializeProcessing()
+       {
+       }
+       
+       //-----------------------------------------------------------------     
+       void AnimationSphere::bbUserFinalizeProcessing()
+       {
+       }
+       
+       //-----------------------------------------------------------------     
+
+}
+// EO namespace bbcreaMaracasVisu
+
+
diff --git a/bbtk/src/bbmaracasvisuAnimationSphere.h b/bbtk/src/bbmaracasvisuAnimationSphere.h
new file mode 100644 (file)
index 0000000..6b1716a
--- /dev/null
@@ -0,0 +1,63 @@
+#ifndef __bbmaracasvisuAnimationSphere_h_INCLUDED__
+#define __bbmaracasvisuAnimationSphere_h_INCLUDED__
+#include "bbtkAtomicBlackBox.h"
+#include "iostream"
+
+
+#include <vtkRenderer.h>
+#include <vtkActor.h>
+#include <vtkSphereSource.h>
+#include <vtkLinearTransform.h>
+
+
+namespace bbcreaMaracasVisu
+{
+
+class /*BBTK_EXPORT*/ AnimationSphere
+ : 
+   public bbtk::AtomicBlackBox
+{
+  BBTK_BLACK_BOX_INTERFACE(AnimationSphere,bbtk::AtomicBlackBox);
+  BBTK_DECLARE_INPUT(Renderer ,vtkRenderer*);
+  BBTK_DECLARE_INPUT(Index,int);
+  BBTK_DECLARE_INPUT(Step,int);
+  BBTK_DECLARE_INPUT(lstIndexs,std::vector<int>);
+  BBTK_DECLARE_INPUT(lstPointX,std::vector<double>);
+  BBTK_DECLARE_INPUT(lstPointY,std::vector<double>);
+  BBTK_DECLARE_INPUT(lstPointZ,std::vector<double>);
+  BBTK_DECLARE_INPUT(lstRadio ,std::vector<double>);
+  BBTK_DECLARE_INPUT(Colour   ,std::vector<double>);
+  BBTK_DECLARE_INPUT(Opacity  ,double);
+  BBTK_DECLARE_INPUT(Transform, vtkLinearTransform *);
+//  BBTK_DECLARE_OUTPUT(Out,double);
+  BBTK_PROCESS(Process);
+  void Process();
+
+  vtkActor                     *sphereActor;
+  vtkSphereSource      *vtksphere;
+
+};
+
+BBTK_BEGIN_DESCRIBE_BLACK_BOX(AnimationSphere,bbtk::AtomicBlackBox);
+BBTK_NAME("AnimationSphere");
+BBTK_AUTHOR("InfoTeam  CREATIS-LRMN");
+BBTK_DESCRIPTION("Animation Sphere");
+BBTK_CATEGORY("Animation");
+BBTK_INPUT(AnimationSphere,Renderer,"Renderer",vtkRenderer*,"");
+BBTK_INPUT(AnimationSphere,Index,"Indexs",int,"");
+BBTK_INPUT(AnimationSphere,Step,"Step",int,"");
+BBTK_INPUT(AnimationSphere,lstIndexs,"list of Indexs",std::vector<int>,"");
+BBTK_INPUT(AnimationSphere,lstPointX,"lstPointX",std::vector<double>,"");
+BBTK_INPUT(AnimationSphere,lstPointY,"lstPointY",std::vector<double>,"");
+BBTK_INPUT(AnimationSphere,lstPointZ,"lstPointZ",std::vector<double>,"");
+BBTK_INPUT(AnimationSphere,lstRadio,"lstRadio",std::vector<double>,"");
+BBTK_INPUT(AnimationSphere,Colour,"Colour",std::vector<double>,"");
+BBTK_INPUT(AnimationSphere,Opacity,"Opacity of the sphere",double,"");
+BBTK_INPUT(AnimationSphere,Transform,"vtkTransform", vtkLinearTransform *,"");
+//BBTK_OUTPUT(AnimationSphere,Out,"First output",double,"");
+BBTK_END_DESCRIBE_BLACK_BOX(AnimationSphere);
+}
+// EO namespace bbcreaMaracasVisu
+
+#endif // __bbmaracasvisuAnimationSphere_h_INCLUDED__
+