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();
179 tube->SetInput(polyData);
180 tube->SetNumberOfSides(nTv);
181 tube->SetVaryRadiusToVaryRadiusByAbsoluteScalar();
183 vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
184 mapper->SetInputConnection(tube->GetOutputPort());
185 // mapper->ScalarVisibilityOn();
186 // mapper->SetScalarModeToUsePointFieldData();
188 mapper->ScalarVisibilityOn();
190 // mapper->SetScalarModeToUseCellData();
191 // mapper->SetScalarModeToUseCellFieldData();
192 // mapper->SetScalarModeToUseFieldData();
193 // mapper->SetScalarModeToUsePointData();
194 mapper->SetScalarModeToUsePointFieldData();
196 mapper->SetColorModeToDefault();
197 // mapper->SetColorModeToMapScalars();
200 mapper->SelectColorArray("Colors");
202 // vtkSmartPointer<vtkActor> actor =vtkSmartPointer<vtkActor>::New();
203 actor = vtkSmartPointer<vtkActor>::New();
204 actor->SetMapper(mapper);
205 actor->GetProperty()->SetOpacity( opacity );
207 if ( transform!=NULL )
209 actor->SetUserTransform( transform );
215 renderer->AddActor(actor);
223 BBTK_ADD_BLACK_BOX_TO_PACKAGE(creaMaracasVisu,TubeFilter)
224 BBTK_BLACK_BOX_IMPLEMENTATION(TubeFilter,bbtk::AtomicBlackBox);
226 // 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)
228 void TubeFilter::Process()
231 // THE MAIN PROCESSING METHOD BODY
232 // Here we simply set the input 'In' value to the output 'Out'
233 // And print out the output value
234 // INPUT/OUTPUT ACCESSORS ARE OF THE FORM :
235 // void bbSet{Input|Output}NAME(const TYPE&)
236 // const TYPE& bbGet{Input|Output}NAME() const
238 // * NAME is the name of the input/output
239 // (the one provided in the attribute 'name' of the tag 'input')
240 // * TYPE is the C++ type of the input/output
241 // (the one provided in the attribute 'type' of the tag 'input')
243 if (tubefilter!=NULL)
248 tubefilter = new MaracasTubeFilter();
249 tubefilter->SetvtkRenderer( bbGetInputRenderer() );
250 tubefilter->SetlstPoints( bbGetInputlstPointX(), bbGetInputlstPointY(), bbGetInputlstPointZ() );
252 // Sets the default value for radius to 1 everywhere, if the radius input vevctor is empty.
253 if (bbGetInputlstRadio().size() == 0)
255 std::vector<double> radio;
256 radio.resize(bbGetInputlstPointX().size(), 1.);
257 bbSetInputlstRadio(radio);
259 tubefilter->SetlstRadius( bbGetInputlstRadio() );
260 tubefilter->SetOpacity( bbGetInputOpacity() );
261 tubefilter->SetTransform( bbGetInputTransform() );
262 tubefilter->SetlstColour( bbGetInputColour() );
264 bbSetOutputOutAxis( tubefilter->GetActor() );
268 // 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)
270 void TubeFilter::bbUserSetDefaultValues()
272 // SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX
273 // Here we initialize the input 'In' to 0
274 bbSetInputOpacity(1);
275 bbSetInputTransform(NULL);
277 std::vector<double> colour;
279 colour.push_back(1.0);
280 colour.push_back(0.0);
281 colour.push_back(0.0);
282 bbSetInputColour(colour);
284 std::vector<double> lstRadius;
285 lstRadius.push_back(1);
286 bbSetInputColour(lstRadius);
290 // 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)
292 void TubeFilter::bbUserInitializeProcessing()
294 // THE INITIALIZATION METHOD BODY :
296 // but this is where you should allocate the internal/output pointers
302 // 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)
304 void TubeFilter::bbUserFinalizeProcessing()
306 // THE FINALIZATION METHOD BODY :
308 // but this is where you should desallocate the internal/output pointers
313 // EO namespace bbcreaMaracasVisu