Visualization - Expose SelectMgr pixel tolerance via IVtk picker (#1204)

- Removes the dead `IVtkTools_ShapePicker::SetTolerance(float)` / `GetTolerance()` API and the unused stored tolerance value.
- Adds `SetPixelTolerance(int)` / `PixelTolerance() const` to `IVtkTools_ShapePicker` and `IVtkOCC_ShapePickerAlgo`, forwarding to `SelectMgr_ViewerSelector`.
- Removes `IVtkOCC_ViewerSelector`’s local cached tolerance fields and updates all `Pick()` overloads to apply `myTolerances.Tolerance()` on every pick.
This commit is contained in:
이대희
2026-04-26 00:58:23 +09:00
committed by GitHub
parent f99887f4e8
commit 152c09a75c
7 changed files with 80 additions and 139 deletions

View File

@@ -363,7 +363,7 @@ void IVtkDraw::ViewerInit(const IVtkWinParams& theParams)
// Init picker
GetPicker() = vtkSmartPointer<IVtkTools_ShapePicker>::New();
GetPicker()->SetTolerance(0.025f);
GetPicker()->SetPixelTolerance(2);
GetPicker()->SetRenderer(GetRenderer());
GetInteractor()->SetShapePicker(GetPicker());

View File

@@ -252,6 +252,20 @@ int IVtkOCC_ShapePickerAlgo::NbPicked()
//=================================================================================================
void IVtkOCC_ShapePickerAlgo::SetPixelTolerance(const int theTolerance)
{
myViewerSelector->SetPixelTolerance(theTolerance);
}
//=================================================================================================
int IVtkOCC_ShapePickerAlgo::PixelTolerance() const
{
return myViewerSelector->PixelTolerance();
}
//=================================================================================================
bool IVtkOCC_ShapePickerAlgo::processPicked()
{
int aNbPicked = myViewerSelector->NbPicked();

View File

@@ -40,6 +40,14 @@ public:
//! Get number of picked entities.
Standard_EXPORT int NbPicked() override;
//! Sets the pixel-space selection tolerance used by every subsequent
//! Pick call.
//! Forwards to SelectMgr_ViewerSelector::SetPixelTolerance.
Standard_EXPORT void SetPixelTolerance(const int theTolerance);
//! Returns the current pixel-space selection tolerance.
Standard_EXPORT int PixelTolerance() const;
//! Get activated selection modes for a shape.
//! @param[in] theShape a shape with activated selection mode(s)
//! @return list of active selection modes

View File

@@ -24,11 +24,7 @@ IMPLEMENT_STANDARD_RTTIEXT(IVtkOCC_ViewerSelector, SelectMgr_ViewerSelector)
//=================================================================================================
IVtkOCC_ViewerSelector::IVtkOCC_ViewerSelector()
: myPixTol(2),
myToUpdateTol(true)
{
}
IVtkOCC_ViewerSelector::IVtkOCC_ViewerSelector() = default;
//=================================================================================================
@@ -86,16 +82,7 @@ void IVtkOCC_ViewerSelector::Pick(const int theXPix,
gp_Pnt2d aMousePos(static_cast<double>(theXPix), static_cast<double>(theYPix));
mySelectingVolumeMgr.InitPointSelectingVolume(aMousePos);
if (myToUpdateTol)
{
// Compute and set a sensitivity tolerance according to the renderer (viewport).
// TODO: Think if this works well in perspective view...'cause result depends
// on position on the screen, but we always use the point close to the
// screen's origin...
mySelectingVolumeMgr.SetPixelTolerance(myPixTol);
myToUpdateTol = false;
}
mySelectingVolumeMgr.SetPixelTolerance(myTolerances.Tolerance());
mySelectingVolumeMgr.SetCamera(ConvertVtkToOccCamera(theView));
@@ -124,16 +111,7 @@ void IVtkOCC_ViewerSelector::Pick(const int theXMin,
gp_Pnt2d aMaxMousePos(static_cast<double>(theXMax), static_cast<double>(theYMax));
mySelectingVolumeMgr.InitBoxSelectingVolume(aMinMousePos, aMaxMousePos);
if (myToUpdateTol)
{
// Compute and set a sensitivity tolerance according to the renderer (viewport).
// TODO: Think if this works well in perspective view...'cause result depends
// on position on the screen, but we always use the point close to the
// screen's origin...
mySelectingVolumeMgr.SetPixelTolerance(myPixTol);
myToUpdateTol = false;
}
mySelectingVolumeMgr.SetPixelTolerance(myTolerances.Tolerance());
int aWidth = 0, aHeight = 0;
double aX = RealLast(), aY = RealLast();
@@ -169,16 +147,7 @@ void IVtkOCC_ViewerSelector::Pick(double** thePoly,
}
mySelectingVolumeMgr.InitPolylineSelectingVolume(aPolyline);
if (myToUpdateTol)
{
// Compute and set a sensitivity tolerance according to the renderer (viewport).
// TODO: Think if this works well in perspective view...'cause result depends
// on position on the screen, but we always use the point close to the
// screen's origin...
mySelectingVolumeMgr.SetPixelTolerance(myPixTol);
myToUpdateTol = false;
}
mySelectingVolumeMgr.SetPixelTolerance(myTolerances.Tolerance());
int aWidth = 0, aHeight = 0;
double aX = RealLast(), aY = RealLast();

View File

@@ -59,10 +59,6 @@ public:
static occ::handle<Graphic3d_Camera> ConvertVtkToOccCamera(const IVtk_IView::Handle& theView);
DEFINE_STANDARD_RTTIEXT(IVtkOCC_ViewerSelector, SelectMgr_ViewerSelector)
private:
int myPixTol;
bool myToUpdateTol;
};
#endif // __IVTKOCC_VIEWERSELECTOR_H__

View File

@@ -29,23 +29,14 @@
#pragma warning(pop)
#endif
//! @class IVtkTools_ShapePicker
//! VTK picker implementation for OCCT shapes.
//! Can pick either whole shapes or sub-shapes.
//! The kind of selectable entities is defined by the current selection mode.
//! NOTE: For performance reasons, setRenderer() method should be called in advance,
//! before the user starts to select interactively, in order for the OCCT selection
//! algorithm to prepare its internal selection data.
vtkStandardNewMacro(IVtkTools_ShapePicker);
vtkStandardNewMacro(IVtkTools_ShapePicker)
//=================================================================================================
//============================================================================
// Method: IVtkTools_ShapePicker
// Purpose: Constructs the picker with empty renderer and ready for point selection.
//============================================================================
IVtkTools_ShapePicker::IVtkTools_ShapePicker()
IVtkTools_ShapePicker::IVtkTools_ShapePicker()
: myRenderer(nullptr),
myIsRectSelection(false)
myIsRectSelection(false),
myIsPolySelection(false)
{
myOccPickerAlgo = new IVtkOCC_ShapePickerAlgo();
}
@@ -54,28 +45,22 @@ vtkStandardNewMacro(IVtkTools_ShapePicker)
IVtkTools_ShapePicker::~IVtkTools_ShapePicker() = default;
//============================================================================
// Method: SetTolerance
// Purpose: Setter for tolerance of picking.
//============================================================================
void IVtkTools_ShapePicker::SetTolerance(float theTolerance)
//=================================================================================================
void IVtkTools_ShapePicker::SetPixelTolerance(const int theTolerance)
{
myTolerance = theTolerance;
myOccPickerAlgo->SetPixelTolerance(theTolerance);
}
//============================================================================
// Method: GetTolerance
// Purpose: Getter for tolerance of picking.
//============================================================================
float IVtkTools_ShapePicker::GetTolerance() const
//=================================================================================================
int IVtkTools_ShapePicker::PixelTolerance() const
{
return myTolerance;
return myOccPickerAlgo->PixelTolerance();
}
//============================================================================
// Method: convertDisplayToWorld
// Purpose: Convert display coordinates to world coordinates
//============================================================================
//=================================================================================================
bool IVtkTools_ShapePicker::convertDisplayToWorld(vtkRenderer* theRenderer,
double theDisplayCoord[3],
double theWorldCoord[3])
@@ -99,10 +84,8 @@ bool IVtkTools_ShapePicker::convertDisplayToWorld(vtkRenderer* theRenderer,
return true;
}
//============================================================================
// Method: Pick
// Purpose: Pick entities in the given point.
//============================================================================
//=================================================================================================
int IVtkTools_ShapePicker::Pick(double theX, double theY, double /*theZ*/, vtkRenderer* theRenderer)
{
double aPos[2] = {theX, theY};
@@ -111,10 +94,8 @@ int IVtkTools_ShapePicker::Pick(double theX, double theY, double /*theZ*/, vtkRe
return pick(aPos, theRenderer);
}
//============================================================================
// Method: pick
// Purpose: Pick entities in the given rectangle area.
//============================================================================
//=================================================================================================
int IVtkTools_ShapePicker::Pick(double theXPMin,
double theYPMin,
double theXPMax,
@@ -127,10 +108,8 @@ int IVtkTools_ShapePicker::Pick(double theXPMin,
return pick(aPos, theRenderer);
}
//============================================================================
// Method: pick
// Purpose: Pick entities in the given polygonal area.
//============================================================================
//=================================================================================================
int IVtkTools_ShapePicker::Pick(double thePoly[][3],
const int theNbPoints,
vtkRenderer* theRenderer)
@@ -140,10 +119,8 @@ int IVtkTools_ShapePicker::Pick(double thePoly[][3],
return pick((double*)thePoly, theRenderer, theNbPoints);
}
//============================================================================
// Method: pick
// Purpose: Pick entities in the given point or area.
//============================================================================
//=================================================================================================
int IVtkTools_ShapePicker::pick(double* thePos, vtkRenderer* theRenderer, const int theNbPoints)
{
// Initialize picking process
@@ -169,10 +146,8 @@ int IVtkTools_ShapePicker::pick(double* thePos, vtkRenderer* theRenderer, const
return myOccPickerAlgo->NbPicked();
}
//============================================================================
// Method: doPickImpl
// Purpose: Implementation of picking algorithm.
//============================================================================
//=================================================================================================
void IVtkTools_ShapePicker::doPickImpl(double* thePos,
vtkRenderer* theRenderer,
const int theNbPoints)
@@ -198,10 +173,8 @@ void IVtkTools_ShapePicker::doPickImpl(double* thePos,
PickPosition[2] = myOccPickerAlgo->TopPickedPoint().Z();
}
//============================================================================
// Method: SetRenderer
// Purpose: Sets the renderer to be used by OCCT selection algorithm
//============================================================================
//=================================================================================================
void IVtkTools_ShapePicker::SetRenderer(vtkRenderer* theRenderer)
{
if (theRenderer == myRenderer.GetPointer())
@@ -224,20 +197,16 @@ void IVtkTools_ShapePicker::SetAreaSelection(bool theIsOn)
myIsRectSelection = theIsOn;
}
//============================================================================
// Method: GetSelectionModes
// Purpose: Get activated selection modes for a shape.
//============================================================================
//=================================================================================================
NCollection_List<IVtk_SelectionMode> IVtkTools_ShapePicker::GetSelectionModes(
const IVtk_IShape::Handle& theShape) const
{
return myOccPickerAlgo->GetSelectionModes(theShape);
}
//============================================================================
// Method: GetSelectionModes
// Purpose: Get activated selection modes for a shape actor.
//============================================================================
//=================================================================================================
NCollection_List<IVtk_SelectionMode> IVtkTools_ShapePicker::GetSelectionModes(
vtkActor* theShapeActor) const
{
@@ -250,10 +219,8 @@ NCollection_List<IVtk_SelectionMode> IVtkTools_ShapePicker::GetSelectionModes(
return aRes;
}
//============================================================================
// Method: SetSelectionMode
// Purpose: Turn on/off a selection mode for a shape.
//============================================================================
//=================================================================================================
void IVtkTools_ShapePicker::SetSelectionMode(const IVtk_IShape::Handle& theShape,
const IVtk_SelectionMode theMode,
const bool theIsTurnOn) const
@@ -261,10 +228,8 @@ void IVtkTools_ShapePicker::SetSelectionMode(const IVtk_IShape::Handle& theShape
myOccPickerAlgo->SetSelectionMode(theShape, theMode, theIsTurnOn);
}
//============================================================================
// Method: SetSelectionMode
// Purpose: Turn on/off a selection mode for a shape actor.
//============================================================================
//=================================================================================================
void IVtkTools_ShapePicker::SetSelectionMode(vtkActor* theShapeActor,
const IVtk_SelectionMode theMode,
const bool theIsTurnOn) const
@@ -276,10 +241,8 @@ void IVtkTools_ShapePicker::SetSelectionMode(vtkActor* theShapeAc
}
}
//============================================================================
// Method: SetSelectionMode
// Purpose: Sets the current selection mode for all visible shape objects.
//============================================================================
//=================================================================================================
void IVtkTools_ShapePicker::SetSelectionMode(const IVtk_SelectionMode theMode,
const bool theIsTurnOn) const
{
@@ -307,10 +270,8 @@ void IVtkTools_ShapePicker::SetSelectionMode(const IVtk_SelectionMode theMode,
}
}
//============================================================================
// Method: GetPickedShapesIds
// Purpose: Access to the list of top-level shapes picked.
//============================================================================
//=================================================================================================
NCollection_List<IVtk_IdType> IVtkTools_ShapePicker::GetPickedShapesIds(bool theIsAll) const
{
if (theIsAll || myIsRectSelection)
@@ -327,19 +288,15 @@ NCollection_List<IVtk_IdType> IVtkTools_ShapePicker::GetPickedShapesIds(bool the
return aRes;
}
//============================================================================
// Method: RemoveSelectableActor
// Purpose: Remove selectable object from the picker (from internal maps).
//============================================================================
//=================================================================================================
void IVtkTools_ShapePicker::RemoveSelectableObject(const IVtk_IShape::Handle& theShape)
{
myOccPickerAlgo->RemoveSelectableObject(theShape);
}
//============================================================================
// Method: RemoveSelectableActor
// Purpose: Remove selectable object from the picker (from internal maps).
//============================================================================
//=================================================================================================
void IVtkTools_ShapePicker::RemoveSelectableActor(vtkActor* theShapeActor)
{
IVtk_IShape::Handle aShape = IVtkTools_ShapeObject::GetOccShape(theShapeActor);
@@ -349,10 +306,8 @@ void IVtkTools_ShapePicker::RemoveSelectableActor(vtkActor* theShapeActor)
}
}
//============================================================================
// Method: GetPickedSubShapesIds
// Purpose: Access to the list of sub-shapes ids picked.
//============================================================================
//=================================================================================================
NCollection_List<IVtk_IdType> IVtkTools_ShapePicker::GetPickedSubShapesIds(const IVtk_IdType theId,
bool theIsAll) const
{
@@ -373,10 +328,8 @@ NCollection_List<IVtk_IdType> IVtkTools_ShapePicker::GetPickedSubShapesIds(const
return aRes;
}
//============================================================================
// Method: GetPickedActors
// Purpose: Access to the list of actors picked.
//============================================================================
//=================================================================================================
vtkSmartPointer<vtkActorCollection> IVtkTools_ShapePicker::GetPickedActors(bool theIsAll) const
{
vtkSmartPointer<vtkActorCollection> aRes = vtkSmartPointer<vtkActorCollection>::New();

View File

@@ -63,10 +63,12 @@ public:
//! @return Number of detected entities.
int Pick(double poly[][3], const int theNbPoints, vtkRenderer* theRenderer = nullptr);
//! Setter for tolerance of picking.
void SetTolerance(float theTolerance);
//! Getter for tolerance of picking.
float GetTolerance() const;
//! Sets the pixel-space selection tolerance applied on every subsequent
//! Pick. Forwards to SelectMgr_ViewerSelector::SetPixelTolerance via the
//! underlying picker algorithm.
void SetPixelTolerance(const int theTolerance);
//! Returns the current pixel-space selection tolerance.
int PixelTolerance() const;
//! Sets the renderer to be used by OCCT selection algorithm
void SetRenderer(vtkRenderer* theRenderer);
@@ -169,7 +171,6 @@ private:
vtkSmartPointer<vtkRenderer> myRenderer; //!< VTK renderer
bool myIsRectSelection; //!< Rectangle selection mode flag
bool myIsPolySelection; //!< Polyline selection mode flag
float myTolerance; //!< Selection tolerance
};
#ifdef _MSC_VER