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