Skip to content

Commit 4894750

Browse files
Merge pull request #5 from LIHPC-Computational-Geometry/pointwidget2
Version 5.6.0. The vtkConstrainedPointWidget2 class displays the poss…
2 parents f499129 + b62e4f1 commit 4894750

File tree

5 files changed

+121
-4
lines changed

5 files changed

+121
-4
lines changed

cmake/version.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#
44

55
set (VTK_CONTRIB_MAJOR_VERSION "5")
6-
set (VTK_CONTRIB_MINOR_VERSION "5")
6+
set (VTK_CONTRIB_MINOR_VERSION "6")
77
set (VTK_CONTRIB_RELEASE_VERSION "0")
88
set (VTK_CONTRIB_VERSION ${VTK_CONTRIB_MAJOR_VERSION}.${VTK_CONTRIB_MINOR_VERSION}.${VTK_CONTRIB_RELEASE_VERSION})
99

src/VtkContrib/public/VtkContrib/vtkConstrainedPointWidget2.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#ifndef VTK_CONSTRAINED_POINT_WIDGET_2_H
88
#define VTK_CONSTRAINED_POINT_WIDGET_2_H
99

10+
#include <vtkActor.h>
1011
#include <vtkHandleWidget.h>
1112
#include <vtkSphereHandleRepresentation.h>
1213

@@ -48,6 +49,14 @@ class vtkConstrainedPointWidget2 : public vtkHandleWidget
4849
*/
4950
virtual void OnChar ( );
5051

52+
53+
protected :
54+
55+
/**
56+
* Masque l'éventuel axe de contrainte affiché.
57+
*/
58+
virtual void EndInteraction ( );
59+
5160

5261
private :
5362

@@ -96,6 +105,13 @@ class vtkConstrainedPointHandleRepresentation2 : public vtkSphereHandleRepresent
96105
* @param Nouvel axe de contrainte de déplacement (0 -> X, 1 -> Y, 2 -> Z, autre => déplacement dans le plan de l'écran).
97106
*/
98107
virtual void SetConstraintAxis (int axis);
108+
109+
/**
110+
* Affiche/Masque une droite représentant l'axe de contrainte.
111+
*/
112+
virtual void DisplayConstraintAxis (bool onOff);
113+
virtual bool DisplayConstraintAxis ( )
114+
{ return _displayConstraintAxis; }
99115

100116

101117
private :
@@ -115,6 +131,12 @@ class vtkConstrainedPointHandleRepresentation2 : public vtkSphereHandleRepresent
115131
*/
116132
vtkConstrainedPointHandleRepresentation2 (const vtkConstrainedPointHandleRepresentation2&);
117133
vtkConstrainedPointHandleRepresentation2& operator = (const vtkConstrainedPointHandleRepresentation2&);
134+
135+
/** Faut-il afficher l'axe de contrainte ? */
136+
bool _displayConstraintAxis;
137+
138+
/** L'éventuel acteur représentant l'axe de contrainte. */
139+
vtkActor* _constraintAxisActor;
118140
}; // class vtkConstrainedPointHandleRepresentation2
119141

120142

src/VtkContrib/vtkConstrainedPointWidget2.cpp

Lines changed: 91 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
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
6669
void 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

89101
vtkConstrainedPointHandleRepresentation2::vtkConstrainedPointHandleRepresentation2 ( )
90-
: vtkSphereHandleRepresentation ( )
102+
: vtkSphereHandleRepresentation ( ), _displayConstraintAxis (false), _constraintAxisActor (0)
91103
{
92104
} // vtkConstrainedPointHandleRepresentation2::vtkConstrainedPointHandleRepresentation2
93105

94106

95107
vtkConstrainedPointHandleRepresentation2::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

109121
vtkConstrainedPointHandleRepresentation2::~vtkConstrainedPointHandleRepresentation2 ( )
110122
{
123+
111124
} // vtkConstrainedPointHandleRepresentation2::~vtkConstrainedPointHandleRepresentation2
112125

113126

@@ -159,6 +172,10 @@ void vtkConstrainedPointHandleRepresentation2::WidgetInteraction (double eventPo
159172

160173
void 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

src/tests/point_widget2.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ int main ( int argc, char *argv[] )
8585
double bounds [6] = { 0., 2., -1., 1., -1., 1. };
8686
vtkSmartPointer<vtkConstrainedPointWidget2> handleWidget = vtkSmartPointer<vtkConstrainedPointWidget2>::New();
8787
handleWidget->GetRepresentation ( );
88+
handleWidget->GetConstrainedPointRepresentation ( )->DisplayConstraintAxis (true);
8889
handleWidget->SetInteractor(iren);
8990
// handleWidget->GetRepresentation ( )->SetPlaceFactor (2.5);
9091
handleWidget->GetRepresentation ( )->SetPlaceFactor (1.);

versions.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
Version 5.6.0 : 05/07/24
2+
===============
3+
4+
La classe vtkConstrainedPointWidget2 permet d'afficher l'�ventuel axe de contrainte utilis�.
5+
6+
17
Version 5.5.0 : 26/06/24
28
===============
39

0 commit comments

Comments
 (0)