From b62e4f155b31233ceb8b4be3fafc049ed61805ed Mon Sep 17 00:00:00 2001 From: Charles PIGNEROL <> Date: Fri, 5 Jul 2024 16:08:40 +0200 Subject: [PATCH] Version 5.6.0. The vtkConstrainedPointWidget2 class displays the possible constraint axis. --- cmake/version.cmake | 2 +- .../VtkContrib/vtkConstrainedPointWidget2.h | 22 +++++ src/VtkContrib/vtkConstrainedPointWidget2.cpp | 94 ++++++++++++++++++- src/tests/point_widget2.cpp | 1 + versions.txt | 6 ++ 5 files changed, 121 insertions(+), 4 deletions(-) diff --git a/cmake/version.cmake b/cmake/version.cmake index b2092fc..bf8857b 100644 --- a/cmake/version.cmake +++ b/cmake/version.cmake @@ -3,7 +3,7 @@ # set (VTK_CONTRIB_MAJOR_VERSION "5") -set (VTK_CONTRIB_MINOR_VERSION "5") +set (VTK_CONTRIB_MINOR_VERSION "6") set (VTK_CONTRIB_RELEASE_VERSION "0") set (VTK_CONTRIB_VERSION ${VTK_CONTRIB_MAJOR_VERSION}.${VTK_CONTRIB_MINOR_VERSION}.${VTK_CONTRIB_RELEASE_VERSION}) diff --git a/src/VtkContrib/public/VtkContrib/vtkConstrainedPointWidget2.h b/src/VtkContrib/public/VtkContrib/vtkConstrainedPointWidget2.h index 9f1385c..255091f 100644 --- a/src/VtkContrib/public/VtkContrib/vtkConstrainedPointWidget2.h +++ b/src/VtkContrib/public/VtkContrib/vtkConstrainedPointWidget2.h @@ -7,6 +7,7 @@ #ifndef VTK_CONSTRAINED_POINT_WIDGET_2_H #define VTK_CONSTRAINED_POINT_WIDGET_2_H +#include #include #include @@ -48,6 +49,14 @@ class vtkConstrainedPointWidget2 : public vtkHandleWidget */ virtual void OnChar ( ); + + protected : + + /** + * Masque l'éventuel axe de contrainte affiché. + */ + virtual void EndInteraction ( ); + private : @@ -96,6 +105,13 @@ class vtkConstrainedPointHandleRepresentation2 : public vtkSphereHandleRepresent * @param Nouvel axe de contrainte de déplacement (0 -> X, 1 -> Y, 2 -> Z, autre => déplacement dans le plan de l'écran). */ virtual void SetConstraintAxis (int axis); + + /** + * Affiche/Masque une droite représentant l'axe de contrainte. + */ + virtual void DisplayConstraintAxis (bool onOff); + virtual bool DisplayConstraintAxis ( ) + { return _displayConstraintAxis; } private : @@ -115,6 +131,12 @@ class vtkConstrainedPointHandleRepresentation2 : public vtkSphereHandleRepresent */ vtkConstrainedPointHandleRepresentation2 (const vtkConstrainedPointHandleRepresentation2&); vtkConstrainedPointHandleRepresentation2& operator = (const vtkConstrainedPointHandleRepresentation2&); + + /** Faut-il afficher l'axe de contrainte ? */ + bool _displayConstraintAxis; + + /** L'éventuel acteur représentant l'axe de contrainte. */ + vtkActor* _constraintAxisActor; }; // class vtkConstrainedPointHandleRepresentation2 diff --git a/src/VtkContrib/vtkConstrainedPointWidget2.cpp b/src/VtkContrib/vtkConstrainedPointWidget2.cpp index 86346e5..e861b49 100644 --- a/src/VtkContrib/vtkConstrainedPointWidget2.cpp +++ b/src/VtkContrib/vtkConstrainedPointWidget2.cpp @@ -1,7 +1,10 @@ #include "VtkContrib/vtkConstrainedPointWidget2.h" #include +#include +#include #include +#include #include #include @@ -66,7 +69,7 @@ vtkConstrainedPointHandleRepresentation2* vtkConstrainedPointWidget2::GetConstra void vtkConstrainedPointWidget2::OnChar ( ) { if ((0 != this->Interactor) && (0 != GetConstrainedPointRepresentation ( ))) - { + { switch (this->Interactor->GetKeyCode ( )) { case ' ' : GetConstrainedPointRepresentation ( )->SetConstraintAxis (-1); break; @@ -82,18 +85,27 @@ void vtkConstrainedPointWidget2::OnChar ( ) } // vtkConstrainedPointWidget2::OnChar +void vtkConstrainedPointWidget2::EndInteraction ( ) +{ + if (0 != GetConstrainedPointRepresentation ( )) + GetConstrainedPointRepresentation ( )->SetConstraintAxis (-1); + + vtkHandleWidget::EndInteraction ( ); +} // vtkConstrainedPointWidget2::EndInteraction + + // ============================================================================= // LA CLASSE vtkConstrainedPointHandleRepresentation2 // ============================================================================= vtkConstrainedPointHandleRepresentation2::vtkConstrainedPointHandleRepresentation2 ( ) - : vtkSphereHandleRepresentation ( ) + : vtkSphereHandleRepresentation ( ), _displayConstraintAxis (false), _constraintAxisActor (0) { } // vtkConstrainedPointHandleRepresentation2::vtkConstrainedPointHandleRepresentation2 vtkConstrainedPointHandleRepresentation2::vtkConstrainedPointHandleRepresentation2 (const vtkConstrainedPointHandleRepresentation2&) - : vtkSphereHandleRepresentation ( ) + : vtkSphereHandleRepresentation ( ), _displayConstraintAxis (false), _constraintAxisActor (0) { assert (0 && "vtkConstrainedPointHandleRepresentation2 copy constructor is not allowed."); } // vtkConstrainedPointHandleRepresentation2::vtkConstrainedPointHandleRepresentation2 @@ -108,6 +120,7 @@ vtkConstrainedPointHandleRepresentation2& vtkConstrainedPointHandleRepresentatio vtkConstrainedPointHandleRepresentation2::~vtkConstrainedPointHandleRepresentation2 ( ) { + } // vtkConstrainedPointHandleRepresentation2::~vtkConstrainedPointHandleRepresentation2 @@ -159,6 +172,10 @@ void vtkConstrainedPointHandleRepresentation2::WidgetInteraction (double eventPo void vtkConstrainedPointHandleRepresentation2::SetConstraintAxis (int axis) { + const bool displayConstraintAxis = _displayConstraintAxis; + if ((0 != GetConstrained ( )) && (axis != this->ConstraintAxis)) + DisplayConstraintAxis (false); + this->ConstraintAxis = axis; switch (axis) { @@ -170,6 +187,77 @@ void vtkConstrainedPointHandleRepresentation2::SetConstraintAxis (int axis) default : ConstrainedOff ( ); } // switch (axis) + + if (true == displayConstraintAxis) + DisplayConstraintAxis (true); } // vtkConstrainedPointHandleRepresentation2::SetConstraintAxis +void vtkConstrainedPointHandleRepresentation2::DisplayConstraintAxis (bool onOff) +{ + if ((true == onOff) && (0 != _constraintAxisActor)) + return; + _displayConstraintAxis = onOff; + + if ((true == onOff) && (0 <= this->ConstraintAxis) && (2 >= this->ConstraintAxis)) + { + // Le point courrant : + double pos [3] = { 0., 0., 0. }; + GetWorldPosition (pos); + + // L'univers : + double bounds [6] = { DBL_MAX, -DBL_MAX, DBL_MAX, -DBL_MAX, DBL_MAX, -DBL_MAX }; + double dx = 0., dy = 0., dz = 0.; + if (0 != this->Renderer) + { + this->Renderer->ComputeVisiblePropBounds (bounds); + dx = bounds [1] - bounds [0]; + dy = bounds [3] - bounds [2]; + dz = bounds [5] - bounds [4]; + } // if (0 != this->Renderer) + + vtkLineSource* line = vtkLineSource::New ( ); + vtkPoints* points = vtkPoints::New ( ); + points->Initialize ( ); + switch (this->ConstraintAxis) + { + case 0 : + line->SetPoint1 (bounds [0] - dx, pos [1], pos [2]); + line->SetPoint2 (bounds [1] + dx, pos [1], pos [2]); + break; + case 1 : + line->SetPoint1 (pos [0], bounds [2] - dy, pos [2]); + line->SetPoint2 (pos [0], bounds [3] + dy, pos [2]); + break; + case 2 : + line->SetPoint1 (pos [0], pos [1], bounds [4] - dz); + line->SetPoint2 (pos [0], pos [1], bounds [5] + dz); + break; + } // switch (this->ConstraintAxis) + vtkPolyDataMapper* mapper = vtkPolyDataMapper::New ( ); + mapper->SetInputConnection (line->GetOutputPort ( )); + mapper->ScalarVisibilityOff ( ); + assert (0 == _constraintAxisActor); + _constraintAxisActor = vtkActor::New ( ); + _constraintAxisActor->SetProperty (this->GetSelectedProperty ( )); // => couleur de la sphère lors des interactions + _constraintAxisActor->SetMapper (mapper); + if (0 != this->Renderer) + { + this->Renderer->AddActor (_constraintAxisActor); + if (0 != this->Renderer->GetRenderWindow ( )) + this->Renderer->GetRenderWindow ( )->Render ( ); + } + line->Delete ( ); + mapper->Delete ( ); + } // if ((true == onOff) && (0 <= this->ConstraintAxis) && (2 >= this->ConstraintAxis)) + else + { + if (0 != _constraintAxisActor) + { + if (0 != this->Renderer) + this->Renderer->RemoveActor (_constraintAxisActor); + _constraintAxisActor->Delete ( ); + } // if (0 != _constraintAxisActor) + _constraintAxisActor = 0; + } // else if ((true == onOff) && (0 <= this->ConstraintAxis) && (2 >= this->ConstraintAxis)) +} // vtkConstrainedPointHandleRepresentation2::DisplayConstraintAxis diff --git a/src/tests/point_widget2.cpp b/src/tests/point_widget2.cpp index dee9362..0e1ec60 100644 --- a/src/tests/point_widget2.cpp +++ b/src/tests/point_widget2.cpp @@ -85,6 +85,7 @@ int main ( int argc, char *argv[] ) double bounds [6] = { 0., 2., -1., 1., -1., 1. }; vtkSmartPointer handleWidget = vtkSmartPointer::New(); handleWidget->GetRepresentation ( ); + handleWidget->GetConstrainedPointRepresentation ( )->DisplayConstraintAxis (true); handleWidget->SetInteractor(iren); // handleWidget->GetRepresentation ( )->SetPlaceFactor (2.5); handleWidget->GetRepresentation ( )->SetPlaceFactor (1.); diff --git a/versions.txt b/versions.txt index 6534d67..fc4941b 100644 --- a/versions.txt +++ b/versions.txt @@ -1,3 +1,9 @@ +Version 5.6.0 : 05/07/24 +=============== + +La classe vtkConstrainedPointWidget2 permet d'afficher l'éventuel axe de contrainte utilisé. + + Version 5.5.0 : 26/06/24 ===============