]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/kernel/PlaneDirectionManagerData.cxx
Support #1768 CREATIS Licence insertion
[creaMaracasVisu.git] / lib / maracasVisuLib / src / kernel / PlaneDirectionManagerData.cxx
1 /*# ---------------------------------------------------------------------
2 #
3 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
4 #                        pour la Sant�)
5 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
6 # Previous Authors : Laurent Guigues, Jean-Pierre Roux
7 # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
8 #
9 #  This software is governed by the CeCILL-B license under French law and
10 #  abiding by the rules of distribution of free software. You can  use,
11 #  modify and/ or redistribute the software under the terms of the CeCILL-B
12 #  license as circulated by CEA, CNRS and INRIA at the following URL
13 #  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
14 #  or in the file LICENSE.txt.
15 #
16 #  As a counterpart to the access to the source code and  rights to copy,
17 #  modify and redistribute granted by the license, users are provided only
18 #  with a limited warranty  and the software's author,  the holder of the
19 #  economic rights,  and the successive licensors  have only  limited
20 #  liability.
21 #
22 #  The fact that you are presently reading this means that you have had
23 #  knowledge of the CeCILL-B license and that you accept its terms.
24 # ------------------------------------------------------------------------ */
25
26
27 #include "PlaneDirectionManagerData.h"
28
29 /********************************************************************************************
30 ** Start of data viewmanagerData
31 *********************************************************************************************/
32
33 PlaneDirectionManagerData::PlaneDirectionManagerData(int radio, double colour[3], int opacity)
34 :PlanesOperations(){    
35         _vtkarrow               = vtkArrowSource::New();        
36         _arrowMapper    = vtkPolyDataMapper::New();
37         _arrowActor     = vtkActor::New();
38
39         _vtkarrow->SetTipResolution(30);
40         _vtkarrow->SetShaftResolution( 30  );   
41         _arrowMapper->SetInput( _vtkarrow->GetOutput() );       
42         _arrowActor->SetMapper(_arrowMapper);   
43
44         _radio = radio;
45         _colour = colour;
46         _opacity = opacity;
47
48         p0 = new double[3];
49         p0[0] = 0;
50         p0[1] = 0;
51         p0[2] = 0;
52         p1 = new double[3];
53         p1[0] = 0;
54         p1[1] = 0;
55         p1[2] = 0;
56         p2 = new double[3];
57         p2[0] = 1;
58         p2[1] = 1;
59         p2[2] = 1;
60         _dir = new double[3];
61         _dir[0] = 0;
62         _dir[1] = 0;
63         _dir[2] = 0;
64 }
65
66
67 PlaneDirectionManagerData::~PlaneDirectionManagerData(){
68
69         _vtkarrow->Delete();
70         _arrowMapper->Delete();
71         _arrowActor->Delete();
72         delete p0;
73         delete p1;
74         delete p2;
75         delete _dir;
76 }
77
78 vtkProp3D* PlaneDirectionManagerData::GetActor(){       
79         return _arrowActor;
80 }
81
82 void PlaneDirectionManagerData::UpdateActor(){  
83
84         _arrowActor->GetProperty()->SetColor( _colour[0] , _colour[1] , _colour[2] );
85         _arrowActor->GetProperty()->SetOpacity( _opacity );
86         
87         
88         double* vect1= getNormal(makeVector(p0, p1));
89         double* vect2= getNormal(makeVector(p0, p2));   
90         _dir = getNormal(getCrossProduct(vect1, vect2));
91         double *newvectnorm = getNormal(getCrossProduct(_dir, vect2));
92         double *midp = GetMidPoint();
93
94         vtkMatrix4x4* _matrix = vtkMatrix4x4::New();  
95         _matrix->Identity();    
96         _matrix->SetElement(0,0,_dir[0]*_radio);
97         _matrix->SetElement(1,0,_dir[1]*_radio);
98         _matrix->SetElement(2,0,_dir[2]*_radio);
99         _matrix->SetElement(0,1,vect2[0]*_radio);
100         _matrix->SetElement(1,1,vect2[1]*_radio);
101         _matrix->SetElement(2,1,vect2[2]*_radio);
102         _matrix->SetElement(0,2,newvectnorm[0]*_radio);
103         _matrix->SetElement(1,2,newvectnorm[1]*_radio);
104         _matrix->SetElement(2,2,newvectnorm[2]*_radio);         
105         _matrix->SetElement(0,3,midp[0]);
106         _matrix->SetElement(1,3,midp[1]);
107         _matrix->SetElement(2,3,midp[2]);
108         _arrowActor->SetUserMatrix(_matrix);    
109
110 }
111
112 void PlaneDirectionManagerData::ChangeColour(double r,double g,double b){
113         _colour[0] = r;
114         _colour[1] = g;
115         _colour[2] = b;
116         if(_arrowActor!=NULL){
117                 _arrowActor->GetProperty()->SetColor( r,g,b );
118         }       
119 }
120
121 double* PlaneDirectionManagerData::GetMidPoint(){
122         if(p0 != NULL && p1 != NULL && p2 != NULL){
123                 double* ret = new double[3];
124                 ret[0] = (p0[0] + p1[0] +p2[0])/3;
125                 ret[1] = (p0[1] + p1[1] +p2[1])/3;
126                 ret[2] = (p0[2] + p1[2] +p2[2])/3;
127                 return ret;
128         }
129         return NULL;
130 }