]> Creatis software - bbtk.git/blob - packages/vtk/src/bbvtkVecIsoSurfaceExtractor.cxx
add a GetVectorVtkImageDataElement
[bbtk.git] / packages / vtk / src / bbvtkVecIsoSurfaceExtractor.cxx
1 #include "bbvtkVecIsoSurfaceExtractor.h"
2 #include "bbvtkPackage.h"
3
4 #include "vtkProperty.h"
5 #include "vtkLinearTransform.h"
6
7 namespace bbvtk
8 {
9
10 BBTK_ADD_BLACK_BOX_TO_PACKAGE(vtk,VecIsoSurfaceExtractor)
11 BBTK_BLACK_BOX_IMPLEMENTATION(VecIsoSurfaceExtractor,bbtk::AtomicBlackBox);
12         
13         //-----------------------------------------------------------   
14         void VecIsoSurfaceExtractor::bbUserSetDefaultValues()
15         {
16                 std::vector<double> colour;
17                 // 1- red
18                 colour.push_back(1.0);
19                 colour.push_back(0.0);
20                 colour.push_back(0.0);
21                 // 2- blue
22                 colour.push_back(0.0);
23                 colour.push_back(0.0);
24                 colour.push_back(1.0);
25                 // 3- yellow
26                 colour.push_back(1.0);
27                 colour.push_back(1.0);
28                 colour.push_back(0.0);
29                 // 4- green
30                 colour.push_back(0.0);
31                 colour.push_back(1.0);
32                 colour.push_back(0.0);
33                 // 5- 
34                 colour.push_back(0.0);
35                 colour.push_back(1.0);
36                 colour.push_back(1.0);
37                 
38                 // 6- 
39                 colour.push_back(0.5);
40                 colour.push_back(0.5);
41                 colour.push_back(0.5);
42                 
43                 bbSetInputColour(colour);
44                 bbSetInputTransform(NULL);
45                 bbSetInputOpacity(1);
46                 
47                 bbSetInputRenderer(NULL);
48                 bbSetInputIsovalue(128);
49                 bbSetInputOpacity(1);
50         }
51         
52         //-----------------------------------------------------------   
53         void VecIsoSurfaceExtractor::bbUserInitializeProcessing() 
54         { 
55                 //    bbSetInputIn(NULL);
56                 //     bbSetInputInVtkObject(NULL);
57                 
58         }
59         
60         //-----------------------------------------------------------   
61         void VecIsoSurfaceExtractor::bbUserFinalizeProcessing()
62         {
63                 int i,size = VecMarchingcubes.size();
64                 for (i=0;i<size;i++)
65                 {
66                         VecMarchingcubes[i]->Delete();
67                         VecPolydatamapper[i]->Delete();
68                         VecVtkactor[i]->Delete();
69                 }
70                 VecMarchingcubes.clear();
71                 VecPolydatamapper.clear();
72                 VecVtkactor.clear();
73         }
74         
75         //-----------------------------------------------------------   
76         void VecIsoSurfaceExtractor::Process()
77         {
78                 double r,g,b;
79                 vtkMarchingCubes        *marchingcubes;
80                 vtkPolyDataMapper       *polydatamapper;
81                 vtkActor                        *vtkactor;
82
83                  int i,size;
84
85                 size = VecVtkactor.size();
86                 for( i=0 ; i<size ; i++)
87                 {
88                         if (bbGetInputRenderer()!=NULL )
89                         {
90                                 bbGetInputRenderer()->RemoveActor( VecVtkactor[i] );
91                                 VecMarchingcubes[i]->Delete();
92                                 VecPolydatamapper[i]->Delete();
93                                 VecVtkactor[i]->Delete();
94                         }
95                 }
96                 VecMarchingcubes.clear();
97                 VecPolydatamapper.clear();
98                 VecVtkactor.clear();
99
100
101                  size = bbGetInputIn().size();
102                 for( i=0 ; i<size ; i++){
103                         marchingcubes           = vtkMarchingCubes::New();
104                         polydatamapper          = vtkPolyDataMapper::New();
105                         vtkactor                        = vtkActor::New();
106
107                         polydatamapper->SetInput(marchingcubes->GetOutput());
108                         vtkactor->SetMapper(polydatamapper);
109
110                         polydatamapper->ScalarVisibilityOff();
111                         polydatamapper->ImmediateModeRenderingOn();
112
113                         VecMarchingcubes.push_back(marchingcubes);
114                         VecPolydatamapper.push_back(polydatamapper);
115                         VecVtkactor.push_back(vtkactor);
116                 } // for i
117
118
119                 for( i=0 ; i<size ; i++){
120                         // Visualisation - result volume
121                         marchingcubes=VecMarchingcubes[i];
122                         vtkactor=(vtkActor*)VecVtkactor[i];
123
124                         marchingcubes->SetInput( bbGetInputIn()[i] );
125                         marchingcubes->SetValue(0,  bbGetInputIsovalue() );
126                         marchingcubes->Update();
127                          
128                         if ( (i*3+1)<(int)(bbGetInputColour().size()) ){
129                                 r = bbGetInputColour()[0+i*3];
130                                 g = bbGetInputColour()[1+i*3]; 
131                                 b = bbGetInputColour()[2+i*3];
132                         } else {
133                                 r = bbGetInputColour()[0];
134                                 g = bbGetInputColour()[1]; 
135                                 b = bbGetInputColour()[2];
136                         }
137                         vtkactor->GetProperty()->SetColor( r,g,b );
138                          
139                         vtkactor->GetProperty()->SetOpacity( bbGetInputOpacity() );
140                         
141                         if ( bbGetInputTransform()!=NULL )
142                         {
143                                 vtkactor->SetUserTransform( bbGetInputTransform() );
144                         }
145
146                         // Interface Update
147                         if (bbGetInputRenderer()!=NULL )
148                         {
149                                 bbGetInputRenderer()->AddActor( vtkactor );
150                         }
151                 } // for i
152
153                  bbSetOutputOut( VecVtkactor );
154         }
155
156
157 }
158 // EO namespace bbvtk
159
160