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( lstPointX.size() );
140 for (i=0 ;i<lstPointX.size() ; i++)
142 if (lstRadius.size()==0)
145 } else if (i<lstRadius.size()) {
146 radio = lstRadius[i];
147 } else if (i>=lstRadius.size()) {
148 radio= lstRadius[ lstRadius.size()-1 ];
151 tubeRadius->SetTuple1(i, radio );
153 polyData->GetPointData()->AddArray(tubeRadius);
154 polyData->GetPointData()->SetActiveScalars("TubeRadius");
156 // RBG array (could add Alpha channel too I guess...)
157 // Varying from blue to red
158 vtkSmartPointer<vtkUnsignedCharArray> colors = vtkSmartPointer<vtkUnsignedCharArray>::New();
159 colors->SetName("Colors");
160 colors->SetNumberOfComponents(3);
161 colors->SetNumberOfTuples( lstPointX.size() );
162 int numberOfColours = lstColour.size()/3;
164 for (i = 0; i < lstPointX.size() ;i++)
166 if (numberOfColours==0){
167 colors->InsertTuple3(i, 1 , 1 , 1 );
169 if (i<numberOfColours){
172 indexcolour=(numberOfColours-1)*3;
174 colors->InsertTuple3(i, 255*lstColour[indexcolour+0] , 255*lstColour[indexcolour+1] , 255*lstColour[indexcolour+2] );
177 polyData->GetPointData()->AddArray(colors);
179 vtkSmartPointer<vtkTubeFilter> tube = vtkSmartPointer<vtkTubeFilter>::New();
181 tube->SetInput(polyData);
182 tube->SetNumberOfSides(nTv);
183 tube->SetVaryRadiusToVaryRadiusByAbsoluteScalar();
185 vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
186 mapper->SetInputConnection(tube->GetOutputPort());
187 // mapper->ScalarVisibilityOn();
188 // mapper->SetScalarModeToUsePointFieldData();
190 mapper->ScalarVisibilityOn();
192 // mapper->SetScalarModeToUseCellData();
193 // mapper->SetScalarModeToUseCellFieldData();
194 // mapper->SetScalarModeToUseFieldData();
195 // mapper->SetScalarModeToUsePointData();
196 mapper->SetScalarModeToUsePointFieldData();
198 mapper->SetColorModeToDefault();
199 // mapper->SetColorModeToMapScalars();
202 mapper->SelectColorArray("Colors");
204 // vtkSmartPointer<vtkActor> actor =vtkSmartPointer<vtkActor>::New();
205 actor = vtkSmartPointer<vtkActor>::New();
206 actor->SetMapper(mapper);
207 actor->GetProperty()->SetOpacity( opacity );
209 if ( transform!=NULL )
211 actor->SetUserTransform( transform );
217 renderer->AddActor(actor);
225 BBTK_ADD_BLACK_BOX_TO_PACKAGE(creaMaracasVisu,TubeFilter)
226 BBTK_BLACK_BOX_IMPLEMENTATION(TubeFilter,bbtk::AtomicBlackBox);
228 // 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)
230 void TubeFilter::Process()
233 // THE MAIN PROCESSING METHOD BODY
234 // Here we simply set the input 'In' value to the output 'Out'
235 // And print out the output value
236 // INPUT/OUTPUT ACCESSORS ARE OF THE FORM :
237 // void bbSet{Input|Output}NAME(const TYPE&)
238 // const TYPE& bbGet{Input|Output}NAME() const
240 // * NAME is the name of the input/output
241 // (the one provided in the attribute 'name' of the tag 'input')
242 // * TYPE is the C++ type of the input/output
243 // (the one provided in the attribute 'type' of the tag 'input')
245 printf("EED TubeFilter::Process start \n");
247 if (tubefilter!=NULL)
252 tubefilter = new MaracasTubeFilter();
253 tubefilter->SetvtkRenderer( bbGetInputRenderer() );
254 tubefilter->SetlstPoints( bbGetInputlstPointX(), bbGetInputlstPointY(), bbGetInputlstPointZ() );
256 // Sets the default value for radius to 1 everywhere, if the radius input vevctor is empty.
257 if (bbGetInputlstRadio().size() == 0)
259 std::vector<double> radio;
260 radio.resize(bbGetInputlstPointX().size(), 1.);
261 bbSetInputlstRadio(radio);
263 tubefilter->SetlstRadius( bbGetInputlstRadio() );
264 tubefilter->SetOpacity( bbGetInputOpacity() );
265 tubefilter->SetTransform( bbGetInputTransform() );
266 tubefilter->SetlstColour( bbGetInputColour() );
268 bbSetOutputOutAxis( tubefilter->GetActor() );
269 printf("EED TubeFilter::Process end \n");
273 // 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)
275 void TubeFilter::bbUserSetDefaultValues()
277 // SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX
278 // Here we initialize the input 'In' to 0
279 bbSetInputOpacity(1);
280 bbSetInputTransform(NULL);
282 std::vector<double> colour;
284 colour.push_back(1.0);
285 colour.push_back(0.0);
286 colour.push_back(0.0);
287 bbSetInputColour(colour);
289 std::vector<double> lstRadius;
290 lstRadius.push_back(1);
291 bbSetInputColour(lstRadius);
295 // 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)
297 void TubeFilter::bbUserInitializeProcessing()
299 // THE INITIALIZATION METHOD BODY :
301 // but this is where you should allocate the internal/output pointers
307 // 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)
309 void TubeFilter::bbUserFinalizeProcessing()
311 // THE FINALIZATION METHOD BODY :
313 // but this is where you should desallocate the internal/output pointers
318 // EO namespace bbcreaMaracasVisu