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)
4 #include "bbcreaMaracasVisuTubeFilter.h"
5 #include "bbcreaMaracasVisuPackage.h"
8 #include <vtkPolyData.h>
10 #include <vtkCellArray.h>
11 #include <vtkDoubleArray.h>
12 #include <vtkPolyData.h>
13 #include <vtkPointData.h>
16 #include <vtkCellData.h>
17 #include <vtkDataSet.h>
18 #include <vtkDataSetAttributes.h>
19 #include <vtkProperty.h>
20 #include <vtkTubeFilter.h>
22 #include <vtkDataSetMapper.h>
23 #include <vtkPolyDataMapper.h>
26 namespace bbcreaMaracasVisu
29 MaracasTubeFilter::MaracasTubeFilter()
33 MaracasTubeFilter::~MaracasTubeFilter()
38 renderer->RemoveActor(actor);
44 void MaracasTubeFilter::SetvtkRenderer(vtkRenderer *render)
46 this->renderer = render;
51 void MaracasTubeFilter::SetlstPoints( std::vector<double> lstPointX , std::vector<double> lstPointY , std::vector<double> lstPointZ )
53 this->lstPointX = lstPointX;
54 this->lstPointY = lstPointY;
55 this->lstPointZ = lstPointZ;
58 void MaracasTubeFilter::SetlstRadius( std::vector<double> lstRadius )
60 this->lstRadius = lstRadius;
63 void MaracasTubeFilter::SetOpacity(double opacity)
65 this->opacity = opacity;
68 void MaracasTubeFilter::SetTransform( vtkLinearTransform* transform )
70 this->transform = transform;
73 vtkActor *MaracasTubeFilter::GetActor()
78 void MaracasTubeFilter::Run()
81 unsigned int nTv = 8; // No. of surface elements for each tube vertex
83 // Create points and cells
84 vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New();
85 for(i = 0; i < lstPointX.size(); i++)
87 points->InsertPoint(i, lstPointX[i], lstPointY[i], lstPointZ[i]);
90 vtkSmartPointer<vtkCellArray> lines =
91 vtkSmartPointer<vtkCellArray>::New();
92 lines->InsertNextCell( lstPointX.size() );
93 for (i = 0; i < lstPointX.size(); i++)
95 lines->InsertCellPoint(i);
98 vtkSmartPointer<vtkPolyData> polyData =
99 vtkSmartPointer<vtkPolyData>::New();
100 polyData->SetPoints(points);
101 polyData->SetLines(lines);
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++)
111 tubeRadius->SetTuple1(i, lstRadius[i] );
113 polyData->GetPointData()->AddArray(tubeRadius);
114 polyData->GetPointData()->SetActiveScalars("TubeRadius");
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++)
125 colors->InsertTuple3(i, 255 , 0.0 , 0.0 );
127 polyData->GetPointData()->AddArray(colors);
129 vtkSmartPointer<vtkTubeFilter> tube
130 = vtkSmartPointer<vtkTubeFilter>::New();
131 tube->SetInput(polyData);
132 tube->SetNumberOfSides(nTv);
133 tube->SetVaryRadiusToVaryRadiusByAbsoluteScalar();
135 vtkSmartPointer<vtkPolyDataMapper> mapper =
136 vtkSmartPointer<vtkPolyDataMapper>::New();
137 mapper->SetInputConnection(tube->GetOutputPort());
138 mapper->ScalarVisibilityOn();
139 mapper->SetScalarModeToUsePointFieldData();
140 mapper->SelectColorArray("Colors");
142 // vtkSmartPointer<vtkActor> actor =vtkSmartPointer<vtkActor>::New();
143 actor = vtkSmartPointer<vtkActor>::New();
144 actor->SetMapper(mapper);
145 actor->GetProperty()->SetOpacity( opacity );
148 if ( transform!=NULL )
150 actor->SetUserTransform( transform );
156 renderer->AddActor(actor);
164 BBTK_ADD_BLACK_BOX_TO_PACKAGE(creaMaracasVisu,TubeFilter)
165 BBTK_BLACK_BOX_IMPLEMENTATION(TubeFilter,bbtk::AtomicBlackBox);
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)
169 void TubeFilter::Process()
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
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')
184 printf("EED TubeFilter::Process start \n");
186 if (tubefilter!=NULL)
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() );
198 bbSetOutputOutAxis( tubefilter->GetActor() );
199 printf("EED TubeFilter::Process end \n");
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)
205 void TubeFilter::bbUserSetDefaultValues()
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);
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)
217 void TubeFilter::bbUserInitializeProcessing()
219 // THE INITIALIZATION METHOD BODY :
221 // but this is where you should allocate the internal/output pointers
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)
229 void TubeFilter::bbUserFinalizeProcessing()
231 // THE FINALIZATION METHOD BODY :
233 // but this is where you should desallocate the internal/output pointers
238 // EO namespace bbcreaMaracasVisu