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