Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-10 09:17:57

0001 // Created on: 1997-05-15
0002 // Created by: Robert COUBLANC
0003 // Copyright (c) 1997-1999 Matra Datavision
0004 // Copyright (c) 1999-2014 OPEN CASCADE SAS
0005 //
0006 // This file is part of Open CASCADE Technology software library.
0007 //
0008 // This library is free software; you can redistribute it and/or modify it under
0009 // the terms of the GNU Lesser General Public License version 2.1 as published
0010 // by the Free Software Foundation, with special exception defined in the file
0011 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
0012 // distribution for complete text of the license and disclaimer of any warranty.
0013 //
0014 // Alternatively, this file may be used under the terms of Open CASCADE
0015 // commercial license or contractual agreement.
0016 
0017 #ifndef _Select3D_SensitiveTriangulation_Header
0018 #define _Select3D_SensitiveTriangulation_Header
0019 
0020 #include <TColStd_HArray1OfInteger.hxx>
0021 #include <Select3D_SensitiveSet.hxx>
0022 
0023 class Poly_Triangle;
0024 class Poly_Triangulation;
0025 
0026 //! A framework to define selection of a sensitive entity made of a set of triangles.
0027 class Select3D_SensitiveTriangulation : public Select3D_SensitiveSet
0028 {
0029   DEFINE_STANDARD_RTTIEXT(Select3D_SensitiveTriangulation, Select3D_SensitiveSet)
0030 public:
0031   //! Constructs a sensitive triangulation object defined by
0032   //! the owner theOwnerId, the triangulation theTrg,
0033   //! the location theInitLoc, and the flag theIsInterior.
0034   Standard_EXPORT Select3D_SensitiveTriangulation(
0035     const Handle(SelectMgr_EntityOwner)& theOwnerId,
0036     const Handle(Poly_Triangulation)&    theTrg,
0037     const TopLoc_Location&               theInitLoc,
0038     const Standard_Boolean               theIsInterior = Standard_True);
0039 
0040   //! Constructs a sensitive triangulation object defined by
0041   //! the owner theOwnerId, the triangulation theTrg,
0042   //! the location theInitLoc, the array of free edges
0043   //! theFreeEdges, the center of gravity theCOG, and the flag theIsInterior.
0044   //! As free edges and the center of gravity do not have
0045   //! to be computed later, this syntax reduces computation time.
0046   Standard_EXPORT Select3D_SensitiveTriangulation(
0047     const Handle(SelectMgr_EntityOwner)&    theOwnerId,
0048     const Handle(Poly_Triangulation)&       theTrg,
0049     const TopLoc_Location&                  theInitLoc,
0050     const Handle(TColStd_HArray1OfInteger)& theFreeEdges,
0051     const gp_Pnt&                           theCOG,
0052     const Standard_Boolean                  theIsInterior);
0053 
0054 public:
0055   //! Get last detected triangle.
0056   //! @param[out] theTriangle  triangle node indexes
0057   //! @return TRUE if defined
0058   Standard_EXPORT bool LastDetectedTriangle(Poly_Triangle& theTriangle) const;
0059 
0060   //! Get last detected triangle.
0061   //! @param[out] theTriangle  triangle node indexes
0062   //! @param[out] theTriNodes  triangle nodes (with pre-applied transformation)
0063   //! @return TRUE if defined
0064   Standard_EXPORT bool LastDetectedTriangle(Poly_Triangle& theTriangle,
0065                                             gp_Pnt         theTriNodes[3]) const;
0066 
0067   //! Return index of last detected triangle within [1..NbTris] range, or -1 if undefined.
0068   Standard_Integer LastDetectedTriangleIndex() const
0069   {
0070     return (myDetectedIdx != -1 && mySensType == Select3D_TOS_INTERIOR
0071             && !myBVHPrimIndexes.IsNull())
0072              ? myBVHPrimIndexes->Value(myDetectedIdx) + 1
0073              : -1;
0074   }
0075 
0076 public:
0077   //! Returns the amount of nodes in triangulation
0078   Standard_EXPORT virtual Standard_Integer NbSubElements() const Standard_OVERRIDE;
0079 
0080   Standard_EXPORT Handle(Select3D_SensitiveEntity) GetConnected() Standard_OVERRIDE;
0081 
0082   const Handle(Poly_Triangulation)& Triangulation() const { return myTriangul; }
0083 
0084   //! Returns the length of array of triangles or edges
0085   Standard_EXPORT virtual Standard_Integer Size() const Standard_OVERRIDE;
0086 
0087   //! Returns bounding box of triangle/edge with index theIdx
0088   Standard_EXPORT virtual Select3D_BndBox3d Box(const Standard_Integer theIdx) const
0089     Standard_OVERRIDE;
0090 
0091   //! Returns geometry center of triangle/edge with index theIdx
0092   //! in array along the given axis theAxis
0093   Standard_EXPORT virtual Standard_Real Center(const Standard_Integer theIdx,
0094                                                const Standard_Integer theAxis) const
0095     Standard_OVERRIDE;
0096 
0097   //! Swaps items with indexes theIdx1 and theIdx2 in array
0098   Standard_EXPORT virtual void Swap(const Standard_Integer theIdx1,
0099                                     const Standard_Integer theIdx2) Standard_OVERRIDE;
0100 
0101   //! Returns bounding box of the triangulation. If location
0102   //! transformation is set, it will be applied
0103   Standard_EXPORT virtual Select3D_BndBox3d BoundingBox() Standard_OVERRIDE;
0104 
0105   //! Returns center of triangulation. If location transformation
0106   //! is set, it will be applied
0107   Standard_EXPORT virtual gp_Pnt CenterOfGeometry() const Standard_OVERRIDE;
0108 
0109   //! Returns true if the shape corresponding to the entity has init location
0110   Standard_EXPORT virtual Standard_Boolean HasInitLocation() const Standard_OVERRIDE;
0111 
0112   //! Returns inversed location transformation matrix if the shape corresponding
0113   //! to this entity has init location set. Otherwise, returns identity matrix.
0114   Standard_EXPORT virtual gp_GTrsf InvInitLocation() const Standard_OVERRIDE;
0115 
0116   const TopLoc_Location& GetInitLocation() const { return myInitLocation; }
0117 
0118   //! Dumps the content of me into the stream
0119   Standard_EXPORT virtual void DumpJson(Standard_OStream& theOStream,
0120                                         Standard_Integer  theDepth = -1) const Standard_OVERRIDE;
0121 
0122   //! Checks whether one or more entities of the set overlap current selecting volume.
0123   Standard_EXPORT virtual Standard_Boolean Matches(SelectBasics_SelectingVolumeManager& theMgr,
0124                                                    SelectBasics_PickResult& thePickResult)
0125     Standard_OVERRIDE;
0126 
0127 protected:
0128   //! Compute bounding box.
0129   void computeBoundingBox();
0130 
0131   //! Inner function for transformation application to bounding
0132   //! box of the triangulation
0133   Select3D_BndBox3d applyTransformation();
0134 
0135 private:
0136   //! Checks whether the element with index theIdx overlaps the current selecting volume
0137   Standard_EXPORT virtual Standard_Boolean overlapsElement(
0138     SelectBasics_PickResult&             thePickResult,
0139     SelectBasics_SelectingVolumeManager& theMgr,
0140     Standard_Integer                     theElemIdx,
0141     Standard_Boolean                     theIsFullInside) Standard_OVERRIDE;
0142 
0143   //! Calculates distance from the 3d projection of used-picked screen point to center of the
0144   //! geometry
0145   Standard_EXPORT virtual Standard_Real distanceToCOG(SelectBasics_SelectingVolumeManager& theMgr)
0146     Standard_OVERRIDE;
0147 
0148   //! Checks whether the entity with index theIdx is inside the current selecting volume
0149   Standard_EXPORT virtual Standard_Boolean elementIsInside(
0150     SelectBasics_SelectingVolumeManager& theMgr,
0151     Standard_Integer                     theElemIdx,
0152     Standard_Boolean                     theIsFullInside) Standard_OVERRIDE;
0153 
0154 protected:
0155   Handle(Poly_Triangulation)       myTriangul;
0156   TopLoc_Location                  myInitLocation;
0157   gp_Pnt                           myCDG3D; //!< Center of the whole triangulation
0158   Handle(TColStd_HArray1OfInteger) myFreeEdges;
0159   // clang-format off
0160   Standard_Boolean                 mySensType;            //!< Type of sensitivity: boundary or interior
0161   Standard_Integer                 myPrimitivesNb;       //!< Amount of free edges or triangles depending on sensitivity type
0162   Handle(TColStd_HArray1OfInteger) myBVHPrimIndexes;     //!< Indexes of edges or triangles for BVH build
0163   mutable Select3D_BndBox3d        myBndBox;             //!< Bounding box of the whole triangulation
0164   // clang-format on
0165   gp_GTrsf myInvInitLocation;
0166 };
0167 
0168 DEFINE_STANDARD_HANDLE(Select3D_SensitiveTriangulation, Select3D_SensitiveSet)
0169 
0170 #endif // _Select3D_SensitiveTriangulation_Header