Commit | Line | Data |
---|---|---|
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 <gp_XY.hxx> |
fc9b36d6 | 18 | #include <gp_XYZ.hxx> |
51c3cc5f O |
19 | #include <Precision.hxx> |
20 | #include <BRepMesh_Vertex.hxx> | |
21 | #include <BRepMesh_VertexInspector.hxx> | |
51c3cc5f O |
22 | |
23 | //======================================================================= | |
fc9b36d6 | 24 | //function : Inspect |
51c3cc5f O |
25 | //purpose : |
26 | //======================================================================= | |
fc9b36d6 | 27 | NCollection_CellFilter_Action BRepMesh_VertexInspector::Inspect( |
28 | const Standard_Integer theTarget) | |
51c3cc5f | 29 | { |
fc9b36d6 | 30 | const BRepMesh_Vertex& aVertex = myVertices(theTarget - 1); |
31 | if(aVertex.Movability() == BRepMesh_Deleted) | |
32 | { | |
33 | myDelNodes.Append(theTarget); | |
34 | return CellFilter_Purge; | |
35 | } | |
51c3cc5f | 36 | |
fc9b36d6 | 37 | gp_XY aVec = (myPoint - aVertex.Coord()); |
38 | Standard_Boolean inTol; | |
39 | if (Abs(myTolerance[1]) < Precision::Confusion()) | |
40 | { | |
41 | inTol = aVec.SquareModulus() < myTolerance[0]; | |
42 | } | |
43 | else | |
44 | { | |
45 | inTol = ((aVec.X() * aVec.X()) < myTolerance[0]) && | |
46 | ((aVec.Y() * aVec.Y()) < myTolerance[1]); | |
47 | } | |
48 | if (inTol) | |
49 | myResIndices.Append(theTarget); | |
51c3cc5f | 50 | |
fc9b36d6 | 51 | return CellFilter_Keep; |
51c3cc5f O |
52 | } |
53 | ||
54 | //======================================================================= | |
fc9b36d6 | 55 | //function : BRepMesh_VertexTool |
51c3cc5f O |
56 | //purpose : |
57 | //======================================================================= | |
fc9b36d6 | 58 | BRepMesh_VertexTool::BRepMesh_VertexTool( |
848fa7e3 | 59 | const Standard_Integer theReservedSize, |
60 | const Handle(NCollection_IncAllocator)& theAllocator) | |
fc9b36d6 | 61 | : myAllocator (theAllocator), |
62 | myCellFilter(0., myAllocator), | |
63 | mySelector (Max(theReservedSize, 64),myAllocator) | |
51c3cc5f | 64 | { |
fc9b36d6 | 65 | const Standard_Real aTol = Precision::Confusion(); |
66 | SetCellSize ( aTol + 0.05 * aTol ); | |
67 | SetTolerance( aTol, aTol ); | |
51c3cc5f O |
68 | } |
69 | ||
70 | //======================================================================= | |
71 | //function : Add | |
72 | //purpose : | |
73 | //======================================================================= | |
74 | Standard_Integer BRepMesh_VertexTool::Add(const BRepMesh_Vertex& theVertex) | |
75 | { | |
fc9b36d6 | 76 | Standard_Integer aIndex = FindIndex(theVertex); |
77 | if (aIndex == 0) | |
51c3cc5f | 78 | { |
848fa7e3 | 79 | BRepMesh::ListOfInteger aParams(myAllocator); |
fc9b36d6 | 80 | aIndex = Add(theVertex, aParams); |
51c3cc5f | 81 | } |
fc9b36d6 | 82 | return aIndex; |
51c3cc5f O |
83 | } |
84 | ||
85 | //======================================================================= | |
86 | //function : Add | |
87 | //purpose : | |
88 | //======================================================================= | |
fc9b36d6 | 89 | Standard_Integer BRepMesh_VertexTool::Add( |
848fa7e3 | 90 | const BRepMesh_Vertex& theVertex, |
91 | const BRepMesh::ListOfInteger& theParams) | |
51c3cc5f | 92 | { |
fc9b36d6 | 93 | Standard_Integer aIndex = mySelector.Add(theVertex); |
94 | myLinksMap.Bind(aIndex, theParams); | |
51c3cc5f | 95 | |
51c3cc5f | 96 | gp_XY aMinPnt, aMaxPnt; |
fc9b36d6 | 97 | expandPoint(theVertex.Coord(), aMinPnt, aMaxPnt); |
98 | myCellFilter.Add(aIndex, aMinPnt, aMaxPnt); | |
51c3cc5f | 99 | |
fc9b36d6 | 100 | return aIndex; |
51c3cc5f O |
101 | } |
102 | ||
103 | //======================================================================= | |
fc9b36d6 | 104 | //function : Delete |
51c3cc5f O |
105 | //purpose : |
106 | //======================================================================= | |
fc9b36d6 | 107 | void BRepMesh_VertexTool::Delete(const Standard_Integer theIndex) |
51c3cc5f | 108 | { |
fc9b36d6 | 109 | BRepMesh_Vertex& aV = mySelector.GetVertex(theIndex); |
51c3cc5f | 110 | |
fc9b36d6 | 111 | gp_XY aMinPnt, aMaxPnt; |
112 | expandPoint(aV.Coord(), aMinPnt, aMaxPnt); | |
51c3cc5f | 113 | |
fc9b36d6 | 114 | myCellFilter.Remove(theIndex, aMinPnt, aMaxPnt); |
115 | mySelector.Delete(theIndex); | |
51c3cc5f O |
116 | } |
117 | ||
118 | //======================================================================= | |
119 | //function : Substitute | |
120 | //purpose : | |
121 | //======================================================================= | |
fc9b36d6 | 122 | void BRepMesh_VertexTool::Substitute( |
848fa7e3 | 123 | const Standard_Integer theIndex, |
124 | const BRepMesh_Vertex& theVertex, | |
125 | const BRepMesh::ListOfInteger& theData) | |
51c3cc5f | 126 | { |
fc9b36d6 | 127 | BRepMesh_Vertex& aV = mySelector.GetVertex(theIndex); |
51c3cc5f | 128 | |
fc9b36d6 | 129 | gp_XY aMinPnt, aMaxPnt; |
130 | expandPoint(aV.Coord(), aMinPnt, aMaxPnt); | |
51c3cc5f | 131 | |
fc9b36d6 | 132 | myCellFilter.Remove(theIndex, aMinPnt, aMaxPnt); |
51c3cc5f | 133 | |
fc9b36d6 | 134 | aV = theVertex; |
135 | expandPoint(aV.Coord(), aMinPnt, aMaxPnt); | |
136 | myCellFilter.Add(theIndex, aMinPnt, aMaxPnt); | |
137 | FindFromIndex(theIndex) = theData; | |
51c3cc5f O |
138 | } |
139 | ||
140 | //======================================================================= | |
141 | //function : Statistics | |
142 | //purpose : | |
143 | //======================================================================= | |
fc9b36d6 | 144 | void BRepMesh_VertexTool::Statistics(Standard_OStream& theStream) const |
51c3cc5f | 145 | { |
fc9b36d6 | 146 | theStream << "\nStructure Statistics\n---------------\n\n"; |
147 | theStream << "This structure has " << mySelector.NbVertices() << " Nodes\n\n"; | |
51c3cc5f | 148 | } |