]> Creatis software - creaMaracasVisu.git/blob - bbtk/src/bbmaracasvisuDrawAxisTree3D.cxx
33bb1d776f08bac7cbcf4ca07a452cc746da09f7
[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         vtkPolyData                     *polydata               = vtkPolyData::New( );
48         vtkPolyDataMapper       *polydatamapper = vtkPolyDataMapper::New();
49         vtkActor                        *vtkactor               = vtkActor::New();
50
51 //      polydatamapper->ScalarVisibilityOff();
52 //EED 2017-01-01 Migration VTK7
53 #if VTK_MAJOR_VERSION <= 5
54         polydatamapper->SetInput(polydata);
55 #else
56         polydatamapper->SetInputData(polydata);
57 #endif
58         vtkactor->SetMapper(polydatamapper);
59
60         vecVtkPolyData.push_back( polydata );
61         vecVtkPolyDataMaper.push_back( polydatamapper );
62         vecVtkActors.push_back( vtkactor );
63
64 //      vtkImageData* img = bbGetInputImage();
65         unsigned int i,size;
66         double spc[3];
67 //      img->GetSpacing(spc);
68         spc[0]=1;
69         spc[1]=1;
70         spc[2]=1;
71
72         int lstpointsXsize =bbGetInputlstPointX().size();
73
74         if( lstpointsXsize>0 ){
75                 vtkPoints* allPoints            = vtkPoints::New( );
76 vtkPolyLine *polyline = vtkPolyLine::New();
77                 vtkCellArray* allTopology       = vtkCellArray::New( );
78 //              allTopology->InsertNextCell( numPoints );
79
80                 size=iGeneral+numPoints;
81                 for (i=iGeneral;i<size;i++)
82                 {
83                         //multiplicar ver parametros spacing, en maracas cuando se toca la imagen y se ve dycom
84                         //hay par·metro dycom, vtkImagedata valor spacing y esos datos hay que multiplicar al polydata
85                         allPoints->InsertNextPoint( bbGetInputlstPointX()[i]*spc[0],
86                                                                                 bbGetInputlstPointY()[i]*spc[1],
87                                                                                 bbGetInputlstPointZ()[i]*spc[2] );
88 //                      printf("DrawAxisTree3D::DrawOneAxis point  %d -> %f, %f, %f \n", i,  bbGetInputlstPointX()[i], bbGetInputlstPointY()[i], bbGetInputlstPointZ()[i] );
89
90 polyline->GetPointIds()->InsertNextId(i-iGeneral);
91
92 //                      allTopology->InsertCellPoint( i-iGeneral );
93                 } // rof
94   allTopology->InsertNextCell(polyline);
95
96  // create cell array for edges
97   vtkCellArray *edges = vtkCellArray::New();
98
99 // connect edge's and vertexes point ids
100   for(vtkIdType i = iGeneral; i < size-1; i++)
101   {
102     vtkLine *edge = vtkLine::New();
103     edge->GetPointIds()->SetId(0, i-iGeneral);
104     edge->GetPointIds()->SetId(1, (i-iGeneral+1) );
105     edges->InsertNextCell(edge);
106     edge->Delete();
107 //    vtkSmartPointer<vtkVertex> vertex = vtkSmartPointer<vtkVertex>::New();
108 //    vertex->GetPointIds()->SetId(0, i);
109 //    vertexes->InsertNextCell(vertex);
110   }
111
112                 polydata->SetPoints( allPoints );
113  polydata->SetLines(edges);
114 //              polydata->SetLines( allTopology );
115
116
117  // polydata->SetPolys( allTopology );
118
119                 edges->Delete();
120                 allPoints->Delete();
121                 allTopology->Delete();
122         }
123
124         // color
125         double r,g,b;
126
127         if (bbGetInputColourLaw()==1)  // the same color for all 
128         {
129                 r = bbGetInputColour()[0];
130                 g = bbGetInputColour()[1];
131                 b = bbGetInputColour()[2];
132                 vtkactor->GetProperty()->SetColor( r,g,b );
133         } // Law 1  color for all
134
135         if (bbGetInputColourLaw()==2) // different colors for each segment
136         {
137                 if ( (iAxis*3+1) < (int)(bbGetInputColour().size()) )   
138                 {
139                         r = bbGetInputColour()[0+iAxis*3];
140                         g = bbGetInputColour()[1+iAxis*3];
141                         b = bbGetInputColour()[2+iAxis*3];
142                 } else {
143                         r = (rand() % 100) / 100.0;
144                         g = (rand() % 100) / 100.0;
145                         b = (rand() % 100) / 100.0;
146                 }
147                 vtkactor->GetProperty()->SetColor( r,g,b );
148         }  // Law 2  color for each segment
149
150
151         if (bbGetInputColourLaw()==3)  // color for each point 
152         {
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;
159
160
161                 for (iPoint=iGeneral; iPoint<pointSize; iPoint++)
162                 {
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);
168                 }
169                 polydata->GetCellData()->SetScalars(colors);
170                 polydata->Modified();
171  
172         }  // Law 3 color for each point
173
174
175         vtkactor->GetProperty()->SetLineWidth( bbGetInputLineWidth() );
176         vtkactor->GetProperty()->SetOpacity( bbGetInputOpacity() );
177
178         if ( bbGetInputTransform()!=NULL )
179         {
180                 vtkactor->SetUserTransform( bbGetInputTransform() );
181         }
182
183      // Interface Update
184      if  (bbGetInputRenderer()!=NULL )
185      {
186             bbGetInputRenderer()->AddActor( vtkactor );
187      }
188 }
189
190
191 void DrawAxisTree3D::Process()
192 {
193         printf("EED DrawAxisTree3D::Process start \n");
194
195         int iGeneral=0;
196         int iAxis,sizeLstAxis=bbGetInputlstIndexs().size();
197     int iActor,sizeActors = vecVtkActors.size();
198         int numPoints;
199
200 //    if (oldLstSize!=sizeLstAxis)
201 //       {
202 //        oldLstSize=sizeLstAxis;
203          for (iActor=0 ; iActor<sizeActors; iActor++)
204          {
205             if (bbGetInputRenderer()!=NULL )
206             {
207                 bbGetInputRenderer()->RemoveActor( vecVtkActors[iActor] );
208                 vecVtkPolyData[iActor]->Delete();
209                 vecVtkPolyDataMaper[iActor]->Delete();
210                 vecVtkActors[iActor]->Delete();
211             } // if
212          } // for iActor
213          vecVtkPolyData.clear();
214          vecVtkPolyDataMaper.clear();
215          vecVtkActors.clear();
216
217         for ( iAxis=0 ; iAxis<sizeLstAxis ; iAxis++)
218         {
219             numPoints = bbGetInputlstIndexs()[iAxis];
220             DrawOneAxis(iGeneral,numPoints,iAxis);
221             iGeneral = iGeneral+numPoints;
222
223     //          if ((iAxis % 1)==0)
224     //          {
225     //                  printf("EED  DrawAxisTree3D::Process  %d/%d\n", iAxis,sizeLstAxis );
226     //          }
227
228         } // for iAxis
229
230         if ( bbGetInputiAxis() < (int)(vecVtkActors.size()-1) )
231         {
232             bbSetOutputOutAxis( vecVtkActors[ bbGetInputiAxis() ] );
233         } else  {
234             printf("DrawAxisTree3D .ERROR. missing index vector...\n");
235         } // if 
236
237  //   } else {// if oldLstSize
238         for (iActor=0 ; iActor<sizeActors; iActor++)
239         {
240             vecVtkActors[iActor]->GetProperty()->SetOpacity( bbGetInputOpacity() );
241             vecVtkActors[iActor]->GetProperty()->SetLineWidth( bbGetInputLineWidth() );
242         }
243 //    } // if oldLstSize
244
245         printf("EED DrawAxisTree3D::Process end \n");
246
247 }
248
249 void DrawAxisTree3D::bbUserSetDefaultValues()
250 {
251     oldLstSize=-1;
252          bbSetInputiAxis(0);
253      std::vector<double> colour;
254          // 1- red
255      colour.push_back(1.0);
256      colour.push_back(0.0);
257      colour.push_back(0.0);
258          // 2- blue
259      colour.push_back(0.0);
260      colour.push_back(0.0);
261      colour.push_back(1.0);
262          // 3- yellow
263      colour.push_back(1.0);
264      colour.push_back(1.0);
265      colour.push_back(0.0);
266          // 4- green
267      colour.push_back(0.0);
268      colour.push_back(1.0);
269      colour.push_back(0.0);
270          // 5-
271      colour.push_back(0.0);
272      colour.push_back(1.0);
273      colour.push_back(1.0);
274
275          // 6-
276      colour.push_back(0.5);
277      colour.push_back(0.5);
278      colour.push_back(0.5);
279
280      bbSetInputColour(colour);
281      bbSetInputOpacity(1);
282      bbSetInputLineWidth(0.5);
283      bbSetInputColourLaw(1);
284
285 }
286
287
288         //-----------------------------------------------------------------
289         void DrawAxisTree3D::bbUserInitializeProcessing()
290         {
291         }
292
293         //-----------------------------------------------------------------
294         void DrawAxisTree3D::bbUserFinalizeProcessing()
295         {
296         }
297
298         //-----------------------------------------------------------------
299
300 }
301 // EO namespace bbcreaMaracasVisu
302
303