Back to home page

EIC code displayed by LXR

 
 

    


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

0001 // Copyright (c) 1999-2014 OPEN CASCADE SAS
0002 //
0003 // This file is part of Open CASCADE Technology software library.
0004 //
0005 // This library is free software; you can redistribute it and/or modify it under
0006 // the terms of the GNU Lesser General Public License version 2.1 as published
0007 // by the Free Software Foundation, with special exception defined in the file
0008 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
0009 // distribution for complete text of the license and disclaimer of any warranty.
0010 //
0011 // Alternatively, this file may be used under the terms of Open CASCADE
0012 // commercial license or contractual agreement.
0013 
0014 #ifndef _Select3D_SensitivePoly_HeaderFile
0015 #define _Select3D_SensitivePoly_HeaderFile
0016 
0017 #include <gp_Circ.hxx>
0018 #include <Select3D_PointData.hxx>
0019 #include <Select3D_SensitiveSet.hxx>
0020 #include <Select3D_TypeOfSensitivity.hxx>
0021 #include <Standard_Integer.hxx>
0022 #include <NCollection_Array1.hxx>
0023 #include <NCollection_HArray1.hxx>
0024 #include <gp_Pnt.hxx>
0025 
0026 //! Sensitive Entity to make a face selectable.
0027 //! In some cases this class can raise Standard_ConstructionError and
0028 //! Standard_OutOfRange exceptions from its member Select3D_PointData
0029 //! myPolyg.
0030 class Select3D_SensitivePoly : public Select3D_SensitiveSet
0031 {
0032   DEFINE_STANDARD_RTTIEXT(Select3D_SensitivePoly, Select3D_SensitiveSet)
0033 public:
0034   //! Constructs a sensitive face object defined by the
0035   //! owner OwnerId, the array of points ThePoints, and
0036   //! the sensitivity type Sensitivity.
0037   //! The array of points is the outer polygon of the geometric face.
0038   Standard_EXPORT Select3D_SensitivePoly(const occ::handle<SelectMgr_EntityOwner>& theOwnerId,
0039                                          const NCollection_Array1<gp_Pnt>&         thePoints,
0040                                          const bool                                theIsBVHEnabled);
0041 
0042   //! Constructs a sensitive face object defined by the
0043   //! owner OwnerId, the array of points ThePoints, and
0044   //! the sensitivity type Sensitivity.
0045   //! The array of points is the outer polygon of the geometric face.
0046   Standard_EXPORT Select3D_SensitivePoly(const occ::handle<SelectMgr_EntityOwner>&       theOwnerId,
0047                                          const occ::handle<NCollection_HArray1<gp_Pnt>>& thePoints,
0048                                          const bool theIsBVHEnabled);
0049 
0050   //! Constructs the sensitive arc object defined by the
0051   //! owner theOwnerId, the circle theCircle, the parameters theU1
0052   //! and theU2, the boolean theIsFilled and the number of points theNbPnts.
0053   //! theU1 and theU2 define the first and last points of the arc on theCircle.
0054   Standard_EXPORT Select3D_SensitivePoly(const occ::handle<SelectMgr_EntityOwner>& theOwnerId,
0055                                          const gp_Circ&                            theCircle,
0056                                          const double                              theU1,
0057                                          const double                              theU2,
0058                                          const bool theIsFilled = false,
0059                                          const int  theNbPnts   = 12);
0060 
0061   //! Constructs a sensitive curve or arc object defined by the
0062   //! owner theOwnerId, the theIsBVHEnabled flag, and the
0063   //! maximum number of points on the curve: theNbPnts.
0064   Standard_EXPORT Select3D_SensitivePoly(const occ::handle<SelectMgr_EntityOwner>& theOwnerId,
0065                                          const bool                                theIsBVHEnabled,
0066                                          const int                                 theNbPnts = 6);
0067 
0068   //! Checks whether the poly overlaps current selecting volume
0069   Standard_EXPORT bool Matches(SelectBasics_SelectingVolumeManager& theMgr,
0070                                SelectBasics_PickResult&             thePickResult) override;
0071 
0072   //! Returns the amount of segments in poly
0073   Standard_EXPORT int NbSubElements() const override;
0074 
0075   //! Returns the 3D points of the array used at construction time.
0076   //! @return handle to array of 3D points
0077   [[nodiscard]] occ::handle<NCollection_HArray1<gp_Pnt>> Points3D() const
0078   {
0079     int                                      aSize = myPolyg.Size();
0080     occ::handle<NCollection_HArray1<gp_Pnt>> aHArrayOfPnt =
0081       new NCollection_HArray1<gp_Pnt>(1, aSize);
0082     for (int anIndex = 1; anIndex <= aSize; anIndex++)
0083     {
0084       aHArrayOfPnt->SetValue(anIndex, myPolyg.Pnt(anIndex - 1));
0085     }
0086     return aHArrayOfPnt;
0087   }
0088 
0089   //! Returns the 3D points of the array used at construction time via output parameter.
0090   //! @deprecated Use Points3D() returning handle by value instead.
0091   Standard_DEPRECATED("Use Points3D() returning handle by value instead")
0092   void Points3D(occ::handle<NCollection_HArray1<gp_Pnt>>& aHArrayOfPnt)
0093   {
0094     aHArrayOfPnt = Points3D();
0095   }
0096 
0097   //! Return array bounds.
0098   void ArrayBounds(int& theLow, int& theUp) const
0099   {
0100     theLow = 0;
0101     theUp  = myPolyg.Size() - 1;
0102   }
0103 
0104   //! Return point.
0105   gp_Pnt GetPoint3d(const int thePntIdx) const
0106   {
0107     return (thePntIdx >= 0 && thePntIdx < myPolyg.Size()) ? myPolyg.Pnt(thePntIdx) : gp_Pnt();
0108   }
0109 
0110   //! Returns bounding box of a polygon. If location
0111   //! transformation is set, it will be applied
0112   Standard_EXPORT Select3D_BndBox3d BoundingBox() override;
0113 
0114   //! Returns center of the point set. If location transformation
0115   //! is set, it will be applied
0116   Standard_EXPORT gp_Pnt CenterOfGeometry() const override;
0117 
0118   //! Returns the amount of segments of the poly
0119   Standard_EXPORT int Size() const override;
0120 
0121   //! Returns bounding box of segment with index theIdx
0122   Standard_EXPORT Select3D_BndBox3d Box(const int theIdx) const override;
0123 
0124   //! Returns geometry center of sensitive entity index theIdx in the vector along
0125   //! the given axis theAxis
0126   Standard_EXPORT double Center(const int theIdx, const int theAxis) const override;
0127 
0128   //! Swaps items with indexes theIdx1 and theIdx2 in the vector
0129   Standard_EXPORT void Swap(const int theIdx1, const int theIdx2) override;
0130 
0131   //! Dumps the content of me into the stream
0132   Standard_EXPORT void DumpJson(Standard_OStream& theOStream, int theDepth = -1) const override;
0133 
0134 protected:
0135   //! Checks whether the segment with index theIdx overlaps the current selecting volume
0136   Standard_EXPORT bool overlapsElement(SelectBasics_PickResult&             thePickResult,
0137                                        SelectBasics_SelectingVolumeManager& theMgr,
0138                                        int                                  theElemIdx,
0139                                        bool theIsFullInside) override;
0140 
0141   //! Checks whether the entity with index theIdx is inside the current selecting volume
0142   Standard_EXPORT bool elementIsInside(SelectBasics_SelectingVolumeManager& theMgr,
0143                                        int                                  theElemIdx,
0144                                        bool theIsFullInside) override;
0145 
0146   //! Calculates distance from the 3d projection of used-picked screen point
0147   //! to center of the geometry
0148   Standard_EXPORT double distanceToCOG(SelectBasics_SelectingVolumeManager& theMgr) override;
0149 
0150 protected:
0151   Select3D_PointData                    myPolyg;          //!< Points of the poly
0152   mutable gp_Pnt                        myCOG;            //!< Center of the poly
0153   occ::handle<NCollection_HArray1<int>> mySegmentIndexes; //!< Segment indexes for BVH tree build
0154   Select3D_BndBox3d                     myBndBox;         //!< Bounding box of the poly
0155   // clang-format off
0156   Select3D_TypeOfSensitivity       mySensType;       //!< Type of sensitivity: boundary or interior
0157   mutable bool         myIsComputed;     //!< Is true if all the points and data structures of polygon are initialized
0158   // clang-format on
0159 };
0160 
0161 #endif // _Select3D_SensitivePoly_HeaderFile