]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/kernel/PlaneDirectionManagerData.cxx
e6f613395b632f5f1c66f7e0f8de9ca1d02061fc
[creaMaracasVisu.git] / lib / maracasVisuLib / src / kernel / PlaneDirectionManagerData.cxx
1
2 #include "PlaneDirectionManagerData.h"
3
4 /********************************************************************************************
5 ** Start of data viewmanagerData
6 *********************************************************************************************/
7
8 PlaneDirectionManagerData::PlaneDirectionManagerData(int radio, double colour[3], int opacity)
9 :PlanesOperations(){    
10         _vtkarrow               = vtkArrowSource::New();        
11         _arrowMapper    = vtkPolyDataMapper::New();
12         _arrowActor     = vtkActor::New();
13
14         _vtkarrow->SetTipResolution(30);
15         _vtkarrow->SetShaftResolution( 30  );   
16         _arrowMapper->SetInput( _vtkarrow->GetOutput() );       
17         _arrowActor->SetMapper(_arrowMapper);   
18
19         _radio = radio;
20         _colour = colour;
21         _opacity = opacity;
22
23         p0 = new double[3];
24         p0[0] = 0;
25         p0[1] = 0;
26         p0[2] = 0;
27         p1 = new double[3];
28         p1[0] = 0;
29         p1[1] = 0;
30         p1[2] = 0;
31         p2 = new double[3];
32         p2[0] = 1;
33         p2[1] = 1;
34         p2[2] = 1;
35         _dir = new double[3];
36         _dir[0] = 0;
37         _dir[1] = 0;
38         _dir[2] = 0;
39 }
40
41
42 PlaneDirectionManagerData::~PlaneDirectionManagerData(){
43
44         _vtkarrow->Delete();
45         _arrowMapper->Delete();
46         _arrowActor->Delete();
47         delete p0;
48         delete p1;
49         delete p2;
50         delete _dir;
51 }
52
53 vtkProp3D* PlaneDirectionManagerData::GetActor(){       
54         return _arrowActor;
55 }
56
57 void PlaneDirectionManagerData::UpdateActor(){  
58
59         _arrowActor->GetProperty()->SetColor( _colour[0] , _colour[1] , _colour[2] );
60         _arrowActor->GetProperty()->SetOpacity( _opacity );
61         
62         
63         double* vect1= getNormal(makeVector(p0, p1));
64         double* vect2= getNormal(makeVector(p0, p2));   
65         _dir = getNormal(getCrossProduct(vect1, vect2));
66         double *newvectnorm = getNormal(getCrossProduct(_dir, vect2));
67         double *midp = GetMidPoint();
68
69         vtkMatrix4x4* _matrix = vtkMatrix4x4::New();  
70         _matrix->Identity();    
71         _matrix->SetElement(0,0,_dir[0]*_radio);
72         _matrix->SetElement(1,0,_dir[1]*_radio);
73         _matrix->SetElement(2,0,_dir[2]*_radio);
74         _matrix->SetElement(0,1,vect2[0]*_radio);
75         _matrix->SetElement(1,1,vect2[1]*_radio);
76         _matrix->SetElement(2,1,vect2[2]*_radio);
77         _matrix->SetElement(0,2,newvectnorm[0]*_radio);
78         _matrix->SetElement(1,2,newvectnorm[1]*_radio);
79         _matrix->SetElement(2,2,newvectnorm[2]*_radio);         
80         _matrix->SetElement(0,3,midp[0]);
81         _matrix->SetElement(1,3,midp[1]);
82         _matrix->SetElement(2,3,midp[2]);
83         _arrowActor->SetUserMatrix(_matrix);    
84
85 }
86
87 void PlaneDirectionManagerData::ChangeColour(double r,double g,double b){
88         _colour[0] = r;
89         _colour[1] = g;
90         _colour[2] = b;
91         if(_arrowActor!=NULL){
92                 _arrowActor->GetProperty()->SetColor( r,g,b );
93         }       
94 }
95
96 double* PlaneDirectionManagerData::GetMidPoint(){
97         if(p0 != NULL && p1 != NULL && p2 != NULL){
98                 double* ret = new double[3];
99                 ret[0] = (p0[0] + p1[0] +p2[0])/3;
100                 ret[1] = (p0[1] + p1[1] +p2[1])/3;
101                 ret[2] = (p0[2] + p1[2] +p2[2])/3;
102                 return ret;
103         }
104         return NULL;
105 }