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)
47 vtkPolyData *polydata = vtkPolyData::New( );
48 vtkPolyDataMapper *polydatamapper = vtkPolyDataMapper::New();
49 vtkActor *vtkactor = vtkActor::New();
51 // polydatamapper->ScalarVisibilityOff();
52 //EED 2017-01-01 Migration VTK7
53 #if VTK_MAJOR_VERSION <= 5
54 polydatamapper->SetInput(polydata);
56 polydatamapper->SetInputData(polydata);
57 polydatamapper->Update();
59 vtkactor->SetMapper(polydatamapper);
61 vecVtkPolyData.push_back( polydata );
62 vecVtkPolyDataMaper.push_back( polydatamapper );
63 vecVtkActors.push_back( vtkactor );
65 // vtkImageData* img = bbGetInputImage();
68 // img->GetSpacing(spc);
73 int lstpointsXsize =bbGetInputlstPointX().size();
75 if( lstpointsXsize>0 ){
76 vtkPoints* allPoints = vtkPoints::New( );
77 vtkPolyLine *polyline = vtkPolyLine::New();
78 vtkCellArray* allTopology = vtkCellArray::New( );
79 // allTopology->InsertNextCell( numPoints );
81 size=iGeneral+numPoints;
82 for (i=iGeneral;i<size;i++)
84 //multiplicar ver parametros spacing, en maracas cuando se toca la imagen y se ve dycom
85 //hay par·metro dycom, vtkImagedata valor spacing y esos datos hay que multiplicar al polydata
86 allPoints->InsertNextPoint( bbGetInputlstPointX()[i]*spc[0],
87 bbGetInputlstPointY()[i]*spc[1],
88 bbGetInputlstPointZ()[i]*spc[2] );
89 // printf("DrawAxisTree3D::DrawOneAxis point %d -> %f, %f, %f \n", i, bbGetInputlstPointX()[i], bbGetInputlstPointY()[i], bbGetInputlstPointZ()[i] );
91 polyline->GetPointIds()->InsertNextId(i-iGeneral);
93 // allTopology->InsertCellPoint( i-iGeneral );
95 allTopology->InsertNextCell(polyline);
97 // create cell array for edges
98 vtkCellArray *edges = vtkCellArray::New();
100 // connect edge's and vertexes point ids
101 for(vtkIdType i = iGeneral; i < size-1; i++)
103 vtkLine *edge = vtkLine::New();
104 edge->GetPointIds()->SetId(0, i-iGeneral);
105 edge->GetPointIds()->SetId(1, (i-iGeneral+1) );
106 edges->InsertNextCell(edge);
108 // vtkSmartPointer<vtkVertex> vertex = vtkSmartPointer<vtkVertex>::New();
109 // vertex->GetPointIds()->SetId(0, i);
110 // vertexes->InsertNextCell(vertex);
113 polydata->SetPoints( allPoints );
114 polydata->SetLines(edges);
115 // polydata->SetLines( allTopology );
118 // polydata->SetPolys( allTopology );
122 allTopology->Delete();
128 if (bbGetInputColourLaw()==1) // the same color for all
130 r = bbGetInputColour()[0];
131 g = bbGetInputColour()[1];
132 b = bbGetInputColour()[2];
133 vtkactor->GetProperty()->SetColor( r,g,b );
134 } // Law 1 color for all
136 if (bbGetInputColourLaw()==2) // different colors for each segment
138 if ( (iAxis*3+1) < (int)(bbGetInputColour().size()) )
140 r = bbGetInputColour()[0+iAxis*3];
141 g = bbGetInputColour()[1+iAxis*3];
142 b = bbGetInputColour()[2+iAxis*3];
144 r = (rand() % 100) / 100.0;
145 g = (rand() % 100) / 100.0;
146 b = (rand() % 100) / 100.0;
148 vtkactor->GetProperty()->SetColor( r,g,b );
149 } // Law 2 color for each segment
151 if (bbGetInputColourLaw()==3) // color for each point
153 // Setup the colors array
154 vtkUnsignedCharArray *colors = vtkUnsignedCharArray::New();
155 colors->SetNumberOfComponents(3);
156 colors->SetName("Colors");
157 // colors->SetName("vertex color");
158 int iPoint,pointSize=iGeneral+numPoints;
161 for (iPoint=iGeneral; iPoint<pointSize; iPoint++)
163 r = bbGetInputColour()[0+iPoint*3]*255.0;
164 g = bbGetInputColour()[1+iPoint*3]*255.0;
165 b = bbGetInputColour()[2+iPoint*3]*255.0;
166 //colors->SetTuple3(iPoint,r,g,b);
167 colors->InsertNextTuple3(r,g,b);
169 polydata->GetCellData()->SetScalars(colors);
170 polydata->Modified();
172 } // Law 3 color for each point
174 vtkactor->GetProperty()->SetLineWidth( bbGetInputLineWidth() );
175 vtkactor->GetProperty()->SetOpacity( bbGetInputOpacity() );
177 if ( bbGetInputTransform()!=NULL )
179 vtkactor->SetUserTransform( bbGetInputTransform() );
183 if (bbGetInputRenderer()!=NULL )
185 bbGetInputRenderer()->AddActor( vtkactor );
191 void DrawAxisTree3D::Process()
195 std::vector<int> lstIndexs = bbGetInputlstIndexs();
196 if ( bbGetInputlstIndexs().size()==0 )
198 lstIndexs.push_back( bbGetInputlstPointX().size() );
200 int iAxis,sizeLstAxis=lstIndexs.size();
201 int iActor,sizeActors = vecVtkActors.size();
205 // if (oldLstSize!=sizeLstAxis)
207 // oldLstSize=sizeLstAxis;
208 for (iActor=0 ; iActor<sizeActors; iActor++)
210 if (bbGetInputRenderer()!=NULL )
212 bbGetInputRenderer()->RemoveActor( vecVtkActors[iActor] );
213 vecVtkPolyData[iActor]->Delete();
214 vecVtkPolyDataMaper[iActor]->Delete();
215 vecVtkActors[iActor]->Delete();
218 vecVtkPolyData.clear();
219 vecVtkPolyDataMaper.clear();
220 vecVtkActors.clear();
223 for ( iAxis=0 ; iAxis<sizeLstAxis ; iAxis++)
225 numPoints = lstIndexs[iAxis];
226 DrawOneAxis(iGeneral,numPoints,iAxis);
227 iGeneral = iGeneral+numPoints;
229 // if ((iAxis % 1)==0)
231 // printf("EED DrawAxisTree3D::Process %d/%d\n", iAxis,sizeLstAxis );
236 if ( bbGetInputiAxis() < (int)(vecVtkActors.size()-1) )
238 bbSetOutputOutAxis( vecVtkActors[ bbGetInputiAxis() ] );
240 printf("DrawAxisTree3D .ERROR. missing index vector...\n");
243 // } else {// if oldLstSize
245 for (iActor=0 ; iActor<sizeActors; iActor++)
247 vecVtkActors[iActor]->GetProperty()->SetOpacity( bbGetInputOpacity() );
248 vecVtkActors[iActor]->GetProperty()->SetLineWidth( bbGetInputLineWidth() );
250 // } // if oldLstSize
254 void DrawAxisTree3D::bbUserSetDefaultValues()
258 std::vector<double> colour;
260 colour.push_back(1.0);
261 colour.push_back(0.0);
262 colour.push_back(0.0);
264 colour.push_back(0.0);
265 colour.push_back(0.0);
266 colour.push_back(1.0);
268 colour.push_back(1.0);
269 colour.push_back(1.0);
270 colour.push_back(0.0);
272 colour.push_back(0.0);
273 colour.push_back(1.0);
274 colour.push_back(0.0);
276 colour.push_back(0.0);
277 colour.push_back(1.0);
278 colour.push_back(1.0);
281 colour.push_back(0.5);
282 colour.push_back(0.5);
283 colour.push_back(0.5);
285 bbSetInputColour(colour);
286 bbSetInputOpacity(1);
287 bbSetInputLineWidth(0.5);
288 bbSetInputColourLaw(1);
289 bbSetInputTransform(NULL);
294 //-----------------------------------------------------------------
295 void DrawAxisTree3D::bbUserInitializeProcessing()
299 //-----------------------------------------------------------------
300 void DrawAxisTree3D::bbUserFinalizeProcessing()
304 //-----------------------------------------------------------------
307 // EO namespace bbcreaMaracasVisu