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