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 //=======================================================================
22 //=======================================================================
23 NCollection_CellFilter_Action BRepMesh_VertexInspector::Inspect(
24 const Standard_Integer theTarget)
26 const BRepMesh_Vertex& aVertex = myVertices->Value(theTarget - 1);
27 if(aVertex.Movability() == BRepMesh_Deleted)
29 myDelNodes.Append(theTarget);
30 return CellFilter_Purge;
33 gp_XY aVec = (myPoint - aVertex.Coord());
34 Standard_Boolean inTol;
35 if (Abs(myTolerance[1]) < Precision::Confusion())
37 inTol = aVec.SquareModulus() < myTolerance[0];
41 inTol = ((aVec.X() * aVec.X()) < myTolerance[0]) &&
42 ((aVec.Y() * aVec.Y()) < myTolerance[1]);
47 const Standard_Real aSqDist = aVec.SquareModulus();
48 if (aSqDist < myMinSqDist)
50 myMinSqDist = aSqDist;
55 return CellFilter_Keep;
58 //=======================================================================
59 //function : BRepMesh_VertexTool
61 //=======================================================================
62 BRepMesh_VertexTool::BRepMesh_VertexTool(
63 const Handle(NCollection_IncAllocator)& theAllocator)
64 : myAllocator (theAllocator),
65 myCellFilter(0., myAllocator),
66 mySelector (myAllocator)
68 const Standard_Real aTol = Precision::Confusion();
69 SetCellSize ( aTol + 0.05 * aTol );
70 SetTolerance( aTol, aTol );
73 //=======================================================================
76 //=======================================================================
77 Standard_Integer BRepMesh_VertexTool::Add(
78 const BRepMesh_Vertex& theVertex,
79 const Standard_Boolean isForceAdd)
81 Standard_Integer aIndex = isForceAdd ? 0 : FindIndex(theVertex);
84 aIndex = mySelector.Add(theVertex);
86 gp_XY aMinPnt, aMaxPnt;
87 expandPoint(theVertex.Coord(), aMinPnt, aMaxPnt);
88 myCellFilter.Add(aIndex, aMinPnt, aMaxPnt);
93 //=======================================================================
96 //=======================================================================
97 void BRepMesh_VertexTool::DeleteVertex(const Standard_Integer theIndex)
99 BRepMesh_Vertex& aV = mySelector.GetVertex(theIndex);
101 gp_XY aMinPnt, aMaxPnt;
102 expandPoint(aV.Coord(), aMinPnt, aMaxPnt);
104 myCellFilter.Remove(theIndex, aMinPnt, aMaxPnt);
105 mySelector.Delete(theIndex);
108 //=======================================================================
109 //function : Substitute
111 //=======================================================================
112 void BRepMesh_VertexTool::Substitute(
113 const Standard_Integer theIndex,
114 const BRepMesh_Vertex& theVertex)
116 BRepMesh_Vertex& aV = mySelector.GetVertex(theIndex);
118 gp_XY aMinPnt, aMaxPnt;
119 expandPoint(aV.Coord(), aMinPnt, aMaxPnt);
121 myCellFilter.Remove(theIndex, aMinPnt, aMaxPnt);
124 expandPoint(aV.Coord(), aMinPnt, aMaxPnt);
125 myCellFilter.Add(theIndex, aMinPnt, aMaxPnt);
128 //=======================================================================
129 //function : Statistics
131 //=======================================================================
132 void BRepMesh_VertexTool::Statistics(Standard_OStream& theStream) const
134 theStream << "\nStructure Statistics\n---------------\n\n";
135 theStream << "This structure has " << mySelector.NbVertices() << " Nodes\n\n";