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);
219 void TubeTreeFilter::DrawOneTube(int iGeneral,int numPoints, int iTube)
222 unsigned int nTv = 8; // No. of surface elements for each tube vertex
225 // img->GetSpacing(spc);
230 int size=iGeneral+numPoints;
232 // Create points and cells
233 vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New();
234 //EED vtkPoints *points = vtkPoints::New();
235 vtkSmartPointer<vtkCellArray> lines = vtkSmartPointer<vtkCellArray>::New();
236 //EED vtkCellArray *lines = vtkCellArray::New();
238 lines->InsertNextCell( numPoints );
240 for (i=iGeneral;i<size;i++)
242 points->InsertPoint(i-iGeneral, bbGetInputlstPointX()[i]*spc[0],
243 bbGetInputlstPointY()[i]*spc[1],
244 bbGetInputlstPointZ()[i]*spc[2] );
245 lines->InsertCellPoint(i-iGeneral);
248 vtkSmartPointer<vtkPolyData> polyData = vtkSmartPointer<vtkPolyData>::New();
249 //EED vtkPolyData *polyData = vtkPolyData::New();
250 polyData->SetPoints(points);
251 polyData->SetLines(lines);
254 // Varying tube radius using sine-function
255 vtkSmartPointer<vtkDoubleArray> tubeRadius = vtkSmartPointer<vtkDoubleArray>::New();
256 //EED vtkDoubleArray *tubeRadius = vtkDoubleArray::New();
257 tubeRadius->SetName("TubeRadius");
258 tubeRadius->SetNumberOfTuples( numPoints );
259 for (i=iGeneral;i<size;i++)
261 tubeRadius->SetTuple1(i-iGeneral, bbGetInputlstRadio()[i] );
263 polyData->GetPointData()->AddArray(tubeRadius);
264 polyData->GetPointData()->SetActiveScalars("TubeRadius");
268 // Adding spheres at the start and end of the tube
272 vtkSphereSource *vtksphereStart = vtkSphereSource::New();
273 vtksphereStart->SetThetaResolution (10);
274 vtksphereStart->SetPhiResolution (10);
275 vtksphereStart->SetRadius( bbGetInputlstRadio()[i] );
276 vtkPolyDataMapper *sphereMapperStart = vtkPolyDataMapper::New();
277 sphereMapperStart->SetInput( vtksphereStart->GetOutput() );
278 vtkActor *sphereActorStart = vtkActor::New();
279 sphereActorStart->SetMapper(sphereMapperStart);
280 sphereActorStart->SetOrigin( 0,0,0 );
281 sphereActorStart->SetPosition(bbGetInputlstPointX()[i]*spc[0], bbGetInputlstPointY()[i]*spc[1], bbGetInputlstPointZ()[i]*spc[2] );
285 vtkSphereSource *vtksphereEnd = vtkSphereSource::New();
286 vtksphereEnd->SetThetaResolution (10);
287 vtksphereEnd->SetPhiResolution (10);
288 vtksphereEnd->SetRadius( bbGetInputlstRadio()[i] );
289 vtkPolyDataMapper *sphereMapperEnd = vtkPolyDataMapper::New();
290 sphereMapperEnd->SetInput( vtksphereEnd->GetOutput() );
291 vtkActor *sphereActorEnd = vtkActor::New();
292 sphereActorEnd->SetMapper(sphereMapperEnd);
293 sphereActorEnd->SetOrigin( 0,0,0 );
294 sphereActorEnd->SetPosition(bbGetInputlstPointX()[i]*spc[0], bbGetInputlstPointY()[i]*spc[1], bbGetInputlstPointZ()[i]*spc[2] );
296 vtkSmartPointer<vtkTubeFilter> tube = vtkSmartPointer<vtkTubeFilter>::New();
297 tube->SetInput(polyData);
298 tube->SetNumberOfSides(nTv);
299 tube->SetVaryRadiusToVaryRadiusByAbsoluteScalar();
301 vtkLookupTableEED* vLutEED = vtkLookupTableEED::New();
303 vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
304 mapper->SetInputConnection(tube->GetOutputPort());
305 mapper->ScalarVisibilityOn();
308 mapper->SetScalarModeToUsePointFieldData();
309 mapper->SetLookupTable( vLutEED );
310 mapper->SelectColorArray( "points_axe" );
312 // vtkSmartPointer<vtkActor> actor =vtkSmartPointer<vtkActor>::New();
313 vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New();
314 actor->SetMapper(mapper);
316 vecVtkActors.push_back( actor );
317 vecVtkActors.push_back( sphereActorEnd );
318 vecVtkActors.push_back( sphereActorStart );
320 // Interface Update // Interface Update
321 if (bbGetInputRenderer()!=NULL )
323 bbGetInputRenderer()->AddActor( actor );
324 bbGetInputRenderer()->AddActor( sphereActorStart );
325 bbGetInputRenderer()->AddActor( sphereActorEnd );
330 void TubeTreeFilter::SetGraphicProperties()
332 int iTube,sizeLstAxis=bbGetInputlstIndexs().size();
335 vtkActor *actorSpherEnd;
336 vtkActor *actorSpherStart;
340 r = bbGetInputColour()[0];
341 g = bbGetInputColour()[1];
342 b = bbGetInputColour()[2];
343 for (iTube=0 ; iTube<sizeLstAxis; iTube++)
346 actorTube=vecVtkActors[0+iTube*3];
347 actorSpherEnd=vecVtkActors[1+iTube*3];
348 actorSpherStart=vecVtkActors[2+iTube*3];
351 actorTube->GetProperty()->SetOpacity( bbGetInputOpacity() );
352 actorSpherEnd->GetProperty()->SetOpacity( bbGetInputOpacity() );
353 actorSpherStart->GetProperty()->SetOpacity( bbGetInputOpacity() );
356 if ( bbGetInputTransform()!=NULL )
358 actorTube->SetUserTransform( bbGetInputTransform() );
359 actorSpherEnd->SetUserTransform( bbGetInputTransform() );
360 actorSpherStart->SetUserTransform( bbGetInputTransform() );
363 if (bbGetInputColourLaw()==1) // One solide colour
368 if (bbGetInputColourLaw()==2) // color for differents tubes
370 if ( (iTube*3+1) < (int)(bbGetInputColour().size()) )
372 r = bbGetInputColour()[0+iTube*3];
373 g = bbGetInputColour()[1+iTube*3];
374 b = bbGetInputColour()[2+iTube*3];
376 r = (rand() % 100) / 100.0;
377 g = (rand() % 100) / 100.0;
378 b = (rand() % 100) / 100.0;
382 actorTube->GetProperty()->SetColor( r,g,b );
383 actorSpherEnd->GetProperty()->SetColor( r,g,b );
384 actorSpherStart->GetProperty()->SetColor( r,g,b );
389 // 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)
391 void TubeTreeFilter::Process()
394 printf("EED TubeTreeFilter::Process start \n");
397 int iTube,sizeLstAxis=bbGetInputlstIndexs().size();
398 int iActor,sizeActors = vecVtkActors.size();
401 if (oldLstSize!=sizeLstAxis)
403 oldLstSize=sizeLstAxis;
404 for (iActor=0 ; iActor<sizeActors; iActor++)
406 if (bbGetInputRenderer()!=NULL )
408 bbGetInputRenderer()->RemoveActor( vecVtkActors[iActor] );
409 //EED vecVtkPolyData[iActor]->Delete();
410 //EED vecVtkPolyDataMaper[iActor]->Delete();
411 //EED vecVtkActors[iActor]->Delete();
415 //EED vecVtkPolyData.clear();
416 //EED vecVtkPolyDataMaper.clear();
417 vecVtkActors.clear();
419 for ( iTube=0 ; iTube<sizeLstAxis ; iTube++)
421 numPoints = bbGetInputlstIndexs()[iTube];
422 DrawOneTube(iGeneral,numPoints,iTube);
423 iGeneral = iGeneral+numPoints;
426 if ( bbGetInputiTube()*3 <= (int)(vecVtkActors.size()-1) )
428 bbSetOutputOutTube( vecVtkActors[ bbGetInputiTube()*3 ] );
430 printf("TubeTreeFilter .ERROR. missing index vector...\n");
431 }// vector Actor size
433 SetGraphicProperties();
435 printf("EED TubeTreeFilter::Process end \n");
438 // 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)
440 void TubeTreeFilter::bbUserSetDefaultValues()
444 // SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX
445 // Here we initialize the input 'In' to 0
447 std::vector<double> colour;
449 colour.push_back(0.5);
450 colour.push_back(0.5);
451 colour.push_back(0.5);
453 colour.push_back(1.0);
454 colour.push_back(0.0);
455 colour.push_back(0.0);
457 colour.push_back(0.0);
458 colour.push_back(0.0);
459 colour.push_back(1.0);
461 colour.push_back(1.0);
462 colour.push_back(1.0);
463 colour.push_back(0.0);
465 colour.push_back(0.0);
466 colour.push_back(1.0);
467 colour.push_back(0.0);
469 colour.push_back(0.0);
470 colour.push_back(1.0);
471 colour.push_back(1.0);
474 colour.push_back(0.5);
475 colour.push_back(0.5);
476 colour.push_back(0.5);
478 bbSetInputColour(colour);
479 bbSetInputTransform(NULL);
480 bbSetInputRenderer(NULL);
481 bbSetInputColourLaw(1);
482 bbSetInputOpacity(1);
486 // 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)
488 void TubeTreeFilter::bbUserInitializeProcessing()
491 // THE INITIALIZATION METHOD BODY :
493 // but this is where you should allocate the internal/output pointers
499 // 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)
501 void TubeTreeFilter::bbUserFinalizeProcessing()
504 // THE FINALIZATION METHOD BODY :
506 // but this is where you should desallocate the internal/output pointers
511 // EO namespace bbcreaMaracasVisu