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>
15 namespace bbcreaMaracasVisu
18 BBTK_ADD_BLACK_BOX_TO_PACKAGE(creaMaracasVisu,TubeTreeFilter)
19 BBTK_BLACK_BOX_IMPLEMENTATION(TubeTreeFilter,bbtk::AtomicBlackBox);
23 void TubeTreeFilter::DrawOneTube(int iGeneral,int numPoints, int iTube)
26 unsigned int nTv = 8; // No. of surface elements for each tube vertex
29 // img->GetSpacing(spc);
34 int size=iGeneral+numPoints;
36 // Create points and cells
37 vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New();
38 //EED vtkPoints *points = vtkPoints::New();
39 vtkSmartPointer<vtkCellArray> lines = vtkSmartPointer<vtkCellArray>::New();
40 //EED vtkCellArray *lines = vtkCellArray::New();
42 lines->InsertNextCell( numPoints );
44 for (i=iGeneral;i<size;i++)
46 points->InsertPoint(i-iGeneral, bbGetInputlstPointX()[i]*spc[0],
47 bbGetInputlstPointY()[i]*spc[1],
48 bbGetInputlstPointZ()[i]*spc[2] );
49 lines->InsertCellPoint(i-iGeneral);
52 vtkSmartPointer<vtkPolyData> polyData = vtkSmartPointer<vtkPolyData>::New();
53 //EED vtkPolyData *polyData = vtkPolyData::New();
54 polyData->SetPoints(points);
55 polyData->SetLines(lines);
58 // Varying tube radius using sine-function
59 vtkSmartPointer<vtkDoubleArray> tubeRadius = vtkSmartPointer<vtkDoubleArray>::New();
60 //EED vtkDoubleArray *tubeRadius = vtkDoubleArray::New();
61 tubeRadius->SetName("TubeRadius");
62 tubeRadius->SetNumberOfTuples( numPoints );
63 for (i=iGeneral;i<size;i++)
65 tubeRadius->SetTuple1(i-iGeneral, bbGetInputlstRadio()[i] );
67 polyData->GetPointData()->AddArray(tubeRadius);
68 polyData->GetPointData()->SetActiveScalars("TubeRadius");
72 // Adding spheres at the start and end of the tube
76 vtkSphereSource *vtksphereStart = vtkSphereSource::New();
77 vtksphereStart->SetThetaResolution (10);
78 vtksphereStart->SetPhiResolution (10);
79 vtksphereStart->SetRadius( bbGetInputlstRadio()[i] );
80 vtkPolyDataMapper *sphereMapperStart = vtkPolyDataMapper::New();
81 sphereMapperStart->SetInput( vtksphereStart->GetOutput() );
82 vtkActor *sphereActorStart = vtkActor::New();
83 sphereActorStart->SetMapper(sphereMapperStart);
84 sphereActorStart->SetOrigin( 0,0,0 );
85 sphereActorStart->SetPosition(bbGetInputlstPointX()[i]*spc[0], bbGetInputlstPointY()[i]*spc[1], bbGetInputlstPointZ()[i]*spc[2] );
89 vtkSphereSource *vtksphereEnd = vtkSphereSource::New();
90 vtksphereEnd->SetThetaResolution (10);
91 vtksphereEnd->SetPhiResolution (10);
92 vtksphereEnd->SetRadius( bbGetInputlstRadio()[i] );
93 vtkPolyDataMapper *sphereMapperEnd = vtkPolyDataMapper::New();
94 sphereMapperEnd->SetInput( vtksphereEnd->GetOutput() );
95 vtkActor *sphereActorEnd = vtkActor::New();
96 sphereActorEnd->SetMapper(sphereMapperEnd);
97 sphereActorEnd->SetOrigin( 0,0,0 );
98 sphereActorEnd->SetPosition(bbGetInputlstPointX()[i]*spc[0], bbGetInputlstPointY()[i]*spc[1], bbGetInputlstPointZ()[i]*spc[2] );
100 vtkSmartPointer<vtkTubeFilter> tube = vtkSmartPointer<vtkTubeFilter>::New();
101 //EED vtkTubeFilter *tube = vtkTubeFilter::New();
102 tube->SetInput(polyData);
103 tube->SetNumberOfSides(nTv);
104 tube->SetVaryRadiusToVaryRadiusByAbsoluteScalar();
106 vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
107 //EED vtkPolyDataMapper *mapper = vtkPolyDataMapper::New();
108 mapper->SetInputConnection(tube->GetOutputPort());
109 mapper->ScalarVisibilityOn();
110 mapper->SetScalarModeToUsePointFieldData();
112 // vtkSmartPointer<vtkActor> actor =vtkSmartPointer<vtkActor>::New();
113 vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New();
114 actor->SetMapper(mapper);
116 vecVtkActors.push_back( actor );
117 vecVtkActors.push_back( sphereActorEnd );
118 vecVtkActors.push_back( sphereActorStart );
120 // Interface Update // Interface Update
121 if (bbGetInputRenderer()!=NULL )
123 bbGetInputRenderer()->AddActor( actor );
124 bbGetInputRenderer()->AddActor( sphereActorStart );
125 bbGetInputRenderer()->AddActor( sphereActorEnd );
130 void TubeTreeFilter::SetGraphicProperties()
132 int iTube,sizeLstAxis=bbGetInputlstIndexs().size();
135 vtkActor *actorSpherEnd;
136 vtkActor *actorSpherStart;
140 r = bbGetInputColour()[0];
141 g = bbGetInputColour()[1];
142 b = bbGetInputColour()[2];
143 for (iTube=0 ; iTube<sizeLstAxis; iTube++)
146 actorTube=vecVtkActors[0+iTube*3];
147 actorSpherEnd=vecVtkActors[1+iTube*3];
148 actorSpherStart=vecVtkActors[2+iTube*3];
151 actorTube->GetProperty()->SetOpacity( bbGetInputOpacity() );
152 actorSpherEnd->GetProperty()->SetOpacity( bbGetInputOpacity() );
153 actorSpherStart->GetProperty()->SetOpacity( bbGetInputOpacity() );
156 if ( bbGetInputTransform()!=NULL )
158 actorTube->SetUserTransform( bbGetInputTransform() );
159 actorSpherEnd->SetUserTransform( bbGetInputTransform() );
160 actorSpherStart->SetUserTransform( bbGetInputTransform() );
163 if (bbGetInputColourLaw()==1) // One solide colour
168 if (bbGetInputColourLaw()==2) // color for differents tubes
170 if ( (iTube*3+1) < (int)(bbGetInputColour().size()) )
172 r = bbGetInputColour()[0+iTube*3];
173 g = bbGetInputColour()[1+iTube*3];
174 b = bbGetInputColour()[2+iTube*3];
176 r = (rand() % 100) / 100.0;
177 g = (rand() % 100) / 100.0;
178 b = (rand() % 100) / 100.0;
182 actorTube->GetProperty()->SetColor( r,g,b );
183 actorSpherEnd->GetProperty()->SetColor( r,g,b );
184 actorSpherStart->GetProperty()->SetColor( r,g,b );
189 // 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)
191 void TubeTreeFilter::Process()
194 printf("EED TubeTreeFilter::Process start \n");
197 int iTube,sizeLstAxis=bbGetInputlstIndexs().size();
198 int iActor,sizeActors = vecVtkActors.size();
201 if (oldLstSize!=sizeLstAxis)
203 oldLstSize=sizeLstAxis;
204 for (iActor=0 ; iActor<sizeActors; iActor++)
206 if (bbGetInputRenderer()!=NULL )
208 bbGetInputRenderer()->RemoveActor( vecVtkActors[iActor] );
209 //EED vecVtkPolyData[iActor]->Delete();
210 //EED vecVtkPolyDataMaper[iActor]->Delete();
211 //EED vecVtkActors[iActor]->Delete();
215 //EED vecVtkPolyData.clear();
216 //EED vecVtkPolyDataMaper.clear();
217 vecVtkActors.clear();
219 for ( iTube=0 ; iTube<sizeLstAxis ; iTube++)
221 numPoints = bbGetInputlstIndexs()[iTube];
222 DrawOneTube(iGeneral,numPoints,iTube);
223 iGeneral = iGeneral+numPoints;
226 if ( bbGetInputiTube()*3 <= (int)(vecVtkActors.size()-1) )
228 bbSetOutputOutTube( vecVtkActors[ bbGetInputiTube()*3 ] );
230 printf("TubeTreeFilter .ERROR. missing index vector...\n");
231 }// vector Actor size
233 SetGraphicProperties();
235 printf("EED TubeTreeFilter::Process end \n");
238 // 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)
240 void TubeTreeFilter::bbUserSetDefaultValues()
244 // SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX
245 // Here we initialize the input 'In' to 0
247 std::vector<double> colour;
249 colour.push_back(0.5);
250 colour.push_back(0.5);
251 colour.push_back(0.5);
253 colour.push_back(1.0);
254 colour.push_back(0.0);
255 colour.push_back(0.0);
257 colour.push_back(0.0);
258 colour.push_back(0.0);
259 colour.push_back(1.0);
261 colour.push_back(1.0);
262 colour.push_back(1.0);
263 colour.push_back(0.0);
265 colour.push_back(0.0);
266 colour.push_back(1.0);
267 colour.push_back(0.0);
269 colour.push_back(0.0);
270 colour.push_back(1.0);
271 colour.push_back(1.0);
274 colour.push_back(0.5);
275 colour.push_back(0.5);
276 colour.push_back(0.5);
278 bbSetInputColour(colour);
279 bbSetInputTransform(NULL);
280 bbSetInputRenderer(NULL);
281 bbSetInputColourLaw(1);
282 bbSetInputOpacity(1);
286 // 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)
288 void TubeTreeFilter::bbUserInitializeProcessing()
291 // THE INITIALIZATION METHOD BODY :
293 // but this is where you should allocate the internal/output pointers
299 // 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)
301 void TubeTreeFilter::bbUserFinalizeProcessing()
304 // THE FINALIZATION METHOD BODY :
306 // but this is where you should desallocate the internal/output pointers
311 // EO namespace bbcreaMaracasVisu