Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-18 09:19:53

0001 // Copyright (c) 2013 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 _BRepMesh_VertexTool_HeaderFile
0015 #define _BRepMesh_VertexTool_HeaderFile
0016 
0017 #include <Standard_Transient.hxx>
0018 #include <BRepMesh_VertexInspector.hxx>
0019 #include <Standard_OStream.hxx>
0020 #include <gp_XY.hxx>
0021 #include <IMeshData_Types.hxx>
0022 
0023 //! Describes data structure intended to keep mesh nodes
0024 //! defined in UV space and implements functionality
0025 //! providing their uniqueness regarding their position.
0026 class BRepMesh_VertexTool : public Standard_Transient
0027 {
0028 public:
0029   //! Constructor.
0030   //! @param theAllocator memory allocator to be used by internal collections.
0031   Standard_EXPORT BRepMesh_VertexTool(const occ::handle<NCollection_IncAllocator>& theAllocator);
0032 
0033   //! Sets new size of cell for cellfilter equal in both directions.
0034   void SetCellSize(const double theSize)
0035   {
0036     myCellFilter.Reset(theSize, myAllocator);
0037     mySelector.Clear();
0038   }
0039 
0040   //! Sets new size of cell for cellfilter.
0041   //! @param theSizeX size for X dimension.
0042   //! @param theSizeY size for Y dimension.
0043   void SetCellSize(const double theSizeX, const double theSizeY)
0044   {
0045     double                     aCellSizeC[2] = {theSizeX, theSizeY};
0046     NCollection_Array1<double> aCellSize(aCellSizeC[0], 1, 2);
0047     myCellFilter.Reset(aCellSize, myAllocator);
0048     mySelector.Clear();
0049   }
0050 
0051   //! Sets the tolerance to be used for identification of
0052   //! coincident vertices equal for both dimensions.
0053   void SetTolerance(const double theTolerance)
0054   {
0055     mySelector.SetTolerance(theTolerance);
0056     myTolerance[0] = theTolerance;
0057     myTolerance[1] = theTolerance;
0058   }
0059 
0060   //! Sets the tolerance to be used for identification of
0061   //! coincident vertices.
0062   //! @param theToleranceX tolerance for X dimension.
0063   //! @param theToleranceY tolerance for Y dimension.
0064   void SetTolerance(const double theToleranceX, const double theToleranceY)
0065   {
0066     mySelector.SetTolerance(theToleranceX, theToleranceY);
0067     myTolerance[0] = theToleranceX;
0068     myTolerance[1] = theToleranceY;
0069   }
0070 
0071   //! Gets the tolerance to be used for identification of
0072   //! coincident vertices.
0073   //! @param theToleranceX tolerance for X dimension.
0074   //! @param theToleranceY tolerance for Y dimension.
0075   void GetTolerance(double& theToleranceX, double& theToleranceY)
0076   {
0077     theToleranceX = myTolerance[0];
0078     theToleranceY = myTolerance[1];
0079   }
0080 
0081   //! Adds vertex with empty data to the tool.
0082   //! @param theVertex node to be added to the mesh.
0083   //! @param isForceAdd adds the given node to structure without
0084   //! checking on coincidence with other nodes.
0085   //! @return index of the node in the structure.
0086   Standard_EXPORT int Add(const BRepMesh_Vertex& theVertex, const bool isForceAdd);
0087 
0088   //! Deletes vertex with the given index from the tool.
0089   Standard_EXPORT void DeleteVertex(const int theIndex);
0090 
0091   //! Returns set of mesh vertices.
0092   const Handle(IMeshData::VectorOfVertex)& Vertices() const { return mySelector.Vertices(); }
0093 
0094   //! Returns set of mesh vertices.
0095   Handle(IMeshData::VectorOfVertex)& ChangeVertices() { return mySelector.ChangeVertices(); }
0096 
0097   //! Returns vertex by the given index.
0098   const BRepMesh_Vertex& FindKey(const int theIndex) { return mySelector.GetVertex(theIndex); }
0099 
0100   //! Returns index of the given vertex.
0101   int FindIndex(const BRepMesh_Vertex& theVertex)
0102   {
0103     mySelector.SetPoint(theVertex.Coord());
0104     myCellFilter.Inspect(theVertex.Coord(), mySelector);
0105     return mySelector.GetCoincidentPoint();
0106   }
0107 
0108   //! Returns a number of vertices.
0109   int Extent() const { return mySelector.NbVertices(); }
0110 
0111   //! Returns True when the map contains no keys.
0112   bool IsEmpty() const { return (Extent() == 0); }
0113 
0114   //! Substitutes vertex with the given by the given vertex with attributes.
0115   //! @param theIndex index of vertex to be substituted.
0116   //! @param theVertex replacement vertex.
0117   Standard_EXPORT void Substitute(const int theIndex, const BRepMesh_Vertex& theVertex);
0118 
0119   //! Remove last node from the structure.
0120   void RemoveLast() { DeleteVertex(Extent()); }
0121 
0122   //! Returns the list with indexes of vertices that have movability attribute
0123   //! equal to BRepMesh_Deleted and can be replaced with another node.
0124   const IMeshData::ListOfInteger& GetListOfDelNodes() const
0125   {
0126     return mySelector.GetListOfDelPoints();
0127   }
0128 
0129   DEFINE_STANDARD_RTTIEXT(BRepMesh_VertexTool, Standard_Transient)
0130 
0131 private:
0132   //! Expands the given point according to specified tolerance.
0133   //! @param thePoint point to be expanded.
0134   //! @param[out] theMinPoint bottom left corner of area defined by expanded point.
0135   //! @param[out] theMaxPoint top right corner of area defined by expanded point.
0136   void expandPoint(const gp_XY& thePoint, gp_XY& theMinPoint, gp_XY& theMaxPoint)
0137   {
0138     theMinPoint.SetX(thePoint.X() - myTolerance[0]);
0139     theMinPoint.SetY(thePoint.Y() - myTolerance[1]);
0140     theMaxPoint.SetX(thePoint.X() + myTolerance[0]);
0141     theMaxPoint.SetY(thePoint.Y() + myTolerance[1]);
0142   }
0143 
0144 private:
0145   occ::handle<NCollection_IncAllocator> myAllocator;
0146   IMeshData::VertexCellFilter           myCellFilter;
0147   BRepMesh_VertexInspector              mySelector;
0148   double                                myTolerance[2];
0149 };
0150 
0151 #endif