1
1
#include " VtkContrib/vtkConstrainedPointWidget2.h"
2
2
3
3
#include < vtkCellPicker.h>
4
+ #include < vtkLineSource.h>
5
+ #include < vtkPolyDataMapper.h>
4
6
#include < vtkRenderer.h>
7
+ #include < vtkRenderWindow.h>
5
8
#include < vtkRenderWindowInteractor.h>
6
9
7
10
#include < assert.h>
@@ -66,7 +69,7 @@ vtkConstrainedPointHandleRepresentation2* vtkConstrainedPointWidget2::GetConstra
66
69
void vtkConstrainedPointWidget2::OnChar ( )
67
70
{
68
71
if ((0 != this ->Interactor ) && (0 != GetConstrainedPointRepresentation ( )))
69
- {
72
+ {
70
73
switch (this ->Interactor ->GetKeyCode ( ))
71
74
{
72
75
case ' ' : GetConstrainedPointRepresentation ( )->SetConstraintAxis (-1 ); break ;
@@ -82,18 +85,27 @@ void vtkConstrainedPointWidget2::OnChar ( )
82
85
} // vtkConstrainedPointWidget2::OnChar
83
86
84
87
88
+ void vtkConstrainedPointWidget2::EndInteraction ( )
89
+ {
90
+ if (0 != GetConstrainedPointRepresentation ( ))
91
+ GetConstrainedPointRepresentation ( )->SetConstraintAxis (-1 );
92
+
93
+ vtkHandleWidget::EndInteraction ( );
94
+ } // vtkConstrainedPointWidget2::EndInteraction
95
+
96
+
85
97
// =============================================================================
86
98
// LA CLASSE vtkConstrainedPointHandleRepresentation2
87
99
// =============================================================================
88
100
89
101
vtkConstrainedPointHandleRepresentation2::vtkConstrainedPointHandleRepresentation2 ( )
90
- : vtkSphereHandleRepresentation ( )
102
+ : vtkSphereHandleRepresentation ( ), _displayConstraintAxis ( false ), _constraintAxisActor ( 0 )
91
103
{
92
104
} // vtkConstrainedPointHandleRepresentation2::vtkConstrainedPointHandleRepresentation2
93
105
94
106
95
107
vtkConstrainedPointHandleRepresentation2::vtkConstrainedPointHandleRepresentation2 (const vtkConstrainedPointHandleRepresentation2&)
96
- : vtkSphereHandleRepresentation ( )
108
+ : vtkSphereHandleRepresentation ( ), _displayConstraintAxis ( false ), _constraintAxisActor ( 0 )
97
109
{
98
110
assert (0 && " vtkConstrainedPointHandleRepresentation2 copy constructor is not allowed." );
99
111
} // vtkConstrainedPointHandleRepresentation2::vtkConstrainedPointHandleRepresentation2
@@ -108,6 +120,7 @@ vtkConstrainedPointHandleRepresentation2& vtkConstrainedPointHandleRepresentatio
108
120
109
121
vtkConstrainedPointHandleRepresentation2::~vtkConstrainedPointHandleRepresentation2 ( )
110
122
{
123
+
111
124
} // vtkConstrainedPointHandleRepresentation2::~vtkConstrainedPointHandleRepresentation2
112
125
113
126
@@ -159,6 +172,10 @@ void vtkConstrainedPointHandleRepresentation2::WidgetInteraction (double eventPo
159
172
160
173
void vtkConstrainedPointHandleRepresentation2::SetConstraintAxis (int axis)
161
174
{
175
+ const bool displayConstraintAxis = _displayConstraintAxis;
176
+ if ((0 != GetConstrained ( )) && (axis != this ->ConstraintAxis ))
177
+ DisplayConstraintAxis (false );
178
+
162
179
this ->ConstraintAxis = axis;
163
180
switch (axis)
164
181
{
@@ -170,6 +187,77 @@ void vtkConstrainedPointHandleRepresentation2::SetConstraintAxis (int axis)
170
187
default :
171
188
ConstrainedOff ( );
172
189
} // switch (axis)
190
+
191
+ if (true == displayConstraintAxis)
192
+ DisplayConstraintAxis (true );
173
193
} // vtkConstrainedPointHandleRepresentation2::SetConstraintAxis
174
194
175
195
196
+ void vtkConstrainedPointHandleRepresentation2::DisplayConstraintAxis (bool onOff)
197
+ {
198
+ if ((true == onOff) && (0 != _constraintAxisActor))
199
+ return ;
200
+ _displayConstraintAxis = onOff;
201
+
202
+ if ((true == onOff) && (0 <= this ->ConstraintAxis ) && (2 >= this ->ConstraintAxis ))
203
+ {
204
+ // Le point courrant :
205
+ double pos [3 ] = { 0 ., 0 ., 0 . };
206
+ GetWorldPosition (pos);
207
+
208
+ // L'univers :
209
+ double bounds [6 ] = { DBL_MAX, -DBL_MAX, DBL_MAX, -DBL_MAX, DBL_MAX, -DBL_MAX };
210
+ double dx = 0 ., dy = 0 ., dz = 0 .;
211
+ if (0 != this ->Renderer )
212
+ {
213
+ this ->Renderer ->ComputeVisiblePropBounds (bounds);
214
+ dx = bounds [1 ] - bounds [0 ];
215
+ dy = bounds [3 ] - bounds [2 ];
216
+ dz = bounds [5 ] - bounds [4 ];
217
+ } // if (0 != this->Renderer)
218
+
219
+ vtkLineSource* line = vtkLineSource::New ( );
220
+ vtkPoints* points = vtkPoints::New ( );
221
+ points->Initialize ( );
222
+ switch (this ->ConstraintAxis )
223
+ {
224
+ case 0 :
225
+ line->SetPoint1 (bounds [0 ] - dx, pos [1 ], pos [2 ]);
226
+ line->SetPoint2 (bounds [1 ] + dx, pos [1 ], pos [2 ]);
227
+ break ;
228
+ case 1 :
229
+ line->SetPoint1 (pos [0 ], bounds [2 ] - dy, pos [2 ]);
230
+ line->SetPoint2 (pos [0 ], bounds [3 ] + dy, pos [2 ]);
231
+ break ;
232
+ case 2 :
233
+ line->SetPoint1 (pos [0 ], pos [1 ], bounds [4 ] - dz);
234
+ line->SetPoint2 (pos [0 ], pos [1 ], bounds [5 ] + dz);
235
+ break ;
236
+ } // switch (this->ConstraintAxis)
237
+ vtkPolyDataMapper* mapper = vtkPolyDataMapper::New ( );
238
+ mapper->SetInputConnection (line->GetOutputPort ( ));
239
+ mapper->ScalarVisibilityOff ( );
240
+ assert (0 == _constraintAxisActor);
241
+ _constraintAxisActor = vtkActor::New ( );
242
+ _constraintAxisActor->SetProperty (this ->GetSelectedProperty ( )); // => couleur de la sphère lors des interactions
243
+ _constraintAxisActor->SetMapper (mapper);
244
+ if (0 != this ->Renderer )
245
+ {
246
+ this ->Renderer ->AddActor (_constraintAxisActor);
247
+ if (0 != this ->Renderer ->GetRenderWindow ( ))
248
+ this ->Renderer ->GetRenderWindow ( )->Render ( );
249
+ }
250
+ line->Delete ( );
251
+ mapper->Delete ( );
252
+ } // if ((true == onOff) && (0 <= this->ConstraintAxis) && (2 >= this->ConstraintAxis))
253
+ else
254
+ {
255
+ if (0 != _constraintAxisActor)
256
+ {
257
+ if (0 != this ->Renderer )
258
+ this ->Renderer ->RemoveActor (_constraintAxisActor);
259
+ _constraintAxisActor->Delete ( );
260
+ } // if (0 != _constraintAxisActor)
261
+ _constraintAxisActor = 0 ;
262
+ } // else if ((true == onOff) && (0 <= this->ConstraintAxis) && (2 >= this->ConstraintAxis))
263
+ } // vtkConstrainedPointHandleRepresentation2::DisplayConstraintAxis
0 commit comments