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