]> Creatis software - creaMaracasVisu.git/blob - bbtk/src/bbmaracasvisuDrawAxisTree3D.cxx
no message
[creaMaracasVisu.git] / bbtk / src / bbmaracasvisuDrawAxisTree3D.cxx
1 #include "bbmaracasvisuDrawAxisTree3D.h"
2 #include "bbcreaMaracasVisuPackage.h"
3 #include "vtkLinearTransform.h"
4
5 namespace bbcreaMaracasVisu
6 {
7
8 BBTK_ADD_BLACK_BOX_TO_PACKAGE(creaMaracasVisu,DrawAxisTree3D)
9 BBTK_BLACK_BOX_IMPLEMENTATION(DrawAxisTree3D,bbtk::AtomicBlackBox);
10
11
12
13 void DrawAxisTree3D::DrawOneAxis(int iGeneral,int numPoints, int iAxis)
14 {
15         vtkPolyData                     *polydata               = vtkPolyData::New( );
16         vtkPolyDataMapper       *polydatamapper = vtkPolyDataMapper::New();
17         vtkActor                        *vtkactor               = vtkActor::New();
18
19         polydatamapper->SetInput(polydata);
20         vtkactor->SetMapper(polydatamapper);
21
22         vecVtkPolyData.push_back( polydata );
23         vecVtkPolyDataMaper.push_back( polydatamapper );
24         vecVtkActors.push_back( vtkactor );
25
26 //      vtkImageData* img = bbGetInputImage();  
27         unsigned int i,size;
28         double spc[3];  
29 //      img->GetSpacing(spc);
30         spc[0]=1;
31         spc[1]=1;
32         spc[2]=1;
33
34         if(!bbGetInputlstPointX().empty()){
35                 vtkPoints* allPoints            = vtkPoints::New( );
36                 vtkCellArray* allTopology       = vtkCellArray::New( );
37                 allTopology->InsertNextCell( numPoints );
38
39                 size=iGeneral+numPoints;
40                 for (i=iGeneral;i<size;i++)
41                 {
42                         //multiplicar ver parametros spacing, en maracas cuando se toca la imagen y se ve dycom
43                         //hay parĀ·metro dycom, vtkImagedata valor spacing y esos datos hay que multiplicar al polydata
44                         allPoints->InsertNextPoint( bbGetInputlstPointX()[i]*spc[0],  
45                                                                                 bbGetInputlstPointY()[i]*spc[1], 
46                                                                                 bbGetInputlstPointZ()[i]*spc[2] );
47                         printf("DrawAxisTree3D::DrawOneAxis point  %d -> %f, %f, %f \n", i,  bbGetInputlstPointX()[i], bbGetInputlstPointY()[i], bbGetInputlstPointZ()[i] );
48                         allTopology->InsertCellPoint( i-iGeneral );
49                 } // rof
50                 polydata->SetPoints( allPoints );
51                 polydata->SetLines( allTopology );
52                 allPoints->Delete();
53                 allTopology->Delete();  
54         }
55
56         // color
57         double r,g,b;
58
59         if ( (iAxis*3+1) < (int)(bbGetInputColour().size()) )
60         {
61                         r = bbGetInputColour()[0+iAxis*3];
62                         g = bbGetInputColour()[1+iAxis*3]; 
63                         b = bbGetInputColour()[2+iAxis*3];
64         } else {
65 //                      r = bbGetInputColour()[0];
66 //                      g = bbGetInputColour()[1]; 
67 //                      b = bbGetInputColour()[2];
68                         r = (rand() % 100) / 100.0;
69                         g = (rand() % 100) / 100.0;
70                         b = (rand() % 100) / 100.0;
71         }
72
73         vtkactor->GetProperty()->SetColor( r,g,b );
74         vtkactor->GetProperty()->SetLineWidth( 0.5 );
75
76         if ( bbGetInputTransform()!=NULL )
77         {
78                 vtkactor->SetUserTransform( bbGetInputTransform() );
79         }
80
81      // Interface Update
82      if  (bbGetInputRenderer()!=NULL )
83      {
84             bbGetInputRenderer()->AddActor( vtkactor );
85      }
86 }
87
88
89 void DrawAxisTree3D::Process()
90 {
91          int iActor,sizeActors = vecVtkActors.size();
92          for (iActor=0 ; iActor<sizeActors; iActor++)
93          {
94                 if (bbGetInputRenderer()!=NULL )
95                 {
96                         bbGetInputRenderer()->RemoveActor( vecVtkActors[iActor] );
97                         vecVtkPolyData[iActor]->Delete();
98                         vecVtkPolyDataMaper[iActor]->Delete();
99                         vecVtkActors[iActor]->Delete();
100                 }
101          }
102      vecVtkPolyData.clear();
103      vecVtkPolyDataMaper.clear();
104          vecVtkActors.clear();
105
106
107         int iGeneral=0;
108         int iAxis,sizeLstAxis=bbGetInputlstIndexs().size();
109         int numPoints;
110         for ( iAxis=0 ; iAxis<sizeLstAxis ; iAxis++)
111         {
112                 numPoints = bbGetInputlstIndexs()[iAxis];
113                 DrawOneAxis(iGeneral,numPoints,iAxis);
114                 iGeneral = iGeneral+numPoints;
115                 
116                 if ((iAxis % 1)==0)
117                 {
118                         printf("EED  DrawAxisTree3D::Process  %d/%d\n", iAxis,sizeLstAxis );
119                 }
120         }
121
122
123         bbSetOutputOutAxis( vecVtkActors[ bbGetInputiAxis() ] );
124
125 }
126
127 void DrawAxisTree3D::bbUserSetDefaultValues()
128
129          bbSetInputiAxis(0);
130      std::vector<double> colour;
131          // 1- red
132      colour.push_back(1.0);
133      colour.push_back(0.0);
134      colour.push_back(0.0);
135          // 2- blue
136      colour.push_back(0.0);
137      colour.push_back(0.0);
138      colour.push_back(1.0);
139          // 3- yellow
140      colour.push_back(1.0);
141      colour.push_back(1.0);
142      colour.push_back(0.0);
143          // 4- green
144      colour.push_back(0.0);
145      colour.push_back(1.0);
146      colour.push_back(0.0);
147          // 5- 
148      colour.push_back(0.0);
149      colour.push_back(1.0);
150      colour.push_back(1.0);
151
152          // 6- 
153      colour.push_back(0.5);
154      colour.push_back(0.5);
155      colour.push_back(0.5);
156
157      bbSetInputColour(colour);
158
159 }
160
161         
162         //-----------------------------------------------------------------     
163         void DrawAxisTree3D::bbUserInitializeProcessing()
164         {
165         }
166         
167         //-----------------------------------------------------------------     
168         void DrawAxisTree3D::bbUserFinalizeProcessing()
169         {
170         }
171         
172         //-----------------------------------------------------------------     
173
174 }
175 // EO namespace bbcreaMaracasVisu
176
177