+//=====
+// 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)
+//=====
+#include "bbcreaMaracasVisuTubeTreeFilter.h"
+#include "bbcreaMaracasVisuPackage.h"
+
+#include <vtkSmartPointer.h>
+#include <vtkDoubleArray.h>
+#include <vtkPolyData.h>
+#include <vtkPointData.h>
+#include <vtkTubeFilter.h>
+#include <vtkSphereSource.h>
+
+
+namespace bbcreaMaracasVisu
+{
+
+BBTK_ADD_BLACK_BOX_TO_PACKAGE(creaMaracasVisu,TubeTreeFilter)
+BBTK_BLACK_BOX_IMPLEMENTATION(TubeTreeFilter,bbtk::AtomicBlackBox);
+
+
+
+void TubeTreeFilter::DrawOneTube(int iGeneral,int numPoints, int iTube)
+{
+ int i;
+ unsigned int nTv = 8; // No. of surface elements for each tube vertex
+
+ double spc[3];
+ // img->GetSpacing(spc);
+ spc[0]=1;
+ spc[1]=1;
+ spc[2]=1;
+
+ int size=iGeneral+numPoints;
+
+ // Create points and cells
+ vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New();
+//EED vtkPoints *points = vtkPoints::New();
+ vtkSmartPointer<vtkCellArray> lines = vtkSmartPointer<vtkCellArray>::New();
+//EED vtkCellArray *lines = vtkCellArray::New();
+
+ lines->InsertNextCell( numPoints );
+
+ for (i=iGeneral;i<size;i++)
+ {
+ points->InsertPoint(i-iGeneral, bbGetInputlstPointX()[i]*spc[0],
+ bbGetInputlstPointY()[i]*spc[1],
+ bbGetInputlstPointZ()[i]*spc[2] );
+ lines->InsertCellPoint(i-iGeneral);
+ }
+
+ vtkSmartPointer<vtkPolyData> polyData = vtkSmartPointer<vtkPolyData>::New();
+//EED vtkPolyData *polyData = vtkPolyData::New();
+ polyData->SetPoints(points);
+ polyData->SetLines(lines);
+
+
+ // Varying tube radius using sine-function
+ vtkSmartPointer<vtkDoubleArray> tubeRadius = vtkSmartPointer<vtkDoubleArray>::New();
+//EED vtkDoubleArray *tubeRadius = vtkDoubleArray::New();
+ tubeRadius->SetName("TubeRadius");
+ tubeRadius->SetNumberOfTuples( numPoints );
+ for (i=iGeneral;i<size;i++)
+ {
+ tubeRadius->SetTuple1(i-iGeneral, bbGetInputlstRadio()[i] );
+ }
+ polyData->GetPointData()->AddArray(tubeRadius);
+ polyData->GetPointData()->SetActiveScalars("TubeRadius");
+
+
+
+// Adding spheres at the start and end of the tube
+
+ // Sphere start
+ i=iGeneral;
+ vtkSphereSource *vtksphereStart = vtkSphereSource::New();
+ vtksphereStart->SetThetaResolution (10);
+ vtksphereStart->SetPhiResolution (10);
+ vtksphereStart->SetRadius( bbGetInputlstRadio()[i] );
+ vtkPolyDataMapper *sphereMapperStart = vtkPolyDataMapper::New();
+ sphereMapperStart->SetInput( vtksphereStart->GetOutput() );
+ vtkActor *sphereActorStart = vtkActor::New();
+ sphereActorStart->SetMapper(sphereMapperStart);
+ sphereActorStart->SetOrigin( 0,0,0 );
+ sphereActorStart->SetPosition(bbGetInputlstPointX()[i]*spc[0], bbGetInputlstPointY()[i]*spc[1], bbGetInputlstPointZ()[i]*spc[2] );
+
+ // Sphere end
+ i=size-1;
+ vtkSphereSource *vtksphereEnd = vtkSphereSource::New();
+ vtksphereEnd->SetThetaResolution (10);
+ vtksphereEnd->SetPhiResolution (10);
+ vtksphereEnd->SetRadius( bbGetInputlstRadio()[i] );
+ vtkPolyDataMapper *sphereMapperEnd = vtkPolyDataMapper::New();
+ sphereMapperEnd->SetInput( vtksphereEnd->GetOutput() );
+ vtkActor *sphereActorEnd = vtkActor::New();
+ sphereActorEnd->SetMapper(sphereMapperEnd);
+ sphereActorEnd->SetOrigin( 0,0,0 );
+ sphereActorEnd->SetPosition(bbGetInputlstPointX()[i]*spc[0], bbGetInputlstPointY()[i]*spc[1], bbGetInputlstPointZ()[i]*spc[2] );
+
+
+ // color
+ double r,g,b;
+ if ( (iTube*3+1) < (int)(bbGetInputColour().size()) )
+ {
+ r = bbGetInputColour()[0+iTube*3];
+ g = bbGetInputColour()[1+iTube*3];
+ b = bbGetInputColour()[2+iTube*3];
+ } else {
+ r = (rand() % 100) / 100.0;
+ g = (rand() % 100) / 100.0;
+ b = (rand() % 100) / 100.0;
+ }
+ r = bbGetInputColour()[0];
+ g = bbGetInputColour()[1];
+ b = bbGetInputColour()[2];
+
+
+
+
+ vtkSmartPointer<vtkTubeFilter> tube = vtkSmartPointer<vtkTubeFilter>::New();
+//EED vtkTubeFilter *tube = vtkTubeFilter::New();
+ tube->SetInput(polyData);
+ tube->SetNumberOfSides(nTv);
+ tube->SetVaryRadiusToVaryRadiusByAbsoluteScalar();
+
+ vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
+//EED vtkPolyDataMapper *mapper = vtkPolyDataMapper::New();
+ mapper->SetInputConnection(tube->GetOutputPort());
+ mapper->ScalarVisibilityOn();
+ mapper->SetScalarModeToUsePointFieldData();
+
+ // vtkSmartPointer<vtkActor> actor =vtkSmartPointer<vtkActor>::New();
+ vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New();
+//EED vtkActor *actor = vtkActor::New();
+ actor->SetMapper(mapper);
+ actor->GetProperty()->SetColor( r,g,b );
+ actor->GetProperty()->SetOpacity( bbGetInputOpacity() );
+ sphereActorStart->GetProperty()->SetColor( r,g,b );;
+ sphereActorEnd->GetProperty()->SetColor( r,g,b );;
+ sphereActorStart->GetProperty()->SetOpacity( bbGetInputOpacity() );
+ sphereActorEnd->GetProperty()->SetOpacity( bbGetInputOpacity() );
+
+ vecVtkActors.push_back( actor );
+ vecVtkActors.push_back( sphereActorStart );
+ vecVtkActors.push_back( sphereActorEnd );
+
+
+ if ( bbGetInputTransform()!=NULL )
+ {
+ actor->SetUserTransform( bbGetInputTransform() );
+ sphereActorStart->SetUserTransform( bbGetInputTransform() );
+ sphereActorEnd->SetUserTransform( bbGetInputTransform() );
+ }
+
+ // Interface Update // Interface Update
+ if (bbGetInputRenderer()!=NULL )
+ {
+ bbGetInputRenderer()->AddActor( actor );
+ bbGetInputRenderer()->AddActor( sphereActorStart );
+ bbGetInputRenderer()->AddActor( sphereActorEnd );
+ }
+}
+
+
+//=====
+// 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)
+//=====
+void TubeTreeFilter::Process()
+{
+
+ printf("EED TubeTreeFilter::Process start \n");
+
+ int iGeneral=0;
+ int iTube,sizeLstAxis=bbGetInputlstIndexs().size();
+ int iActor,sizeActors = vecVtkActors.size();
+
+ int numPoints;
+ if (oldLstSize!=sizeLstAxis)
+ {
+ oldLstSize=sizeLstAxis;
+ for (iActor=0 ; iActor<sizeActors; iActor++)
+ {
+ if (bbGetInputRenderer()!=NULL )
+ {
+ bbGetInputRenderer()->RemoveActor( vecVtkActors[iActor] );
+ //EED vecVtkPolyData[iActor]->Delete();
+ //EED vecVtkPolyDataMaper[iActor]->Delete();
+ //EED vecVtkActors[iActor]->Delete();
+ }
+ }
+
+ //EED vecVtkPolyData.clear();
+ //EED vecVtkPolyDataMaper.clear();
+ vecVtkActors.clear();
+
+ for ( iTube=0 ; iTube<sizeLstAxis ; iTube++)
+ {
+ numPoints = bbGetInputlstIndexs()[iTube];
+ DrawOneTube(iGeneral,numPoints,iTube);
+ iGeneral = iGeneral+numPoints;
+ }
+
+ if ( bbGetInputiTube()*3 <= (int)(vecVtkActors.size()-1) )
+ {
+ bbSetOutputOutTube( vecVtkActors[ bbGetInputiTube()*3 ] );
+ } else {
+ printf("TubeTreeFilter .ERROR. missing index vector...\n");
+ }
+
+ }
+
+ double r,g,b;
+ r = bbGetInputColour()[0];
+ g = bbGetInputColour()[1];
+ b = bbGetInputColour()[2];
+ for (iTube=0 ; iTube<sizeLstAxis; iTube++)
+ {
+ vtkActor *actor1=vecVtkActors[0+iTube*3];
+ vtkActor *actor2=vecVtkActors[1+iTube*3];
+ vtkActor *actor3=vecVtkActors[2+iTube*3];
+
+ actor1->GetProperty()->SetOpacity( bbGetInputOpacity() );
+ actor2->GetProperty()->SetOpacity( bbGetInputOpacity() );
+ actor3->GetProperty()->SetOpacity( bbGetInputOpacity() );
+ if (bbGetInputColourLaw()==1)
+ {
+ actor1->GetProperty()->SetColor( r,g,b );
+ actor2->GetProperty()->SetColor( r,g,b );
+ actor3->GetProperty()->SetColor( r,g,b );
+ }
+ } // for
+
+
+ printf("EED TubeTreeFilter::Process end \n");
+}
+//=====
+// 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)
+//=====
+void TubeTreeFilter::bbUserSetDefaultValues()
+{
+ oldLstSize=-1;
+
+// SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX
+// Here we initialize the input 'In' to 0
+ bbSetInputiTube(0);
+ std::vector<double> colour;
+ // 0- gray
+ colour.push_back(0.5);
+ colour.push_back(0.5);
+ colour.push_back(0.5);
+ // 1- red
+ colour.push_back(1.0);
+ colour.push_back(0.0);
+ colour.push_back(0.0);
+ // 2- blue
+ colour.push_back(0.0);
+ colour.push_back(0.0);
+ colour.push_back(1.0);
+ // 3- yellow
+ colour.push_back(1.0);
+ colour.push_back(1.0);
+ colour.push_back(0.0);
+ // 4- green
+ colour.push_back(0.0);
+ colour.push_back(1.0);
+ colour.push_back(0.0);
+ // 5-
+ colour.push_back(0.0);
+ colour.push_back(1.0);
+ colour.push_back(1.0);
+
+ // 6-
+ colour.push_back(0.5);
+ colour.push_back(0.5);
+ colour.push_back(0.5);
+
+ bbSetInputColour(colour);
+ bbSetInputTransform(NULL);
+ bbSetInputRenderer(NULL);
+ bbSetInputColourLaw(1);
+ bbSetInputOpacity(1);
+
+}
+//=====
+// 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)
+//=====
+void TubeTreeFilter::bbUserInitializeProcessing()
+{
+
+// THE INITIALIZATION METHOD BODY :
+// Here does nothing
+// but this is where you should allocate the internal/output pointers
+// if any
+
+
+}
+//=====
+// 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)
+//=====
+void TubeTreeFilter::bbUserFinalizeProcessing()
+{
+
+// THE FINALIZATION METHOD BODY :
+// Here does nothing
+// but this is where you should desallocate the internal/output pointers
+// if any
+
+}
+}
+// EO namespace bbcreaMaracasVisu
+
+