]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/widgets/manualContour/manualViewPoint.cpp
4a0dedcfc1feb49cb776d0ed02119a905beee28f
[creaMaracasVisu.git] / lib / maracasVisuLib / src / interface / wxWindows / widgets / manualContour / manualViewPoint.cpp
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 #include "manualViewPoint.h"
27
28 // ----------------------------------------------------------------------------
29 manualViewPoint::manualViewPoint(wxVtkBaseView *wxvtkbaseview){
30         _selected                = false;
31         _posibleSelected = false;
32         _pts                     = NULL;
33         _pd                              = NULL;
34         _pointVtkActor   = NULL;
35         _bboxMapper              = NULL;
36         _wxvtkbaseview   = wxvtkbaseview;
37         _spc[0]                  = 1;
38         _spc[1]                  = 1;
39         _spc[2]                  = 1;
40         _widthline               = 1;
41         
42         //Colors
43         _colorNormal_r = 1.0;
44         _colorNormal_g = 0.0;
45         _colorNormal_b = 0.0;
46
47         _colorPosibleSelected_r = 1.0;
48         _colorPosibleSelected_g = 1.0;
49         _colorPosibleSelected_b = 0.0;
50
51 }
52 // ----------------------------------------------------------------------------
53 manualViewPoint::~manualViewPoint(){
54         DeleteVtkObjects();
55 }
56
57
58 // ----------------------------------------------------------------------------
59 manualViewPoint * manualViewPoint :: Clone()
60 {
61         manualViewPoint * clone = new manualViewPoint(_wxvtkbaseview);
62         CopyAttributesTo(clone);
63         return clone;
64 }
65
66 // ---------------------------------------------------------------------------
67
68 void manualViewPoint::CopyAttributesTo( manualViewPoint * cloneObject)
69 {
70         // Fathers object
71         cloneObject->SetPosibleSelected(_posibleSelected);
72         cloneObject->SetSelected(_selected);
73         cloneObject->SetSpacing(_spc);
74         cloneObject->SetWidthLine(_widthline);
75 }
76
77
78 // ----------------------------------------------------------------------------
79 void manualViewPoint::SetWidthLine( double width)
80 {
81         _widthline = width;
82 }
83
84 // ----------------------------------------------------------------------------
85 void manualViewPoint::SetSelected(bool selected){
86         _selected=selected;
87 }
88 // ----------------------------------------------------------------------------
89 void manualViewPoint::SetPosibleSelected(bool posibleSelected){
90         _posibleSelected=posibleSelected;
91 }
92 // ----------------------------------------------------------------------------
93 bool manualViewPoint::GetSelected(){
94         return _selected;
95 }
96 // ----------------------------------------------------------------------------
97 bool manualViewPoint::GetPosibleSelected(){
98         return _posibleSelected;
99 }
100 // ----------------------------------------------------------------------------
101 void manualViewPoint::DeleteVtkObjects(){
102         if (_pointVtkActor      !=NULL)         { _pointVtkActor->Delete(); }
103         if (_bboxMapper         !=NULL)         { _bboxMapper   ->Delete();     }
104         if (_pts                        !=NULL)         { _pts                  ->Delete();     }
105         if (_pd                         !=NULL)         { _pd                   ->Delete();     }
106         _pointVtkActor  =       NULL;
107         _bboxMapper             =       NULL;
108         _pts                    =       NULL;
109         _pd                             =       NULL;
110 }
111
112
113
114 // ----------------------------------------------------------------------------
115 vtkActor* manualViewPoint::CreateVtkPointActor()
116 {
117         DeleteVtkObjects();
118
119         _pts = vtkPoints::New();
120         _pts->SetNumberOfPoints(8);
121
122         _pts->SetPoint(0, -1000 , -1000 , 0 );
123         _pts->SetPoint(1,  1000 , -1000 , 0 );
124         _pts->SetPoint(2,  1000 ,  1000 , 0 );
125         _pts->SetPoint(3, -1000 ,  1000 , 0 );
126         _pts->SetPoint(4, -1000 ,  1000 , 0 );
127         _pts->SetPoint(5, -1000 ,  1000 , 0 );
128         _pts->SetPoint(6, -1000 ,  1000 , 0 );
129         _pts->SetPoint(7, -1000 ,  1000 , 0 );
130         
131         vtkCellArray *lines = vtkCellArray::New();
132         lines->InsertNextCell(17);
133         lines->InsertCellPoint(0);
134         lines->InsertCellPoint(1);
135         lines->InsertCellPoint(2);
136         lines->InsertCellPoint(3);
137         lines->InsertCellPoint(0);
138         lines->InsertCellPoint(4);
139         lines->InsertCellPoint(5);
140         lines->InsertCellPoint(6);
141         lines->InsertCellPoint(7);
142         lines->InsertCellPoint(4);
143         lines->InsertCellPoint(0);
144         lines->InsertCellPoint(3);
145         lines->InsertCellPoint(7);
146         lines->InsertCellPoint(6);
147         lines->InsertCellPoint(2);
148         lines->InsertCellPoint(1);
149         lines->InsertCellPoint(5);
150
151         _pd = vtkPolyData::New();
152         _pd->SetPoints( _pts );
153         _pd->SetLines( lines );
154 //      lines->Delete();  //do not delete lines ??
155
156         _pointVtkActor  =       vtkActor::New();
157     _bboxMapper         =       vtkPolyDataMapper::New();
158
159         _bboxMapper->SetInput(_pd);
160 //      _bboxMapper->ImmediateModeRenderingOn();
161         _pointVtkActor->SetMapper(_bboxMapper);
162 //      _pointVtkActor->GetProperty()->BackfaceCullingOn();
163         UpdateColorActor();
164 //      _pd->ComputeBounds();
165
166         return _pointVtkActor;
167 }
168
169
170 // ----------------------------------------------------------------------------
171 vtkActor* manualViewPoint::GetVtkActor(){
172         return _pointVtkActor;
173 }
174 // ----------------------------------------------------------------------------
175 void manualViewPoint::SetPositionXY(double x, double y,double i_range,double posZ)
176 {
177         double range=i_range;
178
179 //EED 27 sep 2006
180         x        = x * _spc[0];
181         y        = y * _spc[1];
182         posZ = posZ * _spc[2];
183
184         if (_pts!=NULL){
185                 _pts->SetPoint(0, x-range, y+range, posZ-range);
186                 _pts->SetPoint(1, x+range, y+range, posZ-range);
187                 _pts->SetPoint(2, x+range, y-range, posZ-range);
188                 _pts->SetPoint(3, x-range, y-range, posZ-range);
189                 _pts->SetPoint(4, x-range, y+range, posZ+range);
190                 _pts->SetPoint(5, x+range, y+range, posZ+range);
191                 _pts->SetPoint(6, x+range, y-range, posZ+range);
192                 _pts->SetPoint(7, x-range, y-range, posZ+range);
193         }
194 }
195
196
197 // ----------------------------------------------------------------------------
198 void manualViewPoint::UpdateColorActor()
199 {
200         if (_pointVtkActor!=NULL){
201 //EED03
202                 _pointVtkActor->GetProperty()->SetLineWidth( _widthline );
203                 _pointVtkActor->GetProperty()->SetDiffuseColor(_colorNormal_r,_colorNormal_g,_colorNormal_b);
204                 if (_posibleSelected==true){
205                         _pointVtkActor->GetProperty()->SetDiffuseColor(_colorPosibleSelected_r,_colorPosibleSelected_g,_colorPosibleSelected_b);
206                 }
207         }
208 }
209
210 // ----------------------------------------------------------------------------
211 void manualViewPoint::UpdateColorActor(double nR, double nG, double nB)
212 {
213         _colorNormal_r = nR;
214         _colorNormal_g = nG;
215         _colorNormal_b = nB;
216         UpdateColorActor();
217 }
218
219 // ----------------------------------------------------------------------------
220 void manualViewPoint::GetSpacing(double spc[3])
221 {
222         spc[0] = _spc[0];
223         spc[1] = _spc[1];
224         spc[2] = _spc[2];
225 }
226 // ----------------------------------------------------------------------------
227 void manualViewPoint::SetSpacing(double spc[3])
228 {
229         _spc[0] = spc[0];
230         _spc[1] = spc[1];
231         _spc[2] = spc[2];
232 }
233