Skip to content

Commit 1ed1e7d

Browse files
author
Charles PIGNEROL
committed
Version 5.5.0. Class vtkConstrainedPointWidget2 and associated test point_widget2.
1 parent d1a6568 commit 1ed1e7d

File tree

6 files changed

+505
-4
lines changed

6 files changed

+505
-4
lines changed

cmake/version.cmake

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
#
44

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

1010

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
/*
2+
* Widget de saisie d'un point dans l'espace.
3+
* @author Charles PIGNEROL, CEA/DAM/DSSI
4+
* @date 24/06/2024
5+
*/
6+
7+
#ifndef VTK_CONSTRAINED_POINT_WIDGET_2_H
8+
#define VTK_CONSTRAINED_POINT_WIDGET_2_H
9+
10+
#include <vtkHandleWidget.h>
11+
#include <vtkSphereHandleRepresentation.h>
12+
13+
class vtkConstrainedPointHandleRepresentation2;
14+
15+
16+
/**
17+
* <P>Un widget pour saisir interactivement un point dont déplacement peut être contraint le long d'un axe euclidien.</P>
18+
* <P>Par défaut le point, matérialisé par une sphère, est déplacé dans le plan de l'écran, mais on peut contraindre le déplacement
19+
* le long de l'axe des abscisses, ordonnées ou élévations en pressant respectivement et simultanément la touche 'x', 'y' ou 'z'
20+
* (insensibilité à la casse). Une pression sur la touche 'espace' provoque un retour au déplacement dans le plan.
21+
*
22+
* <P>tests/point_widget2.cpp est un exemple d'utilisation avec callback permettant de connaître à tout moment la nouvelle position du point.</P>
23+
*/
24+
class vtkConstrainedPointWidget2 : public vtkHandleWidget
25+
{
26+
public :
27+
28+
vtkTypeMacro(vtkConstrainedPointWidget2,vtkHandleWidget)
29+
30+
31+
/**
32+
* Créé une représentation de type vtkConstrainedPointHandleRepresentation2.
33+
*/
34+
virtual void CreateDefaultRepresentation ( );
35+
36+
/**
37+
* Instanciation de la classe.
38+
*/
39+
static vtkConstrainedPointWidget2* New ( );
40+
41+
/**
42+
* @return La représentation de l'instance.
43+
*/
44+
vtkConstrainedPointHandleRepresentation2* GetConstrainedPointRepresentation ( );
45+
46+
/**
47+
* Modifie l'axe de contrainte de déplacement.
48+
*/
49+
virtual void OnChar ( );
50+
51+
52+
private :
53+
54+
/**
55+
* Constructeur. S'associe une instance de vtkConstrainedPointHandleRepresentation2 pour représenter le point et effectuer son positionnement.
56+
*/
57+
vtkConstrainedPointWidget2 ( );
58+
59+
/**
60+
* Destructeur. RAS.
61+
*/
62+
virtual ~vtkConstrainedPointWidget2 ( );
63+
64+
/**
65+
* Constructeur et opérateur = : interdits.
66+
*/
67+
vtkConstrainedPointWidget2 (const vtkConstrainedPointWidget2&);
68+
vtkConstrainedPointWidget2& operator = (const vtkConstrainedPointWidget2&);
69+
}; // class vtkConstrainedPointWidget2
70+
71+
72+
/**
73+
* <P>Classe de représentation/positionnement d'un point sur une grille non structurée.</P>
74+
* <P>Sa méthode (héritée) <I>GetWorldPosition (double [3])</I> permet de récupére les coordonnées courantes du point saisi.</P>
75+
*/
76+
class vtkConstrainedPointHandleRepresentation2 : public vtkSphereHandleRepresentation
77+
{
78+
public :
79+
80+
vtkTypeMacro(vtkConstrainedPointHandleRepresentation2,vtkSphereHandleRepresentation)
81+
82+
83+
public :
84+
85+
/**
86+
* Instanciation de la classe.
87+
*/
88+
static vtkConstrainedPointHandleRepresentation2* New ( );
89+
90+
/**
91+
* Versions simplifiées de la gestion interactive de la saisie.
92+
*/
93+
virtual void WidgetInteraction (double eventPos [2]);
94+
95+
/**
96+
* @param Nouvel axe de contrainte de déplacement (0 -> X, 1 -> Y, 2 -> Z, autre => déplacement dans le plan de l'écran).
97+
*/
98+
virtual void SetConstraintAxis (int axis);
99+
100+
101+
private :
102+
103+
/**
104+
* Constructeur : RAS.
105+
*/
106+
vtkConstrainedPointHandleRepresentation2 ( );
107+
108+
/**
109+
* Destructeur. RAS.
110+
*/
111+
virtual ~vtkConstrainedPointHandleRepresentation2 ( );
112+
113+
/**
114+
* Constructeur de copie, opérateur = : interdits.
115+
*/
116+
vtkConstrainedPointHandleRepresentation2 (const vtkConstrainedPointHandleRepresentation2&);
117+
vtkConstrainedPointHandleRepresentation2& operator = (const vtkConstrainedPointHandleRepresentation2&);
118+
}; // class vtkConstrainedPointHandleRepresentation2
119+
120+
121+
#endif // VTK_CONSTRAINED_POINT_WIDGET_2_H
Lines changed: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
1+
#include "VtkContrib/vtkConstrainedPointWidget2.h"
2+
3+
#include <vtkCellPicker.h>
4+
#include <vtkRenderer.h>
5+
#include <vtkRenderWindowInteractor.h>
6+
7+
#include <assert.h>
8+
#include <iostream>
9+
using namespace std;
10+
11+
12+
// =============================================================================
13+
// LA CLASSE vtkConstrainedPointWidget2
14+
// =============================================================================
15+
16+
vtkConstrainedPointWidget2::vtkConstrainedPointWidget2 ( )
17+
: vtkHandleWidget ( )
18+
{
19+
} // vtkConstrainedPointWidget2::vtkConstrainedPointWidget2
20+
21+
22+
vtkConstrainedPointWidget2::vtkConstrainedPointWidget2 (const vtkConstrainedPointWidget2&)
23+
: vtkHandleWidget ( )
24+
{
25+
assert (0 && "vtkConstrainedPointWidget2 copy constructor is not allowed.");
26+
} // vtkConstrainedPointWidget2::vtkConstrainedPointWidget2
27+
28+
29+
vtkConstrainedPointWidget2& vtkConstrainedPointWidget2::operator = (const vtkConstrainedPointWidget2&)
30+
{
31+
assert (0 && "vtkConstrainedPointWidget2 assignment operator is not allowed.");
32+
return *this;
33+
} // vtkConstrainedPointWidget2::vtkConstrainedPointWidget2
34+
35+
36+
vtkConstrainedPointWidget2::~vtkConstrainedPointWidget2 ( )
37+
{
38+
} // vtkConstrainedPointWidget2::~vtkConstrainedPointWidget2
39+
40+
41+
void vtkConstrainedPointWidget2::CreateDefaultRepresentation ( )
42+
{
43+
if (0 == WidgetRep)
44+
{
45+
vtkConstrainedPointHandleRepresentation2* rep = vtkConstrainedPointHandleRepresentation2::New ( );
46+
WidgetRep = rep;
47+
rep->SetTolerance (1);
48+
rep->BuildRepresentation ( );
49+
SetWidgetRepresentation (rep);
50+
} // if (0 == WidgetRep)
51+
} // vtkConstrainedPointWidget2::CreateDefaultRepresentation
52+
53+
54+
vtkConstrainedPointWidget2* vtkConstrainedPointWidget2::New ( )
55+
{
56+
return new vtkConstrainedPointWidget2 ( );
57+
} // vtkConstrainedPointWidget2::New
58+
59+
60+
vtkConstrainedPointHandleRepresentation2* vtkConstrainedPointWidget2::GetConstrainedPointRepresentation ( )
61+
{
62+
return dynamic_cast<vtkConstrainedPointHandleRepresentation2*>(GetRepresentation ( ));
63+
} // vtkConstrainedPointWidget2::GetConstrainedPointRepresentation
64+
65+
66+
void vtkConstrainedPointWidget2::OnChar ( )
67+
{
68+
if ((0 != this->Interactor) && (0 != GetConstrainedPointRepresentation ( )))
69+
{
70+
switch (this->Interactor->GetKeyCode ( ))
71+
{
72+
case ' ' : GetConstrainedPointRepresentation ( )->SetConstraintAxis (-1); break;
73+
case 'x' :
74+
case 'X' : GetConstrainedPointRepresentation ( )->SetConstraintAxis (0); break;
75+
case 'y' :
76+
case 'Y' : GetConstrainedPointRepresentation ( )->SetConstraintAxis (1); break;
77+
case 'z' :
78+
case 'Z' : GetConstrainedPointRepresentation ( )->SetConstraintAxis (2); break;
79+
default : vtkHandleWidget::OnChar ( );
80+
} // switch (this->Interactor->GetKeyCode ( ))
81+
} // if ((0 != this->Interactor) && (0 != GetConstrainedPointRepresentation ( )))
82+
} // vtkConstrainedPointWidget2::OnChar
83+
84+
85+
// =============================================================================
86+
// LA CLASSE vtkConstrainedPointHandleRepresentation2
87+
// =============================================================================
88+
89+
vtkConstrainedPointHandleRepresentation2::vtkConstrainedPointHandleRepresentation2 ( )
90+
: vtkSphereHandleRepresentation ( )
91+
{
92+
} // vtkConstrainedPointHandleRepresentation2::vtkConstrainedPointHandleRepresentation2
93+
94+
95+
vtkConstrainedPointHandleRepresentation2::vtkConstrainedPointHandleRepresentation2 (const vtkConstrainedPointHandleRepresentation2&)
96+
: vtkSphereHandleRepresentation ( )
97+
{
98+
assert (0 && "vtkConstrainedPointHandleRepresentation2 copy constructor is not allowed.");
99+
} // vtkConstrainedPointHandleRepresentation2::vtkConstrainedPointHandleRepresentation2
100+
101+
102+
vtkConstrainedPointHandleRepresentation2& vtkConstrainedPointHandleRepresentation2::operator = (const vtkConstrainedPointHandleRepresentation2&)
103+
{
104+
assert (0 && "vtkConstrainedPointHandleRepresentation2 assignment operator is not allowed.");
105+
return *this;
106+
} // vtkConstrainedPointHandleRepresentation2::vtkConstrainedPointHandleRepresentation2
107+
108+
109+
vtkConstrainedPointHandleRepresentation2::~vtkConstrainedPointHandleRepresentation2 ( )
110+
{
111+
} // vtkConstrainedPointHandleRepresentation2::~vtkConstrainedPointHandleRepresentation2
112+
113+
114+
vtkConstrainedPointHandleRepresentation2* vtkConstrainedPointHandleRepresentation2::New ( )
115+
{
116+
return new vtkConstrainedPointHandleRepresentation2 ( );
117+
} // vtkConstrainedPointHandleRepresentation2::New
118+
119+
120+
void vtkConstrainedPointHandleRepresentation2::WidgetInteraction (double eventPos [2])
121+
{ // Code vtkSphereHandleRepresentation::WidgetInteraction VTK 7.1.1 légèrement retouché
122+
// Do different things depending on state Calculations everybody does
123+
double focalPoint[4], pickPoint[4], prevPickPoint[4], startPickPoint[4], z;
124+
125+
// Compute the two points defining the motion vector
126+
vtkInteractorObserver::ComputeWorldToDisplay (this->Renderer, this->LastPickPosition[0], this->LastPickPosition[1], this->LastPickPosition[2], focalPoint);
127+
z = focalPoint[2];
128+
vtkInteractorObserver::ComputeDisplayToWorld (this->Renderer, this->LastEventPosition[0],this->LastEventPosition[1], z, prevPickPoint);
129+
vtkInteractorObserver::ComputeDisplayToWorld (this->Renderer, eventPos[0], eventPos[1], z, pickPoint);
130+
131+
// Process the motion
132+
if (this->InteractionState == vtkHandleRepresentation::Selecting || this->InteractionState == vtkHandleRepresentation::Translating)
133+
{
134+
if (!this->WaitingForMotion || this->WaitCount++ > 3)
135+
{
136+
this->ConstraintAxis = this->DetermineConstraintAxis (this->ConstraintAxis, pickPoint);
137+
if (this->InteractionState == vtkHandleRepresentation::Selecting && !this->TranslationMode)
138+
{
139+
this->MoveFocus(prevPickPoint, pickPoint);
140+
}
141+
else
142+
{
143+
this->Translate(prevPickPoint, pickPoint);
144+
}
145+
}
146+
}
147+
else if (this->InteractionState == vtkHandleRepresentation::Scaling)
148+
{
149+
this->Scale (prevPickPoint, pickPoint, eventPos);
150+
}
151+
152+
// Book keeping
153+
this->LastEventPosition[0] = eventPos[0];
154+
this->LastEventPosition[1] = eventPos[1];
155+
156+
this->Modified ( );
157+
} // vtkConstrainedPointHandleRepresentation2::WidgetInteraction
158+
159+
160+
void vtkConstrainedPointHandleRepresentation2::SetConstraintAxis (int axis)
161+
{
162+
this->ConstraintAxis = axis;
163+
switch (axis)
164+
{
165+
case 0 : // x
166+
case 1 : // y
167+
case 2 : // z
168+
ConstrainedOn ( );
169+
break;
170+
default :
171+
ConstrainedOff ( );
172+
} // switch (axis)
173+
} // vtkConstrainedPointHandleRepresentation2::SetConstraintAxis
174+
175+

