Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:04:54

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 <TColgp_HArray1OfPnt2d.hxx>
0021 
0022 typedef NCollection_List<Handle(SelectMgr_TriangularFrustum)> SelectMgr_TriangFrustums;
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 onto near and far view frustum planes.
0028 //! Thus, the projected triangles make up the bases of selecting frustum.
0029 //! When the set of such frustums is created, the function determining
0030 //! selection iterates through triangular frustum set and searches for overlap with any frustum.
0031 class SelectMgr_TriangularFrustumSet : public SelectMgr_BaseFrustum
0032 {
0033 public:
0034 
0035   //! Auxiliary structure to define selection polyline
0036   struct SelectionPolyline
0037   {
0038     Handle(TColgp_HArray1OfPnt2d) Points;
0039   };
0040 
0041 public:
0042 
0043   //! Constructor.
0044   SelectMgr_TriangularFrustumSet();
0045 
0046   //! Destructor.
0047   Standard_EXPORT virtual ~SelectMgr_TriangularFrustumSet();
0048 
0049   //! Initializes set of triangular frustums by polyline
0050   Standard_EXPORT void Init (const TColgp_Array1OfPnt2d& thePoints);
0051 
0052   //! Meshes polygon bounded by polyline. Than organizes a set of triangular frustums,
0053   //! where each triangle's projection onto near and far view frustum planes is considered as a frustum base
0054   //! NOTE: it should be called after Init() method
0055   Standard_EXPORT virtual void Build() Standard_OVERRIDE;
0056 
0057   //! Returns FALSE (not applicable to this volume).
0058   virtual Standard_Boolean IsScalable() const Standard_OVERRIDE { return false; }
0059 
0060   //! Returns a copy of the frustum with all sub-volumes transformed according to the matrix given
0061   Standard_EXPORT virtual Handle(SelectMgr_BaseIntersector) ScaleAndTransform (const Standard_Integer theScale,
0062                                                                                const gp_GTrsf& theTrsf,
0063                                                                                const Handle(SelectMgr_FrustumBuilder)& theBuilder) const Standard_OVERRIDE;
0064 
0065 public:
0066 
0067   Standard_EXPORT virtual Standard_Boolean OverlapsBox (const SelectMgr_Vec3& theMinPnt,
0068                                                         const SelectMgr_Vec3& theMaxPnt,
0069                                                         const SelectMgr_ViewClipRange& theClipRange,
0070                                                         SelectBasics_PickResult& thePickResult) const Standard_OVERRIDE;
0071 
0072   Standard_EXPORT virtual Standard_Boolean OverlapsBox (const SelectMgr_Vec3& theMinPnt,
0073                                                         const SelectMgr_Vec3& theMaxPnt,
0074                                                         Standard_Boolean* theInside) const Standard_OVERRIDE;
0075 
0076   Standard_EXPORT virtual Standard_Boolean OverlapsPoint (const gp_Pnt& thePnt,
0077                                                           const SelectMgr_ViewClipRange& theClipRange,
0078                                                           SelectBasics_PickResult& thePickResult) const Standard_OVERRIDE;
0079 
0080   //! Always returns FALSE (not applicable to this selector).
0081   virtual Standard_Boolean OverlapsPoint (const gp_Pnt& ) const Standard_OVERRIDE
0082   {
0083     return Standard_False;
0084   }
0085 
0086   Standard_EXPORT virtual Standard_Boolean OverlapsPolygon (const TColgp_Array1OfPnt& theArrayOfPnts,
0087                                                             Select3D_TypeOfSensitivity theSensType,
0088                                                             const SelectMgr_ViewClipRange& theClipRange,
0089                                                             SelectBasics_PickResult& thePickResult) const Standard_OVERRIDE;
0090 
0091   Standard_EXPORT virtual Standard_Boolean OverlapsSegment (const gp_Pnt& thePnt1,
0092                                                             const gp_Pnt& thePnt2,
0093                                                             const SelectMgr_ViewClipRange& theClipRange,
0094                                                             SelectBasics_PickResult& thePickResult) const Standard_OVERRIDE;
0095 
0096   Standard_EXPORT virtual Standard_Boolean OverlapsTriangle (const gp_Pnt& thePnt1,
0097                                                              const gp_Pnt& thePnt2,
0098                                                              const gp_Pnt& thePnt3,
0099                                                              Select3D_TypeOfSensitivity theSensType,
0100                                                              const SelectMgr_ViewClipRange& theClipRange,
0101                                                              SelectBasics_PickResult& thePickResult) const Standard_OVERRIDE;
0102 
0103 public:
0104 
0105   //! Calculates the point on a view ray that was detected during the run of selection algo by given depth
0106   Standard_EXPORT virtual gp_Pnt DetectedPoint (const Standard_Real theDepth) const Standard_OVERRIDE;
0107 
0108   //! Returns true if selecting volume is overlapped by sphere with center theCenter
0109   //! and radius theRadius
0110   Standard_EXPORT virtual Standard_Boolean OverlapsSphere (const gp_Pnt& theCenter,
0111                                                            const Standard_Real theRadius,
0112                                                            Standard_Boolean* theInside = NULL) const Standard_OVERRIDE;
0113 
0114   //! Returns true if selecting volume is overlapped by sphere with center theCenter
0115   //! and radius theRadius
0116   Standard_EXPORT virtual Standard_Boolean OverlapsSphere (const gp_Pnt& theCenter,
0117                                                            const Standard_Real theRadius,
0118                                                            const SelectMgr_ViewClipRange& theClipRange,
0119                                                            SelectBasics_PickResult& thePickResult) const Standard_OVERRIDE;
0120 
0121   //! Returns true if selecting volume is overlapped by cylinder (or cone) with radiuses theBottomRad
0122   //! and theTopRad, height theHeight and transformation to apply theTrsf.
0123   Standard_EXPORT virtual Standard_Boolean OverlapsCylinder (const Standard_Real theBottomRad,
0124                                                              const Standard_Real theTopRad,
0125                                                              const Standard_Real theHeight,
0126                                                              const gp_Trsf& theTrsf,
0127                                                              const Standard_Boolean theIsHollow,
0128                                                              const SelectMgr_ViewClipRange& theClipRange,
0129                                                              SelectBasics_PickResult& thePickResult) const Standard_OVERRIDE;
0130 
0131   //! Returns true if selecting volume is overlapped by cylinder (or cone) with radiuses theBottomRad
0132   //! and theTopRad, height theHeight and transformation to apply theTrsf.
0133   Standard_EXPORT virtual Standard_Boolean OverlapsCylinder (const Standard_Real theBottomRad,
0134                                                              const Standard_Real theTopRad,
0135                                                              const Standard_Real theHeight,
0136                                                              const gp_Trsf& theTrsf,
0137                                                              const Standard_Boolean theIsHollow,
0138                                                              Standard_Boolean* theInside = NULL) const Standard_OVERRIDE;
0139 
0140   //! Returns true if selecting volume is overlapped by cylinder (or cone) with radiuses theBottomRad
0141   //! and theTopRad, height theHeight and transformation to apply theTrsf.
0142   Standard_EXPORT virtual Standard_Boolean OverlapsCircle (const Standard_Real theBottomRad,
0143                                                            const gp_Trsf& theTrsf,
0144                                                            const Standard_Boolean theIsFilled,
0145                                                            const SelectMgr_ViewClipRange& theClipRange,
0146                                                            SelectBasics_PickResult& thePickResult) const Standard_OVERRIDE;
0147 
0148   //! Returns true if selecting volume is overlapped by cylinder (or cone) with radiuses theBottomRad
0149   //! and theTopRad, height theHeight and transformation to apply theTrsf.
0150   Standard_EXPORT virtual Standard_Boolean OverlapsCircle (const Standard_Real theBottomRad,
0151                                                            const gp_Trsf& theTrsf,
0152                                                            const Standard_Boolean theIsFilled,
0153                                                            Standard_Boolean* theInside = NULL) const Standard_OVERRIDE;
0154 
0155   //! Stores plane equation coefficients (in the following form:
0156   //! Ax + By + Cz + D = 0) to the given vector
0157   Standard_EXPORT virtual void GetPlanes (NCollection_Vector<SelectMgr_Vec4>& thePlaneEquations) const Standard_OVERRIDE;
0158 
0159   //! If theIsToAllow is false, only fully included sensitives will be detected, otherwise the algorithm will
0160   //! mark both included and overlapped entities as matched
0161   Standard_EXPORT virtual void SetAllowOverlapDetection (const Standard_Boolean theIsToAllow);
0162 
0163   //! Dumps the content of me into the stream
0164   Standard_EXPORT virtual void DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth = -1) const Standard_OVERRIDE;
0165 
0166 private:
0167 
0168   //! Checks whether the segment intersects with the boundary of the current volume selection
0169   Standard_EXPORT Standard_Boolean isIntersectBoundary (const gp_Pnt& thePnt1, const gp_Pnt& thePnt2) const;
0170 
0171   //! Checks whether the circle intersects with the boundary of the current volume selection
0172   Standard_EXPORT Standard_Boolean isIntersectBoundary (const Standard_Real theRadius,
0173                                                         const gp_Trsf& theTrsf,
0174                                                         const Standard_Boolean theIsFilled) const;
0175 
0176   //! Checks whether the triangle intersects with a segment
0177   Standard_EXPORT static Standard_Boolean segmentTriangleIntersection (const gp_Pnt &theOrig, const gp_Vec& theDir,
0178                                                                        const gp_Pnt& theV1, const gp_Pnt& theV2, const gp_Pnt& theV3);
0179 
0180   Standard_EXPORT static Standard_Boolean segmentSegmentIntersection (const gp_Pnt& theStartPnt1,
0181                                                                       const gp_Pnt& theEndPnt1,
0182                                                                       const gp_Pnt& theStartPnt2,
0183                                                                       const gp_Pnt& theEndPnt2);
0184 
0185   Standard_EXPORT static Standard_Boolean pointInTriangle (const gp_Pnt& thePnt,
0186                                                            const gp_Pnt& theV1, const gp_Pnt& theV2, const gp_Pnt& theV3);
0187 
0188 private:
0189 
0190   SelectMgr_TriangFrustums      myFrustums;          //!< set of triangular frustums
0191   SelectionPolyline             mySelPolyline;       //!< parameters of selection polyline (it is used to build triangle frustum set)
0192   TColgp_Array1OfPnt            myBoundaryPoints;    //!< boundary points
0193                                                      //!       1_____2
0194                                                      //!      /|     |\ .
0195                                                      //!    4/_|_____|_\3
0196                                                      //!    | 5|_____|6 |
0197                                                      //!    | /       \ |
0198                                                      //!   8|/_________\|7
0199   Standard_Boolean              myToAllowOverlap;    //!< flag to detect only fully included sensitives or not
0200 };
0201 
0202 #endif // _SelectMgr_TriangularFrustumSet_HeaderFile