]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/kernel/PlaneDirectionManager.cxx
0a95f5c7f3e627c36d1686be97b4c19cea15e2a4
[creaMaracasVisu.git] / lib / maracasVisuLib / src / kernel / PlaneDirectionManager.cxx
1
2 #include "PlaneDirectionManager.h"
3
4 /********************************************************************************************
5 ** Start of data viewmanagerData
6 *********************************************************************************************/
7
8 PlaneDirectionManager::PlaneDirectionManager(int radio, double colour[3] , int opacity){        
9         _radio = radio;
10         _colour = colour;
11         _opacity = opacity;
12 }
13
14
15 PlaneDirectionManager::~PlaneDirectionManager(){
16         RemoveAllActorsFromIndex();
17 }
18
19 void PlaneDirectionManager::SetRenderer(vtkRenderer* render){
20     _render = render;
21 }
22 void PlaneDirectionManager::SetVectors( std::vector<double> lstPointsx, std::vector<double> lstPointsy, std::vector<double> lstPointsz){        
23
24         _lstPointsx = lstPointsx;
25         _lstPointsy = lstPointsy;
26         _lstPointsz = lstPointsz;
27 }
28
29 void PlaneDirectionManager::UpdateDirections() throw (std::exception){  
30         UpdateVectors();
31         UpdateActors();
32         AddActors();
33
34 }
35 void PlaneDirectionManager::AddActors(){
36     for(int i = 0; i < _vectdata.size();i++){
37                 _render->AddViewProp (_vectdata[i]->GetActor());                
38         }
39 }
40 void PlaneDirectionManager::RemoveAllActorsFromIndex(int n)throw (std::exception){
41         /*due to incompleate set of points to create the plane
42         */                              
43         if(_render==NULL){
44                 throw std::exception();
45         }
46         for(int i = _vectdata.size()-1; i >= n;i--){
47                 _render->RemoveViewProp(_vectdata[i]->GetActor());
48                 delete _vectdata[i];
49                 _vectdata.pop_back();
50         }       
51 }
52 void PlaneDirectionManager::UpdateVectors()throw (std::exception){
53         PlaneDirectionManagerData* temp;
54         bool deletelast = false;
55         int currentdata = 0;
56         for(int i = 0; i < _lstPointsx.size();i++){
57                 if(i % 3 == 0){ 
58                         if(_vectdata.size()>currentdata){
59                                 temp = _vectdata[currentdata];
60                         }else{
61                                 temp = new PlaneDirectionManagerData(_radio, _colour, _opacity);
62                                 _vectdata.push_back(temp);
63                         }
64                         temp->setPoint0(_lstPointsx[i],_lstPointsy[i],_lstPointsz[i]);
65                         deletelast = true;
66                 }else if(i % 3 == 1){
67             temp->setPoint1(_lstPointsx[i],_lstPointsy[i],_lstPointsz[i]);                      
68                 }else if(i % 3 == 2){
69                         temp->setPoint2(_lstPointsx[i],_lstPointsy[i],_lstPointsz[i]);                                          
70                         currentdata++;
71                         deletelast = false;
72                 }
73         }
74         RemoveAllActorsFromIndex(currentdata);
75 }
76
77 void PlaneDirectionManager::UpdateActors(){
78     for(int i = 0; i < _vectdata.size();i++){
79                 _vectdata[i]->UpdateActor();
80         }
81 }
82
83 void PlaneDirectionManager::addRemoveActor(int index, bool addremove){
84
85         if(index < _vectdata.size()){
86                 if(addremove){
87                         _render->AddViewProp (_vectdata[index]->GetActor());
88                 }else{
89                         _render->RemoveViewProp (_vectdata[index]->GetActor());
90                 }       
91         }       
92 }
93
94 void PlaneDirectionManager::changeColor(int index,double r,double g,double b)
95 {
96     GetPlaneDirectionManagerData(index)->ChangeColour(r,g,b);
97 }
98
99 PlaneDirectionManagerData* PlaneDirectionManager::GetPlaneDirectionManagerData(int id) 
100 {
101         return _vectdata[id];
102 }
103
104 void PlaneDirectionManager::WriteInformation(std::string  filename, double* spc){
105         FILE *ff;       
106         ff = fopen( filename.c_str() , "w+" );
107         if(spc ==NULL){
108                 spc = new double[3];
109                 spc[0] = 1;
110                 spc[1] = 1;
111                 spc[2] = 1;
112         }
113         if (ff!=NULL)
114         {               
115                 for(int i = 0; i < _vectdata.size();i++){
116
117                         double* p0 = _vectdata[i]->getPoint0();
118                         double* p1 = _vectdata[i]->getPoint1();
119                         double* p2 = _vectdata[i]->getPoint2();
120                         double* dir = _vectdata[i]->GetDirection();
121
122                         double p0x = p0[0]/spc[0];
123                         double p0y = p0[1]/spc[1];
124                         double p0z = p0[2]/spc[2];
125
126                         double p1x = p1[0]/spc[0];
127                         double p1y = p1[1]/spc[1];
128                         double p1z = p1[2]/spc[2];
129
130                         double p2x = p2[0]/spc[0];
131                         double p2y = p2[1]/spc[1];
132                         double p2z = p2[2]/spc[2];
133
134                         double dirx = dir[0]/spc[0];
135                         double diry = dir[1]/spc[1];
136                         double dirz = dir[2]/spc[2];
137
138                         fprintf(ff,"Dir%d\n",i);
139             fprintf(ff,"\tP0[%f, %f, %f]\tP1[%f, %f, %f]\tP2[%f, %f, %f]\tDir[%f, %f, %f] \n",
140                                                         p0x,p0y,p0z,    p1x,p1y,p1z,    p2x,p2y,p2z,    dirx,diry,dirz);
141                 }                       
142                 fclose(ff);
143         } else {   // else ff
144                 printf("PlaneDirectionManager::WriteInformation  ...Error... creating file");
145         } //ff  
146 }
147
148 void  PlaneDirectionManager::SetArrowSize(int arrowsize){
149     _radio = arrowsize;
150 }