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 <vtkSphereSource.h>
38 #include "vtkObjectFactory.h"
42 vtkStandardNewMacro(vtkLookupTableEED);
44 // Construct with range=(0,1); and hsv ranges set up for rainbow color table
45 // (from red to blue).
46 vtkLookupTableEED::vtkLookupTableEED(int sze, int ext)
48 this->TableRange[0] = 0.0;
49 this->TableRange[1] = 1.0;
52 //----------------------------------------------------------------------------
53 vtkLookupTableEED::~vtkLookupTableEED()
59 unsigned char *vtkLookupTableEED::MapValue(double v)
62 //int idx = this->GetIndex(v);
63 //return (this->Table->GetPointer(0) + 4*idx);
68 void vtkLookupTableEED::GetColor(double v, double rgb[3])
70 // unsigned char *rgb8 = this->MapValue(v);
71 // rgb[0] = rgb8[0]/255.0;
72 // rgb[1] = rgb8[1]/255.0;
73 // rgb[2] = rgb8[2]/255.0;
81 void vtkLookupTableEED::SetTableRange(double r[2])
83 this->SetTableRange(r[0],r[1]);
86 //----------------------------------------------------------------------------
87 // Set the minimum/maximum scalar values for scalar mapping. Scalar values
88 // less than minimum range value are clamped to minimum range value.
89 // Scalar values greater than maximum range value are clamped to maximum
91 void vtkLookupTableEED::SetTableRange(double rmin, double rmax)
95 vtkErrorMacro("Bad table range: ["<<rmin<<", "<<rmax<<"]");
99 if (this->TableRange[0] == rmin && this->TableRange[1] == rmax)
104 this->TableRange[0] = rmin;
105 this->TableRange[1] = rmax;
112 //----------------------------------------------------------------------------
113 // Although this is a relatively expensive calculation,
114 // it is only done on the first render. Colors are cached
115 // for subsequent renders.
117 void vtkLookupTableMapDirVectorEED(vtkLookupTableEED *self, T *input,
118 unsigned char *output, int length,
119 int inIncr, int outFormat)
124 double dirx,diry,dirz;
127 printf("EED length %d %p\n", length,input);
128 // mag = new double[length];
129 for (i = 0; i < length; ++i)
135 for (j = 0; j < inIncr; ++j)
137 if (j==0) dirx= static_cast<double>(*input);
138 if (j==1) diry= static_cast<double>(*input);
139 if (j==2) dirz= static_cast<double>(*input);
140 tmp = static_cast<double>(*input);
145 *output++ = (unsigned char) abs( (255*dirx/sum) );
146 *output++ = (unsigned char) abs( (255*diry/sum) );
147 *output++ = (unsigned char) abs( (255*dirz/sum) );
149 // printf("%d %d %d ",(int)(255*dirx/sum),(int)(255*diry/sum),(int)(255*dirz/sum));
152 // vtkLookupTableMapData(self, mag, output, length, 1, outFormat);
159 //----------------------------------------------------------------------------
160 void vtkLookupTableEED::MapScalarsThroughTable2(void *input,
161 unsigned char *output,
168 printf("vtkLookupTableEED::MapScalarsThroughTable2 inputIncrement=%d inputDataType=%d\n",inputIncrement,inputDataType);
171 // if (this->UseMagnitude && inputIncrement > 1)
173 switch (inputDataType)
176 vtkLookupTableMapDirVectorEED(this,static_cast<VTK_TT*>(input),output,
177 numberOfValues,inputIncrement,outputFormat);
181 vtkErrorMacro("Cannot comput magnitude of bit array.");
184 vtkErrorMacro(<< "MapImageThroughTable: Unknown input ScalarType");
191 //----------------------------------------------------------------------------
192 void vtkLookupTableEED::PrintSelf(ostream& os, vtkIndent indent)
194 this->Superclass::PrintSelf(os,indent);
200 //----------------------------------
201 //----------------------------------
202 //----------------------------------
203 //----------------------------------
204 //----------------------------------
208 namespace bbcreaMaracasVisu
214 BBTK_ADD_BLACK_BOX_TO_PACKAGE(creaMaracasVisu,TubeTreeFilter)
215 BBTK_BLACK_BOX_IMPLEMENTATION(TubeTreeFilter,bbtk::AtomicBlackBox);
218 void TubeTreeFilter::SetRadioTube(int iGeneral,int numPoints, int iTube)
222 int size=iGeneral+numPoints;
223 vtkDoubleArray *tubeRadius = vecTubeRadiosArray[iTube];
225 if (bbGetInputlstRadio().size()>=1)
227 if (bbGetInputlstRadioLaw()==0) // for All
229 radiotmp=bbGetInputlstRadio()[0];
232 if (bbGetInputlstRadioLaw()==1) // by segment
234 if (bbGetInputlstRadio().size()>=iTube)
236 radiotmp=bbGetInputlstRadio()[iTube];
238 radiotmp=bbGetInputlstRadio()[ bbGetInputlstRadio().size()-1 ];
240 } // Law 1 by segment
242 for (i=iGeneral;i<size;i++)
244 if (bbGetInputlstRadioLaw()==2) // by point
246 if (bbGetInputlstRadio().size()>=i)
248 radiotmp=bbGetInputlstRadio()[i];
250 radiotmp=bbGetInputlstRadio()[ bbGetInputlstRadio().size()-1 ];
253 tubeRadius->SetTuple1(i-iGeneral, radiotmp );
255 tubeRadius->Modified();
256 } // bbGetInputlstRadio().size()>=1
262 void TubeTreeFilter::DrawOneTube(int iGeneral,int numPoints, int iTube)
265 unsigned int nTv = 8; // No. of surface elements for each tube vertex
268 // img->GetSpacing(spc);
273 int size=iGeneral+numPoints;
275 // Create points and cells
276 vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New();
277 //EED vtkPoints *points = vtkPoints::New();
278 vtkSmartPointer<vtkCellArray> lines = vtkSmartPointer<vtkCellArray>::New();
279 //EED vtkCellArray *lines = vtkCellArray::New();
281 lines->InsertNextCell( numPoints );
283 for (i=iGeneral;i<size;i++)
285 points->InsertPoint(i-iGeneral, bbGetInputlstPointX()[i]*spc[0],
286 bbGetInputlstPointY()[i]*spc[1],
287 bbGetInputlstPointZ()[i]*spc[2] );
288 lines->InsertCellPoint(i-iGeneral);
291 vtkSmartPointer<vtkPolyData> polyData = vtkSmartPointer<vtkPolyData>::New();
292 //EED vtkPolyData *polyData = vtkPolyData::New();
293 polyData->SetPoints(points);
294 polyData->SetLines(lines);
297 // Varying tube radius using sine-function
298 vtkSmartPointer<vtkDoubleArray> tubeRadius = vtkSmartPointer<vtkDoubleArray>::New();
299 //EED vtkDoubleArray *tubeRadius = vtkDoubleArray::New();
300 tubeRadius->SetName("TubeRadius");
301 tubeRadius->SetNumberOfTuples( numPoints );
302 vecTubeRadiosArray.push_back( tubeRadius );
305 polyData->GetPointData()->AddArray(tubeRadius);
306 polyData->GetPointData()->SetActiveScalars("TubeRadius");
310 // Adding spheres at the start and end of the tube
314 vtkSphereSource *vtksphereStart = vtkSphereSource::New();
315 vtksphereStart->SetThetaResolution (10);
316 vtksphereStart->SetPhiResolution (10);
317 vtksphereStart->SetRadius( bbGetInputlstRadio()[i] );
318 vtkPolyDataMapper *sphereMapperStart = vtkPolyDataMapper::New();
319 sphereMapperStart->SetInput( vtksphereStart->GetOutput() );
320 vtkActor *sphereActorStart = vtkActor::New();
321 sphereActorStart->SetMapper(sphereMapperStart);
322 sphereActorStart->SetOrigin( 0,0,0 );
323 sphereActorStart->SetPosition(bbGetInputlstPointX()[i]*spc[0], bbGetInputlstPointY()[i]*spc[1], bbGetInputlstPointZ()[i]*spc[2] );
327 vtkSphereSource *vtksphereEnd = vtkSphereSource::New();
328 vtksphereEnd->SetThetaResolution (10);
329 vtksphereEnd->SetPhiResolution (10);
330 vtksphereEnd->SetRadius( bbGetInputlstRadio()[i] );
331 vtkPolyDataMapper *sphereMapperEnd = vtkPolyDataMapper::New();
332 sphereMapperEnd->SetInput( vtksphereEnd->GetOutput() );
333 vtkActor *sphereActorEnd = vtkActor::New();
334 sphereActorEnd->SetMapper(sphereMapperEnd);
335 sphereActorEnd->SetOrigin( 0,0,0 );
336 sphereActorEnd->SetPosition(bbGetInputlstPointX()[i]*spc[0], bbGetInputlstPointY()[i]*spc[1], bbGetInputlstPointZ()[i]*spc[2] );
338 vtkSmartPointer<vtkTubeFilter> tube = vtkSmartPointer<vtkTubeFilter>::New();
339 tube->SetInput(polyData);
340 tube->SetNumberOfSides(nTv);
341 tube->SetVaryRadiusToVaryRadiusByAbsoluteScalar();
343 vtkLookupTableEED* vLutEED = vtkLookupTableEED::New();
345 vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
346 mapper->SetInputConnection(tube->GetOutputPort());
347 mapper->ScalarVisibilityOn();
350 mapper->SetScalarModeToUsePointFieldData();
351 mapper->SetLookupTable( vLutEED );
352 mapper->SelectColorArray( "points_axe" );
354 // vtkSmartPointer<vtkActor> actor =vtkSmartPointer<vtkActor>::New();
355 vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New();
356 actor->SetMapper(mapper);
358 vecVtkActors.push_back( actor );
359 vecVtkActors.push_back( sphereActorEnd );
360 vecVtkActors.push_back( sphereActorStart );
362 // Interface Update // Interface Update
363 if (bbGetInputRenderer()!=NULL )
365 bbGetInputRenderer()->AddActor( actor );
366 bbGetInputRenderer()->AddActor( sphereActorStart );
367 bbGetInputRenderer()->AddActor( sphereActorEnd );
372 void TubeTreeFilter::SetGraphicProperties()
374 int iTube,sizeLstAxis=bbGetInputlstIndexs().size();
380 vtkActor *actorSpherEnd;
381 vtkActor *actorSpherStart;
385 r = bbGetInputColour()[0];
386 g = bbGetInputColour()[1];
387 b = bbGetInputColour()[2];
388 for (iTube=0 ; iTube<sizeLstAxis; iTube++)
391 actorTube=vecVtkActors[0+iTube*3];
392 actorSpherEnd=vecVtkActors[1+iTube*3];
393 actorSpherStart=vecVtkActors[2+iTube*3];
396 actorTube->GetProperty()->SetOpacity( bbGetInputOpacity() );
397 actorSpherEnd->GetProperty()->SetOpacity( bbGetInputOpacity() );
398 actorSpherStart->GetProperty()->SetOpacity( bbGetInputOpacity() );
401 if ( bbGetInputTransform()!=NULL )
403 actorTube->SetUserTransform( bbGetInputTransform() );
404 actorSpherEnd->SetUserTransform( bbGetInputTransform() );
405 actorSpherStart->SetUserTransform( bbGetInputTransform() );
409 if (bbGetInputColourLaw()==1) // One solide colour
414 if (bbGetInputColourLaw()==2) // color for differents tubes
416 if ( (iTube*3+1) < (int)(bbGetInputColour().size()) )
418 r = bbGetInputColour()[0+iTube*3];
419 g = bbGetInputColour()[1+iTube*3];
420 b = bbGetInputColour()[2+iTube*3];
422 r = (rand() % 100) / 100.0;
423 g = (rand() % 100) / 100.0;
424 b = (rand() % 100) / 100.0;
428 actorTube->GetProperty()->SetColor( r,g,b );
429 actorSpherEnd->GetProperty()->SetColor( r,g,b );
430 actorSpherStart->GetProperty()->SetColor( r,g,b );
434 numPoints = bbGetInputlstIndexs()[iTube];
435 SetRadioTube(iGeneral,numPoints,iTube);
436 iGeneral = iGeneral+numPoints;
442 // 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)
444 void TubeTreeFilter::Process()
447 printf("EED TubeTreeFilter::Process start \n");
450 int iTube,sizeLstAxis=bbGetInputlstIndexs().size();
451 int iActor,sizeActors = vecVtkActors.size();
454 if (oldLstSize!=sizeLstAxis)
456 oldLstSize=sizeLstAxis;
457 for (iActor=0 ; iActor<sizeActors; iActor++)
459 if (bbGetInputRenderer()!=NULL )
461 bbGetInputRenderer()->RemoveActor( vecVtkActors[iActor] );
462 //EED vecVtkPolyData[iActor]->Delete();
463 //EED vecVtkPolyDataMaper[iActor]->Delete();
464 //EED vecVtkActors[iActor]->Delete();
468 //EED vecVtkPolyData.clear();
469 //EED vecVtkPolyDataMaper.clear();
470 vecVtkActors.clear();
471 vecTubeRadiosArray.clear();
473 for ( iTube=0 ; iTube<sizeLstAxis ; iTube++)
475 numPoints = bbGetInputlstIndexs()[iTube];
476 DrawOneTube(iGeneral,numPoints,iTube);
477 iGeneral = iGeneral+numPoints;
480 if ( bbGetInputiTube()*3 <= (int)(vecVtkActors.size()-1) )
482 bbSetOutputOutTube( vecVtkActors[ bbGetInputiTube()*3 ] );
484 printf("TubeTreeFilter .ERROR. missing index vector...\n");
485 }// vector Actor size
487 SetGraphicProperties();
489 printf("EED TubeTreeFilter::Process end \n");
492 // 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)
494 void TubeTreeFilter::bbUserSetDefaultValues()
498 // SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX
499 // Here we initialize the input 'In' to 0
501 std::vector<double> colour;
503 colour.push_back(0.5);
504 colour.push_back(0.5);
505 colour.push_back(0.5);
507 colour.push_back(1.0);
508 colour.push_back(0.0);
509 colour.push_back(0.0);
511 colour.push_back(0.0);
512 colour.push_back(0.0);
513 colour.push_back(1.0);
515 colour.push_back(1.0);
516 colour.push_back(1.0);
517 colour.push_back(0.0);
519 colour.push_back(0.0);
520 colour.push_back(1.0);
521 colour.push_back(0.0);
523 colour.push_back(0.0);
524 colour.push_back(1.0);
525 colour.push_back(1.0);
528 colour.push_back(0.5);
529 colour.push_back(0.5);
530 colour.push_back(0.5);
532 bbSetInputColour(colour);
533 bbSetInputTransform(NULL);
534 bbSetInputRenderer(NULL);
535 bbSetInputColourLaw(1);
536 bbSetInputOpacity(1);
538 std::vector<double> radio;
540 bbSetInputlstRadio( radio );
541 bbSetInputlstRadioLaw( 0 ); // for all
545 // 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)
547 void TubeTreeFilter::bbUserInitializeProcessing()
550 // THE INITIALIZATION METHOD BODY :
552 // but this is where you should allocate the internal/output pointers
558 // 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)
560 void TubeTreeFilter::bbUserFinalizeProcessing()
563 // THE FINALIZATION METHOD BODY :
565 // but this is where you should desallocate the internal/output pointers
570 // EO namespace bbcreaMaracasVisu