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