]> Creatis software - creaMaracasVisu.git/blob - bbtk/src/bbmaracasvisuDrawAxisTree3D.cxx
52ab1bdc6af7c50d896426b4cf80e297a0e0579c
[creaMaracasVisu.git] / bbtk / src / bbmaracasvisuDrawAxisTree3D.cxx
1 /*# ---------------------------------------------------------------------
2 #
3 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
4 #                        pour la Sant�)
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
8 #
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.
15 #
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
20 #  liability.
21 #
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 # ------------------------------------------------------------------------ */
25
26 #include "bbmaracasvisuDrawAxisTree3D.h"
27 #include "bbcreaMaracasVisuPackage.h"
28 #include "vtkLinearTransform.h"
29
30 #include "vtkUnsignedCharArray.h"
31 #include "vtkCellData.h"
32 #include "vtkPolyLine.h"
33 #include "vtkLine.h"
34
35
36
37 namespace bbcreaMaracasVisu
38 {
39
40 BBTK_ADD_BLACK_BOX_TO_PACKAGE(creaMaracasVisu,DrawAxisTree3D)
41 BBTK_BLACK_BOX_IMPLEMENTATION(DrawAxisTree3D,bbtk::AtomicBlackBox);
42
43
44
45 void DrawAxisTree3D::DrawOneAxis(int iGeneral,int numPoints, int iAxis)
46 {
47 printf("8.1 ");
48         vtkPolyData                     *polydata               = vtkPolyData::New( );
49         vtkPolyDataMapper       *polydatamapper = vtkPolyDataMapper::New();
50         vtkActor                        *vtkactor               = vtkActor::New();
51
52 //      polydatamapper->ScalarVisibilityOff();
53 //EED 2017-01-01 Migration VTK7
54 #if VTK_MAJOR_VERSION <= 5
55         polydatamapper->SetInput(polydata);
56 #else
57         polydatamapper->SetInputData(polydata);
58         polydatamapper->Update();
59 #endif
60         vtkactor->SetMapper(polydatamapper);
61
62 printf("8.2 ");
63
64         vecVtkPolyData.push_back( polydata );
65         vecVtkPolyDataMaper.push_back( polydatamapper );
66         vecVtkActors.push_back( vtkactor );
67
68 printf("8.3 ");
69
70 //      vtkImageData* img = bbGetInputImage();
71         unsigned int i,size;
72         double spc[3];
73 //      img->GetSpacing(spc);
74         spc[0]=1;
75         spc[1]=1;
76         spc[2]=1;
77
78         int lstpointsXsize =bbGetInputlstPointX().size();
79
80 printf("8.4 ");
81
82         if( lstpointsXsize>0 )
83         {
84 printf("8.5 ");
85                 vtkPoints       *allPoints              = vtkPoints::New( );
86                 vtkPolyLine *polyline           = vtkPolyLine::New();
87                 vtkCellArray* allTopology       = vtkCellArray::New( );
88 //              allTopology->InsertNextCell( numPoints );
89 printf("8.6 ");
90
91                 size=iGeneral+numPoints;
92                 for (i=iGeneral;i<size;i++)
93                 {
94 printf("8.7(%d) ",i);
95                         //multiplicar ver parametros spacing, en maracas cuando se toca la imagen y se ve dycom
96                         //hay par·metro dycom, vtkImagedata valor spacing y esos datos hay que multiplicar al polydata
97                         allPoints->InsertNextPoint( bbGetInputlstPointX()[i]*spc[0],
98                                                                                 bbGetInputlstPointY()[i]*spc[1],
99                                                                                 bbGetInputlstPointZ()[i]*spc[2] );
100 //                      printf("DrawAxisTree3D::DrawOneAxis point  %d -> %f, %f, %f \n", i,  bbGetInputlstPointX()[i], bbGetInputlstPointY()[i], bbGetInputlstPointZ()[i] );
101
102 polyline->GetPointIds()->InsertNextId(i-iGeneral);
103
104 //                      allTopology->InsertCellPoint( i-iGeneral );
105                 } // rof
106 printf("8.8 ");
107                 
108   allTopology->InsertNextCell(polyline);
109
110  // create cell array for edges
111   vtkCellArray *edges = vtkCellArray::New();
112 printf("8.9 ");
113
114 // connect edge's and vertexes point ids
115   for(vtkIdType i = iGeneral; i < size-1; i++)
116   {
117 printf("8.10(%d) ",i);
118     vtkLine *edge = vtkLine::New();
119     edge->GetPointIds()->SetId(0, i-iGeneral);
120     edge->GetPointIds()->SetId(1, (i-iGeneral+1) );
121     edges->InsertNextCell(edge);
122     edge->Delete();
123 //    vtkSmartPointer<vtkVertex> vertex = vtkSmartPointer<vtkVertex>::New();
124 //    vertex->GetPointIds()->SetId(0, i);
125 //    vertexes->InsertNextCell(vertex);
126   }
127
128 printf("8.11 ");
129                 polydata->SetPoints( allPoints );
130  polydata->SetLines(edges);
131 //              polydata->SetLines( allTopology );
132
133
134  // polydata->SetPolys( allTopology );
135
136                 edges->Delete();
137                 allPoints->Delete();
138                 allTopology->Delete();
139 printf("8.12 ");
140                 
141         }
142
143         // color
144         double r,g,b;
145
146         if (bbGetInputColourLaw()==1)  // the same color for all 
147         {
148 printf("8.13(%d) ",bbGetInputColour().size() );
149
150                 r = bbGetInputColour()[0];
151                 g = bbGetInputColour()[1];
152                 b = bbGetInputColour()[2];
153                 vtkactor->GetProperty()->SetColor( r,g,b );
154         } // Law 1  color for all
155
156         if (bbGetInputColourLaw()==2) // different colors for each segment
157         {
158 printf("8.14 ");
159                 if ( (iAxis*3+1) < (int)(bbGetInputColour().size()) )   
160                 {
161                         r = bbGetInputColour()[0+iAxis*3];
162                         g = bbGetInputColour()[1+iAxis*3];
163                         b = bbGetInputColour()[2+iAxis*3];
164                 } else {
165                         r = (rand() % 100) / 100.0;
166                         g = (rand() % 100) / 100.0;
167                         b = (rand() % 100) / 100.0;
168                 }
169 printf("8.15 ");
170                 vtkactor->GetProperty()->SetColor( r,g,b );
171         }  // Law 2  color for each segment
172
173         if (bbGetInputColourLaw()==3)  // color for each point 
174         {
175 printf("8.16 ");
176                 // Setup the colors array
177                 vtkUnsignedCharArray *colors = vtkUnsignedCharArray::New();
178                 colors->SetNumberOfComponents(3);
179                 colors->SetName("Colors");
180 //              colors->SetName("vertex color");
181                 int iPoint,pointSize=iGeneral+numPoints;
182
183
184                 for (iPoint=iGeneral; iPoint<pointSize; iPoint++)
185                 {
186                         r = bbGetInputColour()[0+iPoint*3]*255.0;
187                         g = bbGetInputColour()[1+iPoint*3]*255.0;
188                         b = bbGetInputColour()[2+iPoint*3]*255.0;
189                         //colors->SetTuple3(iPoint,r,g,b);
190                         colors->InsertNextTuple3(r,g,b);
191                 }
192                 polydata->GetCellData()->SetScalars(colors);
193                 polydata->Modified();
194  
195         }  // Law 3 color for each point
196
197 printf("8.17 ");
198         vtkactor->GetProperty()->SetLineWidth( bbGetInputLineWidth() );
199         vtkactor->GetProperty()->SetOpacity( bbGetInputOpacity() );
200
201         if ( bbGetInputTransform()!=NULL )
202         {
203 printf("8.18 ");
204                 vtkactor->SetUserTransform( bbGetInputTransform() );
205         }
206
207      // Interface Update
208      if  (bbGetInputRenderer()!=NULL )
209      {
210 printf("8.19 ");
211             bbGetInputRenderer()->AddActor( vtkactor );
212      }
213 printf("8.20 ");
214
215 }
216
217
218 void DrawAxisTree3D::Process()
219 {
220 printf("1 ");
221         int iGeneral=0;
222         std::vector<int> lstIndexs = bbGetInputlstIndexs();
223         if ( bbGetInputlstIndexs().size()==0 )
224         {
225 printf("2 ");
226                 lstIndexs.push_back( bbGetInputlstPointX().size() );
227         } // if
228         int iAxis,sizeLstAxis=lstIndexs.size();
229     int iActor,sizeActors = vecVtkActors.size();
230         int numPoints;
231
232 printf("3 ");
233
234 //    if (oldLstSize!=sizeLstAxis)
235 //       {
236 //        oldLstSize=sizeLstAxis;
237          for (iActor=0 ; iActor<sizeActors; iActor++)
238          {
239 printf("4-%d ",iActor);
240             if (bbGetInputRenderer()!=NULL )
241             {
242 printf("5 ");
243                 bbGetInputRenderer()->RemoveActor( vecVtkActors[iActor] );
244                 vecVtkPolyData[iActor]->Delete();
245                 vecVtkPolyDataMaper[iActor]->Delete();
246                 vecVtkActors[iActor]->Delete();
247 printf("6 ");
248             } // if
249          } // for iActor
250          vecVtkPolyData.clear();
251          vecVtkPolyDataMaper.clear();
252          vecVtkActors.clear();
253 printf("7 ");
254          for ( iAxis=0 ; iAxis<sizeLstAxis ; iAxis++)
255          {
256 printf("8(%d) ",iAxis);
257             numPoints = lstIndexs[iAxis];
258 printf("9(%d) ",iAxis);
259             DrawOneAxis(iGeneral,numPoints,iAxis);
260 printf("10 ");   
261             iGeneral = iGeneral+numPoints;
262     //          if ((iAxis % 1)==0)
263     //          {
264     //                  printf("EED  DrawAxisTree3D::Process  %d/%d\n", iAxis,sizeLstAxis );
265     //          }
266          } // for iAxis
267
268 printf("11 ");
269
270         if ( bbGetInputiAxis() < (int)(vecVtkActors.size() ) )
271         {
272             bbSetOutputOutAxis( vecVtkActors[ bbGetInputiAxis() ] );            
273         } else  {
274             printf("DrawAxisTree3D .ERROR.  iAxis for exist in actors vector ...\n");
275         } // if 
276  //   } else {// if oldLstSize
277 //    } // if oldLstSize
278
279 printf("12 \n");
280
281
282 }
283
284 void DrawAxisTree3D::bbUserSetDefaultValues()
285 {
286     oldLstSize=-1;
287          bbSetInputiAxis(0);
288      std::vector<double> colour;
289          // 1- red
290      colour.push_back(1.0);
291      colour.push_back(0.0);
292      colour.push_back(0.0);
293          // 2- blue
294      colour.push_back(0.0);
295      colour.push_back(0.0);
296      colour.push_back(1.0);
297          // 3- yellow
298      colour.push_back(1.0);
299      colour.push_back(1.0);
300      colour.push_back(0.0);
301          // 4- green
302      colour.push_back(0.0);
303      colour.push_back(1.0);
304      colour.push_back(0.0);
305          // 5-
306      colour.push_back(0.0);
307      colour.push_back(1.0);
308      colour.push_back(1.0);
309
310          // 6-
311      colour.push_back(0.5);
312      colour.push_back(0.5);
313      colour.push_back(0.5);
314
315      bbSetInputColour(colour);
316      bbSetInputOpacity(1);
317      bbSetInputLineWidth(0.5);
318      bbSetInputColourLaw(1);
319      bbSetInputTransform(NULL);
320
321 }
322
323
324         //-----------------------------------------------------------------
325         void DrawAxisTree3D::bbUserInitializeProcessing()
326         {
327         }
328
329         //-----------------------------------------------------------------
330         void DrawAxisTree3D::bbUserFinalizeProcessing()
331         {
332         }
333
334         //-----------------------------------------------------------------
335
336 }
337 // EO namespace bbcreaMaracasVisu
338
339