]> Creatis software - creaMaracasVisu.git/blob - bbtk/src/bbmaracasvisuDrawAxisTree3D.cxx
Support #1768 CREATIS Licence insertion
[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 namespace bbcreaMaracasVisu
31 {
32
33 BBTK_ADD_BLACK_BOX_TO_PACKAGE(creaMaracasVisu,DrawAxisTree3D)
34 BBTK_BLACK_BOX_IMPLEMENTATION(DrawAxisTree3D,bbtk::AtomicBlackBox);
35
36
37
38 void DrawAxisTree3D::DrawOneAxis(int iGeneral,int numPoints, int iAxis)
39 {
40         vtkPolyData                     *polydata               = vtkPolyData::New( );
41         vtkPolyDataMapper       *polydatamapper = vtkPolyDataMapper::New();
42         vtkActor                        *vtkactor               = vtkActor::New();
43
44         polydatamapper->SetInput(polydata);
45         vtkactor->SetMapper(polydatamapper);
46
47         vecVtkPolyData.push_back( polydata );
48         vecVtkPolyDataMaper.push_back( polydatamapper );
49         vecVtkActors.push_back( vtkactor );
50
51 //      vtkImageData* img = bbGetInputImage();
52         unsigned int i,size;
53         double spc[3];
54 //      img->GetSpacing(spc);
55         spc[0]=1;
56         spc[1]=1;
57         spc[2]=1;
58
59         int lstpointsXsize =bbGetInputlstPointX().size();
60
61         if( lstpointsXsize>0 ){
62                 vtkPoints* allPoints            = vtkPoints::New( );
63                 vtkCellArray* allTopology       = vtkCellArray::New( );
64                 allTopology->InsertNextCell( numPoints );
65
66                 size=iGeneral+numPoints;
67                 for (i=iGeneral;i<size;i++)
68                 {
69                         //multiplicar ver parametros spacing, en maracas cuando se toca la imagen y se ve dycom
70                         //hay par·metro dycom, vtkImagedata valor spacing y esos datos hay que multiplicar al polydata
71                         allPoints->InsertNextPoint( bbGetInputlstPointX()[i]*spc[0],
72                                                                                 bbGetInputlstPointY()[i]*spc[1],
73                                                                                 bbGetInputlstPointZ()[i]*spc[2] );
74 //                      printf("DrawAxisTree3D::DrawOneAxis point  %d -> %f, %f, %f \n", i,  bbGetInputlstPointX()[i], bbGetInputlstPointY()[i], bbGetInputlstPointZ()[i] );
75                         allTopology->InsertCellPoint( i-iGeneral );
76                 } // rof
77                 polydata->SetPoints( allPoints );
78                 polydata->SetLines( allTopology );
79                 allPoints->Delete();
80                 allTopology->Delete();
81         }
82
83         // color
84         double r,g,b;
85
86         if ( (iAxis*3+1) < (int)(bbGetInputColour().size()) )
87         {
88                         r = bbGetInputColour()[0+iAxis*3];
89                         g = bbGetInputColour()[1+iAxis*3];
90                         b = bbGetInputColour()[2+iAxis*3];
91         } else {
92                         r = (rand() % 100) / 100.0;
93                         g = (rand() % 100) / 100.0;
94                         b = (rand() % 100) / 100.0;
95         }
96
97         vtkactor->GetProperty()->SetColor( r,g,b );
98         vtkactor->GetProperty()->SetLineWidth( 0.5 );
99         vtkactor->GetProperty()->SetOpacity( bbGetInputOpacity() );
100
101         if ( bbGetInputTransform()!=NULL )
102         {
103                 vtkactor->SetUserTransform( bbGetInputTransform() );
104         }
105
106      // Interface Update
107      if  (bbGetInputRenderer()!=NULL )
108      {
109             bbGetInputRenderer()->AddActor( vtkactor );
110      }
111 }
112
113
114 void DrawAxisTree3D::Process()
115 {
116         printf("EED DrawAxisTree3D::Process start \n");
117
118         int iGeneral=0;
119         int iAxis,sizeLstAxis=bbGetInputlstIndexs().size();
120     int iActor,sizeActors = vecVtkActors.size();
121         int numPoints;
122
123     if (oldLstSize!=sizeLstAxis)
124          {
125         oldLstSize=sizeLstAxis;
126          for (iActor=0 ; iActor<sizeActors; iActor++)
127          {
128             if (bbGetInputRenderer()!=NULL )
129             {
130                 bbGetInputRenderer()->RemoveActor( vecVtkActors[iActor] );
131                 vecVtkPolyData[iActor]->Delete();
132                 vecVtkPolyDataMaper[iActor]->Delete();
133                 vecVtkActors[iActor]->Delete();
134             }
135          }
136          vecVtkPolyData.clear();
137          vecVtkPolyDataMaper.clear();
138          vecVtkActors.clear();
139
140         for ( iAxis=0 ; iAxis<sizeLstAxis ; iAxis++)
141         {
142             numPoints = bbGetInputlstIndexs()[iAxis];
143             DrawOneAxis(iGeneral,numPoints,iAxis);
144             iGeneral = iGeneral+numPoints;
145
146     //          if ((iAxis % 1)==0)
147     //          {
148     //                  printf("EED  DrawAxisTree3D::Process  %d/%d\n", iAxis,sizeLstAxis );
149     //          }
150
151         }
152
153         if ( bbGetInputiAxis() < (int)(vecVtkActors.size()-1) )
154         {
155             bbSetOutputOutAxis( vecVtkActors[ bbGetInputiAxis() ] );
156         } else  {
157             printf("TubeTreeFilter .ERROR. missing index vector...\n");
158         }
159
160     } else {// if oldLstSize
161         for (iActor=0 ; iActor<sizeActors; iActor++)
162         {
163             vecVtkActors[iActor]->GetProperty()->SetOpacity( bbGetInputOpacity() );
164         }
165     }
166
167         printf("EED DrawAxisTree3D::Process end \n");
168
169 }
170
171 void DrawAxisTree3D::bbUserSetDefaultValues()
172 {
173     oldLstSize=-1;
174          bbSetInputiAxis(0);
175      std::vector<double> colour;
176          // 1- red
177      colour.push_back(1.0);
178      colour.push_back(0.0);
179      colour.push_back(0.0);
180          // 2- blue
181      colour.push_back(0.0);
182      colour.push_back(0.0);
183      colour.push_back(1.0);
184          // 3- yellow
185      colour.push_back(1.0);
186      colour.push_back(1.0);
187      colour.push_back(0.0);
188          // 4- green
189      colour.push_back(0.0);
190      colour.push_back(1.0);
191      colour.push_back(0.0);
192          // 5-
193      colour.push_back(0.0);
194      colour.push_back(1.0);
195      colour.push_back(1.0);
196
197          // 6-
198      colour.push_back(0.5);
199      colour.push_back(0.5);
200      colour.push_back(0.5);
201
202      bbSetInputColour(colour);
203      bbSetInputOpacity(1);
204      bbSetInputColourLaw(1);
205
206 }
207
208
209         //-----------------------------------------------------------------
210         void DrawAxisTree3D::bbUserInitializeProcessing()
211         {
212         }
213
214         //-----------------------------------------------------------------
215         void DrawAxisTree3D::bbUserFinalizeProcessing()
216         {
217         }
218
219         //-----------------------------------------------------------------
220
221 }
222 // EO namespace bbcreaMaracasVisu
223
224