]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/widgets/manualContour/manualViewPoint.cpp
#3012 creaMaracasVisu Bug New Normal - Update Image in ViewerNV #3065 creaMara...
[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 //EED
123 //      _pts->SetPoint(0, -1000 , -1000 , 0 );
124 //      _pts->SetPoint(1,  1000 , -1000 , 0 );
125 //      _pts->SetPoint(2,  1000 ,  1000 , 0 );
126 //      _pts->SetPoint(3, -1000 ,  1000 , 0 );
127 //      _pts->SetPoint(4, -1000 ,  1000 , 0 );
128 //      _pts->SetPoint(5, -1000 ,  1000 , 0 );
129 //      _pts->SetPoint(6, -1000 ,  1000 , 0 );
130 //      _pts->SetPoint(7, -1000 ,  1000 , 0 );
131         
132         vtkCellArray *lines = vtkCellArray::New();
133         lines->InsertNextCell(17);
134         lines->InsertCellPoint(0);
135         lines->InsertCellPoint(1);
136         lines->InsertCellPoint(2);
137         lines->InsertCellPoint(3);
138         lines->InsertCellPoint(0);
139         lines->InsertCellPoint(4);
140         lines->InsertCellPoint(5);
141         lines->InsertCellPoint(6);
142         lines->InsertCellPoint(7);
143         lines->InsertCellPoint(4);
144         lines->InsertCellPoint(0);
145         lines->InsertCellPoint(3);
146         lines->InsertCellPoint(7);
147         lines->InsertCellPoint(6);
148         lines->InsertCellPoint(2);
149         lines->InsertCellPoint(1);
150         lines->InsertCellPoint(5);
151
152         _pd = vtkPolyData::New();
153         _pd->SetPoints( _pts );
154         _pd->SetLines( lines );
155 //      lines->Delete();  //do not delete lines ??
156
157         _pointVtkActor  =       vtkActor::New();
158     _bboxMapper         =       vtkPolyDataMapper::New();
159
160         _bboxMapper->SetInput(_pd);
161 //      _bboxMapper->ImmediateModeRenderingOn();
162         _pointVtkActor->SetMapper(_bboxMapper);
163 //      _pointVtkActor->GetProperty()->BackfaceCullingOn();
164         UpdateColorActor();
165 //      _pd->ComputeBounds();
166
167         return _pointVtkActor;
168 }
169
170
171 // ----------------------------------------------------------------------------
172 vtkActor* manualViewPoint::GetVtkActor(){
173         return _pointVtkActor;
174 }
175 // ----------------------------------------------------------------------------
176 void manualViewPoint::SetPositionXY(double x, double y,double i_range,double posZ)
177 {
178         double range=i_range;
179
180 //EED 27 sep 2006
181         x        = x * _spc[0];
182         y        = y * _spc[1];
183         posZ = posZ * _spc[2];
184
185         if (_pts!=NULL){
186                 _pts->SetPoint(0, x-range, y+range, posZ-range);
187                 _pts->SetPoint(1, x+range, y+range, posZ-range);
188                 _pts->SetPoint(2, x+range, y-range, posZ-range);
189                 _pts->SetPoint(3, x-range, y-range, posZ-range);
190                 _pts->SetPoint(4, x-range, y+range, posZ+range);
191                 _pts->SetPoint(5, x+range, y+range, posZ+range);
192                 _pts->SetPoint(6, x+range, y-range, posZ+range);
193                 _pts->SetPoint(7, x-range, y-range, posZ+range);
194
195 //EED 2017-03-02
196                 _pts->Modified();
197         }
198 }
199
200
201 // ----------------------------------------------------------------------------
202 void manualViewPoint::UpdateColorActor()
203 {
204         if (_pointVtkActor!=NULL){
205 //EED03
206                 _pointVtkActor->GetProperty()->SetLineWidth( _widthline );
207                 _pointVtkActor->GetProperty()->SetDiffuseColor(_colorNormal_r,_colorNormal_g,_colorNormal_b);
208                 if (_posibleSelected==true){
209                         _pointVtkActor->GetProperty()->SetDiffuseColor(_colorPosibleSelected_r,_colorPosibleSelected_g,_colorPosibleSelected_b);
210                 }
211         }
212 }
213
214 // ----------------------------------------------------------------------------
215 void manualViewPoint::UpdateColorActor(double nR, double nG, double nB)
216 {
217         _colorNormal_r = nR;
218         _colorNormal_g = nG;
219         _colorNormal_b = nB;
220         UpdateColorActor();
221 }
222
223 // ----------------------------------------------------------------------------
224 void manualViewPoint::GetSpacing(double spc[3])
225 {
226         spc[0] = _spc[0];
227         spc[1] = _spc[1];
228         spc[2] = _spc[2];
229 }
230 // ----------------------------------------------------------------------------
231 void manualViewPoint::SetSpacing(double spc[3])
232 {
233         _spc[0] = spc[0];
234         _spc[1] = spc[1];
235         _spc[2] = spc[2];
236 }
237