2 // 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)
4 #include "bbcreaMaracasVisuTubeTreeFilter.h"
5 #include "bbcreaMaracasVisuPackage.h"
7 #include <vtkSmartPointer.h>
8 #include <vtkDoubleArray.h>
9 #include <vtkPolyData.h>
10 #include <vtkPointData.h>
11 #include <vtkTubeFilter.h>
12 #include <vtkSphereSource.h>
13 #include "vtkObjectFactory.h"
17 vtkStandardNewMacro(vtkLookupTableEED);
19 // Construct with range=(0,1); and hsv ranges set up for rainbow color table
20 // (from red to blue).
21 vtkLookupTableEED::vtkLookupTableEED(int sze, int ext)
23 this->TableRange[0] = 0.0;
24 this->TableRange[1] = 1.0;
27 //----------------------------------------------------------------------------
28 vtkLookupTableEED::~vtkLookupTableEED()
34 unsigned char *vtkLookupTableEED::MapValue(double v)
37 //int idx = this->GetIndex(v);
38 //return (this->Table->GetPointer(0) + 4*idx);
43 void vtkLookupTableEED::GetColor(double v, double rgb[3])
45 // unsigned char *rgb8 = this->MapValue(v);
46 // rgb[0] = rgb8[0]/255.0;
47 // rgb[1] = rgb8[1]/255.0;
48 // rgb[2] = rgb8[2]/255.0;
56 void vtkLookupTableEED::SetTableRange(double r[2])
58 this->SetTableRange(r[0],r[1]);
61 //----------------------------------------------------------------------------
62 // Set the minimum/maximum scalar values for scalar mapping. Scalar values
63 // less than minimum range value are clamped to minimum range value.
64 // Scalar values greater than maximum range value are clamped to maximum
66 void vtkLookupTableEED::SetTableRange(double rmin, double rmax)
70 vtkErrorMacro("Bad table range: ["<<rmin<<", "<<rmax<<"]");
74 if (this->TableRange[0] == rmin && this->TableRange[1] == rmax)
79 this->TableRange[0] = rmin;
80 this->TableRange[1] = rmax;
87 //----------------------------------------------------------------------------
88 // Although this is a relatively expensive calculation,
89 // it is only done on the first render. Colors are cached
90 // for subsequent renders.
92 void vtkLookupTableMapDirVectorEED(vtkLookupTableEED *self, T *input,
93 unsigned char *output, int length,
94 int inIncr, int outFormat)
99 double dirx,diry,dirz;
102 printf("EED length %d %p\n", length,input);
103 // mag = new double[length];
104 for (i = 0; i < length; ++i)
110 for (j = 0; j < inIncr; ++j)
112 if (j==0) dirx= static_cast<double>(*input);
113 if (j==1) diry= static_cast<double>(*input);
114 if (j==2) dirz= static_cast<double>(*input);
115 tmp = static_cast<double>(*input);
120 *output++ = (unsigned char) abs( (255*dirx/sum) );
121 *output++ = (unsigned char) abs( (255*diry/sum) );
122 *output++ = (unsigned char) abs( (255*dirz/sum) );
124 // printf("%d %d %d ",(int)(255*dirx/sum),(int)(255*diry/sum),(int)(255*dirz/sum));
127 // vtkLookupTableMapData(self, mag, output, length, 1, outFormat);
134 //----------------------------------------------------------------------------
135 void vtkLookupTableEED::MapScalarsThroughTable2(void *input,
136 unsigned char *output,
143 printf("vtkLookupTableEED::MapScalarsThroughTable2 inputIncrement=%d inputDataType=%d\n",inputIncrement,inputDataType);
146 // if (this->UseMagnitude && inputIncrement > 1)
148 switch (inputDataType)
151 vtkLookupTableMapDirVectorEED(this,static_cast<VTK_TT*>(input),output,
152 numberOfValues,inputIncrement,outputFormat);
156 vtkErrorMacro("Cannot comput magnitude of bit array.");
159 vtkErrorMacro(<< "MapImageThroughTable: Unknown input ScalarType");
166 //----------------------------------------------------------------------------
167 void vtkLookupTableEED::PrintSelf(ostream& os, vtkIndent indent)
169 this->Superclass::PrintSelf(os,indent);
175 //----------------------------------
176 //----------------------------------
177 //----------------------------------
178 //----------------------------------
179 //----------------------------------
183 namespace bbcreaMaracasVisu
189 BBTK_ADD_BLACK_BOX_TO_PACKAGE(creaMaracasVisu,TubeTreeFilter)
190 BBTK_BLACK_BOX_IMPLEMENTATION(TubeTreeFilter,bbtk::AtomicBlackBox);
194 void TubeTreeFilter::DrawOneTube(int iGeneral,int numPoints, int iTube)
197 unsigned int nTv = 8; // No. of surface elements for each tube vertex
200 // img->GetSpacing(spc);
205 int size=iGeneral+numPoints;
207 // Create points and cells
208 vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New();
209 //EED vtkPoints *points = vtkPoints::New();
210 vtkSmartPointer<vtkCellArray> lines = vtkSmartPointer<vtkCellArray>::New();
211 //EED vtkCellArray *lines = vtkCellArray::New();
213 lines->InsertNextCell( numPoints );
215 for (i=iGeneral;i<size;i++)
217 points->InsertPoint(i-iGeneral, bbGetInputlstPointX()[i]*spc[0],
218 bbGetInputlstPointY()[i]*spc[1],
219 bbGetInputlstPointZ()[i]*spc[2] );
220 lines->InsertCellPoint(i-iGeneral);
223 vtkSmartPointer<vtkPolyData> polyData = vtkSmartPointer<vtkPolyData>::New();
224 //EED vtkPolyData *polyData = vtkPolyData::New();
225 polyData->SetPoints(points);
226 polyData->SetLines(lines);
229 // Varying tube radius using sine-function
230 vtkSmartPointer<vtkDoubleArray> tubeRadius = vtkSmartPointer<vtkDoubleArray>::New();
231 //EED vtkDoubleArray *tubeRadius = vtkDoubleArray::New();
232 tubeRadius->SetName("TubeRadius");
233 tubeRadius->SetNumberOfTuples( numPoints );
234 for (i=iGeneral;i<size;i++)
236 tubeRadius->SetTuple1(i-iGeneral, bbGetInputlstRadio()[i] );
238 polyData->GetPointData()->AddArray(tubeRadius);
239 polyData->GetPointData()->SetActiveScalars("TubeRadius");
243 // Adding spheres at the start and end of the tube
247 vtkSphereSource *vtksphereStart = vtkSphereSource::New();
248 vtksphereStart->SetThetaResolution (10);
249 vtksphereStart->SetPhiResolution (10);
250 vtksphereStart->SetRadius( bbGetInputlstRadio()[i] );
251 vtkPolyDataMapper *sphereMapperStart = vtkPolyDataMapper::New();
252 sphereMapperStart->SetInput( vtksphereStart->GetOutput() );
253 vtkActor *sphereActorStart = vtkActor::New();
254 sphereActorStart->SetMapper(sphereMapperStart);
255 sphereActorStart->SetOrigin( 0,0,0 );
256 sphereActorStart->SetPosition(bbGetInputlstPointX()[i]*spc[0], bbGetInputlstPointY()[i]*spc[1], bbGetInputlstPointZ()[i]*spc[2] );
260 vtkSphereSource *vtksphereEnd = vtkSphereSource::New();
261 vtksphereEnd->SetThetaResolution (10);
262 vtksphereEnd->SetPhiResolution (10);
263 vtksphereEnd->SetRadius( bbGetInputlstRadio()[i] );
264 vtkPolyDataMapper *sphereMapperEnd = vtkPolyDataMapper::New();
265 sphereMapperEnd->SetInput( vtksphereEnd->GetOutput() );
266 vtkActor *sphereActorEnd = vtkActor::New();
267 sphereActorEnd->SetMapper(sphereMapperEnd);
268 sphereActorEnd->SetOrigin( 0,0,0 );
269 sphereActorEnd->SetPosition(bbGetInputlstPointX()[i]*spc[0], bbGetInputlstPointY()[i]*spc[1], bbGetInputlstPointZ()[i]*spc[2] );
271 vtkSmartPointer<vtkTubeFilter> tube = vtkSmartPointer<vtkTubeFilter>::New();
272 tube->SetInput(polyData);
273 tube->SetNumberOfSides(nTv);
274 tube->SetVaryRadiusToVaryRadiusByAbsoluteScalar();
276 vtkLookupTableEED* vLutEED = vtkLookupTableEED::New();
278 vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
279 mapper->SetInputConnection(tube->GetOutputPort());
280 mapper->ScalarVisibilityOn();
283 mapper->SetScalarModeToUsePointFieldData();
284 mapper->SetLookupTable( vLutEED );
285 mapper->SelectColorArray( "points_axe" );
287 // vtkSmartPointer<vtkActor> actor =vtkSmartPointer<vtkActor>::New();
288 vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New();
289 actor->SetMapper(mapper);
291 vecVtkActors.push_back( actor );
292 vecVtkActors.push_back( sphereActorEnd );
293 vecVtkActors.push_back( sphereActorStart );
295 // Interface Update // Interface Update
296 if (bbGetInputRenderer()!=NULL )
298 bbGetInputRenderer()->AddActor( actor );
299 bbGetInputRenderer()->AddActor( sphereActorStart );
300 bbGetInputRenderer()->AddActor( sphereActorEnd );
305 void TubeTreeFilter::SetGraphicProperties()
307 int iTube,sizeLstAxis=bbGetInputlstIndexs().size();
310 vtkActor *actorSpherEnd;
311 vtkActor *actorSpherStart;
315 r = bbGetInputColour()[0];
316 g = bbGetInputColour()[1];
317 b = bbGetInputColour()[2];
318 for (iTube=0 ; iTube<sizeLstAxis; iTube++)
321 actorTube=vecVtkActors[0+iTube*3];
322 actorSpherEnd=vecVtkActors[1+iTube*3];
323 actorSpherStart=vecVtkActors[2+iTube*3];
326 actorTube->GetProperty()->SetOpacity( bbGetInputOpacity() );
327 actorSpherEnd->GetProperty()->SetOpacity( bbGetInputOpacity() );
328 actorSpherStart->GetProperty()->SetOpacity( bbGetInputOpacity() );
331 if ( bbGetInputTransform()!=NULL )
333 actorTube->SetUserTransform( bbGetInputTransform() );
334 actorSpherEnd->SetUserTransform( bbGetInputTransform() );
335 actorSpherStart->SetUserTransform( bbGetInputTransform() );
338 if (bbGetInputColourLaw()==1) // One solide colour
343 if (bbGetInputColourLaw()==2) // color for differents tubes
345 if ( (iTube*3+1) < (int)(bbGetInputColour().size()) )
347 r = bbGetInputColour()[0+iTube*3];
348 g = bbGetInputColour()[1+iTube*3];
349 b = bbGetInputColour()[2+iTube*3];
351 r = (rand() % 100) / 100.0;
352 g = (rand() % 100) / 100.0;
353 b = (rand() % 100) / 100.0;
357 actorTube->GetProperty()->SetColor( r,g,b );
358 actorSpherEnd->GetProperty()->SetColor( r,g,b );
359 actorSpherStart->GetProperty()->SetColor( r,g,b );
364 // 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)
366 void TubeTreeFilter::Process()
369 printf("EED TubeTreeFilter::Process start \n");
372 int iTube,sizeLstAxis=bbGetInputlstIndexs().size();
373 int iActor,sizeActors = vecVtkActors.size();
376 if (oldLstSize!=sizeLstAxis)
378 oldLstSize=sizeLstAxis;
379 for (iActor=0 ; iActor<sizeActors; iActor++)
381 if (bbGetInputRenderer()!=NULL )
383 bbGetInputRenderer()->RemoveActor( vecVtkActors[iActor] );
384 //EED vecVtkPolyData[iActor]->Delete();
385 //EED vecVtkPolyDataMaper[iActor]->Delete();
386 //EED vecVtkActors[iActor]->Delete();
390 //EED vecVtkPolyData.clear();
391 //EED vecVtkPolyDataMaper.clear();
392 vecVtkActors.clear();
394 for ( iTube=0 ; iTube<sizeLstAxis ; iTube++)
396 numPoints = bbGetInputlstIndexs()[iTube];
397 DrawOneTube(iGeneral,numPoints,iTube);
398 iGeneral = iGeneral+numPoints;
401 if ( bbGetInputiTube()*3 <= (int)(vecVtkActors.size()-1) )
403 bbSetOutputOutTube( vecVtkActors[ bbGetInputiTube()*3 ] );
405 printf("TubeTreeFilter .ERROR. missing index vector...\n");
406 }// vector Actor size
408 SetGraphicProperties();
410 printf("EED TubeTreeFilter::Process end \n");
413 // 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)
415 void TubeTreeFilter::bbUserSetDefaultValues()
419 // SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX
420 // Here we initialize the input 'In' to 0
422 std::vector<double> colour;
424 colour.push_back(0.5);
425 colour.push_back(0.5);
426 colour.push_back(0.5);
428 colour.push_back(1.0);
429 colour.push_back(0.0);
430 colour.push_back(0.0);
432 colour.push_back(0.0);
433 colour.push_back(0.0);
434 colour.push_back(1.0);
436 colour.push_back(1.0);
437 colour.push_back(1.0);
438 colour.push_back(0.0);
440 colour.push_back(0.0);
441 colour.push_back(1.0);
442 colour.push_back(0.0);
444 colour.push_back(0.0);
445 colour.push_back(1.0);
446 colour.push_back(1.0);
449 colour.push_back(0.5);
450 colour.push_back(0.5);
451 colour.push_back(0.5);
453 bbSetInputColour(colour);
454 bbSetInputTransform(NULL);
455 bbSetInputRenderer(NULL);
456 bbSetInputColourLaw(1);
457 bbSetInputOpacity(1);
461 // 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)
463 void TubeTreeFilter::bbUserInitializeProcessing()
466 // THE INITIALIZATION METHOD BODY :
468 // but this is where you should allocate the internal/output pointers
474 // 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)
476 void TubeTreeFilter::bbUserFinalizeProcessing()
479 // THE FINALIZATION METHOD BODY :
481 // but this is where you should desallocate the internal/output pointers
486 // EO namespace bbcreaMaracasVisu