Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-07-04 08:33:01

0001 // Created on: 2015-03-16
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_Frustum_HeaderFile
0017 #define _SelectMgr_Frustum_HeaderFile
0018 
0019 #include <SelectMgr_BaseFrustum.hxx>
0020 
0021 //! This is an internal class containing representation of rectangular selecting frustum, created in
0022 //! case of point and box selection, and algorithms for overlap detection between selecting frustum
0023 //! and sensitive entities. The principle of frustum calculation:
0024 //! - for point selection: on a near view frustum plane rectangular neighborhood of
0025 //!                        user-picked point is created according to the pixel tolerance
0026 //!                        given and then this rectangle is projected onto far view frustum
0027 //!                        plane. This rectangles define the parallel bases of selecting frustum;
0028 //! - for box selection: box points are projected onto near and far view frustum planes.
0029 //!                      These 2 projected rectangles define parallel bases of selecting frustum.
0030 //! Overlap detection tests are implemented according to the terms of separating axis
0031 //! theorem (SAT).
0032 //! Vertex order:
0033 //! - for triangular frustum: V0_Near, V1_Near, V2_Near,
0034 //!                           V0_Far, V1_Far, V2_Far;
0035 //! - for rectangular frustum: LeftTopNear, LeftTopFar,
0036 //!                            LeftBottomNear,LeftBottomFar,
0037 //!                            RightTopNear, RightTopFar,
0038 //!                            RightBottomNear, RightBottomFar.
0039 //! Plane order in array:
0040 //! - for triangular frustum: V0V1, V1V2, V0V2, Near, Far;
0041 //! - for rectangular frustum: Top, Bottom, Left, Right, Near, Far.
0042 //! Uncollinear edge directions order:
0043 //! - for rectangular frustum: Horizontal, Vertical,
0044 //!                            LeftLower, RightLower,
0045 //!                            LeftUpper, RightUpper;
0046 //! - for triangular frustum: V0_Near - V0_Far, V1_Near - V1_Far, V2_Near - V2_Far,
0047 //!                           V1_Near - V0_Near, V2_Near - V1_Near, V2_Near - V0_Near.
0048 template <int N>
0049 class SelectMgr_Frustum : public SelectMgr_BaseFrustum
0050 {
0051 public:
0052   SelectMgr_Frustum()
0053       : SelectMgr_BaseFrustum()
0054   {
0055     memset(myMaxOrthoVertsProjections, 0, sizeof(myMaxOrthoVertsProjections));
0056     memset(myMinOrthoVertsProjections, 0, sizeof(myMinOrthoVertsProjections));
0057     memset(myMaxVertsProjections, 0, sizeof(myMaxVertsProjections));
0058     memset(myMinVertsProjections, 0, sizeof(myMinVertsProjections));
0059   }
0060 
0061   //! Dumps the content of me into the stream
0062   inline virtual void DumpJson(Standard_OStream& theOStream,
0063                                Standard_Integer  theDepth = -1) const Standard_OVERRIDE;
0064 
0065 protected:
0066   // SAT Tests for different objects
0067 
0068   //! Returns true if selecting volume is overlapped by axis-aligned bounding box
0069   //! with minimum corner at point theMinPt and maximum at point theMaxPt
0070   Standard_Boolean hasBoxOverlap(const SelectMgr_Vec3& theBoxMin,
0071                                  const SelectMgr_Vec3& theBoxMax,
0072                                  Standard_Boolean*     theInside = NULL) const;
0073 
0074   //! SAT intersection test between defined volume and given point
0075   Standard_Boolean hasPointOverlap(const gp_Pnt& thePnt) const;
0076 
0077   //! SAT intersection test between defined volume and given segment
0078   Standard_Boolean hasSegmentOverlap(const gp_Pnt& thePnt1, const gp_Pnt& thePnt2) const;
0079 
0080   //! SAT intersection test between frustum given and planar convex polygon represented as ordered
0081   //! point set
0082   Standard_Boolean hasPolygonOverlap(const TColgp_Array1OfPnt& theArrayOfPnts,
0083                                      gp_Vec&                   theNormal) const;
0084 
0085   //! SAT intersection test between defined volume and given triangle
0086   Standard_Boolean hasTriangleOverlap(const gp_Pnt& thePnt1,
0087                                       const gp_Pnt& thePnt2,
0088                                       const gp_Pnt& thePnt3,
0089                                       gp_Vec&       theNormal) const;
0090 
0091   //! Intersection test between defined volume and given sphere
0092   Standard_Boolean hasSphereOverlap(const gp_Pnt&       thePnt1,
0093                                     const Standard_Real theRadius,
0094                                     Standard_Boolean*   theInside = NULL) const;
0095 
0096   //! Intersection test between defined volume and given cylinder (or cone).
0097   Standard_Boolean hasCylinderOverlap(const Standard_Real    theBottomRad,
0098                                       const Standard_Real    theTopRad,
0099                                       const Standard_Real    theHeight,
0100                                       const gp_Trsf&         theTrsf,
0101                                       const Standard_Boolean theIsHollow,
0102                                       Standard_Boolean*      theInside = NULL) const;
0103 
0104   //! Intersection test between defined volume and given circle.
0105   Standard_Boolean hasCircleOverlap(const Standard_Real    theRadius,
0106                                     const gp_Trsf&         theTrsf,
0107                                     const Standard_Boolean theIsFilled,
0108                                     Standard_Boolean*      theInside = NULL) const;
0109 
0110   //! Returns True if all vertices (theVertices) are inside the top and bottom sides of the
0111   //! cylinder.
0112   Standard_Boolean isInsideCylinderEndFace(const Standard_Real       theBottomRad,
0113                                            const Standard_Real       theTopRad,
0114                                            const Standard_Real       theHeight,
0115                                            const gp_Trsf&            theTrsf,
0116                                            const TColgp_Array1OfPnt& theVertices) const;
0117 
0118   //! Checking whether the point thePnt is inside the shape with borders theVertices.
0119   //! thePnt and theVertices lie in the same plane.
0120   Standard_Boolean isDotInside(const gp_Pnt& thePnt, const TColgp_Array1OfPnt& theVertices) const;
0121 
0122 private:
0123   //! Return true if one segment enclosed between the points thePnt1Seg1 and thePnt2Seg1
0124   //! intersects another segment that enclosed between thePnt1Seg2 and thePnt2Seg2.
0125   Standard_Boolean isSegmentsIntersect(const gp_Pnt& thePnt1Seg1,
0126                                        const gp_Pnt& thePnt2Seg1,
0127                                        const gp_Pnt& thePnt1Seg2,
0128                                        const gp_Pnt& thePnt2Seg2) const;
0129 
0130   //! Checking whether the borders theVertices of the shape intersect
0131   //! the cylinder (or cone) end face with the center theCenter and radius theRadius
0132   Standard_Boolean isIntersectCircle(const Standard_Real       theRadius,
0133                                      const gp_Pnt&             theCenter,
0134                                      const gp_Trsf&            theTrsf,
0135                                      const TColgp_Array1OfPnt& theVertices) const;
0136 
0137   //! Checks if AABB and frustum are separated along the given axis
0138   Standard_Boolean isSeparated(const SelectMgr_Vec3& theBoxMin,
0139                                const SelectMgr_Vec3& theBoxMax,
0140                                const gp_XYZ&         theDirect,
0141                                Standard_Boolean*     theInside) const;
0142 
0143   //! Checks if triangle and frustum are separated along the given axis
0144   Standard_Boolean isSeparated(const gp_Pnt& thePnt1,
0145                                const gp_Pnt& thePnt2,
0146                                const gp_Pnt& thePnt3,
0147                                const gp_XYZ& theAxis) const;
0148 
0149 protected:
0150   gp_Vec myPlanes[N + 2];   //!< Plane equations
0151   gp_Pnt myVertices[N * 2]; //!< Vertices coordinates
0152 
0153   // clang-format off
0154   Standard_Real myMaxVertsProjections[N + 2];      //!< Cached projections of vertices onto frustum plane directions
0155   Standard_Real myMinVertsProjections[N + 2];      //!< Cached projections of vertices onto frustum plane directions
0156   Standard_Real myMaxOrthoVertsProjections[3];     //!< Cached projections of vertices onto directions of ortho unit vectors
0157   Standard_Real myMinOrthoVertsProjections[3];     //!< Cached projections of vertices onto directions of ortho unit vectors
0158   // clang-format on
0159 
0160   gp_Vec myEdgeDirs[6]; //!< Cached edge directions
0161 };
0162 
0163 #include <SelectMgr_Frustum.lxx>
0164 
0165 #endif // _SelectMgr_Frustum_HeaderFile