1 // Created on: 2011-06-02
2 // Created by: Oleg AGASHIN
3 // Copyright (c) 2011-2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 #include <BRepMesh_VertexTool.hxx>
17 #include <Precision.hxx>
19 IMPLEMENT_STANDARD_RTTIEXT(BRepMesh_VertexTool, Standard_Transient)
21 //=======================================================================
24 //=======================================================================
25 NCollection_CellFilter_Action BRepMesh_VertexInspector::Inspect(
26 const Standard_Integer theTarget)
28 const BRepMesh_Vertex& aVertex = myVertices->Value(theTarget - 1);
29 if(aVertex.Movability() == BRepMesh_Deleted)
31 myDelNodes.Append(theTarget);
32 return CellFilter_Purge;
35 gp_XY aVec = (myPoint - aVertex.Coord());
36 Standard_Boolean inTol;
37 if (Abs(myTolerance[1]) < Precision::Confusion())
39 inTol = aVec.SquareModulus() < myTolerance[0];
43 inTol = ((aVec.X() * aVec.X()) < myTolerance[0]) &&
44 ((aVec.Y() * aVec.Y()) < myTolerance[1]);
49 const Standard_Real aSqDist = aVec.SquareModulus();
50 if (aSqDist < myMinSqDist)
52 myMinSqDist = aSqDist;
57 return CellFilter_Keep;
60 //=======================================================================
61 //function : BRepMesh_VertexTool
63 //=======================================================================
64 BRepMesh_VertexTool::BRepMesh_VertexTool(
65 const Handle(NCollection_IncAllocator)& theAllocator)
66 : myAllocator (theAllocator),
67 myCellFilter(0., myAllocator),
68 mySelector (myAllocator)
70 const Standard_Real aTol = Precision::Confusion();
71 SetCellSize ( aTol + 0.05 * aTol );
72 SetTolerance( aTol, aTol );
75 //=======================================================================
78 //=======================================================================
79 Standard_Integer BRepMesh_VertexTool::Add(
80 const BRepMesh_Vertex& theVertex,
81 const Standard_Boolean isForceAdd)
83 Standard_Integer aIndex = isForceAdd ? 0 : FindIndex(theVertex);
86 aIndex = mySelector.Add(theVertex);
88 gp_XY aMinPnt, aMaxPnt;
89 expandPoint(theVertex.Coord(), aMinPnt, aMaxPnt);
90 myCellFilter.Add(aIndex, aMinPnt, aMaxPnt);
95 //=======================================================================
98 //=======================================================================
99 void BRepMesh_VertexTool::DeleteVertex(const Standard_Integer theIndex)
101 BRepMesh_Vertex& aV = mySelector.GetVertex(theIndex);
103 gp_XY aMinPnt, aMaxPnt;
104 expandPoint(aV.Coord(), aMinPnt, aMaxPnt);
106 myCellFilter.Remove(theIndex, aMinPnt, aMaxPnt);
107 mySelector.Delete(theIndex);
110 //=======================================================================
111 //function : Substitute
113 //=======================================================================
114 void BRepMesh_VertexTool::Substitute(
115 const Standard_Integer theIndex,
116 const BRepMesh_Vertex& theVertex)
118 BRepMesh_Vertex& aV = mySelector.GetVertex(theIndex);
120 gp_XY aMinPnt, aMaxPnt;
121 expandPoint(aV.Coord(), aMinPnt, aMaxPnt);
123 myCellFilter.Remove(theIndex, aMinPnt, aMaxPnt);
126 expandPoint(aV.Coord(), aMinPnt, aMaxPnt);
127 myCellFilter.Add(theIndex, aMinPnt, aMaxPnt);
130 //=======================================================================
131 //function : Statistics
133 //=======================================================================
134 void BRepMesh_VertexTool::Statistics(Standard_OStream& theStream) const
136 theStream << "\nStructure Statistics\n---------------\n\n";
137 theStream << "This structure has " << mySelector.NbVertices() << " Nodes\n\n";