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 tube->SetInput(polyData);
311 tube->SetNumberOfSides(nTv);
312 tube->SetVaryRadiusToVaryRadiusByAbsoluteScalar();
315 vtkLookupTableEED* vLutEED = vtkLookupTableEED::New();
317 vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
318 mapper->SetInputConnection(tube->GetOutputPort());
319 mapper->ScalarVisibilityOn();
322 mapper->SetScalarModeToUsePointFieldData();
323 mapper->SetLookupTable( vLutEED );
324 mapper->SelectColorArray( "points_axe" );
326 // vtkSmartPointer<vtkActor> actor =vtkSmartPointer<vtkActor>::New();
327 vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New();
328 actor->SetMapper(mapper);
330 vecVtkActors.push_back( actor );
332 // Interface Update // Interface Update
333 if (bbGetInputRenderer()!=NULL )
335 bbGetInputRenderer()->AddActor( actor );
340 void TubeTreeFilter::SetGraphicProperties()
342 int iTube,sizeLstAxis=bbGetInputlstIndexs().size();
350 r = bbGetInputColour()[0];
351 g = bbGetInputColour()[1];
352 b = bbGetInputColour()[2];
353 for (iTube=0 ; iTube<sizeLstAxis; iTube++)
357 actorTube=vecVtkActors[iTube];
360 actorTube->GetProperty()->SetOpacity( bbGetInputOpacity() );
363 if ( bbGetInputTransform()!=NULL )
365 actorTube->SetUserTransform( bbGetInputTransform() );
369 if (bbGetInputColourLaw()==1) // One solide colour
374 if (bbGetInputColourLaw()==2) // color for differents tubes
376 if ( (iTube*3+1) < (int)(bbGetInputColour().size()) )
378 r = bbGetInputColour()[0+iTube*3];
379 g = bbGetInputColour()[1+iTube*3];
380 b = bbGetInputColour()[2+iTube*3];
382 r = (rand() % 100) / 100.0;
383 g = (rand() % 100) / 100.0;
384 b = (rand() % 100) / 100.0;
388 actorTube->GetProperty()->SetColor( r,g,b );
392 numPoints = bbGetInputlstIndexs()[iTube];
393 SetRadioTube(iGeneral,numPoints,iTube);
394 iGeneral = iGeneral+numPoints;
400 // 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)
402 void TubeTreeFilter::Process()
405 printf("EED TubeTreeFilter::Process start \n");
408 int iTube,sizeLstAxis=bbGetInputlstIndexs().size();
409 int iActor,sizeActors = vecVtkActors.size();
412 if (oldLstSize!=sizeLstAxis)
414 oldLstSize=sizeLstAxis;
415 for (iActor=0 ; iActor<sizeActors; iActor++)
417 if (bbGetInputRenderer()!=NULL )
419 bbGetInputRenderer()->RemoveActor( vecVtkActors[iActor] );
420 //EED vecVtkPolyData[iActor]->Delete();
421 //EED vecVtkPolyDataMaper[iActor]->Delete();
422 //EED vecVtkActors[iActor]->Delete();
426 //EED vecVtkPolyData.clear();
427 //EED vecVtkPolyDataMaper.clear();
428 vecVtkActors.clear();
429 vecTubeRadiosArray.clear();
431 for ( iTube=0 ; iTube<sizeLstAxis ; iTube++)
433 numPoints = bbGetInputlstIndexs()[iTube];
434 DrawOneTube(iGeneral,numPoints,iTube);
435 iGeneral = iGeneral+numPoints;
438 if ( bbGetInputiTube() <= (int)(vecVtkActors.size()-1) )
440 bbSetOutputOutTube( vecVtkActors[ bbGetInputiTube() ] );
442 printf("TubeTreeFilter .ERROR. missing index vector...\n");
443 }// vector Actor size
446 SetGraphicProperties();
448 printf("EED TubeTreeFilter::Process end \n");
451 // 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)
453 void TubeTreeFilter::bbUserSetDefaultValues()
457 // SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX
458 // Here we initialize the input 'In' to 0
460 std::vector<double> colour;
462 colour.push_back(0.5);
463 colour.push_back(0.5);
464 colour.push_back(0.5);
466 colour.push_back(1.0);
467 colour.push_back(0.0);
468 colour.push_back(0.0);
470 colour.push_back(0.0);
471 colour.push_back(0.0);
472 colour.push_back(1.0);
474 colour.push_back(1.0);
475 colour.push_back(1.0);
476 colour.push_back(0.0);
478 colour.push_back(0.0);
479 colour.push_back(1.0);
480 colour.push_back(0.0);
482 colour.push_back(0.0);
483 colour.push_back(1.0);
484 colour.push_back(1.0);
487 colour.push_back(0.5);
488 colour.push_back(0.5);
489 colour.push_back(0.5);
491 bbSetInputColour(colour);
492 bbSetInputTransform(NULL);
493 bbSetInputRenderer(NULL);
494 bbSetInputColourLaw(1);
495 bbSetInputOpacity(1);
497 std::vector<double> radio;
499 bbSetInputlstRadio( radio );
500 bbSetInputlstRadioLaw( 0 ); // for all
504 // 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)
506 void TubeTreeFilter::bbUserInitializeProcessing()
509 // THE INITIALIZATION METHOD BODY :
511 // but this is where you should allocate the internal/output pointers
517 // 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)
519 void TubeTreeFilter::bbUserFinalizeProcessing()
522 // THE FINALIZATION METHOD BODY :
524 // but this is where you should desallocate the internal/output pointers
529 // EO namespace bbcreaMaracasVisu