Back to home page

EIC code displayed by LXR

 
 

    


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

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 case
0022 //! of point and box selection, and algorithms for overlap detection between selecting
0023 //! frustum 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 
0053   SelectMgr_Frustum() : 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, Standard_Integer theDepth = -1) const Standard_OVERRIDE;
0063 
0064 protected:
0065 
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,
0079                                       const gp_Pnt& thePnt2) const;
0080 
0081   //! SAT intersection test between frustum given and planar convex polygon represented as ordered 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 cylinder.
0111   Standard_Boolean isInsideCylinderEndFace (const Standard_Real theBottomRad,
0112                                             const Standard_Real theTopRad,
0113                                             const Standard_Real theHeight,
0114                                             const gp_Trsf& theTrsf,
0115                                             const TColgp_Array1OfPnt& theVertices) const;
0116 
0117   //! Checking whether the point thePnt is inside the shape with borders theVertices.
0118   //! thePnt and theVertices lie in the same plane.
0119   Standard_Boolean isDotInside (const gp_Pnt& thePnt,
0120                                 const TColgp_Array1OfPnt& theVertices) const;
0121 
0122 private:
0123 
0124   //! Return true if one segment enclosed between the points thePnt1Seg1 and thePnt2Seg1
0125   //! intersects another segment that enclosed between thePnt1Seg2 and thePnt2Seg2.
0126   Standard_Boolean isSegmentsIntersect (const gp_Pnt& thePnt1Seg1,
0127                                         const gp_Pnt& thePnt2Seg1,
0128                                         const gp_Pnt& thePnt1Seg2,
0129                                         const gp_Pnt& thePnt2Seg2) const;
0130 
0131   //! Checking whether the borders theVertices of the shape intersect
0132   //! the cylinder (or cone) end face with the center theCenter and radius theRadius
0133   Standard_Boolean isIntersectCircle (const Standard_Real theRadius,
0134                                       const gp_Pnt& theCenter,
0135                                       const gp_Trsf& theTrsf,
0136                                       const TColgp_Array1OfPnt& theVertices) const;
0137 
0138   //! Checks if AABB and frustum are separated along the given axis
0139   Standard_Boolean isSeparated (const SelectMgr_Vec3& theBoxMin,
0140                                 const SelectMgr_Vec3& theBoxMax,
0141                                 const gp_XYZ&         theDirect,
0142                                 Standard_Boolean*     theInside) const;
0143 
0144   //! Checks if triangle and frustum are separated along the given axis
0145   Standard_Boolean isSeparated (const gp_Pnt& thePnt1,
0146                                 const gp_Pnt& thePnt2,
0147                                 const gp_Pnt& thePnt3,
0148                                 const gp_XYZ& theAxis) const;
0149 
0150 protected:
0151 
0152   gp_Vec myPlanes[N + 2];        //!< Plane equations
0153   gp_Pnt myVertices[N * 2];      //!< Vertices coordinates
0154 
0155   Standard_Real myMaxVertsProjections[N + 2];      //!< Cached projections of vertices onto frustum plane directions
0156   Standard_Real myMinVertsProjections[N + 2];      //!< Cached projections of vertices onto frustum plane directions
0157   Standard_Real myMaxOrthoVertsProjections[3];     //!< Cached projections of vertices onto directions of ortho unit vectors
0158   Standard_Real myMinOrthoVertsProjections[3];     //!< Cached projections of vertices onto directions of ortho unit vectors
0159 
0160   gp_Vec myEdgeDirs[6];                    //!< Cached edge directions
0161 };
0162 
0163 #include <SelectMgr_Frustum.lxx>
0164 
0165 #endif // _SelectMgr_Frustum_HeaderFile