Skip to content

Commit

Permalink
Merge pull request #5 from LIHPC-Computational-Geometry/pointwidget2
Browse files Browse the repository at this point in the history
Version 5.6.0. The vtkConstrainedPointWidget2 class displays the poss…
  • Loading branch information
CharlesPignerol authored Jul 5, 2024
2 parents f499129 + b62e4f1 commit 4894750
Show file tree
Hide file tree
Showing 5 changed files with 121 additions and 4 deletions.
2 changes: 1 addition & 1 deletion cmake/version.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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})

Expand Down
22 changes: 22 additions & 0 deletions src/VtkContrib/public/VtkContrib/vtkConstrainedPointWidget2.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#ifndef VTK_CONSTRAINED_POINT_WIDGET_2_H
#define VTK_CONSTRAINED_POINT_WIDGET_2_H

#include <vtkActor.h>
#include <vtkHandleWidget.h>
#include <vtkSphereHandleRepresentation.h>

Expand Down Expand Up @@ -48,6 +49,14 @@ class vtkConstrainedPointWidget2 : public vtkHandleWidget
*/
virtual void OnChar ( );


protected :

/**
* Masque l'éventuel axe de contrainte affiché.
*/
virtual void EndInteraction ( );


private :

Expand Down Expand Up @@ -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 :
Expand All @@ -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


Expand Down
94 changes: 91 additions & 3 deletions src/VtkContrib/vtkConstrainedPointWidget2.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
#include "VtkContrib/vtkConstrainedPointWidget2.h"

#include <vtkCellPicker.h>
#include <vtkLineSource.h>
#include <vtkPolyDataMapper.h>
#include <vtkRenderer.h>
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>

#include <assert.h>
Expand Down Expand Up @@ -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;
Expand All @@ -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
Expand All @@ -108,6 +120,7 @@ vtkConstrainedPointHandleRepresentation2& vtkConstrainedPointHandleRepresentatio

vtkConstrainedPointHandleRepresentation2::~vtkConstrainedPointHandleRepresentation2 ( )
{

} // vtkConstrainedPointHandleRepresentation2::~vtkConstrainedPointHandleRepresentation2


Expand Down Expand Up @@ -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)
{
Expand All @@ -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
1 change: 1 addition & 0 deletions src/tests/point_widget2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ int main ( int argc, char *argv[] )
double bounds [6] = { 0., 2., -1., 1., -1., 1. };
vtkSmartPointer<vtkConstrainedPointWidget2> handleWidget = vtkSmartPointer<vtkConstrainedPointWidget2>::New();
handleWidget->GetRepresentation ( );
handleWidget->GetConstrainedPointRepresentation ( )->DisplayConstraintAxis (true);
handleWidget->SetInteractor(iren);
// handleWidget->GetRepresentation ( )->SetPlaceFactor (2.5);
handleWidget->GetRepresentation ( )->SetPlaceFactor (1.);
Expand Down
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.0 : 05/07/24
===============

La classe vtkConstrainedPointWidget2 permet d'afficher l'�ventuel axe de contrainte utilis�.


Version 5.5.0 : 26/06/24
===============

Expand Down

0 comments on commit 4894750

Please sign in to comment.