Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-12 09:16:50

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
0027 {
0028 public:
0029   static constexpr int Dimension = 2;
0030 
0031   typedef gp_XY Point;
0032   typedef int   Target;
0033 
0034   static double Coord(int i, const Point& thePnt) { return thePnt.Coord(i + 1); }
0035 
0036   static Point Shift(const Point& thePnt, double theTol)
0037   {
0038     return Point(thePnt.X() + theTol, thePnt.Y() + theTol);
0039   }
0040 
0041   //! Constructor.
0042   //! @param theAllocator memory allocator to be used by internal collections.
0043   BRepMesh_VertexInspector(const occ::handle<NCollection_IncAllocator>& theAllocator)
0044       : myIndex(0),
0045         myMinSqDist(RealLast()),
0046         myVertices(new IMeshData::VectorOfVertex),
0047         myDelNodes(theAllocator)
0048   {
0049     SetTolerance(Precision::Confusion());
0050   }
0051 
0052   //! Registers the given vertex.
0053   //! @param theVertex vertex to be registered.
0054   int Add(const BRepMesh_Vertex& theVertex)
0055   {
0056     if (myDelNodes.IsEmpty())
0057     {
0058       myVertices->Append(theVertex);
0059       return myVertices->Length();
0060     }
0061 
0062     int aNodeIndex                          = myDelNodes.First();
0063     myVertices->ChangeValue(aNodeIndex - 1) = theVertex;
0064     myDelNodes.RemoveFirst();
0065     return aNodeIndex;
0066   }
0067 
0068   //! Sets the tolerance to be used for identification of
0069   //! coincident vertices equal for both dimensions.
0070   void SetTolerance(const double theTolerance)
0071   {
0072     myTolerance[0] = theTolerance * theTolerance;
0073     myTolerance[1] = 0.;
0074   }
0075 
0076   //! Sets 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 SetTolerance(const double theToleranceX, const double theToleranceY)
0081   {
0082     myTolerance[0] = theToleranceX * theToleranceX;
0083     myTolerance[1] = theToleranceY * theToleranceY;
0084   }
0085 
0086   //! Clear inspector's internal data structures.
0087   void Clear()
0088   {
0089     myVertices->Clear();
0090     myDelNodes.Clear();
0091   }
0092 
0093   //! Deletes vertex with the given index.
0094   //! @param theIndex index of vertex to be removed.
0095   void Delete(const int theIndex)
0096   {
0097     myVertices->ChangeValue(theIndex - 1).SetMovability(BRepMesh_Deleted);
0098     myDelNodes.Append(theIndex);
0099   }
0100 
0101   //! Returns number of registered vertices.
0102   int NbVertices() const { return myVertices->Length(); }
0103 
0104   //! Returns vertex with the given index.
0105   BRepMesh_Vertex& GetVertex(int theIndex) { return myVertices->ChangeValue(theIndex - 1); }
0106 
0107   //! Set reference point to be checked.
0108   void SetPoint(const gp_XY& thePoint)
0109   {
0110     myIndex     = 0;
0111     myMinSqDist = RealLast();
0112     myPoint     = thePoint;
0113   }
0114 
0115   //! Returns index of point coinciding with regerence one.
0116   int GetCoincidentPoint() const { return myIndex; }
0117 
0118   //! Returns list with indexes of vertices that have movability attribute
0119   //! equal to BRepMesh_Deleted and can be replaced with another node.
0120   const IMeshData::ListOfInteger& GetListOfDelPoints() const { return myDelNodes; }
0121 
0122   //! Returns set of mesh vertices.
0123   const Handle(IMeshData::VectorOfVertex)& Vertices() const { return myVertices; }
0124 
0125   //! Returns set of mesh vertices for modification.
0126   Handle(IMeshData::VectorOfVertex)& ChangeVertices() { return myVertices; }
0127 
0128   //! Performs inspection of a point with the given index.
0129   //! @param theTargetIndex index of a circle to be checked.
0130   //! @return status of the check.
0131   Standard_EXPORT NCollection_CellFilter_Action Inspect(const int theTargetIndex);
0132 
0133   //! Checks indices for equality.
0134   static bool IsEqual(const int theIndex, const int theTargetIndex)
0135   {
0136     return (theIndex == theTargetIndex);
0137   }
0138 
0139 private:
0140   int                               myIndex;
0141   double                            myMinSqDist;
0142   double                            myTolerance[2];
0143   Handle(IMeshData::VectorOfVertex) myVertices;
0144   IMeshData::ListOfInteger          myDelNodes;
0145   gp_XY                             myPoint;
0146 };
0147 
0148 #endif