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()
113 unsigned int nTv = 8; // No. of surface elements for each tube vertex
115 // Create points and cells
116 vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New();
117 for(i = 0; i < lstPointX.size(); i++)
119 points->InsertPoint(i, lstPointX[i], lstPointY[i], lstPointZ[i]);
122 vtkSmartPointer<vtkCellArray> lines = vtkSmartPointer<vtkCellArray>::New();
123 lines->InsertNextCell( lstPointX.size() );
124 for (i = 0; i < lstPointX.size(); i++)
126 lines->InsertCellPoint(i);
129 vtkSmartPointer<vtkPolyData> polyData = vtkSmartPointer<vtkPolyData>::New();
130 polyData->SetPoints(points);
131 polyData->SetLines(lines);
134 // Varying tube radius using sine-function
135 vtkSmartPointer<vtkDoubleArray> tubeRadius = vtkSmartPointer<vtkDoubleArray>::New();
136 tubeRadius->SetName("TubeRadius");
137 tubeRadius->SetNumberOfTuples( lstPointX.size() );
138 for (i=0 ;i<lstPointX.size() ; i++)
140 if (lstRadius.size()==0)
143 } else if (i<lstRadius.size()) {
144 radio = lstRadius[i];
145 } else if (i>=lstRadius.size()) {
146 radio= lstRadius[ lstRadius.size()-1 ];
149 tubeRadius->SetTuple1(i, radio );
151 polyData->GetPointData()->AddArray(tubeRadius);
152 polyData->GetPointData()->SetActiveScalars("TubeRadius");
154 // RBG array (could add Alpha channel too I guess...)
155 // Varying from blue to red
156 vtkSmartPointer<vtkUnsignedCharArray> colors = vtkSmartPointer<vtkUnsignedCharArray>::New();
157 colors->SetName("Colors");
158 colors->SetNumberOfComponents(3);
159 colors->SetNumberOfTuples( lstPointX.size() );
160 int numberOfColours = lstColour.size()/3;
162 for (i = 0; i < lstPointX.size() ;i++)
164 if (numberOfColours==0){
165 colors->InsertTuple3(i, 1 , 1 , 1 );
167 if (i<numberOfColours){
170 indexcolour=(numberOfColours-1)*3;
172 colors->InsertTuple3(i, 255*lstColour[indexcolour+0] , 255*lstColour[indexcolour+1] , 255*lstColour[indexcolour+2] );
175 polyData->GetPointData()->AddArray(colors);
177 vtkSmartPointer<vtkTubeFilter> tube = vtkSmartPointer<vtkTubeFilter>::New();
180 //EED 2017-01-01 Migration VTK7
181 #if VTK_MAJOR_VERSION <= 5
182 tube->SetInput(polyData);
184 tube->SetInputData(polyData);
187 tube->SetNumberOfSides(nTv);
188 tube->SetVaryRadiusToVaryRadiusByAbsoluteScalar();
190 vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
191 mapper->SetInputConnection(tube->GetOutputPort());
192 // mapper->ScalarVisibilityOn();
193 // mapper->SetScalarModeToUsePointFieldData();
195 mapper->ScalarVisibilityOn();
197 // mapper->SetScalarModeToUseCellData();
198 // mapper->SetScalarModeToUseCellFieldData();
199 // mapper->SetScalarModeToUseFieldData();
200 // mapper->SetScalarModeToUsePointData();
201 mapper->SetScalarModeToUsePointFieldData();
203 mapper->SetColorModeToDefault();
204 // mapper->SetColorModeToMapScalars();
207 mapper->SelectColorArray("Colors");
209 // vtkSmartPointer<vtkActor> actor =vtkSmartPointer<vtkActor>::New();
210 actor = vtkSmartPointer<vtkActor>::New();
211 actor->SetMapper(mapper);
212 actor->GetProperty()->SetOpacity( opacity );
214 if ( transform!=NULL )
216 actor->SetUserTransform( transform );
222 renderer->AddActor(actor);
230 BBTK_ADD_BLACK_BOX_TO_PACKAGE(creaMaracasVisu,TubeFilter)
231 BBTK_BLACK_BOX_IMPLEMENTATION(TubeFilter,bbtk::AtomicBlackBox);
233 // 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)
235 void TubeFilter::Process()
238 // THE MAIN PROCESSING METHOD BODY
239 // Here we simply set the input 'In' value to the output 'Out'
240 // And print out the output value
241 // INPUT/OUTPUT ACCESSORS ARE OF THE FORM :
242 // void bbSet{Input|Output}NAME(const TYPE&)
243 // const TYPE& bbGet{Input|Output}NAME() const
245 // * NAME is the name of the input/output
246 // (the one provided in the attribute 'name' of the tag 'input')
247 // * TYPE is the C++ type of the input/output
248 // (the one provided in the attribute 'type' of the tag 'input')
250 if (tubefilter!=NULL)
255 tubefilter = new MaracasTubeFilter();
256 tubefilter->SetvtkRenderer( bbGetInputRenderer() );
257 tubefilter->SetlstPoints( bbGetInputlstPointX(), bbGetInputlstPointY(), bbGetInputlstPointZ() );
259 // Sets the default value for radius to 1 everywhere, if the radius input vevctor is empty.
260 if (bbGetInputlstRadio().size() == 0)
262 std::vector<double> radio;
263 radio.resize(bbGetInputlstPointX().size(), 1.);
264 bbSetInputlstRadio(radio);
266 tubefilter->SetlstRadius( bbGetInputlstRadio() );
267 tubefilter->SetOpacity( bbGetInputOpacity() );
268 tubefilter->SetTransform( bbGetInputTransform() );
269 tubefilter->SetlstColour( bbGetInputColour() );
271 bbSetOutputOutAxis( tubefilter->GetActor() );
275 // 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)
277 void TubeFilter::bbUserSetDefaultValues()
279 // SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX
280 // Here we initialize the input 'In' to 0
281 bbSetInputOpacity(1);
282 bbSetInputTransform(NULL);
284 std::vector<double> colour;
286 colour.push_back(1.0);
287 colour.push_back(0.0);
288 colour.push_back(0.0);
289 bbSetInputColour(colour);
291 std::vector<double> lstRadius;
292 lstRadius.push_back(1);
293 bbSetInputColour(lstRadius);
297 // 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)
299 void TubeFilter::bbUserInitializeProcessing()
301 // THE INITIALIZATION METHOD BODY :
303 // but this is where you should allocate the internal/output pointers
309 // 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)
311 void TubeFilter::bbUserFinalizeProcessing()
313 // THE FINALIZATION METHOD BODY :
315 // but this is where you should desallocate the internal/output pointers
320 // EO namespace bbcreaMaracasVisu