diff --git a/src/Draw/TKIVtkDraw/IVtkDraw/IVtkDraw.cxx b/src/Draw/TKIVtkDraw/IVtkDraw/IVtkDraw.cxx index 06f8c830d6..a855e78a5f 100644 --- a/src/Draw/TKIVtkDraw/IVtkDraw/IVtkDraw.cxx +++ b/src/Draw/TKIVtkDraw/IVtkDraw/IVtkDraw.cxx @@ -363,7 +363,7 @@ void IVtkDraw::ViewerInit(const IVtkWinParams& theParams) // Init picker GetPicker() = vtkSmartPointer::New(); - GetPicker()->SetTolerance(0.025f); + GetPicker()->SetPixelTolerance(2); GetPicker()->SetRenderer(GetRenderer()); GetInteractor()->SetShapePicker(GetPicker()); diff --git a/src/Visualization/TKIVtk/IVtkOCC/IVtkOCC_ShapePickerAlgo.cxx b/src/Visualization/TKIVtk/IVtkOCC/IVtkOCC_ShapePickerAlgo.cxx index 6046ab96a4..05a965ecb6 100644 --- a/src/Visualization/TKIVtk/IVtkOCC/IVtkOCC_ShapePickerAlgo.cxx +++ b/src/Visualization/TKIVtk/IVtkOCC/IVtkOCC_ShapePickerAlgo.cxx @@ -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(); diff --git a/src/Visualization/TKIVtk/IVtkOCC/IVtkOCC_ShapePickerAlgo.hxx b/src/Visualization/TKIVtk/IVtkOCC/IVtkOCC_ShapePickerAlgo.hxx index 2f9d5a358a..9e41b2711f 100644 --- a/src/Visualization/TKIVtk/IVtkOCC/IVtkOCC_ShapePickerAlgo.hxx +++ b/src/Visualization/TKIVtk/IVtkOCC/IVtkOCC_ShapePickerAlgo.hxx @@ -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 diff --git a/src/Visualization/TKIVtk/IVtkOCC/IVtkOCC_ViewerSelector.cxx b/src/Visualization/TKIVtk/IVtkOCC/IVtkOCC_ViewerSelector.cxx index 0804ca8c1a..7437f91b00 100644 --- a/src/Visualization/TKIVtk/IVtkOCC/IVtkOCC_ViewerSelector.cxx +++ b/src/Visualization/TKIVtk/IVtkOCC/IVtkOCC_ViewerSelector.cxx @@ -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(theXPix), static_cast(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(theXMax), static_cast(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(); diff --git a/src/Visualization/TKIVtk/IVtkOCC/IVtkOCC_ViewerSelector.hxx b/src/Visualization/TKIVtk/IVtkOCC/IVtkOCC_ViewerSelector.hxx index 6772aa140f..18d41f0470 100644 --- a/src/Visualization/TKIVtk/IVtkOCC/IVtkOCC_ViewerSelector.hxx +++ b/src/Visualization/TKIVtk/IVtkOCC/IVtkOCC_ViewerSelector.hxx @@ -59,10 +59,6 @@ public: static occ::handle ConvertVtkToOccCamera(const IVtk_IView::Handle& theView); DEFINE_STANDARD_RTTIEXT(IVtkOCC_ViewerSelector, SelectMgr_ViewerSelector) - -private: - int myPixTol; - bool myToUpdateTol; }; #endif // __IVTKOCC_VIEWERSELECTOR_H__ diff --git a/src/Visualization/TKIVtk/IVtkTools/IVtkTools_ShapePicker.cxx b/src/Visualization/TKIVtk/IVtkTools/IVtkTools_ShapePicker.cxx index d6440ea512..90c3f7a0b7 100644 --- a/src/Visualization/TKIVtk/IVtkTools/IVtkTools_ShapePicker.cxx +++ b/src/Visualization/TKIVtk/IVtkTools/IVtkTools_ShapePicker.cxx @@ -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 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 IVtkTools_ShapePicker::GetSelectionModes( vtkActor* theShapeActor) const { @@ -250,10 +219,8 @@ NCollection_List 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 IVtkTools_ShapePicker::GetPickedShapesIds(bool theIsAll) const { if (theIsAll || myIsRectSelection) @@ -327,19 +288,15 @@ NCollection_List 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 IVtkTools_ShapePicker::GetPickedSubShapesIds(const IVtk_IdType theId, bool theIsAll) const { @@ -373,10 +328,8 @@ NCollection_List IVtkTools_ShapePicker::GetPickedSubShapesIds(const return aRes; } -//============================================================================ -// Method: GetPickedActors -// Purpose: Access to the list of actors picked. -//============================================================================ +//================================================================================================= + vtkSmartPointer IVtkTools_ShapePicker::GetPickedActors(bool theIsAll) const { vtkSmartPointer aRes = vtkSmartPointer::New(); diff --git a/src/Visualization/TKIVtk/IVtkTools/IVtkTools_ShapePicker.hxx b/src/Visualization/TKIVtk/IVtkTools/IVtkTools_ShapePicker.hxx index 8aa3653e01..a055efed8c 100644 --- a/src/Visualization/TKIVtk/IVtkTools/IVtkTools_ShapePicker.hxx +++ b/src/Visualization/TKIVtk/IVtkTools/IVtkTools_ShapePicker.hxx @@ -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 myRenderer; //!< VTK renderer bool myIsRectSelection; //!< Rectangle selection mode flag bool myIsPolySelection; //!< Polyline selection mode flag - float myTolerance; //!< Selection tolerance }; #ifdef _MSC_VER