Skip to content

Commit

Permalink
Version 5.6.1. Area picker test (rubber banding).
Browse files Browse the repository at this point in the history
  • Loading branch information
Charles PIGNEROL committed Oct 4, 2024
1 parent 4894750 commit aae7112
Show file tree
Hide file tree
Showing 5 changed files with 136 additions and 22 deletions.
2 changes: 1 addition & 1 deletion cmake/version.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

set (VTK_CONTRIB_MAJOR_VERSION "5")
set (VTK_CONTRIB_MINOR_VERSION "6")
set (VTK_CONTRIB_RELEASE_VERSION "0")
set (VTK_CONTRIB_RELEASE_VERSION "1")
set (VTK_CONTRIB_VERSION ${VTK_CONTRIB_MAJOR_VERSION}.${VTK_CONTRIB_MINOR_VERSION}.${VTK_CONTRIB_RELEASE_VERSION})


2 changes: 2 additions & 0 deletions src/VtkContrib/vtkConstrainedPointWidget2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,9 @@ void vtkConstrainedPointHandleRepresentation2::WidgetInteraction (double eventPo
{
if (!this->WaitingForMotion || this->WaitCount++ > 3)
{
#ifdef VTK_7
this->ConstraintAxis = this->DetermineConstraintAxis (this->ConstraintAxis, pickPoint);
#endif // VTK_7
if (this->InteractionState == vtkHandleRepresentation::Selecting && !this->TranslationMode)
{
this->MoveFocus(prevPickPoint, pickPoint);
Expand Down
31 changes: 10 additions & 21 deletions src/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,15 @@ find_package (GUIToolkitsVariables)
include (${GUIToolkitsVariables_CMAKE_DIR}/common.cmake)
include (${GUIToolkitsVariables_CMAKE_DIR}/workarounds.cmake)

add_executable (point_widget point_widget.cpp)
add_executable (point_widget2 point_widget2.cpp)
add_executable (trihedrons trihedrons.cpp)
add_executable (torus torus.cpp)
set (ALL_EXECUTABLES areapicker point_widget point_widget2 trihedrons torus)

target_include_directories (point_widget PRIVATE ../VtkContrib/public ${CMAKE_CURRENT_SOURCE_DIR})
target_compile_options (point_widget PRIVATE ${SHARED_CFLAGS}) # Requested by Qt ...
target_link_libraries (point_widget PUBLIC VtkContrib)
target_include_directories (point_widget2 PRIVATE ../VtkContrib/public ${CMAKE_CURRENT_SOURCE_DIR})
target_compile_options (point_widget2 PRIVATE ${SHARED_CFLAGS}) # Requested by Qt ...
target_link_libraries (point_widget2 PUBLIC VtkContrib)
target_include_directories (trihedrons PRIVATE ../VtkContrib/public ${CMAKE_CURRENT_SOURCE_DIR})
target_compile_options (trihedrons PRIVATE ${SHARED_CFLAGS}) # Requested by Qt ...
target_link_libraries (trihedrons PUBLIC VtkContrib)
target_include_directories (torus PRIVATE ../VtkContrib/public ${CMAKE_CURRENT_SOURCE_DIR})
target_compile_options (torus PRIVATE ${SHARED_CFLAGS}) # Requested by Qt ...
target_link_libraries (torus PUBLIC VtkContrib)
foreach (exe ${ALL_EXECUTABLES})
add_executable (${exe} ${exe}.cpp)
target_include_directories (${exe} PRIVATE ../VtkContrib/public ${CMAKE_CURRENT_SOURCE_DIR})
target_compile_options (${exe} PRIVATE ${SHARED_CFLAGS})
target_link_libraries (${exe} PUBLIC VtkContrib)
# INSTALL_RPATH modifie le rpath pour les libs internes au projet :
set_target_properties (${exe} PROPERTIES INSTALL_RPATH_USE_LINK_PATH 1 INSTALL_RPATH ${CMAKE_PACKAGE_RPATH_DIR})
endforeach (exe)


# INSTALL_RPATH modifie le rpath pour les libs internes au projet :
set_target_properties (point_widget PROPERTIES INSTALL_RPATH_USE_LINK_PATH 1 INSTALL_RPATH ${CMAKE_PACKAGE_RPATH_DIR})
set_target_properties (point_widget2 PROPERTIES INSTALL_RPATH_USE_LINK_PATH 1 INSTALL_RPATH ${CMAKE_PACKAGE_RPATH_DIR})
set_target_properties (trihedrons PROPERTIES INSTALL_RPATH_USE_LINK_PATH 1 INSTALL_RPATH ${CMAKE_PACKAGE_RPATH_DIR})
set_target_properties (torus PROPERTIES INSTALL_RPATH_USE_LINK_PATH 1 INSTALL_RPATH ${CMAKE_PACKAGE_RPATH_DIR})
117 changes: 117 additions & 0 deletions src/tests/areapicker.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
#include "VtkContrib/vtkConstrainedPointWidget.h"

#include <vtkActor.h>
#include <vtkAreaPicker.h>
#include <vtkCallbackCommand.h>
#include <vtkCellArray.h>
#include <vtkInteractorStyleRubberBandPick.h>
#include <vtkInteractorStyleTrackball.h>
#include <vtkNamedColors.h>
#include <vtkSmartPointer.h>
#include <vtkPoints.h>
#include <vtkPolyData.h>
#include <vtkPolyDataMapper.h>
#include <vtkProp3DCollection.h>
#include <vtkProperty.h>
#include <vtkRenderer.h>
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkRenderedAreaPicker.h>

#ifdef VTK_9
#include "VtkContrib/vtkLandmarkActor.h"
#endif // VTK_9


using namespace std;


static void PickCallbackFunction (vtkObject* caller, long unsigned int vtkNotUsed(eventId), void* vtkNotUsed(clientData), void* vtkNotUsed(callData))
{
cout << "Pick." << endl;
vtkAreaPicker* areaPicker = static_cast<vtkAreaPicker*>(caller);
vtkProp3DCollection* props = areaPicker->GetProp3Ds();
props->InitTraversal();

for (vtkIdType i = 0; i < props->GetNumberOfItems(); i++)
{
vtkProp3D const* prop = props->GetNextProp3D();
cout << "Picked prop: " << prop << endl;
}
} // PickCallbackFunction



int main (int argc, char* argv [], char* envp [])
{
vtkSmartPointer<vtkRenderer> renderer = vtkSmartPointer<vtkRenderer>::New ( );
vtkSmartPointer<vtkRenderWindow> renderWindow = vtkSmartPointer<vtkRenderWindow>::New ( );
renderWindow->AddRenderer (renderer);
renderWindow->SetWindowName ("AreaPicking");
#ifdef VTK_9
vtkLandmarkActor* landmarkActor = vtkLandmarkActor::New ( ); // WHY ??? Empêche la main loop de tomber ...
#endif // VTK_9

vtkSmartPointer<vtkAreaPicker> areaPicker = vtkSmartPointer<vtkAreaPicker>::New ( );
vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor = vtkSmartPointer<vtkRenderWindowInteractor>::New ( );
renderWindowInteractor->SetRenderWindow (renderWindow);
renderWindowInteractor->SetPicker (areaPicker);

// Create sets of set of points :
const int number = 5;
for (int i = 1;i <= number; i++)
{
vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New ( );
vtkSmartPointer<vtkCellArray> vertices = vtkSmartPointer<vtkCellArray>::New ( );
vtkIdType pid [1];
pid [0] = points->InsertNextPoint (1.0, i, 0.0);
vertices->InsertNextCell (1, pid);
pid [0] = points->InsertNextPoint (0.0, i, 0.0);
vertices->InsertNextCell (1, pid);
pid [0] = points->InsertNextPoint (0.0, i, 1.0);
vertices->InsertNextCell (1, pid);

// Create a polydata
vtkSmartPointer<vtkPolyData> polydata = vtkSmartPointer<vtkPolyData>::New ( );
polydata->SetPoints(points);
polydata->SetVerts(vertices);

// Visualize
vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New ( );
mapper->SetInputData(polydata);
vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New ( );
actor->SetMapper (mapper);
actor->GetProperty ( )->SetPointSize (8);
actor->GetProperty ( )->SetColor (0.5, 0.5, 0.5);

renderer->AddActor (actor);
} // for (int i = 1;i <= number; i++)

renderWindowInteractor->Initialize ( );
renderWindow->Render ( );
renderWindow->SetSize (1800, 1200);
renderer->ResetCamera();
renderer->ResetCameraClippingRange();
renderWindow->Render();

// For vtkInteractorStyleRubberBandPick - use 'r' and left-mouse to draw a selection box used to pick.
vtkSmartPointer<vtkInteractorStyleRubberBandPick> style = vtkSmartPointer<vtkInteractorStyleRubberBandPick>::New ( );
style->SetCurrentRenderer (renderer);
renderWindowInteractor->SetInteractorStyle (style);

vtkSmartPointer<vtkCallbackCommand> pickCallback = vtkSmartPointer<vtkCallbackCommand>::New ( );
pickCallback->SetCallback (PickCallbackFunction);

areaPicker->AddObserver (vtkCommand::EndPickEvent, pickCallback);
cout << "Positionnez la vue à la souris, puis pressez la touche \'r\' pour sélectionner des acteurs au rectangle élastique." << endl;
#ifdef VTK_9
cout << __FILE__ << ' ' << __LINE__ << endl;
#endif // VTK_9
renderWindowInteractor->Start ( );
#ifdef VTK_9
cout << __FILE__ << ' ' << __LINE__ << endl;
#endif // VTK_9

return EXIT_SUCCESS;
} // main

6 changes: 6 additions & 0 deletions versions.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
Version 5.6.1 : 21/09/24
===============

Test areapicker.cpp


Version 5.6.0 : 05/07/24
===============

Expand Down

0 comments on commit aae7112

Please sign in to comment.