1 /*# ---------------------------------------------------------------------
3 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
5 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
6 # Previous Authors : Laurent Guigues, Jean-Pierre Roux
7 # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
9 # This software is governed by the CeCILL-B license under French law and
10 # abiding by the rules of distribution of free software. You can use,
11 # modify and/ or redistribute the software under the terms of the CeCILL-B
12 # license as circulated by CEA, CNRS and INRIA at the following URL
13 # http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
14 # or in the file LICENSE.txt.
16 # As a counterpart to the access to the source code and rights to copy,
17 # modify and redistribute granted by the license, users are provided only
18 # with a limited warranty and the software's author, the holder of the
19 # economic rights, and the successive licensors have only limited
22 # The fact that you are presently reading this means that you have had
23 # knowledge of the CeCILL-B license and that you accept its terms.
24 # ------------------------------------------------------------------------ */
27 // 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)
29 #include "bbcreaMaracasVisuTubeFilter.h"
30 #include "bbcreaMaracasVisuPackage.h"
33 #include <vtkPolyData.h>
34 #include <vtkPoints.h>
35 #include <vtkCellArray.h>
36 #include <vtkDoubleArray.h>
37 #include <vtkPolyData.h>
38 #include <vtkPointData.h>
41 #include <vtkCellData.h>
42 #include <vtkDataSet.h>
43 #include <vtkDataSetAttributes.h>
44 #include <vtkProperty.h>
45 #include <vtkTubeFilter.h>
47 #include <vtkDataSetMapper.h>
48 #include <vtkPolyDataMapper.h>
51 namespace bbcreaMaracasVisu
54 MaracasTubeFilter::MaracasTubeFilter()
58 MaracasTubeFilter::~MaracasTubeFilter()
63 renderer->RemoveActor(actor);
69 void MaracasTubeFilter::SetvtkRenderer(vtkRenderer *render)
71 this->renderer = render;
76 void MaracasTubeFilter::SetlstPoints( std::vector<double> lstPointX , std::vector<double> lstPointY , std::vector<double> lstPointZ )
78 this->lstPointX = lstPointX;
79 this->lstPointY = lstPointY;
80 this->lstPointZ = lstPointZ;
84 void MaracasTubeFilter::SetlstColour( std::vector<double> lstColour )
86 this->lstColour=lstColour;
90 void MaracasTubeFilter::SetlstRadius( std::vector<double> lstRadius )
92 this->lstRadius = lstRadius;
95 void MaracasTubeFilter::SetOpacity(double opacity)
97 this->opacity = opacity;
100 void MaracasTubeFilter::SetTransform( vtkLinearTransform* transform )
102 this->transform = transform;
105 vtkActor *MaracasTubeFilter::GetActor()
110 void MaracasTubeFilter::Run()
115 unsigned int nTv = 8; // No. of surface elements for each tube vertex
117 // Create points and cells
118 vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New();
119 for(i = 0; i < lstPointX.size(); i++)
121 points->InsertPoint(i, lstPointX[i], lstPointY[i], lstPointZ[i]);
124 vtkSmartPointer<vtkCellArray> lines = vtkSmartPointer<vtkCellArray>::New();
125 lines->InsertNextCell( lstPointX.size() );
126 for (i = 0; i < lstPointX.size(); i++)
128 lines->InsertCellPoint(i);
131 vtkSmartPointer<vtkPolyData> polyData = vtkSmartPointer<vtkPolyData>::New();
132 polyData->SetPoints(points);
133 polyData->SetLines(lines);
136 // Varying tube radius using sine-function
137 vtkSmartPointer<vtkDoubleArray> tubeRadius = vtkSmartPointer<vtkDoubleArray>::New();
138 tubeRadius->SetName("TubeRadius");
139 tubeRadius->SetNumberOfTuples( lstRadius.size() );
140 for (i=0 ;i<lstRadius.size() ; i++)
142 tubeRadius->SetTuple1(i, lstRadius[i] );
144 polyData->GetPointData()->AddArray(tubeRadius);
145 polyData->GetPointData()->SetActiveScalars("TubeRadius");
147 // RBG array (could add Alpha channel too I guess...)
148 // Varying from blue to red
149 vtkSmartPointer<vtkUnsignedCharArray> colors = vtkSmartPointer<vtkUnsignedCharArray>::New();
150 colors->SetName("Colors");
151 colors->SetNumberOfComponents(3);
152 colors->SetNumberOfTuples( lstPointX.size() );
153 int numberOfColours = lstColour.size()/3;
155 for (i = 0; i < lstPointX.size() ;i++)
157 if (numberOfColours==0){
158 colors->InsertTuple3(i, 1 , 1 , 1 );
160 if (i<numberOfColours){
163 indexcolour=(numberOfColours-1)*3;
165 colors->InsertTuple3(i, 255*lstColour[indexcolour+0] , 255*lstColour[indexcolour+1] , 255*lstColour[indexcolour+2] );
168 polyData->GetPointData()->AddArray(colors);
170 vtkSmartPointer<vtkTubeFilter> tube = vtkSmartPointer<vtkTubeFilter>::New();
172 tube->SetInput(polyData);
173 tube->SetNumberOfSides(nTv);
174 tube->SetVaryRadiusToVaryRadiusByAbsoluteScalar();
176 vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
177 mapper->SetInputConnection(tube->GetOutputPort());
178 // mapper->ScalarVisibilityOn();
179 // mapper->SetScalarModeToUsePointFieldData();
181 mapper->ScalarVisibilityOn();
183 // mapper->SetScalarModeToUseCellData();
184 // mapper->SetScalarModeToUseCellFieldData();
185 // mapper->SetScalarModeToUseFieldData();
186 // mapper->SetScalarModeToUsePointData();
187 mapper->SetScalarModeToUsePointFieldData();
189 mapper->SetColorModeToDefault();
190 // mapper->SetColorModeToMapScalars();
193 mapper->SelectColorArray("Colors");
195 // vtkSmartPointer<vtkActor> actor =vtkSmartPointer<vtkActor>::New();
196 actor = vtkSmartPointer<vtkActor>::New();
197 actor->SetMapper(mapper);
198 actor->GetProperty()->SetOpacity( opacity );
200 if ( transform!=NULL )
202 actor->SetUserTransform( transform );
208 renderer->AddActor(actor);
216 BBTK_ADD_BLACK_BOX_TO_PACKAGE(creaMaracasVisu,TubeFilter)
217 BBTK_BLACK_BOX_IMPLEMENTATION(TubeFilter,bbtk::AtomicBlackBox);
219 // 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)
221 void TubeFilter::Process()
224 // THE MAIN PROCESSING METHOD BODY
225 // Here we simply set the input 'In' value to the output 'Out'
226 // And print out the output value
227 // INPUT/OUTPUT ACCESSORS ARE OF THE FORM :
228 // void bbSet{Input|Output}NAME(const TYPE&)
229 // const TYPE& bbGet{Input|Output}NAME() const
231 // * NAME is the name of the input/output
232 // (the one provided in the attribute 'name' of the tag 'input')
233 // * TYPE is the C++ type of the input/output
234 // (the one provided in the attribute 'type' of the tag 'input')
236 printf("EED TubeFilter::Process start \n");
238 if (tubefilter!=NULL)
243 tubefilter = new MaracasTubeFilter();
244 tubefilter->SetvtkRenderer( bbGetInputRenderer() );
245 tubefilter->SetlstPoints( bbGetInputlstPointX(), bbGetInputlstPointY(), bbGetInputlstPointZ() );
247 // Sets the default value for radius to 1 everywhere, if the radius input vevctor is empty.
248 if (bbGetInputlstRadio().size() == 0)
250 std::vector<double> radio;
251 radio.resize(bbGetInputlstPointX().size(), 1.);
252 bbSetInputlstRadio(radio);
254 tubefilter->SetlstRadius( bbGetInputlstRadio() );
255 tubefilter->SetOpacity( bbGetInputOpacity() );
256 tubefilter->SetTransform( bbGetInputTransform() );
257 tubefilter->SetlstColour( bbGetInputColour() );
259 bbSetOutputOutAxis( tubefilter->GetActor() );
260 printf("EED TubeFilter::Process end \n");
264 // 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)
266 void TubeFilter::bbUserSetDefaultValues()
268 // SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX
269 // Here we initialize the input 'In' to 0
270 bbSetInputOpacity(1);
271 bbSetInputTransform(NULL);
273 std::vector<double> colour;
275 colour.push_back(1.0);
276 colour.push_back(0.0);
277 colour.push_back(0.0);
278 bbSetInputColour(colour);
282 // 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)
284 void TubeFilter::bbUserInitializeProcessing()
286 // THE INITIALIZATION METHOD BODY :
288 // but this is where you should allocate the internal/output pointers
294 // 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)
296 void TubeFilter::bbUserFinalizeProcessing()
298 // THE FINALIZATION METHOD BODY :
300 // but this is where you should desallocate the internal/output pointers
305 // EO namespace bbcreaMaracasVisu