]> Creatis software - creaMaracasVisu.git/blob - bbtk/src/bbcreaMaracasVisuTubeFilter.cxx
16441924a4e790b274dd027b7d2054fa4e3ecb3c
[creaMaracasVisu.git] / bbtk / src / bbcreaMaracasVisuTubeFilter.cxx
1 //===== 
2 // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
3 //===== 
4 #include "bbcreaMaracasVisuTubeFilter.h"
5 #include "bbcreaMaracasVisuPackage.h"
6
7
8 #include <vtkPolyData.h>
9 #include <vtkPoints.h>
10 #include <vtkCellArray.h>
11 #include <vtkDoubleArray.h>
12 #include <vtkPolyData.h>
13 #include <vtkPointData.h>
14
15 #include <vtkCell.h>
16 #include <vtkCellData.h>
17 #include <vtkDataSet.h>
18 #include <vtkDataSetAttributes.h>
19 #include <vtkProperty.h>
20 #include <vtkTubeFilter.h>
21
22 #include <vtkDataSetMapper.h>
23 #include <vtkPolyDataMapper.h>
24
25
26 namespace bbcreaMaracasVisu
27 {
28
29         MaracasTubeFilter::MaracasTubeFilter()
30         {
31         }
32
33         MaracasTubeFilter::~MaracasTubeFilter()
34         {
35                 // Interface Update
36                 if (renderer!=NULL )
37                 {
38                         renderer->RemoveActor(actor);
39                 }
40                 
41         }
42         
43
44         void MaracasTubeFilter::SetvtkRenderer(vtkRenderer *render)
45         {
46                 this->renderer = render;
47         }
48         
49
50         
51         void MaracasTubeFilter::SetlstPoints( std::vector<double> lstPointX , std::vector<double> lstPointY , std::vector<double> lstPointZ )
52         {
53                 this->lstPointX = lstPointX;
54                 this->lstPointY = lstPointY;
55                 this->lstPointZ = lstPointZ;
56         }
57         
58         void MaracasTubeFilter::SetlstRadius( std::vector<double> lstRadius  )
59         {
60                 this->lstRadius = lstRadius;
61         }
62         
63         void MaracasTubeFilter::SetOpacity(double opacity)
64         {
65                 this->opacity = opacity;
66         }
67         
68         void MaracasTubeFilter::SetTransform( vtkLinearTransform* transform  )
69         {
70                 this->transform = transform;
71         }
72
73         vtkActor *MaracasTubeFilter::GetActor()
74         {
75                 return actor;
76         }
77         
78         void MaracasTubeFilter::Run()
79         {
80                 unsigned int i;
81                 unsigned int nTv = 8;       // No. of surface elements for each tube vertex             
82                 
83                 // Create points and cells 
84                 vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New();
85                 for(i = 0; i < lstPointX.size(); i++)
86                 {
87                         points->InsertPoint(i, lstPointX[i],  lstPointY[i],  lstPointZ[i]);
88                 }
89                 
90                 vtkSmartPointer<vtkCellArray> lines =
91                 vtkSmartPointer<vtkCellArray>::New();
92                 lines->InsertNextCell( lstPointX.size() );
93                 for (i = 0; i < lstPointX.size(); i++)
94                 {
95                         lines->InsertCellPoint(i);
96                 }
97                 
98                 vtkSmartPointer<vtkPolyData> polyData =
99                 vtkSmartPointer<vtkPolyData>::New();
100                 polyData->SetPoints(points);
101                 polyData->SetLines(lines);
102                 
103
104                 // Varying tube radius using sine-function
105                 vtkSmartPointer<vtkDoubleArray> tubeRadius =
106                 vtkSmartPointer<vtkDoubleArray>::New();
107                 tubeRadius->SetName("TubeRadius");
108                 tubeRadius->SetNumberOfTuples( lstRadius.size() );
109                 for (i=0 ;i<lstRadius.size() ; i++)
110                 {
111                         tubeRadius->SetTuple1(i, lstRadius[i] );
112                 }
113                 polyData->GetPointData()->AddArray(tubeRadius);
114                 polyData->GetPointData()->SetActiveScalars("TubeRadius");
115                 
116                 // RBG array (could add Alpha channel too I guess...)
117                 // Varying from blue to red
118                 vtkSmartPointer<vtkUnsignedCharArray> colors =
119                 vtkSmartPointer<vtkUnsignedCharArray>::New();
120                 colors->SetName("Colors");
121                 colors->SetNumberOfComponents(3);
122                 colors->SetNumberOfTuples( lstPointX.size() );
123                 for (i = 0; i < lstPointX.size() ;i++)
124                 {
125                         colors->InsertTuple3(i, 255 , 0.0 , 0.0 );
126                 }
127                 polyData->GetPointData()->AddArray(colors);
128                 
129                 vtkSmartPointer<vtkTubeFilter> tube
130                 = vtkSmartPointer<vtkTubeFilter>::New();
131                 tube->SetInput(polyData);
132                 tube->SetNumberOfSides(nTv);
133                 tube->SetVaryRadiusToVaryRadiusByAbsoluteScalar();
134                 
135                 vtkSmartPointer<vtkPolyDataMapper> mapper =
136                 vtkSmartPointer<vtkPolyDataMapper>::New();
137                 mapper->SetInputConnection(tube->GetOutputPort());
138                 mapper->ScalarVisibilityOn();
139                 mapper->SetScalarModeToUsePointFieldData();
140                 mapper->SelectColorArray("Colors");
141                 
142                 //              vtkSmartPointer<vtkActor> actor =vtkSmartPointer<vtkActor>::New();
143                 actor = vtkSmartPointer<vtkActor>::New();
144                 actor->SetMapper(mapper);
145                 actor->GetProperty()->SetOpacity( opacity );
146
147                 
148                 if ( transform!=NULL )
149                 {
150                         actor->SetUserTransform( transform );
151                 }
152                 
153                 // Interface Update
154                 if (renderer!=NULL )
155                 {
156                         renderer->AddActor(actor);
157                 }
158                                 
159         }
160         
161         
162         
163         
164 BBTK_ADD_BLACK_BOX_TO_PACKAGE(creaMaracasVisu,TubeFilter)
165 BBTK_BLACK_BOX_IMPLEMENTATION(TubeFilter,bbtk::AtomicBlackBox);
166 //===== 
167 // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
168 //===== 
169 void TubeFilter::Process()
170 {
171
172 // THE MAIN PROCESSING METHOD BODY
173 //   Here we simply set the input 'In' value to the output 'Out'
174 //   And print out the output value
175 // INPUT/OUTPUT ACCESSORS ARE OF THE FORM :
176 //    void bbSet{Input|Output}NAME(const TYPE&)
177 //    const TYPE& bbGet{Input|Output}NAME() const 
178 //    Where :
179 //    * NAME is the name of the input/output
180 //      (the one provided in the attribute 'name' of the tag 'input')
181 //    * TYPE is the C++ type of the input/output
182 //      (the one provided in the attribute 'type' of the tag 'input')
183         
184         printf("EED TubeFilter::Process start \n");
185
186         if (tubefilter!=NULL) 
187         { 
188                 delete tubefilter;
189         }
190         
191         tubefilter = new MaracasTubeFilter();
192         tubefilter->SetvtkRenderer( bbGetInputRenderer() );     
193         tubefilter->SetlstPoints( bbGetInputlstPointX(), bbGetInputlstPointY(), bbGetInputlstPointZ() );
194         tubefilter->SetlstRadius( bbGetInputlstRadio() );
195         tubefilter->SetOpacity( bbGetInputOpacity() );
196         tubefilter->SetTransform( bbGetInputTransform() );      
197         tubefilter->Run();
198     bbSetOutputOutAxis( tubefilter->GetActor() );       
199         printf("EED TubeFilter::Process end \n");
200 }
201         
202 //===== 
203 // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
204 //===== 
205 void TubeFilter::bbUserSetDefaultValues()
206 {
207 //  SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX 
208 //    Here we initialize the input 'In' to 0
209         bbSetInputOpacity(1);
210         bbSetInputTransform(NULL);
211
212 }
213         
214 //===== 
215 // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
216 //===== 
217 void TubeFilter::bbUserInitializeProcessing()
218 {
219 //  THE INITIALIZATION METHOD BODY :
220 //    Here does nothing 
221 //    but this is where you should allocate the internal/output pointers 
222 //    if any    
223         tubefilter = NULL; 
224 }
225         
226 //===== 
227 // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
228 //===== 
229 void TubeFilter::bbUserFinalizeProcessing()
230 {
231 //  THE FINALIZATION METHOD BODY :
232 //    Here does nothing 
233 //    but this is where you should desallocate the internal/output pointers 
234 //    if any
235 }
236         
237 }
238 // EO namespace bbcreaMaracasVisu
239
240