summaryrefslogtreecommitdiff
path: root/src/BOP/BOP_ShellFaceClassifier.cxx
blob: 206792e2e1cbfc42207f2b721219db15258c095e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#include <BOP_ShellFaceClassifier.ixx>

#include <Precision.hxx>
#include <TopoDS.hxx>
#include <TopoDS_Vertex.hxx>
#include <TopoDS_Face.hxx>
#include <TopExp_Explorer.hxx>
#include <BRep_Tool.hxx>
#include <BRepAdaptor_Surface.hxx>

// ==================================================================
// function: BOP_ShellFaceClassifier::BOP_ShellFaceClassifier
// purpose:
// ==================================================================
  BOP_ShellFaceClassifier::BOP_ShellFaceClassifier
    (const BOP_BlockBuilder& theBlockBuilder)
:
  BOP_CompositeClassifier(theBlockBuilder)
{
}

// ===============================================================================================
// function: Clear
// purpose: 
// ===============================================================================================
  void BOP_ShellFaceClassifier::Clear() 
{
  mySolidClassifier.Clear();
  myFaceShellMap.Clear();
}

// ===============================================================================================
// function: CompareShapes
// purpose: 
// ===============================================================================================
  TopAbs_State BOP_ShellFaceClassifier::CompareShapes(const TopoDS_Shape& theShape1,
						      const TopoDS_Shape& theShape2) 
{
  ResetShape(theShape1);
  myShell = TopoDS::Shell(theShape2);
  mySolidClassifier.LoadShell(myShell);
  TopAbs_State aState = State();
  return aState;
}

// ===============================================================================================
// function: CompareElementToShape
// purpose: 
// ===============================================================================================
  TopAbs_State BOP_ShellFaceClassifier::CompareElementToShape(const TopoDS_Shape& theElement,
							      const TopoDS_Shape& theShape) 
{
  ResetElement(theElement);
  myShell = TopoDS::Shell(theShape);
  mySolidClassifier.LoadShell(myShell);
  TopAbs_State aState = State();
  return aState;
}

// ===============================================================================================
// function: ResetShape
// purpose: 
// ===============================================================================================
  void BOP_ShellFaceClassifier::ResetShape(const TopoDS_Shape& theShape) 
{
  TopExp_Explorer anExp(theShape, TopAbs_FACE);
  const TopoDS_Face& aFace = TopoDS::Face(anExp.Current());
  ResetElement(aFace);
}

// ===============================================================================================
// function: ResetElement
// purpose: 
// ===============================================================================================
  void BOP_ShellFaceClassifier::ResetElement(const TopoDS_Shape& theElement) 
{
  const TopAbs_ShapeEnum aShapeType= theElement.ShapeType();

  // initialize myPoint with first vertex of face <E>
  myFirstCompare = Standard_True;
  TopExp_Explorer anExp(theElement, TopAbs_VERTEX);

  if(anExp.More()) {
    const TopoDS_Vertex& aVertex = TopoDS::Vertex(anExp.Current());
    myPoint = BRep_Tool::Pnt(aVertex);
  }
  else {

    if(aShapeType == TopAbs_FACE) {
      BRepAdaptor_Surface BAS(TopoDS::Face(theElement));
      myPoint = BAS.Value((BAS.FirstUParameter()+BAS.LastUParameter()) * 0.5,
			  (BAS.FirstVParameter()+BAS.LastVParameter()) * 0.5);
    }
    else {
      myPoint.SetCoord(0., 0., 0.);
    }
  }
}

// ===============================================================================================
// function: CompareElement
// purpose: 
// ===============================================================================================
  void BOP_ShellFaceClassifier::CompareElement(const TopoDS_Shape& theElement) 
{
  
  if(myFirstCompare) {
    Standard_Boolean found = myFaceShellMap.IsBound(theElement);
    
    if(!found) {
      myBuilder.MakeShell(myShell);
      myBuilder.Add(myShell, theElement);
      myFaceShellMap.Bind(theElement, myShell);
    }
    else {
      TopoDS_Shape sbid = myFaceShellMap.Find(theElement);
      myShell = TopoDS::Shell(sbid);
    }
    myFirstCompare = Standard_False;
  }
  else {
    myBuilder.Add(myShell, theElement);
  }
}

// ==================================================================
// function: State
// purpose: 
// ==================================================================
  TopAbs_State BOP_ShellFaceClassifier::State() 
{
  TopAbs_State aState = TopAbs_UNKNOWN;
  Standard_Real aTolerance = Precision::Confusion();
  mySolidClassifier.Classify(myShell, myPoint, aTolerance);
  aState = mySolidClassifier.State();
  return aState;
}