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