Back to home page

EIC code displayed by LXR

 
 

    


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

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 
0032   //! Constructs a sensitive triangulation object defined by
0033   //! the owner theOwnerId, the triangulation theTrg,
0034   //! the location theInitLoc, and the flag theIsInterior.
0035   Standard_EXPORT Select3D_SensitiveTriangulation (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 (const Handle(SelectMgr_EntityOwner)& theOwnerId,
0047                                                    const Handle(Poly_Triangulation)& theTrg,
0048                                                    const TopLoc_Location& theInitLoc,
0049                                                    const Handle(TColStd_HArray1OfInteger)& theFreeEdges,
0050                                                    const gp_Pnt& theCOG,
0051                                                    const Standard_Boolean theIsInterior);
0052 public:
0053 
0054   //! Get last detected triangle.
0055   //! @param theTriangle [out] triangle node indexes
0056   //! @return TRUE if defined
0057   Standard_EXPORT bool LastDetectedTriangle (Poly_Triangle& theTriangle) const;
0058 
0059   //! Get last detected triangle.
0060   //! @param theTriangle [out] triangle node indexes
0061   //! @param theTriNodes [out] triangle nodes (with pre-applied transformation)
0062   //! @return TRUE if defined
0063   Standard_EXPORT bool LastDetectedTriangle (Poly_Triangle& theTriangle,
0064                                              gp_Pnt theTriNodes[3]) const;
0065 
0066   //! Return index of last detected triangle within [1..NbTris] range, or -1 if undefined.
0067   Standard_Integer LastDetectedTriangleIndex() const
0068   {
0069     return (myDetectedIdx != -1 && mySensType == Select3D_TOS_INTERIOR && !myBVHPrimIndexes.IsNull())
0070           ? myBVHPrimIndexes->Value (myDetectedIdx) + 1
0071           : -1;
0072   }
0073 
0074 public:
0075 
0076   //! Returns the amount of nodes in triangulation
0077   Standard_EXPORT virtual Standard_Integer NbSubElements() const Standard_OVERRIDE;
0078 
0079   Standard_EXPORT Handle(Select3D_SensitiveEntity) GetConnected() Standard_OVERRIDE;
0080 
0081   const Handle(Poly_Triangulation)& Triangulation() const { return myTriangul; }
0082 
0083   //! Returns the length of array of triangles or edges
0084   Standard_EXPORT virtual Standard_Integer Size() const Standard_OVERRIDE;
0085 
0086   //! Returns bounding box of triangle/edge with index theIdx
0087   Standard_EXPORT virtual Select3D_BndBox3d Box (const Standard_Integer theIdx) const Standard_OVERRIDE;
0088 
0089   //! Returns geometry center of triangle/edge with index theIdx
0090   //! in array along the given axis theAxis
0091   Standard_EXPORT virtual Standard_Real Center (const Standard_Integer theIdx,
0092                                                 const Standard_Integer theAxis) const Standard_OVERRIDE;
0093 
0094   //! Swaps items with indexes theIdx1 and theIdx2 in array
0095   Standard_EXPORT virtual void Swap (const Standard_Integer theIdx1,
0096                                      const Standard_Integer theIdx2) Standard_OVERRIDE;
0097 
0098   //! Returns bounding box of the triangulation. If location
0099   //! transformation is set, it will be applied
0100   Standard_EXPORT virtual Select3D_BndBox3d BoundingBox() Standard_OVERRIDE;
0101 
0102   //! Returns center of triangulation. If location transformation
0103   //! is set, it will be applied
0104   Standard_EXPORT virtual gp_Pnt CenterOfGeometry() const Standard_OVERRIDE;
0105 
0106   //! Returns true if the shape corresponding to the entity has init location
0107   Standard_EXPORT virtual Standard_Boolean HasInitLocation() const Standard_OVERRIDE;
0108 
0109   //! Returns inversed location transformation matrix if the shape corresponding
0110   //! to this entity has init location set. Otherwise, returns identity matrix.
0111   Standard_EXPORT virtual gp_GTrsf InvInitLocation() const Standard_OVERRIDE;
0112 
0113   const TopLoc_Location& GetInitLocation() const { return myInitLocation; }
0114 
0115   //! Dumps the content of me into the stream
0116   Standard_EXPORT virtual void DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth = -1) const Standard_OVERRIDE;
0117 
0118   //! Checks whether one or more entities of the set overlap current selecting volume.
0119   Standard_EXPORT virtual Standard_Boolean Matches (SelectBasics_SelectingVolumeManager& theMgr,
0120                                                     SelectBasics_PickResult& thePickResult) Standard_OVERRIDE;
0121 
0122 protected:
0123 
0124   //! Compute bounding box.
0125   void computeBoundingBox();
0126 
0127   //! Inner function for transformation application to bounding
0128   //! box of the triangulation
0129   Select3D_BndBox3d applyTransformation();
0130 
0131 private:
0132 
0133   //! Checks whether the element with index theIdx overlaps the current selecting volume
0134   Standard_EXPORT virtual Standard_Boolean overlapsElement (SelectBasics_PickResult& thePickResult,
0135                                                             SelectBasics_SelectingVolumeManager& theMgr,
0136                                                             Standard_Integer theElemIdx,
0137                                                             Standard_Boolean theIsFullInside) Standard_OVERRIDE;
0138 
0139   //! Calculates distance from the 3d projection of used-picked screen point to center of the geometry
0140   Standard_EXPORT virtual Standard_Real distanceToCOG (SelectBasics_SelectingVolumeManager& theMgr) Standard_OVERRIDE;
0141 
0142   //! Checks whether the entity with index theIdx is inside the current selecting volume
0143   Standard_EXPORT virtual Standard_Boolean elementIsInside (SelectBasics_SelectingVolumeManager& theMgr,
0144                                                             Standard_Integer theElemIdx,
0145                                                             Standard_Boolean theIsFullInside) Standard_OVERRIDE;
0146 
0147 protected:
0148 
0149   Handle(Poly_Triangulation)       myTriangul;
0150   TopLoc_Location                  myInitLocation;
0151   gp_Pnt                           myCDG3D;              //!< Center of the whole triangulation
0152   Handle(TColStd_HArray1OfInteger) myFreeEdges;
0153   Standard_Boolean                 mySensType;            //!< Type of sensitivity: boundary or interior
0154   Standard_Integer                 myPrimitivesNb;       //!< Amount of free edges or triangles depending on sensitivity type
0155   Handle(TColStd_HArray1OfInteger) myBVHPrimIndexes;     //!< Indexes of edges or triangles for BVH build
0156   mutable Select3D_BndBox3d        myBndBox;             //!< Bounding box of the whole triangulation
0157   gp_GTrsf                         myInvInitLocation;
0158 };
0159 
0160 DEFINE_STANDARD_HANDLE(Select3D_SensitiveTriangulation, Select3D_SensitiveSet)
0161 
0162 #endif // _Select3D_SensitiveTriangulation_Header