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