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 printf("EED DrawAxisTree3D::DrawOneAxis Start \n");
48 vtkPolyData *polydata = vtkPolyData::New( );
49 vtkPolyDataMapper *polydatamapper = vtkPolyDataMapper::New();
50 vtkActor *vtkactor = vtkActor::New();
52 // polydatamapper->ScalarVisibilityOff();
53 polydatamapper->SetInput(polydata);
54 vtkactor->SetMapper(polydatamapper);
56 vecVtkPolyData.push_back( polydata );
57 vecVtkPolyDataMaper.push_back( polydatamapper );
58 vecVtkActors.push_back( vtkactor );
60 // vtkImageData* img = bbGetInputImage();
63 // img->GetSpacing(spc);
68 int lstpointsXsize =bbGetInputlstPointX().size();
70 if( lstpointsXsize>0 ){
71 vtkPoints* allPoints = vtkPoints::New( );
72 vtkPolyLine *polyline = vtkPolyLine::New();
73 vtkCellArray* allTopology = vtkCellArray::New( );
74 // allTopology->InsertNextCell( numPoints );
76 size=iGeneral+numPoints;
77 for (i=iGeneral;i<size;i++)
79 //multiplicar ver parametros spacing, en maracas cuando se toca la imagen y se ve dycom
80 //hay par·metro dycom, vtkImagedata valor spacing y esos datos hay que multiplicar al polydata
81 allPoints->InsertNextPoint( bbGetInputlstPointX()[i]*spc[0],
82 bbGetInputlstPointY()[i]*spc[1],
83 bbGetInputlstPointZ()[i]*spc[2] );
84 // printf("DrawAxisTree3D::DrawOneAxis point %d -> %f, %f, %f \n", i, bbGetInputlstPointX()[i], bbGetInputlstPointY()[i], bbGetInputlstPointZ()[i] );
86 polyline->GetPointIds()->InsertNextId(i-iGeneral);
88 // allTopology->InsertCellPoint( i-iGeneral );
90 allTopology->InsertNextCell(polyline);
92 // create cell array for edges
93 vtkCellArray *edges = vtkCellArray::New();
95 // connect edge's and vertexes point ids
96 for(vtkIdType i = iGeneral; i < size-1; i++)
98 vtkLine *edge = vtkLine::New();
99 edge->GetPointIds()->SetId(0, i-iGeneral);
100 edge->GetPointIds()->SetId(1, (i-iGeneral+1) );
101 edges->InsertNextCell(edge);
103 // vtkSmartPointer<vtkVertex> vertex = vtkSmartPointer<vtkVertex>::New();
104 // vertex->GetPointIds()->SetId(0, i);
105 // vertexes->InsertNextCell(vertex);
108 polydata->SetPoints( allPoints );
109 polydata->SetLines(edges);
110 // polydata->SetLines( allTopology );
113 // polydata->SetPolys( allTopology );
117 allTopology->Delete();
123 if (bbGetInputColourLaw()==1) // the same color for all
125 r = bbGetInputColour()[0];
126 g = bbGetInputColour()[1];
127 b = bbGetInputColour()[2];
128 vtkactor->GetProperty()->SetColor( r,g,b );
129 } // Law 1 color for all
131 if (bbGetInputColourLaw()==2) // different colors for each segment
133 if ( (iAxis*3+1) < (int)(bbGetInputColour().size()) )
135 r = bbGetInputColour()[0+iAxis*3];
136 g = bbGetInputColour()[1+iAxis*3];
137 b = bbGetInputColour()[2+iAxis*3];
139 r = (rand() % 100) / 100.0;
140 g = (rand() % 100) / 100.0;
141 b = (rand() % 100) / 100.0;
143 vtkactor->GetProperty()->SetColor( r,g,b );
144 } // Law 2 color for each segment
147 if (bbGetInputColourLaw()==3) // color for each point
149 // Setup the colors array
150 vtkUnsignedCharArray *colors = vtkUnsignedCharArray::New();
151 colors->SetNumberOfComponents(3);
152 colors->SetName("Colors");
153 // colors->SetName("vertex color");
154 int iPoint,pointSize=iGeneral+numPoints;
157 for (iPoint=iGeneral; iPoint<pointSize; iPoint++)
159 r = bbGetInputColour()[0+iPoint*3]*255.0;
160 g = bbGetInputColour()[1+iPoint*3]*255.0;
161 b = bbGetInputColour()[2+iPoint*3]*255.0;
162 //colors->SetTuple3(iPoint,r,g,b);
163 printf("EED DrawAxisTree3D::DrawOneAxis iPoint=%d size=%d rgb=%f% f% f \n", iPoint , bbGetInputColour().size() , r,g,b);
164 colors->InsertNextTuple3(r,g,b);
166 polydata->GetCellData()->SetScalars(colors);
167 polydata->Modified();
169 } // Law 3 color for each point
171 vtkactor->GetProperty()->SetLineWidth( bbGetInputLineWidth() );
172 vtkactor->GetProperty()->SetOpacity( bbGetInputOpacity() );
174 if ( bbGetInputTransform()!=NULL )
176 vtkactor->SetUserTransform( bbGetInputTransform() );
180 if (bbGetInputRenderer()!=NULL )
182 bbGetInputRenderer()->AddActor( vtkactor );
184 printf("EED DrawAxisTree3D::DrawOneAxis End \n");
188 void DrawAxisTree3D::Process()
190 printf("EED DrawAxisTree3D::Process start \n");
193 int iAxis,sizeLstAxis=bbGetInputlstIndexs().size();
194 int iActor,sizeActors = vecVtkActors.size();
197 if (oldLstSize!=sizeLstAxis)
199 oldLstSize=sizeLstAxis;
200 for (iActor=0 ; iActor<sizeActors; iActor++)
202 if (bbGetInputRenderer()!=NULL )
204 bbGetInputRenderer()->RemoveActor( vecVtkActors[iActor] );
205 vecVtkPolyData[iActor]->Delete();
206 vecVtkPolyDataMaper[iActor]->Delete();
207 vecVtkActors[iActor]->Delete();
210 vecVtkPolyData.clear();
211 vecVtkPolyDataMaper.clear();
212 vecVtkActors.clear();
214 for ( iAxis=0 ; iAxis<sizeLstAxis ; iAxis++)
216 numPoints = bbGetInputlstIndexs()[iAxis];
217 DrawOneAxis(iGeneral,numPoints,iAxis);
218 iGeneral = iGeneral+numPoints;
220 // if ((iAxis % 1)==0)
222 // printf("EED DrawAxisTree3D::Process %d/%d\n", iAxis,sizeLstAxis );
227 if ( bbGetInputiAxis() < (int)(vecVtkActors.size()-1) )
229 bbSetOutputOutAxis( vecVtkActors[ bbGetInputiAxis() ] );
231 printf("DrawAxisTree3D .ERROR. missing index vector...\n");
234 } else {// if oldLstSize
235 for (iActor=0 ; iActor<sizeActors; iActor++)
237 vecVtkActors[iActor]->GetProperty()->SetOpacity( bbGetInputOpacity() );
241 printf("EED DrawAxisTree3D::Process end \n");
245 void DrawAxisTree3D::bbUserSetDefaultValues()
249 std::vector<double> colour;
251 colour.push_back(1.0);
252 colour.push_back(0.0);
253 colour.push_back(0.0);
255 colour.push_back(0.0);
256 colour.push_back(0.0);
257 colour.push_back(1.0);
259 colour.push_back(1.0);
260 colour.push_back(1.0);
261 colour.push_back(0.0);
263 colour.push_back(0.0);
264 colour.push_back(1.0);
265 colour.push_back(0.0);
267 colour.push_back(0.0);
268 colour.push_back(1.0);
269 colour.push_back(1.0);
272 colour.push_back(0.5);
273 colour.push_back(0.5);
274 colour.push_back(0.5);
276 bbSetInputColour(colour);
277 bbSetInputOpacity(1);
278 bbSetInputLineWidth(0.5);
279 bbSetInputColourLaw(1);
284 //-----------------------------------------------------------------
285 void DrawAxisTree3D::bbUserInitializeProcessing()
289 //-----------------------------------------------------------------
290 void DrawAxisTree3D::bbUserFinalizeProcessing()
294 //-----------------------------------------------------------------
297 // EO namespace bbcreaMaracasVisu