11#include " VtkContrib/vtkConstrainedPointWidget2.h"
22
33#include < vtkCellPicker.h>
4+ #include < vtkLineSource.h>
5+ #include < vtkPolyDataMapper.h>
46#include < vtkRenderer.h>
7+ #include < vtkRenderWindow.h>
58#include < vtkRenderWindowInteractor.h>
69
710#include < assert.h>
@@ -66,7 +69,7 @@ vtkConstrainedPointHandleRepresentation2* vtkConstrainedPointWidget2::GetConstra
6669void vtkConstrainedPointWidget2::OnChar ( )
6770{
6871 if ((0 != this ->Interactor ) && (0 != GetConstrainedPointRepresentation ( )))
69- {
72+ {
7073 switch (this ->Interactor ->GetKeyCode ( ))
7174 {
7275 case ' ' : GetConstrainedPointRepresentation ( )->SetConstraintAxis (-1 ); break ;
@@ -82,18 +85,27 @@ void vtkConstrainedPointWidget2::OnChar ( )
8285} // vtkConstrainedPointWidget2::OnChar
8386
8487
88+ void vtkConstrainedPointWidget2::EndInteraction ( )
89+ {
90+ if (0 != GetConstrainedPointRepresentation ( ))
91+ GetConstrainedPointRepresentation ( )->SetConstraintAxis (-1 );
92+
93+ vtkHandleWidget::EndInteraction ( );
94+ } // vtkConstrainedPointWidget2::EndInteraction
95+
96+
8597// =============================================================================
8698// LA CLASSE vtkConstrainedPointHandleRepresentation2
8799// =============================================================================
88100
89101vtkConstrainedPointHandleRepresentation2::vtkConstrainedPointHandleRepresentation2 ( )
90- : vtkSphereHandleRepresentation ( )
102+ : vtkSphereHandleRepresentation ( ), _displayConstraintAxis ( false ), _constraintAxisActor ( 0 )
91103{
92104} // vtkConstrainedPointHandleRepresentation2::vtkConstrainedPointHandleRepresentation2
93105
94106
95107vtkConstrainedPointHandleRepresentation2::vtkConstrainedPointHandleRepresentation2 (const vtkConstrainedPointHandleRepresentation2&)
96- : vtkSphereHandleRepresentation ( )
108+ : vtkSphereHandleRepresentation ( ), _displayConstraintAxis ( false ), _constraintAxisActor ( 0 )
97109{
98110 assert (0 && " vtkConstrainedPointHandleRepresentation2 copy constructor is not allowed." );
99111} // vtkConstrainedPointHandleRepresentation2::vtkConstrainedPointHandleRepresentation2
@@ -108,6 +120,7 @@ vtkConstrainedPointHandleRepresentation2& vtkConstrainedPointHandleRepresentatio
108120
109121vtkConstrainedPointHandleRepresentation2::~vtkConstrainedPointHandleRepresentation2 ( )
110122{
123+
111124} // vtkConstrainedPointHandleRepresentation2::~vtkConstrainedPointHandleRepresentation2
112125
113126
@@ -159,6 +172,10 @@ void vtkConstrainedPointHandleRepresentation2::WidgetInteraction (double eventPo
159172
160173void vtkConstrainedPointHandleRepresentation2::SetConstraintAxis (int axis)
161174{
175+ const bool displayConstraintAxis = _displayConstraintAxis;
176+ if ((0 != GetConstrained ( )) && (axis != this ->ConstraintAxis ))
177+ DisplayConstraintAxis (false );
178+
162179 this ->ConstraintAxis = axis;
163180 switch (axis)
164181 {
@@ -170,6 +187,77 @@ void vtkConstrainedPointHandleRepresentation2::SetConstraintAxis (int axis)
170187 default :
171188 ConstrainedOff ( );
172189 } // switch (axis)
190+
191+ if (true == displayConstraintAxis)
192+ DisplayConstraintAxis (true );
173193} // vtkConstrainedPointHandleRepresentation2::SetConstraintAxis
174194
175195
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