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