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();
74 if( lstpointsXsize>0 )
76 vtkPoints *allPoints = vtkPoints::New( );
77 vtkPolyLine *polyline = vtkPolyLine::New();
78 vtkCellArray* allTopology = vtkCellArray::New( );
79 // allTopology->InsertNextCell( numPoints );
80 size=iGeneral+numPoints;
81 std::vector<double> lstX =bbGetInputlstPointX();
82 std::vector<double> lstY =bbGetInputlstPointY();
83 std::vector<double> lstZ =bbGetInputlstPointZ();
84 for (i=iGeneral;i<size;i++)
86 //multiplicar ver parametros spacing, en maracas cuando se toca la imagen y se ve dycom
87 //hay par·metro dycom, vtkImagedata valor spacing y esos datos hay que multiplicar al polydata
88 allPoints->InsertNextPoint( lstX[i],
92 // printf("DrawAxisTree3D::DrawOneAxis point %d -> %f, %f, %f \n", i, bbGetInputlstPointX()[i], bbGetInputlstPointY()[i], bbGetInputlstPointZ()[i] );
93 polyline->GetPointIds()->InsertNextId(i-iGeneral);
94 // allTopology->InsertCellPoint( i-iGeneral );
96 allTopology->InsertNextCell(polyline);
97 // create cell array for edges
98 vtkCellArray *edges = vtkCellArray::New();
99 // connect edge's and vertexes point ids
100 for(vtkIdType i = iGeneral; i < size-1; i++)
102 vtkLine *edge = vtkLine::New();
103 edge->GetPointIds()->SetId(0, i-iGeneral);
104 edge->GetPointIds()->SetId(1, (i-iGeneral+1) );
105 edges->InsertNextCell(edge);
107 // vtkSmartPointer<vtkVertex> vertex = vtkSmartPointer<vtkVertex>::New();
108 // vertex->GetPointIds()->SetId(0, i);
109 // vertexes->InsertNextCell(vertex);
111 polydata->SetPoints( allPoints );
112 polydata->SetLines(edges);
113 // polydata->SetLines( allTopology );
114 // polydata->SetPolys( allTopology );
117 allTopology->Delete();
118 } // if lstpointsXsize
122 std::vector<double> lstColor = bbGetInputColour();
123 if (bbGetInputColourLaw()==1) // the same color for all
128 vtkactor->GetProperty()->SetColor( r,g,b );
129 } // Law 1 color for all
130 if (bbGetInputColourLaw()==2) // different colors for each segment
132 if ( (iAxis*3+1) < (int)(bbGetInputColour().size()) )
134 r = lstColor[0+iAxis*3];
135 g = lstColor[1+iAxis*3];
136 b = lstColor[2+iAxis*3];
138 r = (rand() % 100) / 100.0;
139 g = (rand() % 100) / 100.0;
140 b = (rand() % 100) / 100.0;
142 vtkactor->GetProperty()->SetColor( r,g,b );
143 } // Law 2 color for each segment
144 if (bbGetInputColourLaw()==3) // color for each point
146 // Setup the colors array
147 vtkUnsignedCharArray *colors = vtkUnsignedCharArray::New();
148 colors->SetNumberOfComponents(3);
149 colors->SetName("Colors");
150 // colors->SetName("vertex color");
151 int iPoint,pointSize=iGeneral+numPoints;
152 for (iPoint=iGeneral; iPoint<pointSize; iPoint++)
154 r = lstColor[0+iPoint*3]*255.0;
155 g = lstColor[1+iPoint*3]*255.0;
156 b = lstColor[2+iPoint*3]*255.0;
157 colors->InsertNextTuple3(r,g,b);
159 polydata->GetCellData()->SetScalars(colors);
160 polydata->Modified();
161 } // Law 3 color for each point
163 vtkactor->GetProperty()->SetLineWidth( bbGetInputLineWidth() );
164 vtkactor->GetProperty()->SetOpacity( bbGetInputOpacity() );
165 if ( bbGetInputTransform()!=NULL )
167 vtkactor->SetUserTransform( bbGetInputTransform() );
170 if (bbGetInputRenderer()!=NULL )
172 bbGetInputRenderer()->AddActor( vtkactor );
177 void DrawAxisTree3D::Process()
180 int iActor,sizeActors = vecVtkActors.size();
181 for (iActor=0 ; iActor<sizeActors; iActor++)
183 if (bbGetInputRenderer()!=NULL )
185 bbGetInputRenderer()->RemoveActor( vecVtkActors[iActor] );
186 vecVtkPolyData[iActor]->Delete();
187 vecVtkPolyDataMaper[iActor]->Delete();
188 vecVtkActors[iActor]->Delete();
191 vecVtkPolyData.clear();
192 vecVtkPolyDataMaper.clear();
193 vecVtkActors.clear();
195 if (bbGetInputActive()==true)
197 if ( (bbGetInputlstPointX().size()==bbGetInputlstPointY().size()) &&
198 (bbGetInputlstPointX().size()==bbGetInputlstPointZ().size()) )
201 std::vector<int> lstIndexs = bbGetInputlstIndexs();
202 if ( bbGetInputlstIndexs().size()==0 )
204 lstIndexs.push_back( bbGetInputlstPointX().size() );
206 int iAxis,sizeLstAxis=lstIndexs.size();
208 for ( iAxis=0 ; iAxis<sizeLstAxis ; iAxis++)
210 numPoints = lstIndexs[iAxis];
211 DrawOneAxis(iGeneral,numPoints,iAxis);
212 iGeneral = iGeneral+numPoints;
214 if ( bbGetInputiAxis() < (int)(vecVtkActors.size() ) )
216 bbSetOutputOutAxis( vecVtkActors[ bbGetInputiAxis() ] );
218 printf("DrawAxisTree3D .ERROR. iAxis for exist in actors vector ...\n");
221 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() );
226 void DrawAxisTree3D::bbUserSetDefaultValues()
229 std::vector<double> colour;
231 colour.push_back(1.0);
232 colour.push_back(0.0);
233 colour.push_back(0.0);
235 colour.push_back(0.0);
236 colour.push_back(0.0);
237 colour.push_back(1.0);
239 colour.push_back(1.0);
240 colour.push_back(1.0);
241 colour.push_back(0.0);
243 colour.push_back(0.0);
244 colour.push_back(1.0);
245 colour.push_back(0.0);
247 colour.push_back(0.0);
248 colour.push_back(1.0);
249 colour.push_back(1.0);
252 colour.push_back(0.5);
253 colour.push_back(0.5);
254 colour.push_back(0.5);
256 bbSetInputActive(true);
258 bbSetInputColour(colour);
259 bbSetInputOpacity(1);
260 bbSetInputLineWidth(0.5);
261 bbSetInputColourLaw(1);
262 bbSetInputTransform(NULL);
263 bbSetOutputOutAxis(NULL);
268 //-----------------------------------------------------------------
269 void DrawAxisTree3D::bbUserInitializeProcessing()
273 //-----------------------------------------------------------------
274 void DrawAxisTree3D::bbUserFinalizeProcessing()
278 //-----------------------------------------------------------------
281 // EO namespace bbcreaMaracasVisu