Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-14 09:15:47

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_TriangularFrustumSet_HeaderFile
0017 #define _SelectMgr_TriangularFrustumSet_HeaderFile
0018 
0019 #include <SelectMgr_TriangularFrustum.hxx>
0020 #include <gp_Pnt2d.hxx>
0021 #include <NCollection_Array1.hxx>
0022 #include <NCollection_HArray1.hxx>
0023 
0024 //! This class is used to handle polyline selection. The main principle of polyline selection
0025 //! algorithm is to split the polygon defined by polyline onto triangles.
0026 //! Than each of them is considered as a base for triangular frustum building.
0027 //! In other words, each triangle vertex will be projected from 2d screen space to 3d world space
0028 //! onto near and far view frustum planes. Thus, the projected triangles make up the bases of
0029 //! selecting frustum. When the set of such frustums is created, the function determining selection
0030 //! iterates through triangular frustum set and searches for overlap with any frustum.
0031 class SelectMgr_TriangularFrustumSet : public SelectMgr_BaseFrustum
0032 {
0033 public:
0034   //! Auxiliary structure to define selection polyline
0035   struct SelectionPolyline
0036   {
0037     occ::handle<NCollection_HArray1<gp_Pnt2d>> Points;
0038   };
0039 
0040 public:
0041   //! Constructor.
0042   SelectMgr_TriangularFrustumSet();
0043 
0044   //! Destructor.
0045   Standard_EXPORT ~SelectMgr_TriangularFrustumSet() override;
0046 
0047   //! Initializes set of triangular frustums by polyline
0048   Standard_EXPORT void Init(const NCollection_Array1<gp_Pnt2d>& thePoints);
0049 
0050   //! Meshes polygon bounded by polyline. Than organizes a set of triangular frustums,
0051   //! where each triangle's projection onto near and far view frustum planes is considered as a
0052   //! frustum base NOTE: it should be called after Init() method
0053   Standard_EXPORT void Build() override;
0054 
0055   //! Returns FALSE (not applicable to this volume).
0056   bool IsScalable() const override { return false; }
0057 
0058   //! Returns a copy of the frustum with all sub-volumes transformed according to the matrix given
0059   Standard_EXPORT occ::handle<SelectMgr_BaseIntersector> ScaleAndTransform(
0060     const int                                    theScale,
0061     const gp_GTrsf&                              theTrsf,
0062     const occ::handle<SelectMgr_FrustumBuilder>& theBuilder) const override;
0063 
0064   //! Returns a copy of the frustum using the given frustum builder configuration.
0065   //! Returned frustum should be re-constructed before being used.
0066   //! @param[in] theBuilder  argument that represents corresponding settings for re-constructing
0067   //! transformed frustum from scratch;
0068   //!                        should NOT be NULL.
0069   //! @return a copy of the frustum with the input builder assigned
0070   Standard_EXPORT occ::handle<SelectMgr_BaseIntersector> CopyWithBuilder(
0071     const occ::handle<SelectMgr_FrustumBuilder>& theBuilder) const override;
0072 
0073 public:
0074   Standard_EXPORT bool OverlapsBox(const NCollection_Vec3<double>& theMinPnt,
0075                                    const NCollection_Vec3<double>& theMaxPnt,
0076                                    const SelectMgr_ViewClipRange&  theClipRange,
0077                                    SelectBasics_PickResult&        thePickResult) const override;
0078 
0079   Standard_EXPORT bool OverlapsBox(const NCollection_Vec3<double>& theMinPnt,
0080                                    const NCollection_Vec3<double>& theMaxPnt,
0081                                    bool*                           theInside) const override;
0082 
0083   Standard_EXPORT bool OverlapsPoint(const gp_Pnt&                  thePnt,
0084                                      const SelectMgr_ViewClipRange& theClipRange,
0085                                      SelectBasics_PickResult&       thePickResult) const override;
0086 
0087   //! Returns TRUE when the point's near-plane projection lies inside the polyline loop.
0088   Standard_EXPORT bool OverlapsPoint(const gp_Pnt& thePnt) const override;
0089 
0090   Standard_EXPORT bool OverlapsPolygon(const NCollection_Array1<gp_Pnt>& theArrayOfPnts,
0091                                        Select3D_TypeOfSensitivity        theSensType,
0092                                        const SelectMgr_ViewClipRange&    theClipRange,
0093                                        SelectBasics_PickResult& thePickResult) const override;
0094 
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   Standard_EXPORT bool OverlapsTriangle(const gp_Pnt&                  thePnt1,
0101                                         const gp_Pnt&                  thePnt2,
0102                                         const gp_Pnt&                  thePnt3,
0103                                         Select3D_TypeOfSensitivity     theSensType,
0104                                         const SelectMgr_ViewClipRange& theClipRange,
0105                                         SelectBasics_PickResult& thePickResult) const override;
0106 
0107 public:
0108   //! Calculates the point on a view ray that was detected during the run of selection algo by given
0109   //! depth
0110   Standard_EXPORT gp_Pnt DetectedPoint(const double theDepth) const override;
0111 
0112   //! Returns true if selecting volume is overlapped by sphere with center theCenter
0113   //! and radius theRadius
0114   Standard_EXPORT bool OverlapsSphere(const gp_Pnt& theCenter,
0115                                       const double  theRadius,
0116                                       bool*         theInside = nullptr) const override;
0117 
0118   //! Returns true if selecting volume is overlapped by sphere with center theCenter
0119   //! and radius theRadius
0120   Standard_EXPORT bool OverlapsSphere(const gp_Pnt&                  theCenter,
0121                                       const double                   theRadius,
0122                                       const SelectMgr_ViewClipRange& theClipRange,
0123                                       SelectBasics_PickResult&       thePickResult) const override;
0124 
0125   //! Returns true if selecting volume is overlapped by cylinder (or cone) with radiuses
0126   //! theBottomRad and theTopRad, height theHeight and transformation to apply theTrsf.
0127   Standard_EXPORT bool OverlapsCylinder(const double                   theBottomRad,
0128                                         const double                   theTopRad,
0129                                         const double                   theHeight,
0130                                         const gp_Trsf&                 theTrsf,
0131                                         const bool                     theIsHollow,
0132                                         const SelectMgr_ViewClipRange& theClipRange,
0133                                         SelectBasics_PickResult& thePickResult) const override;
0134 
0135   //! Returns true if selecting volume is overlapped by cylinder (or cone) with radiuses
0136   //! theBottomRad and theTopRad, height theHeight and transformation to apply theTrsf.
0137   Standard_EXPORT bool OverlapsCylinder(const double   theBottomRad,
0138                                         const double   theTopRad,
0139                                         const double   theHeight,
0140                                         const gp_Trsf& theTrsf,
0141                                         const bool     theIsHollow,
0142                                         bool*          theInside = nullptr) const override;
0143 
0144   //! Returns true if selecting volume is overlapped by cylinder (or cone) with radiuses
0145   //! theBottomRad and theTopRad, height theHeight and transformation to apply theTrsf.
0146   Standard_EXPORT bool OverlapsCircle(const double                   theBottomRad,
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 cylinder (or cone) with radiuses
0153   //! theBottomRad and theTopRad, height theHeight and transformation to apply theTrsf.
0154   Standard_EXPORT bool OverlapsCircle(const double   theBottomRad,
0155                                       const gp_Trsf& theTrsf,
0156                                       const bool     theIsFilled,
0157                                       bool*          theInside = nullptr) const override;
0158 
0159   //! Stores plane equation coefficients (in the following form:
0160   //! Ax + By + Cz + D = 0) to the given vector
0161   Standard_EXPORT void GetPlanes(
0162     NCollection_DynamicArray<NCollection_Vec4<double>>& thePlaneEquations) const override;
0163 
0164   //! If theIsToAllow is false, only fully included sensitives will be detected, otherwise the
0165   //! algorithm will mark both included and overlapped entities as matched
0166   Standard_EXPORT virtual void SetAllowOverlapDetection(const bool theIsToAllow);
0167 
0168   //! Dumps the content of me into the stream
0169   Standard_EXPORT void DumpJson(Standard_OStream& theOStream, int theDepth = -1) const override;
0170 
0171 private:
0172   //! Returns TRUE when the given world-space point lies inside any of the
0173   //! triangular frustums of the polyline prism. Delegates to the SAT-based
0174   //! hasPointOverlap() on each child frustum, which is correct for both
0175   //! orthographic and perspective cameras.
0176   Standard_EXPORT bool isPointInsideAnyFrustum(const gp_Pnt& thePnt) const;
0177 
0178   //! Checks whether the segment intersects with the boundary of the current volume selection
0179   Standard_EXPORT bool isIntersectBoundary(const gp_Pnt& thePnt1, const gp_Pnt& thePnt2) const;
0180 
0181   //! Checks whether the circle intersects with the boundary of the current volume selection
0182   Standard_EXPORT bool isIntersectBoundary(const double   theRadius,
0183                                            const gp_Trsf& theTrsf,
0184                                            const bool     theIsFilled) const;
0185 
0186   //! Checks whether the triangle intersects with a segment
0187   Standard_EXPORT static bool segmentTriangleIntersection(const gp_Pnt& theOrig,
0188                                                           const gp_Vec& theDir,
0189                                                           const gp_Pnt& theV1,
0190                                                           const gp_Pnt& theV2,
0191                                                           const gp_Pnt& theV3);
0192 
0193   Standard_EXPORT static bool segmentSegmentIntersection(const gp_Pnt& theStartPnt1,
0194                                                          const gp_Pnt& theEndPnt1,
0195                                                          const gp_Pnt& theStartPnt2,
0196                                                          const gp_Pnt& theEndPnt2);
0197 
0198   Standard_EXPORT static bool pointInTriangle(const gp_Pnt& thePnt,
0199                                               const gp_Pnt& theV1,
0200                                               const gp_Pnt& theV2,
0201                                               const gp_Pnt& theV3);
0202 
0203 private:
0204   NCollection_List<occ::handle<SelectMgr_TriangularFrustum>>
0205     myFrustums; //!< set of triangular frustums
0206   // clang-format off
0207   SelectionPolyline             mySelPolyline;       //!< parameters of selection polyline (it is used to build triangle frustum set)
0208   NCollection_Array1<gp_Pnt>            myBoundaryPoints;    //!< boundary points
0209                                                      //!       1_____2
0210                                                      //!      /|     |\ .
0211                                                      //!    4/_|_____|_\3
0212                                                      //!    | 5|_____|6 |
0213                                                      //!    | /       \ |
0214                                                      //!   8|/_________\|7
0215   bool              myToAllowOverlap;    //!< flag to detect only fully included sensitives or not
0216   // clang-format on
0217 };
0218 
0219 #endif // _SelectMgr_TriangularFrustumSet_HeaderFile