Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-16 09:18:26

0001 // Created on: 2014-05-22
0002 // Created by: Varvara POSKONINA
0003 // Copyright (c) 2005-2014 OPEN CASCADE SAS
0004 //
0005 // This file is part of Open CASCADE Technology software library.
0006 //
0007 // This library is free software; you can redistribute it and/or modify it under
0008 // the terms of the GNU Lesser General Public License version 2.1 as published
0009 // by the Free Software Foundation, with special exception defined in the file
0010 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
0011 // distribution for complete text of the license and disclaimer of any warranty.
0012 //
0013 // Alternatively, this file may be used under the terms of Open CASCADE
0014 // commercial license or contractual agreement.
0015 
0016 #ifndef _SelectMgr_TriangularFrustum_HeaderFile
0017 #define _SelectMgr_TriangularFrustum_HeaderFile
0018 
0019 #include <SelectMgr_Frustum.hxx>
0020 
0021 //! This class contains representation of triangular selecting frustum, created in case
0022 //! of polyline selection, and algorithms for overlap detection between selecting frustum and
0023 //! sensitive entities. Overlap detection tests are implemented according to the terms of separating
0024 //! axis theorem (SAT). NOTE: the object of this class can be created only as part of
0025 //! SelectMgr_TriangularFrustumSet.
0026 class SelectMgr_TriangularFrustum : public SelectMgr_Frustum<3>
0027 {
0028 public:
0029   //! Auxiliary structure to define selection triangle
0030   struct SelectionTriangle
0031   {
0032     gp_Pnt2d Points[3];
0033   };
0034 
0035 public:
0036   //! Destructor.
0037   Standard_EXPORT ~SelectMgr_TriangularFrustum() override;
0038 
0039   //! Initializes selection triangle by input points
0040   Standard_EXPORT void Init(const gp_Pnt2d& theP1, const gp_Pnt2d& theP2, const gp_Pnt2d& theP3);
0041 
0042   //! Creates new triangular frustum with bases of triangles with vertices theP1, theP2 and theP3
0043   //! projections onto near and far view frustum planes (only for triangular frustums)
0044   //! NOTE: it should be called after Init() method
0045   Standard_EXPORT void Build() override;
0046 
0047   //! Returns FALSE (not applicable to this volume).
0048   bool IsScalable() const override { return false; }
0049 
0050   //! Returns a copy of the frustum transformed according to the matrix given
0051   Standard_EXPORT occ::handle<SelectMgr_BaseIntersector> ScaleAndTransform(
0052     const int                                    theScale,
0053     const gp_GTrsf&                              theTrsf,
0054     const occ::handle<SelectMgr_FrustumBuilder>& theBuilder) const override;
0055 
0056   //! Returns a copy of the frustum using the given frustum builder configuration.
0057   //! Returned frustum should be re-constructed before being used.
0058   //! @param[in] theBuilder  argument that represents corresponding settings for re-constructing
0059   //! transformed frustum from scratch;
0060   //!                        should NOT be NULL.
0061   //! @return a copy of the frustum with the input builder assigned
0062   Standard_EXPORT occ::handle<SelectMgr_BaseIntersector> CopyWithBuilder(
0063     const occ::handle<SelectMgr_FrustumBuilder>& theBuilder) const override;
0064 
0065 public: //! @name SAT Tests for different objects
0066   //! SAT intersection test between defined volume and given axis-aligned box
0067   Standard_EXPORT bool OverlapsBox(const NCollection_Vec3<double>& theMinPnt,
0068                                    const NCollection_Vec3<double>& theMaxPnt,
0069                                    const SelectMgr_ViewClipRange&  theClipRange,
0070                                    SelectBasics_PickResult&        thePickResult) const override;
0071 
0072   //! Returns true if selecting volume is overlapped by axis-aligned bounding box
0073   //! with minimum corner at point theMinPt and maximum at point theMaxPt
0074   Standard_EXPORT bool OverlapsBox(const NCollection_Vec3<double>& theMinPt,
0075                                    const NCollection_Vec3<double>& theMaxPt,
0076                                    bool*                           theInside) const override;
0077 
0078   //! Intersection test between defined volume and given point
0079   Standard_EXPORT bool OverlapsPoint(const gp_Pnt&                  thePnt,
0080                                      const SelectMgr_ViewClipRange& theClipRange,
0081                                      SelectBasics_PickResult&       thePickResult) const override;
0082 
0083   //! Always returns FALSE (not applicable to this selector).
0084   bool OverlapsPoint(const gp_Pnt&) const override { return false; }
0085 
0086   //! SAT intersection test between defined volume and given ordered set of points,
0087   //! representing line segments. The test may be considered of interior part or
0088   //! boundary line defined by segments depending on given sensitivity type
0089   Standard_EXPORT bool OverlapsPolygon(const NCollection_Array1<gp_Pnt>& theArrayOfPnts,
0090                                        Select3D_TypeOfSensitivity        theSensType,
0091                                        const SelectMgr_ViewClipRange&    theClipRange,
0092                                        SelectBasics_PickResult& thePickResult) const override;
0093 
0094   //! Checks if line segment overlaps selecting frustum
0095   Standard_EXPORT bool OverlapsSegment(const gp_Pnt&                  thePnt1,
0096                                        const gp_Pnt&                  thePnt2,
0097                                        const SelectMgr_ViewClipRange& theClipRange,
0098                                        SelectBasics_PickResult&       thePickResult) const override;
0099 
0100   //! SAT intersection test between defined volume and given triangle. The test may
0101   //! be considered of interior part or boundary line defined by triangle vertices
0102   //! depending on given sensitivity type
0103   Standard_EXPORT bool OverlapsTriangle(const gp_Pnt&                  thePnt1,
0104                                         const gp_Pnt&                  thePnt2,
0105                                         const gp_Pnt&                  thePnt3,
0106                                         Select3D_TypeOfSensitivity     theSensType,
0107                                         const SelectMgr_ViewClipRange& theClipRange,
0108                                         SelectBasics_PickResult& thePickResult) const override;
0109 
0110   //! Returns true if selecting volume is overlapped by sphere with center theCenter
0111   //! and radius theRadius
0112   Standard_EXPORT bool OverlapsSphere(const gp_Pnt& theCenter,
0113                                       const double  theRadius,
0114                                       bool*         theInside = nullptr) const override;
0115 
0116   //! Returns true if selecting volume is overlapped by sphere with center theCenter
0117   //! and radius theRadius
0118   Standard_EXPORT bool OverlapsSphere(const gp_Pnt&                  theCenter,
0119                                       const double                   theRadius,
0120                                       const SelectMgr_ViewClipRange& theClipRange,
0121                                       SelectBasics_PickResult&       thePickResult) const override;
0122 
0123   //! Returns true if selecting volume is overlapped by cylinder (or cone) with radiuses
0124   //! theBottomRad and theTopRad, height theHeight and transformation to apply theTrsf.
0125   Standard_EXPORT bool OverlapsCylinder(const double                   theBottomRad,
0126                                         const double                   theTopRad,
0127                                         const double                   theHeight,
0128                                         const gp_Trsf&                 theTrsf,
0129                                         const bool                     theIsHollow,
0130                                         const SelectMgr_ViewClipRange& theClipRange,
0131                                         SelectBasics_PickResult& thePickResult) const override;
0132 
0133   //! Returns true if selecting volume is overlapped by cylinder (or cone) with radiuses
0134   //! theBottomRad and theTopRad, height theHeight and transformation to apply theTrsf.
0135   Standard_EXPORT bool OverlapsCylinder(const double   theBottomRad,
0136                                         const double   theTopRad,
0137                                         const double   theHeight,
0138                                         const gp_Trsf& theTrsf,
0139                                         const bool     theIsHollow,
0140                                         bool*          theInside = nullptr) const override;
0141 
0142   //! Returns true if selecting volume is overlapped by circle with radius theRadius,
0143   //! boolean theIsFilled and transformation to apply theTrsf.
0144   //! The position and orientation of the circle are specified
0145   //! via theTrsf transformation for gp::XOY() with center in gp::Origin().
0146   Standard_EXPORT bool OverlapsCircle(const double                   theRadius,
0147                                       const gp_Trsf&                 theTrsf,
0148                                       const bool                     theIsFilled,
0149                                       const SelectMgr_ViewClipRange& theClipRange,
0150                                       SelectBasics_PickResult&       thePickResult) const override;
0151 
0152   //! Returns true if selecting volume is overlapped by circle with radius theRadius,
0153   //! boolean theIsFilled and transformation to apply theTrsf.
0154   //! The position and orientation of the circle are specified
0155   //! via theTrsf transformation for gp::XOY() with center in gp::Origin().
0156   Standard_EXPORT bool OverlapsCircle(const double   theRadius,
0157                                       const gp_Trsf& theTrsf,
0158                                       const bool     theIsFilled,
0159                                       bool*          theInside = nullptr) const override;
0160 
0161 public:
0162   //! Nullifies the handle to corresponding builder instance to prevent memory leaks
0163   Standard_EXPORT void Clear();
0164 
0165   //! Stores plane equation coefficients (in the following form:
0166   //! Ax + By + Cz + D = 0) to the given vector
0167   Standard_EXPORT void GetPlanes(
0168     NCollection_DynamicArray<NCollection_Vec4<double>>& thePlaneEquations) const override;
0169 
0170   //! Dumps the content of me into the stream
0171   Standard_EXPORT void DumpJson(Standard_OStream& theOStream, int theDepth = -1) const override;
0172 
0173 protected:
0174   //! Creates an empty triangular frustum.
0175   Standard_EXPORT SelectMgr_TriangularFrustum();
0176 
0177 private:
0178   void cacheVertexProjections(SelectMgr_TriangularFrustum* theFrustum) const;
0179 
0180 protected:
0181   // clang-format off
0182   SelectionTriangle mySelTriangle; //!< parameters of selection triangle (it is used to build triangle frustum)
0183   // clang-format on
0184 
0185 public:
0186   DEFINE_STANDARD_RTTIEXT(SelectMgr_TriangularFrustum, SelectMgr_Frustum<3>)
0187   friend class SelectMgr_TriangularFrustumSet;
0188 };
0189 
0190 #endif // _SelectMgr_TriangularFrustum_HeaderFile