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 "bbcreaMaracasVisuTubeTreeFilter.h"
30 #include "bbcreaMaracasVisuPackage.h"
32 #include <vtkSmartPointer.h>
33 #include <vtkDoubleArray.h>
34 #include <vtkPolyData.h>
35 #include <vtkPointData.h>
36 #include <vtkTubeFilter.h>
37 #include "vtkObjectFactory.h"
41 vtkStandardNewMacro(vtkLookupTableEED);
43 // Construct with range=(0,1); and hsv ranges set up for rainbow color table
44 // (from red to blue).
45 vtkLookupTableEED::vtkLookupTableEED(int sze, int ext)
47 this->TableRange[0] = 0.0;
48 this->TableRange[1] = 1.0;
51 //----------------------------------------------------------------------------
52 vtkLookupTableEED::~vtkLookupTableEED()
58 unsigned char *vtkLookupTableEED::MapValue(double v)
61 //int idx = this->GetIndex(v);
62 //return (this->Table->GetPointer(0) + 4*idx);
67 void vtkLookupTableEED::GetColor(double v, double rgb[3])
69 // unsigned char *rgb8 = this->MapValue(v);
70 // rgb[0] = rgb8[0]/255.0;
71 // rgb[1] = rgb8[1]/255.0;
72 // rgb[2] = rgb8[2]/255.0;
80 void vtkLookupTableEED::SetTableRange(double r[2])
82 this->SetTableRange(r[0],r[1]);
85 //----------------------------------------------------------------------------
86 // Set the minimum/maximum scalar values for scalar mapping. Scalar values
87 // less than minimum range value are clamped to minimum range value.
88 // Scalar values greater than maximum range value are clamped to maximum
90 void vtkLookupTableEED::SetTableRange(double rmin, double rmax)
94 vtkErrorMacro("Bad table range: ["<<rmin<<", "<<rmax<<"]");
98 if (this->TableRange[0] == rmin && this->TableRange[1] == rmax)
103 this->TableRange[0] = rmin;
104 this->TableRange[1] = rmax;
111 //----------------------------------------------------------------------------
112 // Although this is a relatively expensive calculation,
113 // it is only done on the first render. Colors are cached
114 // for subsequent renders.
116 void vtkLookupTableMapDirVectorEED(vtkLookupTableEED *self, T *input,
117 unsigned char *output, int length,
118 int inIncr, int outFormat)
123 double dirx,diry,dirz;
126 printf("EED length %d %p\n", length,input);
127 // mag = new double[length];
128 for (i = 0; i < length; ++i)
134 for (j = 0; j < inIncr; ++j)
136 if (j==0) dirx= static_cast<double>(*input);
137 if (j==1) diry= static_cast<double>(*input);
138 if (j==2) dirz= static_cast<double>(*input);
139 tmp = static_cast<double>(*input);
144 *output++ = (unsigned char) abs( (255*dirx/sum) );
145 *output++ = (unsigned char) abs( (255*diry/sum) );
146 *output++ = (unsigned char) abs( (255*dirz/sum) );
148 // printf("%d %d %d ",(int)(255*dirx/sum),(int)(255*diry/sum),(int)(255*dirz/sum));
151 // vtkLookupTableMapData(self, mag, output, length, 1, outFormat);
158 //----------------------------------------------------------------------------
159 void vtkLookupTableEED::MapScalarsThroughTable2(void *input,
160 unsigned char *output,
167 printf("vtkLookupTableEED::MapScalarsThroughTable2 inputIncrement=%d inputDataType=%d\n",inputIncrement,inputDataType);
170 // if (this->UseMagnitude && inputIncrement > 1)
172 switch (inputDataType)
175 vtkLookupTableMapDirVectorEED(this,static_cast<VTK_TT*>(input),output,
176 numberOfValues,inputIncrement,outputFormat);
180 vtkErrorMacro("Cannot comput magnitude of bit array.");
183 vtkErrorMacro(<< "MapImageThroughTable: Unknown input ScalarType");
190 //----------------------------------------------------------------------------
191 void vtkLookupTableEED::PrintSelf(ostream& os, vtkIndent indent)
193 this->Superclass::PrintSelf(os,indent);
199 //----------------------------------
200 //----------------------------------
201 //----------------------------------
202 //----------------------------------
203 //----------------------------------
207 namespace bbcreaMaracasVisu
213 BBTK_ADD_BLACK_BOX_TO_PACKAGE(creaMaracasVisu,TubeTreeFilter)
214 BBTK_BLACK_BOX_IMPLEMENTATION(TubeTreeFilter,bbtk::AtomicBlackBox);
217 void TubeTreeFilter::SetRadioTube(int iGeneral,int numPoints, int iTube)
221 int size=iGeneral+numPoints;
222 vtkDoubleArray *tubeRadius = vecTubeRadiosArray[iTube];
224 if (bbGetInputlstRadio().size()>=1)
226 if (bbGetInputlstRadioLaw()==0) // for All
228 radiotmp=bbGetInputlstRadio()[0];
231 if (bbGetInputlstRadioLaw()==1) // by segment
233 if (bbGetInputlstRadio().size()>=iTube)
235 radiotmp=bbGetInputlstRadio()[iTube];
237 radiotmp=bbGetInputlstRadio()[ bbGetInputlstRadio().size()-1 ];
239 } // Law 1 by segment
241 for (i=iGeneral;i<size;i++)
243 if (bbGetInputlstRadioLaw()==2) // by point
245 if (bbGetInputlstRadio().size()>=i)
247 radiotmp=bbGetInputlstRadio()[i];
249 radiotmp=bbGetInputlstRadio()[ bbGetInputlstRadio().size()-1 ];
252 tubeRadius->SetTuple1(i-iGeneral, radiotmp );
254 tubeRadius->Modified();
255 } // bbGetInputlstRadio().size()>=1
261 void TubeTreeFilter::DrawOneTube(int iGeneral,int numPoints, int iTube)
264 unsigned int nTv = 8; // No. of surface elements for each tube vertex
267 // img->GetSpacing(spc);
272 int size=iGeneral+numPoints;
274 // Create points and cells
275 vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New();
276 //EED vtkPoints *points = vtkPoints::New();
277 vtkSmartPointer<vtkCellArray> lines = vtkSmartPointer<vtkCellArray>::New();
278 //EED vtkCellArray *lines = vtkCellArray::New();
280 lines->InsertNextCell( numPoints );
282 for (i=iGeneral;i<size;i++)
284 points->InsertPoint(i-iGeneral, bbGetInputlstPointX()[i]*spc[0],
285 bbGetInputlstPointY()[i]*spc[1],
286 bbGetInputlstPointZ()[i]*spc[2] );
287 lines->InsertCellPoint(i-iGeneral);
290 vtkSmartPointer<vtkPolyData> polyData = vtkSmartPointer<vtkPolyData>::New();
291 //EED vtkPolyData *polyData = vtkPolyData::New();
292 polyData->SetPoints(points);
293 polyData->SetLines(lines);
296 // Varying tube radius using sine-function
297 vtkSmartPointer<vtkDoubleArray> tubeRadius = vtkSmartPointer<vtkDoubleArray>::New();
298 //EED vtkDoubleArray *tubeRadius = vtkDoubleArray::New();
299 tubeRadius->SetName("TubeRadius");
300 tubeRadius->SetNumberOfTuples( numPoints );
301 vecTubeRadiosArray.push_back( tubeRadius );
304 polyData->GetPointData()->AddArray(tubeRadius);
305 polyData->GetPointData()->SetActiveScalars("TubeRadius");
309 vtkSmartPointer<vtkTubeFilter> tube = vtkSmartPointer<vtkTubeFilter>::New();
310 //EED 2017-01-01 Migration VTK7
311 #if VTK_MAJOR_VERSION <= 5
312 tube->SetInput(polyData);
314 tube->SetInputData(polyData);
316 tube->SetNumberOfSides(nTv);
317 tube->SetVaryRadiusToVaryRadiusByAbsoluteScalar();
320 vtkLookupTableEED* vLutEED = vtkLookupTableEED::New();
322 vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
323 mapper->SetInputConnection(tube->GetOutputPort());
324 mapper->ScalarVisibilityOn();
327 mapper->SetScalarModeToUsePointFieldData();
328 mapper->SetLookupTable( vLutEED );
329 mapper->SelectColorArray( "points_axe" );
331 // vtkSmartPointer<vtkActor> actor =vtkSmartPointer<vtkActor>::New();
332 vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New();
333 actor->SetMapper(mapper);
335 vecVtkActors.push_back( actor );
337 // Interface Update // Interface Update
338 if (bbGetInputRenderer()!=NULL )
340 bbGetInputRenderer()->AddActor( actor );
345 void TubeTreeFilter::SetGraphicProperties()
347 int iTube,sizeLstAxis=bbGetInputlstIndexs().size();
355 r = bbGetInputColour()[0];
356 g = bbGetInputColour()[1];
357 b = bbGetInputColour()[2];
358 for (iTube=0 ; iTube<sizeLstAxis; iTube++)
362 actorTube=vecVtkActors[iTube];
365 actorTube->GetProperty()->SetOpacity( bbGetInputOpacity() );
368 if ( bbGetInputTransform()!=NULL )
370 actorTube->SetUserTransform( bbGetInputTransform() );
374 if (bbGetInputColourLaw()==1) // One solide colour
379 if (bbGetInputColourLaw()==2) // color for differents tubes
381 if ( (iTube*3+1) < (int)(bbGetInputColour().size()) )
383 r = bbGetInputColour()[0+iTube*3];
384 g = bbGetInputColour()[1+iTube*3];
385 b = bbGetInputColour()[2+iTube*3];
387 r = (rand() % 100) / 100.0;
388 g = (rand() % 100) / 100.0;
389 b = (rand() % 100) / 100.0;
393 actorTube->GetProperty()->SetColor( r,g,b );
397 numPoints = bbGetInputlstIndexs()[iTube];
398 SetRadioTube(iGeneral,numPoints,iTube);
399 iGeneral = iGeneral+numPoints;
405 // 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)
407 void TubeTreeFilter::Process()
410 printf("EED TubeTreeFilter::Process start \n");
413 int iTube,sizeLstAxis=bbGetInputlstIndexs().size();
414 int iActor,sizeActors = vecVtkActors.size();
417 if (oldLstSize!=sizeLstAxis)
419 oldLstSize=sizeLstAxis;
420 for (iActor=0 ; iActor<sizeActors; iActor++)
422 if (bbGetInputRenderer()!=NULL )
424 bbGetInputRenderer()->RemoveActor( vecVtkActors[iActor] );
425 //EED vecVtkPolyData[iActor]->Delete();
426 //EED vecVtkPolyDataMaper[iActor]->Delete();
427 //EED vecVtkActors[iActor]->Delete();
431 //EED vecVtkPolyData.clear();
432 //EED vecVtkPolyDataMaper.clear();
433 vecVtkActors.clear();
434 vecTubeRadiosArray.clear();
436 for ( iTube=0 ; iTube<sizeLstAxis ; iTube++)
438 numPoints = bbGetInputlstIndexs()[iTube];
439 DrawOneTube(iGeneral,numPoints,iTube);
440 iGeneral = iGeneral+numPoints;
443 if ( bbGetInputiTube() <= (int)(vecVtkActors.size()-1) )
445 bbSetOutputOutTube( vecVtkActors[ bbGetInputiTube() ] );
447 printf("TubeTreeFilter .ERROR. missing index vector...\n");
448 }// vector Actor size
451 SetGraphicProperties();
453 printf("EED TubeTreeFilter::Process end \n");
456 // 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)
458 void TubeTreeFilter::bbUserSetDefaultValues()
462 // SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX
463 // Here we initialize the input 'In' to 0
465 std::vector<double> colour;
467 colour.push_back(0.5);
468 colour.push_back(0.5);
469 colour.push_back(0.5);
471 colour.push_back(1.0);
472 colour.push_back(0.0);
473 colour.push_back(0.0);
475 colour.push_back(0.0);
476 colour.push_back(0.0);
477 colour.push_back(1.0);
479 colour.push_back(1.0);
480 colour.push_back(1.0);
481 colour.push_back(0.0);
483 colour.push_back(0.0);
484 colour.push_back(1.0);
485 colour.push_back(0.0);
487 colour.push_back(0.0);
488 colour.push_back(1.0);
489 colour.push_back(1.0);
492 colour.push_back(0.5);
493 colour.push_back(0.5);
494 colour.push_back(0.5);
496 bbSetInputColour(colour);
497 bbSetInputTransform(NULL);
498 bbSetInputRenderer(NULL);
499 bbSetInputColourLaw(1);
500 bbSetInputOpacity(1);
502 std::vector<double> radio;
504 bbSetInputlstRadio( radio );
505 bbSetInputlstRadioLaw( 0 ); // for all
509 // 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)
511 void TubeTreeFilter::bbUserInitializeProcessing()
514 // THE INITIALIZATION METHOD BODY :
516 // but this is where you should allocate the internal/output pointers
522 // 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)
524 void TubeTreeFilter::bbUserFinalizeProcessing()
527 // THE FINALIZATION METHOD BODY :
529 // but this is where you should desallocate the internal/output pointers
534 // EO namespace bbcreaMaracasVisu