0030694: Data Exchange - support non-standard GB2312-encoded STEP files
[occt.git] / src / BRepMesh / BRepMesh_VertexTool.cxx
CommitLineData
b311480e 1// Created on: 2011-06-02
2// Created by: Oleg AGASHIN
973c2be1 3// Copyright (c) 2011-2014 OPEN CASCADE SAS
b311480e 4//
973c2be1 5// This file is part of Open CASCADE Technology software library.
b311480e 6//
d5f74e42 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
973c2be1 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.
b311480e 12//
973c2be1 13// Alternatively, this file may be used under the terms of Open CASCADE
14// commercial license or contractual agreement.
51c3cc5f 15
fc9b36d6 16#include <BRepMesh_VertexTool.hxx>
51c3cc5f 17#include <Precision.hxx>
51c3cc5f
O
18
19//=======================================================================
fc9b36d6 20//function : Inspect
51c3cc5f
O
21//purpose :
22//=======================================================================
fc9b36d6 23NCollection_CellFilter_Action BRepMesh_VertexInspector::Inspect(
24 const Standard_Integer theTarget)
51c3cc5f 25{
2caff0b3 26 const BRepMesh_Vertex& aVertex = myVertices->Value(theTarget - 1);
fc9b36d6 27 if(aVertex.Movability() == BRepMesh_Deleted)
28 {
29 myDelNodes.Append(theTarget);
30 return CellFilter_Purge;
31 }
51c3cc5f 32
fc9b36d6 33 gp_XY aVec = (myPoint - aVertex.Coord());
34 Standard_Boolean inTol;
35 if (Abs(myTolerance[1]) < Precision::Confusion())
36 {
37 inTol = aVec.SquareModulus() < myTolerance[0];
38 }
39 else
40 {
41 inTol = ((aVec.X() * aVec.X()) < myTolerance[0]) &&
42 ((aVec.Y() * aVec.Y()) < myTolerance[1]);
43 }
7bd071ed 44
fc9b36d6 45 if (inTol)
7bd071ed 46 {
47 const Standard_Real aSqDist = aVec.SquareModulus();
48 if (aSqDist < myMinSqDist)
49 {
50 myMinSqDist = aSqDist;
51 myIndex = theTarget;
52 }
53 }
51c3cc5f 54
fc9b36d6 55 return CellFilter_Keep;
51c3cc5f
O
56}
57
58//=======================================================================
fc9b36d6 59//function : BRepMesh_VertexTool
51c3cc5f
O
60//purpose :
61//=======================================================================
fc9b36d6 62BRepMesh_VertexTool::BRepMesh_VertexTool(
848fa7e3 63 const Handle(NCollection_IncAllocator)& theAllocator)
fc9b36d6 64 : myAllocator (theAllocator),
a7653f4f 65 myCellFilter(0., myAllocator),
e1c1b6b9 66 mySelector (myAllocator)
51c3cc5f 67{
fc9b36d6 68 const Standard_Real aTol = Precision::Confusion();
69 SetCellSize ( aTol + 0.05 * aTol );
70 SetTolerance( aTol, aTol );
51c3cc5f
O
71}
72
73//=======================================================================
74//function : Add
75//purpose :
76//=======================================================================
2caff0b3 77Standard_Integer BRepMesh_VertexTool::Add(
78 const BRepMesh_Vertex& theVertex,
79 const Standard_Boolean isForceAdd)
51c3cc5f 80{
2caff0b3 81 Standard_Integer aIndex = isForceAdd ? 0 : FindIndex(theVertex);
fc9b36d6 82 if (aIndex == 0)
51c3cc5f 83 {
2caff0b3 84 aIndex = mySelector.Add(theVertex);
51c3cc5f 85
2caff0b3 86 gp_XY aMinPnt, aMaxPnt;
87 expandPoint(theVertex.Coord(), aMinPnt, aMaxPnt);
88 myCellFilter.Add(aIndex, aMinPnt, aMaxPnt);
89 }
fc9b36d6 90 return aIndex;
51c3cc5f
O
91}
92
93//=======================================================================
fc9b36d6 94//function : Delete
51c3cc5f
O
95//purpose :
96//=======================================================================
7bd071ed 97void BRepMesh_VertexTool::DeleteVertex(const Standard_Integer theIndex)
51c3cc5f 98{
fc9b36d6 99 BRepMesh_Vertex& aV = mySelector.GetVertex(theIndex);
51c3cc5f 100
fc9b36d6 101 gp_XY aMinPnt, aMaxPnt;
102 expandPoint(aV.Coord(), aMinPnt, aMaxPnt);
51c3cc5f 103
fc9b36d6 104 myCellFilter.Remove(theIndex, aMinPnt, aMaxPnt);
105 mySelector.Delete(theIndex);
51c3cc5f
O
106}
107
108//=======================================================================
109//function : Substitute
110//purpose :
111//=======================================================================
fc9b36d6 112void BRepMesh_VertexTool::Substitute(
2caff0b3 113 const Standard_Integer theIndex,
114 const BRepMesh_Vertex& theVertex)
51c3cc5f 115{
fc9b36d6 116 BRepMesh_Vertex& aV = mySelector.GetVertex(theIndex);
51c3cc5f 117
fc9b36d6 118 gp_XY aMinPnt, aMaxPnt;
119 expandPoint(aV.Coord(), aMinPnt, aMaxPnt);
51c3cc5f 120
fc9b36d6 121 myCellFilter.Remove(theIndex, aMinPnt, aMaxPnt);
51c3cc5f 122
fc9b36d6 123 aV = theVertex;
124 expandPoint(aV.Coord(), aMinPnt, aMaxPnt);
125 myCellFilter.Add(theIndex, aMinPnt, aMaxPnt);
51c3cc5f
O
126}
127
128//=======================================================================
129//function : Statistics
130//purpose :
131//=======================================================================
fc9b36d6 132void BRepMesh_VertexTool::Statistics(Standard_OStream& theStream) const
51c3cc5f 133{
fc9b36d6 134 theStream << "\nStructure Statistics\n---------------\n\n";
135 theStream << "This structure has " << mySelector.NbVertices() << " Nodes\n\n";
51c3cc5f 136}