Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-06-14 08:28:38

0001 // Created on: 2011-06-01
0002 // Created by: Oleg AGASHIN
0003 // Copyright (c) 2011-2014 OPEN CASCADE SAS
0004 //
0005 // This file is part of Open CASCADE Technology software library.
0006 //
0007 // This library is free software; you can redistribute it and/or modify it under
0008 // the terms of the GNU Lesser General Public License version 2.1 as published
0009 // by the Free Software Foundation, with special exception defined in the file
0010 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
0011 // distribution for complete text of the license and disclaimer of any warranty.
0012 //
0013 // Alternatively, this file may be used under the terms of Open CASCADE
0014 // commercial license or contractual agreement.
0015 
0016 #ifndef _BRepMesh_VertexInspector_HeaderFile
0017 #define _BRepMesh_VertexInspector_HeaderFile
0018 
0019 #include <Precision.hxx>
0020 #include <gp_XY.hxx>
0021 #include <IMeshData_Types.hxx>
0022 #include <NCollection_CellFilter.hxx>
0023 #include <BRepMesh_Vertex.hxx>
0024 
0025 //! Class intended for fast searching of the coincidence points.
0026 class BRepMesh_VertexInspector : public NCollection_CellFilter_InspectorXY
0027 {
0028 public:
0029   typedef Standard_Integer Target;
0030 
0031   //! Constructor.
0032   //! @param theAllocator memory allocator to be used by internal collections.
0033   BRepMesh_VertexInspector(const Handle(NCollection_IncAllocator)& theAllocator)
0034       : myIndex(0),
0035         myMinSqDist(RealLast()),
0036         myVertices(new IMeshData::VectorOfVertex),
0037         myDelNodes(theAllocator)
0038   {
0039     SetTolerance(Precision::Confusion());
0040   }
0041 
0042   //! Registers the given vertex.
0043   //! @param theVertex vertex to be registered.
0044   Standard_Integer Add(const BRepMesh_Vertex& theVertex)
0045   {
0046     if (myDelNodes.IsEmpty())
0047     {
0048       myVertices->Append(theVertex);
0049       return myVertices->Length();
0050     }
0051 
0052     Standard_Integer aNodeIndex             = myDelNodes.First();
0053     myVertices->ChangeValue(aNodeIndex - 1) = theVertex;
0054     myDelNodes.RemoveFirst();
0055     return aNodeIndex;
0056   }
0057 
0058   //! Sets the tolerance to be used for identification of
0059   //! coincident vertices equal for both dimensions.
0060   void SetTolerance(const Standard_Real theTolerance)
0061   {
0062     myTolerance[0] = theTolerance * theTolerance;
0063     myTolerance[1] = 0.;
0064   }
0065 
0066   //! Sets the tolerance to be used for identification of
0067   //! coincident vertices.
0068   //! @param theToleranceX tolerance for X dimension.
0069   //! @param theToleranceY tolerance for Y dimension.
0070   void SetTolerance(const Standard_Real theToleranceX, const Standard_Real theToleranceY)
0071   {
0072     myTolerance[0] = theToleranceX * theToleranceX;
0073     myTolerance[1] = theToleranceY * theToleranceY;
0074   }
0075 
0076   //! Clear inspector's internal data structures.
0077   void Clear()
0078   {
0079     myVertices->Clear();
0080     myDelNodes.Clear();
0081   }
0082 
0083   //! Deletes vertex with the given index.
0084   //! @param theIndex index of vertex to be removed.
0085   void Delete(const Standard_Integer theIndex)
0086   {
0087     myVertices->ChangeValue(theIndex - 1).SetMovability(BRepMesh_Deleted);
0088     myDelNodes.Append(theIndex);
0089   }
0090 
0091   //! Returns number of registered vertices.
0092   Standard_Integer NbVertices() const { return myVertices->Length(); }
0093 
0094   //! Returns vertex with the given index.
0095   BRepMesh_Vertex& GetVertex(Standard_Integer theIndex)
0096   {
0097     return myVertices->ChangeValue(theIndex - 1);
0098   }
0099 
0100   //! Set reference point to be checked.
0101   void SetPoint(const gp_XY& thePoint)
0102   {
0103     myIndex     = 0;
0104     myMinSqDist = RealLast();
0105     myPoint     = thePoint;
0106   }
0107 
0108   //! Returns index of point coinciding with regerence one.
0109   Standard_Integer GetCoincidentPoint() const { return myIndex; }
0110 
0111   //! Returns list with indexes of vertices that have movability attribute
0112   //! equal to BRepMesh_Deleted and can be replaced with another node.
0113   const IMeshData::ListOfInteger& GetListOfDelPoints() const { return myDelNodes; }
0114 
0115   //! Returns set of mesh vertices.
0116   const Handle(IMeshData::VectorOfVertex)& Vertices() const { return myVertices; }
0117 
0118   //! Returns set of mesh vertices for modification.
0119   Handle(IMeshData::VectorOfVertex)& ChangeVertices() { return myVertices; }
0120 
0121   //! Performs inspection of a point with the given index.
0122   //! @param theTargetIndex index of a circle to be checked.
0123   //! @return status of the check.
0124   Standard_EXPORT NCollection_CellFilter_Action Inspect(const Standard_Integer theTargetIndex);
0125 
0126   //! Checks indices for equality.
0127   static Standard_Boolean IsEqual(const Standard_Integer theIndex,
0128                                   const Standard_Integer theTargetIndex)
0129   {
0130     return (theIndex == theTargetIndex);
0131   }
0132 
0133 private:
0134   Standard_Integer                  myIndex;
0135   Standard_Real                     myMinSqDist;
0136   Standard_Real                     myTolerance[2];
0137   Handle(IMeshData::VectorOfVertex) myVertices;
0138   IMeshData::ListOfInteger          myDelNodes;
0139   gp_XY                             myPoint;
0140 };
0141 
0142 #endif