Skip to content

Commit aae7112

Browse files
author
Charles PIGNEROL
committed
Version 5.6.1. Area picker test (rubber banding).
1 parent 4894750 commit aae7112

File tree

5 files changed

+136
-22
lines changed

5 files changed

+136
-22
lines changed

cmake/version.cmake

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

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

1010

src/VtkContrib/vtkConstrainedPointWidget2.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,9 @@ void vtkConstrainedPointHandleRepresentation2::WidgetInteraction (double eventPo
146146
{
147147
if (!this->WaitingForMotion || this->WaitCount++ > 3)
148148
{
149+
#ifdef VTK_7
149150
this->ConstraintAxis = this->DetermineConstraintAxis (this->ConstraintAxis, pickPoint);
151+
#endif // VTK_7
150152
if (this->InteractionState == vtkHandleRepresentation::Selecting && !this->TranslationMode)
151153
{
152154
this->MoveFocus(prevPickPoint, pickPoint);

src/tests/CMakeLists.txt

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,15 @@ find_package (GUIToolkitsVariables)
55
include (${GUIToolkitsVariables_CMAKE_DIR}/common.cmake)
66
include (${GUIToolkitsVariables_CMAKE_DIR}/workarounds.cmake)
77

8-
add_executable (point_widget point_widget.cpp)
9-
add_executable (point_widget2 point_widget2.cpp)
10-
add_executable (trihedrons trihedrons.cpp)
11-
add_executable (torus torus.cpp)
8+
set (ALL_EXECUTABLES areapicker point_widget point_widget2 trihedrons torus)
129

13-
target_include_directories (point_widget PRIVATE ../VtkContrib/public ${CMAKE_CURRENT_SOURCE_DIR})
14-
target_compile_options (point_widget PRIVATE ${SHARED_CFLAGS}) # Requested by Qt ...
15-
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)
19-
target_include_directories (trihedrons PRIVATE ../VtkContrib/public ${CMAKE_CURRENT_SOURCE_DIR})
20-
target_compile_options (trihedrons PRIVATE ${SHARED_CFLAGS}) # Requested by Qt ...
21-
target_link_libraries (trihedrons PUBLIC VtkContrib)
22-
target_include_directories (torus PRIVATE ../VtkContrib/public ${CMAKE_CURRENT_SOURCE_DIR})
23-
target_compile_options (torus PRIVATE ${SHARED_CFLAGS}) # Requested by Qt ...
24-
target_link_libraries (torus PUBLIC VtkContrib)
10+
foreach (exe ${ALL_EXECUTABLES})
11+
add_executable (${exe} ${exe}.cpp)
12+
target_include_directories (${exe} PRIVATE ../VtkContrib/public ${CMAKE_CURRENT_SOURCE_DIR})
13+
target_compile_options (${exe} PRIVATE ${SHARED_CFLAGS})
14+
target_link_libraries (${exe} PUBLIC VtkContrib)
15+
# INSTALL_RPATH modifie le rpath pour les libs internes au projet :
16+
set_target_properties (${exe} PROPERTIES INSTALL_RPATH_USE_LINK_PATH 1 INSTALL_RPATH ${CMAKE_PACKAGE_RPATH_DIR})
17+
endforeach (exe)
18+
2519

26-
# INSTALL_RPATH modifie le rpath pour les libs internes au projet :
27-
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})
29-
set_target_properties (trihedrons PROPERTIES INSTALL_RPATH_USE_LINK_PATH 1 INSTALL_RPATH ${CMAKE_PACKAGE_RPATH_DIR})
30-
set_target_properties (torus PROPERTIES INSTALL_RPATH_USE_LINK_PATH 1 INSTALL_RPATH ${CMAKE_PACKAGE_RPATH_DIR})

src/tests/areapicker.cpp

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
#include "VtkContrib/vtkConstrainedPointWidget.h"
2+
3+
#include <vtkActor.h>
4+
#include <vtkAreaPicker.h>
5+
#include <vtkCallbackCommand.h>
6+
#include <vtkCellArray.h>
7+
#include <vtkInteractorStyleRubberBandPick.h>
8+
#include <vtkInteractorStyleTrackball.h>
9+
#include <vtkNamedColors.h>
10+
#include <vtkSmartPointer.h>
11+
#include <vtkPoints.h>
12+
#include <vtkPolyData.h>
13+
#include <vtkPolyDataMapper.h>
14+
#include <vtkProp3DCollection.h>
15+
#include <vtkProperty.h>
16+
#include <vtkRenderer.h>
17+
#include <vtkRenderWindow.h>
18+
#include <vtkRenderWindowInteractor.h>
19+
#include <vtkRenderedAreaPicker.h>
20+
21+
#ifdef VTK_9
22+
#include "VtkContrib/vtkLandmarkActor.h"
23+
#endif // VTK_9
24+
25+
26+
using namespace std;
27+
28+
29+
static void PickCallbackFunction (vtkObject* caller, long unsigned int vtkNotUsed(eventId), void* vtkNotUsed(clientData), void* vtkNotUsed(callData))
30+
{
31+
cout << "Pick." << endl;
32+
vtkAreaPicker* areaPicker = static_cast<vtkAreaPicker*>(caller);
33+
vtkProp3DCollection* props = areaPicker->GetProp3Ds();
34+
props->InitTraversal();
35+
36+
for (vtkIdType i = 0; i < props->GetNumberOfItems(); i++)
37+
{
38+
vtkProp3D const* prop = props->GetNextProp3D();
39+
cout << "Picked prop: " << prop << endl;
40+
}
41+
} // PickCallbackFunction
42+
43+
44+
45+
int main (int argc, char* argv [], char* envp [])
46+
{
47+
vtkSmartPointer<vtkRenderer> renderer = vtkSmartPointer<vtkRenderer>::New ( );
48+
vtkSmartPointer<vtkRenderWindow> renderWindow = vtkSmartPointer<vtkRenderWindow>::New ( );
49+
renderWindow->AddRenderer (renderer);
50+
renderWindow->SetWindowName ("AreaPicking");
51+
#ifdef VTK_9
52+
vtkLandmarkActor* landmarkActor = vtkLandmarkActor::New ( ); // WHY ??? Empêche la main loop de tomber ...
53+
#endif // VTK_9
54+
55+
vtkSmartPointer<vtkAreaPicker> areaPicker = vtkSmartPointer<vtkAreaPicker>::New ( );
56+
vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor = vtkSmartPointer<vtkRenderWindowInteractor>::New ( );
57+
renderWindowInteractor->SetRenderWindow (renderWindow);
58+
renderWindowInteractor->SetPicker (areaPicker);
59+
60+
// Create sets of set of points :
61+
const int number = 5;
62+
for (int i = 1;i <= number; i++)
63+
{
64+
vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New ( );
65+
vtkSmartPointer<vtkCellArray> vertices = vtkSmartPointer<vtkCellArray>::New ( );
66+
vtkIdType pid [1];
67+
pid [0] = points->InsertNextPoint (1.0, i, 0.0);
68+
vertices->InsertNextCell (1, pid);
69+
pid [0] = points->InsertNextPoint (0.0, i, 0.0);
70+
vertices->InsertNextCell (1, pid);
71+
pid [0] = points->InsertNextPoint (0.0, i, 1.0);
72+
vertices->InsertNextCell (1, pid);
73+
74+
// Create a polydata
75+
vtkSmartPointer<vtkPolyData> polydata = vtkSmartPointer<vtkPolyData>::New ( );
76+
polydata->SetPoints(points);
77+
polydata->SetVerts(vertices);
78+
79+
// Visualize
80+
vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New ( );
81+
mapper->SetInputData(polydata);
82+
vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New ( );
83+
actor->SetMapper (mapper);
84+
actor->GetProperty ( )->SetPointSize (8);
85+
actor->GetProperty ( )->SetColor (0.5, 0.5, 0.5);
86+
87+
renderer->AddActor (actor);
88+
} // for (int i = 1;i <= number; i++)
89+
90+
renderWindowInteractor->Initialize ( );
91+
renderWindow->Render ( );
92+
renderWindow->SetSize (1800, 1200);
93+
renderer->ResetCamera();
94+
renderer->ResetCameraClippingRange();
95+
renderWindow->Render();
96+
97+
// For vtkInteractorStyleRubberBandPick - use 'r' and left-mouse to draw a selection box used to pick.
98+
vtkSmartPointer<vtkInteractorStyleRubberBandPick> style = vtkSmartPointer<vtkInteractorStyleRubberBandPick>::New ( );
99+
style->SetCurrentRenderer (renderer);
100+
renderWindowInteractor->SetInteractorStyle (style);
101+
102+
vtkSmartPointer<vtkCallbackCommand> pickCallback = vtkSmartPointer<vtkCallbackCommand>::New ( );
103+
pickCallback->SetCallback (PickCallbackFunction);
104+
105+
areaPicker->AddObserver (vtkCommand::EndPickEvent, pickCallback);
106+
cout << "Positionnez la vue à la souris, puis pressez la touche \'r\' pour sélectionner des acteurs au rectangle élastique." << endl;
107+
#ifdef VTK_9
108+
cout << __FILE__ << ' ' << __LINE__ << endl;
109+
#endif // VTK_9
110+
renderWindowInteractor->Start ( );
111+
#ifdef VTK_9
112+
cout << __FILE__ << ' ' << __LINE__ << endl;
113+
#endif // VTK_9
114+
115+
return EXIT_SUCCESS;
116+
} // main
117+

versions.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
Version 5.6.1 : 21/09/24
2+
===============
3+
4+
Test areapicker.cpp
5+
6+
17
Version 5.6.0 : 05/07/24
28
===============
39

0 commit comments

Comments
 (0)