]> Creatis software - creaMaracasVisu.git/blob - bbtk/src/bbmaracasvisuDrawAxisTree3D.cxx
.
[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                         allTopology->InsertCellPoint( i-iGeneral );
48                 } // rof
49                 polydata->SetPoints( allPoints );
50                 polydata->SetLines( allTopology );
51                 allPoints->Delete();
52                 allTopology->Delete();  
53         }
54
55         // color
56         double r,g,b;
57
58         if ( (iAxis*3+1) < (int)(bbGetInputColour().size()) ){
59                         r = bbGetInputColour()[0+iAxis*3];
60                         g = bbGetInputColour()[1+iAxis*3]; 
61                         b = bbGetInputColour()[2+iAxis*3];
62                 } else {
63                         r = bbGetInputColour()[0];
64                         g = bbGetInputColour()[1]; 
65                         b = bbGetInputColour()[2];
66                 }
67
68         vtkactor->GetProperty()->SetColor( 1,0,0 );
69         vtkactor->GetProperty()->SetLineWidth( 3 );
70
71         if ( bbGetInputTransform()!=NULL )
72         {
73                 vtkactor->SetUserTransform( bbGetInputTransform() );
74         }
75
76      // Interface Update
77      if  (bbGetInputRenderer()!=NULL )
78      {
79             bbGetInputRenderer()->AddActor( vtkactor );
80      }
81 }
82
83
84 void DrawAxisTree3D::Process()
85 {
86          int iActor,sizeActors = vecVtkActors.size();
87          for (iActor=0 ; iActor<sizeActors; iActor++)
88          {
89                 if (bbGetInputRenderer()!=NULL )
90                 {
91                         bbGetInputRenderer()->RemoveActor( vecVtkActors[iActor] );
92                         vecVtkPolyData[iActor]->Delete();
93                         vecVtkPolyDataMaper[iActor]->Delete();
94                         vecVtkActors[iActor]->Delete();
95                 }
96          }
97      vecVtkPolyData.clear();
98      vecVtkPolyDataMaper.clear();
99          vecVtkActors.clear();
100
101
102         int iGeneral=0;
103         int iAxis,sizeLstAxis=bbGetInputlstIndexs().size();
104         int numPoints;
105         for ( iAxis=0 ; iAxis<sizeLstAxis ; iAxis++)
106         {
107                 numPoints = bbGetInputlstIndexs()[iAxis];
108                 DrawOneAxis(iGeneral,numPoints,iAxis);
109                 iGeneral = iGeneral+numPoints;
110         }
111
112
113         bbSetOutputOutAxis( vecVtkActors[ bbGetInputiAxis() ] );
114
115 }
116
117 void DrawAxisTree3D::bbUserSetDefaultValues()
118
119          bbSetInputiAxis(0);
120      std::vector<double> colour;
121          // 1- red
122      colour.push_back(1.0);
123      colour.push_back(0.0);
124      colour.push_back(0.0);
125          // 2- blue
126      colour.push_back(0.0);
127      colour.push_back(0.0);
128      colour.push_back(1.0);
129          // 3- yellow
130      colour.push_back(1.0);
131      colour.push_back(1.0);
132      colour.push_back(0.0);
133          // 4- green
134      colour.push_back(0.0);
135      colour.push_back(1.0);
136      colour.push_back(0.0);
137          // 5- 
138      colour.push_back(0.0);
139      colour.push_back(1.0);
140      colour.push_back(1.0);
141
142          // 6- 
143      colour.push_back(0.5);
144      colour.push_back(0.5);
145      colour.push_back(0.5);
146
147      bbSetInputColour(colour);
148
149 }
150
151         
152         //-----------------------------------------------------------------     
153         void DrawAxisTree3D::bbUserInitializeProcessing()
154         {
155         }
156         
157         //-----------------------------------------------------------------     
158         void DrawAxisTree3D::bbUserFinalizeProcessing()
159         {
160         }
161         
162         //-----------------------------------------------------------------     
163
164 }
165 // EO namespace bbcreaMaracasVisu
166
167