]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/kernel/PlaneDirectionManagerData.cxx
#3109 creaMaracasVisu Bug New Normal - branch vtk7itk4 compilation with vtk7
[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
42 //EED 2017-01-01 Migration VTK7
43 #if VTK_MAJOR_VERSION <= 5
44         _arrowMapper->SetInput( _vtkarrow->GetOutput() );       
45 #else
46         _arrowMapper->SetInputData( _vtkarrow->GetOutput() );   
47 #endif
48
49         _arrowActor->SetMapper(_arrowMapper);   
50
51         _radio                  = radio;
52         _colour                 = colour;
53         _opacity                = opacity;
54
55         p0                              = new double[3];
56         p0[0]                   = 0;
57         p0[1]                   = 0;
58         p0[2]                   = 0;
59         p1                              = new double[3];
60         p1[0]                   = 0;
61         p1[1]                   = 0;
62         p1[2]                   = 0;
63         p2                              = new double[3];
64         p2[0]                   = 1;
65         p2[1]                   = 1;
66         p2[2]                   = 1;
67         _dir                    = new double[3];
68         _dir[0]                 = 0;
69         _dir[1]                 = 0;
70         _dir[2]                 = 0;
71 }
72
73
74 PlaneDirectionManagerData::~PlaneDirectionManagerData(){
75
76         _vtkarrow->Delete();
77         _arrowMapper->Delete();
78         _arrowActor->Delete();
79         delete p0;
80         delete p1;
81         delete p2;
82         delete _dir;
83 }
84
85 vtkProp3D* PlaneDirectionManagerData::GetActor(){       
86         return _arrowActor;
87 }
88
89 void PlaneDirectionManagerData::UpdateActor(){  
90
91         _arrowActor->GetProperty()->SetColor( _colour[0] , _colour[1] , _colour[2] );
92         _arrowActor->GetProperty()->SetOpacity( _opacity );
93         
94         
95         double* vect1= getNormal(makeVector(p0, p1));
96         double* vect2= getNormal(makeVector(p0, p2));   
97         _dir = getNormal(getCrossProduct(vect1, vect2));
98         double *newvectnorm = getNormal(getCrossProduct(_dir, vect2));
99         double *midp = GetMidPoint();
100
101         vtkMatrix4x4* _matrix = vtkMatrix4x4::New();  
102         _matrix->Identity();    
103         _matrix->SetElement(0,0,_dir[0]*_radio);
104         _matrix->SetElement(1,0,_dir[1]*_radio);
105         _matrix->SetElement(2,0,_dir[2]*_radio);
106         _matrix->SetElement(0,1,vect2[0]*_radio);
107         _matrix->SetElement(1,1,vect2[1]*_radio);
108         _matrix->SetElement(2,1,vect2[2]*_radio);
109         _matrix->SetElement(0,2,newvectnorm[0]*_radio);
110         _matrix->SetElement(1,2,newvectnorm[1]*_radio);
111         _matrix->SetElement(2,2,newvectnorm[2]*_radio);         
112         _matrix->SetElement(0,3,midp[0]);
113         _matrix->SetElement(1,3,midp[1]);
114         _matrix->SetElement(2,3,midp[2]);
115         _arrowActor->SetUserMatrix(_matrix);    
116
117 }
118
119 void PlaneDirectionManagerData::ChangeColour(double r,double g,double b){
120         _colour[0] = r;
121         _colour[1] = g;
122         _colour[2] = b;
123         if(_arrowActor!=NULL){
124                 _arrowActor->GetProperty()->SetColor( r,g,b );
125         }       
126 }
127
128 double* PlaneDirectionManagerData::GetMidPoint(){
129         if(p0 != NULL && p1 != NULL && p2 != NULL){
130                 double* ret = new double[3];
131                 ret[0] = (p0[0] + p1[0] +p2[0])/3;
132                 ret[1] = (p0[1] + p1[1] +p2[1])/3;
133                 ret[2] = (p0[2] + p1[2] +p2[2])/3;
134                 return ret;
135         }
136         return NULL;
137 }