src/tests/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,16 @@ include (${GUIToolkitsVariables_CMAKE_DIR}/common.cmake)
66
include (${GUIToolkitsVariables_CMAKE_DIR}/workarounds.cmake)
77

88
add_executable (point_widget point_widget.cpp)
9+
add_executable (point_widget2 point_widget2.cpp)
910
add_executable (trihedrons trihedrons.cpp)
1011
add_executable (torus torus.cpp)
1112

1213
target_include_directories (point_widget PRIVATE ../VtkContrib/public ${CMAKE_CURRENT_SOURCE_DIR})
1314
target_compile_options (point_widget PRIVATE ${SHARED_CFLAGS}) # Requested by Qt ...
1415
target_link_libraries (point_widget PUBLIC VtkContrib)
16+
target_include_directories (point_widget2 PRIVATE ../VtkContrib/public ${CMAKE_CURRENT_SOURCE_DIR})
17+
target_compile_options (point_widget2 PRIVATE ${SHARED_CFLAGS}) # Requested by Qt ...
18+
target_link_libraries (point_widget2 PUBLIC VtkContrib)
1519
target_include_directories (trihedrons PRIVATE ../VtkContrib/public ${CMAKE_CURRENT_SOURCE_DIR})
1620
target_compile_options (trihedrons PRIVATE ${SHARED_CFLAGS}) # Requested by Qt ...
1721
target_link_libraries (trihedrons PUBLIC VtkContrib)
@@ -21,5 +25,6 @@ target_link_libraries (torus PUBLIC VtkContrib)
2125

2226
# INSTALL_RPATH modifie le rpath pour les libs internes au projet :
2327
set_target_properties (point_widget PROPERTIES INSTALL_RPATH_USE_LINK_PATH 1 INSTALL_RPATH ${CMAKE_PACKAGE_RPATH_DIR})
28+
set_target_properties (point_widget2 PROPERTIES INSTALL_RPATH_USE_LINK_PATH 1 INSTALL_RPATH ${CMAKE_PACKAGE_RPATH_DIR})
2429
set_target_properties (trihedrons PROPERTIES INSTALL_RPATH_USE_LINK_PATH 1 INSTALL_RPATH ${CMAKE_PACKAGE_RPATH_DIR})
2530
set_target_properties (torus PROPERTIES INSTALL_RPATH_USE_LINK_PATH 1 INSTALL_RPATH ${CMAKE_PACKAGE_RPATH_DIR})

0 commit comments

Comments
 (0)