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 # ------------------------------------------------------------------------ */
26 #include "bbmaracasvisuDrawAxisTree3D.h"
27 #include "bbcreaMaracasVisuPackage.h"
28 #include "vtkLinearTransform.h"
30 #include "vtkUnsignedCharArray.h"
31 #include "vtkCellData.h"
32 #include "vtkPolyLine.h"
37 namespace bbcreaMaracasVisu
40 BBTK_ADD_BLACK_BOX_TO_PACKAGE(creaMaracasVisu,DrawAxisTree3D)
41 BBTK_BLACK_BOX_IMPLEMENTATION(DrawAxisTree3D,bbtk::AtomicBlackBox);
45 void DrawAxisTree3D::DrawOneAxis(int iGeneral,int numPoints, int iAxis)
48 vtkPolyData *polydata = vtkPolyData::New( );
49 vtkPolyDataMapper *polydatamapper = vtkPolyDataMapper::New();
50 vtkActor *vtkactor = vtkActor::New();
52 // polydatamapper->ScalarVisibilityOff();
53 //EED 2017-01-01 Migration VTK7
54 #if VTK_MAJOR_VERSION <= 5
55 polydatamapper->SetInput(polydata);
57 polydatamapper->SetInputData(polydata);
58 polydatamapper->Update();
60 vtkactor->SetMapper(polydatamapper);
64 vecVtkPolyData.push_back( polydata );
65 vecVtkPolyDataMaper.push_back( polydatamapper );
66 vecVtkActors.push_back( vtkactor );
70 // vtkImageData* img = bbGetInputImage();
73 // img->GetSpacing(spc);
78 int lstpointsXsize =bbGetInputlstPointX().size();
82 if( lstpointsXsize>0 )
85 vtkPoints *allPoints = vtkPoints::New( );
86 vtkPolyLine *polyline = vtkPolyLine::New();
87 vtkCellArray* allTopology = vtkCellArray::New( );
88 // allTopology->InsertNextCell( numPoints );
91 size=iGeneral+numPoints;
92 //EED printf("8.6a %p %d %d ",allPoints, iGeneral,size);
93 //EED printf("8.6b %d %d %d ",bbGetInputlstPointX().size(), bbGetInputlstPointY().size(), bbGetInputlstPointZ().size() );
95 for (i=iGeneral;i<size;i++)
97 //EED printf("8.7(%d) ",i);
98 //multiplicar ver parametros spacing, en maracas cuando se toca la imagen y se ve dycom
99 //hay par·metro dycom, vtkImagedata valor spacing y esos datos hay que multiplicar al polydata
100 allPoints->InsertNextPoint( bbGetInputlstPointX()[i]*spc[0],
101 bbGetInputlstPointY()[i]*spc[1],
102 bbGetInputlstPointZ()[i]*spc[2] );
103 // printf("DrawAxisTree3D::DrawOneAxis point %d -> %f, %f, %f \n", i, bbGetInputlstPointX()[i], bbGetInputlstPointY()[i], bbGetInputlstPointZ()[i] );
105 polyline->GetPointIds()->InsertNextId(i-iGeneral);
107 // allTopology->InsertCellPoint( i-iGeneral );
109 //EED printf("8.8 ");
111 allTopology->InsertNextCell(polyline);
113 // create cell array for edges
114 vtkCellArray *edges = vtkCellArray::New();
115 //EED printf("8.9 ");
117 // connect edge's and vertexes point ids
118 for(vtkIdType i = iGeneral; i < size-1; i++)
120 //EED printf("8.10(%d) ",i);
121 vtkLine *edge = vtkLine::New();
122 edge->GetPointIds()->SetId(0, i-iGeneral);
123 edge->GetPointIds()->SetId(1, (i-iGeneral+1) );
124 edges->InsertNextCell(edge);
126 // vtkSmartPointer<vtkVertex> vertex = vtkSmartPointer<vtkVertex>::New();
127 // vertex->GetPointIds()->SetId(0, i);
128 // vertexes->InsertNextCell(vertex);
131 //EED printf("8.11 ");
132 polydata->SetPoints( allPoints );
133 polydata->SetLines(edges);
134 // polydata->SetLines( allTopology );
137 // polydata->SetPolys( allTopology );
141 allTopology->Delete();
142 //EED printf("8.12 ");
149 if (bbGetInputColourLaw()==1) // the same color for all
151 //EED printf("8.13(%d) ",bbGetInputColour().size() );
153 r = bbGetInputColour()[0];
154 g = bbGetInputColour()[1];
155 b = bbGetInputColour()[2];
156 vtkactor->GetProperty()->SetColor( r,g,b );
157 } // Law 1 color for all
159 if (bbGetInputColourLaw()==2) // different colors for each segment
161 //EED printf("8.14 ");
162 if ( (iAxis*3+1) < (int)(bbGetInputColour().size()) )
164 r = bbGetInputColour()[0+iAxis*3];
165 g = bbGetInputColour()[1+iAxis*3];
166 b = bbGetInputColour()[2+iAxis*3];
168 r = (rand() % 100) / 100.0;
169 g = (rand() % 100) / 100.0;
170 b = (rand() % 100) / 100.0;
172 //EED printf("8.15 ");
173 vtkactor->GetProperty()->SetColor( r,g,b );
174 } // Law 2 color for each segment
176 if (bbGetInputColourLaw()==3) // color for each point
178 //EED printf("8.16 ");
179 // Setup the colors array
180 vtkUnsignedCharArray *colors = vtkUnsignedCharArray::New();
181 colors->SetNumberOfComponents(3);
182 colors->SetName("Colors");
183 // colors->SetName("vertex color");
184 int iPoint,pointSize=iGeneral+numPoints;
187 for (iPoint=iGeneral; iPoint<pointSize; iPoint++)
189 r = bbGetInputColour()[0+iPoint*3]*255.0;
190 g = bbGetInputColour()[1+iPoint*3]*255.0;
191 b = bbGetInputColour()[2+iPoint*3]*255.0;
192 //colors->SetTuple3(iPoint,r,g,b);
193 colors->InsertNextTuple3(r,g,b);
195 polydata->GetCellData()->SetScalars(colors);
196 polydata->Modified();
198 } // Law 3 color for each point
200 //EED printf("8.17 ");
201 vtkactor->GetProperty()->SetLineWidth( bbGetInputLineWidth() );
202 vtkactor->GetProperty()->SetOpacity( bbGetInputOpacity() );
204 if ( bbGetInputTransform()!=NULL )
206 //EED printf("8.18 ");
207 vtkactor->SetUserTransform( bbGetInputTransform() );
211 if (bbGetInputRenderer()!=NULL )
213 //EED printf("8.19 ");
214 bbGetInputRenderer()->AddActor( vtkactor );
216 //EED printf("8.20 ");
221 void DrawAxisTree3D::Process()
223 printf("DrawAxisTree3D::Process Start >> %s\n", bbGetFullName().c_str() );
225 if ( (bbGetInputlstPointX().size()==bbGetInputlstPointY().size()) &&
226 (bbGetInputlstPointX().size()==bbGetInputlstPointZ().size()) )
229 std::vector<int> lstIndexs = bbGetInputlstIndexs();
230 if ( bbGetInputlstIndexs().size()==0 )
233 lstIndexs.push_back( bbGetInputlstPointX().size() );
235 int iAxis,sizeLstAxis=lstIndexs.size();
236 int iActor,sizeActors = vecVtkActors.size();
241 // if (oldLstSize!=sizeLstAxis)
243 // oldLstSize=sizeLstAxis;
244 for (iActor=0 ; iActor<sizeActors; iActor++)
246 //EED printf("4-%d ",iActor);
247 if (bbGetInputRenderer()!=NULL )
250 bbGetInputRenderer()->RemoveActor( vecVtkActors[iActor] );
251 vecVtkPolyData[iActor]->Delete();
252 vecVtkPolyDataMaper[iActor]->Delete();
253 vecVtkActors[iActor]->Delete();
257 vecVtkPolyData.clear();
258 vecVtkPolyDataMaper.clear();
259 vecVtkActors.clear();
261 for ( iAxis=0 ; iAxis<sizeLstAxis ; iAxis++)
263 //EED printf("8(%d) ",iAxis);
264 numPoints = lstIndexs[iAxis];
265 //EED printf("9(%d) ",iAxis);
266 DrawOneAxis(iGeneral,numPoints,iAxis);
268 iGeneral = iGeneral+numPoints;
269 // if ((iAxis % 1)==0)
271 // printf("EED DrawAxisTree3D::Process %d/%d\n", iAxis,sizeLstAxis );
277 if ( bbGetInputiAxis() < (int)(vecVtkActors.size() ) )
279 bbSetOutputOutAxis( vecVtkActors[ bbGetInputiAxis() ] );
281 printf("DrawAxisTree3D .ERROR. iAxis for exist in actors vector ...\n");
283 // } else {// if oldLstSize
284 // } // if oldLstSize
286 printf("\nDrawAxisTree3D .ERROR. size of vectors lstPointX.size=%d lstPointY.size=%d lstPointZ.size=%d are not coherent \n\n",bbGetInputlstPointX().size(), bbGetInputlstPointY().size(), bbGetInputlstPointZ().size() );
288 printf("DrawAxisTree3D::Process End \n");
292 void DrawAxisTree3D::bbUserSetDefaultValues()
296 std::vector<double> colour;
298 colour.push_back(1.0);
299 colour.push_back(0.0);
300 colour.push_back(0.0);
302 colour.push_back(0.0);
303 colour.push_back(0.0);
304 colour.push_back(1.0);
306 colour.push_back(1.0);
307 colour.push_back(1.0);
308 colour.push_back(0.0);
310 colour.push_back(0.0);
311 colour.push_back(1.0);
312 colour.push_back(0.0);
314 colour.push_back(0.0);
315 colour.push_back(1.0);
316 colour.push_back(1.0);
319 colour.push_back(0.5);
320 colour.push_back(0.5);
321 colour.push_back(0.5);
323 bbSetInputColour(colour);
324 bbSetInputOpacity(1);
325 bbSetInputLineWidth(0.5);
326 bbSetInputColourLaw(1);
327 bbSetInputTransform(NULL);
328 bbSetOutputOutAxis(NULL);
333 //-----------------------------------------------------------------
334 void DrawAxisTree3D::bbUserInitializeProcessing()
338 //-----------------------------------------------------------------
339 void DrawAxisTree3D::bbUserFinalizeProcessing()
343 //-----------------------------------------------------------------
346 // EO namespace bbcreaMaracasVisu