Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:03:15

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