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