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;
59 void MaracasTubeFilter::SetlstColour( std::vector<double> lstColour )
61 this->lstColour=lstColour;
65 void MaracasTubeFilter::SetlstRadius( std::vector<double> lstRadius )
67 this->lstRadius = lstRadius;
70 void MaracasTubeFilter::SetOpacity(double opacity)
72 this->opacity = opacity;
75 void MaracasTubeFilter::SetTransform( vtkLinearTransform* transform )
77 this->transform = transform;
80 vtkActor *MaracasTubeFilter::GetActor()
85 void MaracasTubeFilter::Run()
90 unsigned int nTv = 8; // No. of surface elements for each tube vertex
92 // Create points and cells
93 vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New();
94 for(i = 0; i < lstPointX.size(); i++)
96 points->InsertPoint(i, lstPointX[i], lstPointY[i], lstPointZ[i]);
99 vtkSmartPointer<vtkCellArray> lines = vtkSmartPointer<vtkCellArray>::New();
100 lines->InsertNextCell( lstPointX.size() );
101 for (i = 0; i < lstPointX.size(); i++)
103 lines->InsertCellPoint(i);
106 vtkSmartPointer<vtkPolyData> polyData = vtkSmartPointer<vtkPolyData>::New();
107 polyData->SetPoints(points);
108 polyData->SetLines(lines);
111 // Varying tube radius using sine-function
112 vtkSmartPointer<vtkDoubleArray> tubeRadius = vtkSmartPointer<vtkDoubleArray>::New();
113 tubeRadius->SetName("TubeRadius");
114 tubeRadius->SetNumberOfTuples( lstRadius.size() );
115 for (i=0 ;i<lstRadius.size() ; i++)
117 tubeRadius->SetTuple1(i, lstRadius[i] );
119 polyData->GetPointData()->AddArray(tubeRadius);
120 polyData->GetPointData()->SetActiveScalars("TubeRadius");
122 // RBG array (could add Alpha channel too I guess...)
123 // Varying from blue to red
124 vtkSmartPointer<vtkUnsignedCharArray> colors = vtkSmartPointer<vtkUnsignedCharArray>::New();
125 colors->SetName("Colors");
126 colors->SetNumberOfComponents(3);
127 colors->SetNumberOfTuples( lstPointX.size() );
128 int numberOfColours = lstColour.size()/3;
130 for (i = 0; i < lstPointX.size() ;i++)
132 if (numberOfColours==0){
133 colors->InsertTuple3(i, 1 , 1 , 1 );
135 if (i<numberOfColours){
138 indexcolour=(numberOfColours-1)*3;
140 colors->InsertTuple3(i, 255*lstColour[indexcolour+0] , 255*lstColour[indexcolour+1] , 255*lstColour[indexcolour+2] );
143 polyData->GetPointData()->AddArray(colors);
145 vtkSmartPointer<vtkTubeFilter> tube = vtkSmartPointer<vtkTubeFilter>::New();
147 tube->SetInput(polyData);
148 tube->SetNumberOfSides(nTv);
149 tube->SetVaryRadiusToVaryRadiusByAbsoluteScalar();
151 vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
152 mapper->SetInputConnection(tube->GetOutputPort());
153 // mapper->ScalarVisibilityOn();
154 // mapper->SetScalarModeToUsePointFieldData();
156 mapper->ScalarVisibilityOn();
158 // mapper->SetScalarModeToUseCellData();
159 // mapper->SetScalarModeToUseCellFieldData();
160 // mapper->SetScalarModeToUseFieldData();
161 // mapper->SetScalarModeToUsePointData();
162 mapper->SetScalarModeToUsePointFieldData();
164 mapper->SetColorModeToDefault();
165 // mapper->SetColorModeToMapScalars();
168 mapper->SelectColorArray("Colors");
170 // vtkSmartPointer<vtkActor> actor =vtkSmartPointer<vtkActor>::New();
171 actor = vtkSmartPointer<vtkActor>::New();
172 actor->SetMapper(mapper);
173 actor->GetProperty()->SetOpacity( opacity );
175 if ( transform!=NULL )
177 actor->SetUserTransform( transform );
183 renderer->AddActor(actor);
191 BBTK_ADD_BLACK_BOX_TO_PACKAGE(creaMaracasVisu,TubeFilter)
192 BBTK_BLACK_BOX_IMPLEMENTATION(TubeFilter,bbtk::AtomicBlackBox);
194 // 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)
196 void TubeFilter::Process()
199 // THE MAIN PROCESSING METHOD BODY
200 // Here we simply set the input 'In' value to the output 'Out'
201 // And print out the output value
202 // INPUT/OUTPUT ACCESSORS ARE OF THE FORM :
203 // void bbSet{Input|Output}NAME(const TYPE&)
204 // const TYPE& bbGet{Input|Output}NAME() const
206 // * NAME is the name of the input/output
207 // (the one provided in the attribute 'name' of the tag 'input')
208 // * TYPE is the C++ type of the input/output
209 // (the one provided in the attribute 'type' of the tag 'input')
211 printf("EED TubeFilter::Process start \n");
213 if (tubefilter!=NULL)
218 tubefilter = new MaracasTubeFilter();
219 tubefilter->SetvtkRenderer( bbGetInputRenderer() );
220 tubefilter->SetlstPoints( bbGetInputlstPointX(), bbGetInputlstPointY(), bbGetInputlstPointZ() );
222 // Sets the default value for radius to 1 everywhere, if the radius input vevctor is empty.
223 if (bbGetInputlstRadio().size() == 0)
225 std::vector<double> radio;
226 radio.resize(bbGetInputlstPointX().size(), 1.);
227 bbSetInputlstRadio(radio);
229 tubefilter->SetlstRadius( bbGetInputlstRadio() );
230 tubefilter->SetOpacity( bbGetInputOpacity() );
231 tubefilter->SetTransform( bbGetInputTransform() );
232 tubefilter->SetlstColour( bbGetInputColour() );
234 bbSetOutputOutAxis( tubefilter->GetActor() );
235 printf("EED TubeFilter::Process end \n");
239 // 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)
241 void TubeFilter::bbUserSetDefaultValues()
243 // SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX
244 // Here we initialize the input 'In' to 0
245 bbSetInputOpacity(1);
246 bbSetInputTransform(NULL);
248 std::vector<double> colour;
250 colour.push_back(1.0);
251 colour.push_back(0.0);
252 colour.push_back(0.0);
253 bbSetInputColour(colour);
257 // 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)
259 void TubeFilter::bbUserInitializeProcessing()
261 // THE INITIALIZATION METHOD BODY :
263 // but this is where you should allocate the internal/output pointers
269 // 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)
271 void TubeFilter::bbUserFinalizeProcessing()
273 // THE FINALIZATION METHOD BODY :
275 // but this is where you should desallocate the internal/output pointers
280 // EO namespace bbcreaMaracasVisu