summaryrefslogtreecommitdiff
path: root/src/ShapeAnalysis/ShapeAnalysis_Shell.cxx
blob: ee69a3a3149c7e5e2efb134d3d715494fd47642b (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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
//szv#4 S4163
#include <ShapeAnalysis_Shell.ixx>

#include <BRep_Builder.hxx>
#include <BRep_Tool.hxx>

#include <TopoDS.hxx>
#include <TopoDS_Edge.hxx>
#include <TopoDS_Iterator.hxx>
#include <TopExp_Explorer.hxx>

//=======================================================================
//function : Clear
//purpose  : 
//=======================================================================

 void ShapeAnalysis_Shell::Clear() 
{
  myShells.Clear();
  myBad.Clear();
  myFree.Clear();
  myConex = Standard_False;
}

//=======================================================================
//function : LoadShells
//purpose  : 
//=======================================================================

 void ShapeAnalysis_Shell::LoadShells(const TopoDS_Shape& shape) 
{
  if (shape.IsNull()) return;

  if (shape.ShapeType() == TopAbs_SHELL) myShells.Add (shape); //szv#4:S4163:12Mar99 i =
  else {
    for (TopExp_Explorer exs (shape,TopAbs_SHELL); exs.More(); exs.Next()) {
      TopoDS_Shape sh = exs.Current();
      myShells.Add (sh); //szv#4:S4163:12Mar99 i =
    }
  }
}


//  CheckOrientedShells : alimente BadEdges et FreeEdges
//  BadEdges : edges presentes plus d une fois dans une meme orientation
//  FreeEdges : edges presentes une seule fois
//  On utilise pour cela une fonction auxiliaire : CheckEdges
//    Qui alimente 2 maps auxiliaires : les edges directes et les inverses

static  Standard_Boolean CheckEdges(const TopoDS_Shape& shape,
                                    TopTools_IndexedMapOfShape& bads,
                                    TopTools_IndexedMapOfShape& dirs,
                                    TopTools_IndexedMapOfShape& revs,
                                    TopTools_IndexedMapOfShape& ints)
{
  Standard_Boolean res = Standard_False;

  if (shape.ShapeType() != TopAbs_EDGE) {
    for (TopoDS_Iterator it(shape); it.More(); it.Next()) {
      if (CheckEdges (it.Value(),bads,dirs,revs,ints)) res = Standard_True;
    }
  }
  else {
    TopoDS_Edge E = TopoDS::Edge(shape);
    if (BRep_Tool::Degenerated(E)) return Standard_False;

    if (shape.Orientation() == TopAbs_FORWARD) {
      //szv#4:S4163:12Mar99 optimized
      if (dirs.FindIndex (shape) == 0) dirs.Add (shape);
      else { bads.Add (shape); res = Standard_True; }
    }
    if (shape.Orientation() == TopAbs_REVERSED) {
      //szv#4:S4163:12Mar99 optimized
      if (revs.FindIndex (shape) == 0) revs.Add (shape);
      else { bads.Add (shape); res = Standard_True; }
    }
    if (shape.Orientation() == TopAbs_INTERNAL) {
      if (ints.FindIndex (shape) == 0) ints.Add (shape);
      //else { bads.Add (shape); res = Standard_True; }
    }
  }

  return res;
}

//=======================================================================
//function : CheckOrientedShells
//purpose  : 
//=======================================================================

Standard_Boolean ShapeAnalysis_Shell::CheckOrientedShells(const TopoDS_Shape& shape,
							  const Standard_Boolean alsofree,
                                                          const Standard_Boolean checkinternaledges)
{
  myConex = Standard_False;
  if (shape.IsNull()) return Standard_False;
  Standard_Boolean res = Standard_False;

  TopTools_IndexedMapOfShape dirs, revs, ints;
  for (TopExp_Explorer exs(shape,TopAbs_SHELL); exs.More(); exs.Next()) {
    TopoDS_Shape sh = exs.Current();
    //szv#4:S4163:12Mar99 optimized
    if (CheckEdges (sh,myBad,dirs,revs,ints))
      if (myShells.Add (sh)) res = Standard_True;
  }

  //  Resteraient a faire les FreeEdges
  if (!alsofree) return res;

  //  Free Edges . Ce sont les edges d une map pas dans l autre
  //  et lycee de Versailles  (les maps dirs et revs)
  Standard_Integer nb = dirs.Extent();
  Standard_Integer i; // svv Jan11 2000 : porting on DEC
  for (i = 1; i <= nb; i ++) {
    TopoDS_Shape sh = dirs.FindKey (i);
    if (!myBad.Contains(sh)) {
      if (!revs.Contains(sh)) {
        if(checkinternaledges) {
          if (!ints.Contains(sh)) {
            myFree.Add (sh);
          }
          else myConex = Standard_True;
        }
        else {
          myFree.Add (sh);
        }
      }
      else myConex = Standard_True;
    }
    else myConex = Standard_True;
  }

  nb = revs.Extent();
  for (i = 1; i <= nb; i ++) {
    TopoDS_Shape sh = revs.FindKey (i);
    if (!myBad.Contains(sh)) {
      if (!dirs.Contains(sh)) {
        if(checkinternaledges) {
          if (!ints.Contains(sh)) {
            myFree.Add (sh);
          }
          else myConex = Standard_True;
        }
        else {
          myFree.Add (sh);
        }
      }
      else myConex = Standard_True;
    }
    else myConex = Standard_True;
  }

  return res;
}

//=======================================================================
//function : IsLoaded
//purpose  : 
//=======================================================================

 Standard_Boolean ShapeAnalysis_Shell::IsLoaded(const TopoDS_Shape& shape) const
{
  if (shape.IsNull()) return Standard_False;
  return myShells.Contains (shape);
}

//=======================================================================
//function : NbLoaded
//purpose  : 
//=======================================================================

 Standard_Integer ShapeAnalysis_Shell::NbLoaded() const
{
  return myShells.Extent();
}

//=======================================================================
//function : Loaded
//purpose  : 
//=======================================================================

 TopoDS_Shape ShapeAnalysis_Shell::Loaded(const Standard_Integer num) const
{
  return myShells.FindKey (num);
}

//=======================================================================
//function : HasBadEdges
//purpose  : 
//=======================================================================

 Standard_Boolean ShapeAnalysis_Shell::HasBadEdges() const
{
  return (myBad.Extent() > 0);
}

//=======================================================================
//function : BadEdges
//purpose  : 
//=======================================================================

 TopoDS_Compound ShapeAnalysis_Shell::BadEdges() const
{
  TopoDS_Compound C;
  BRep_Builder B;
  B.MakeCompound (C);
  Standard_Integer n = myBad.Extent();
  for (Standard_Integer i = 1; i <= n; i ++)  B.Add (C,myBad.FindKey(i));
  return C;
}

//=======================================================================
//function : HasFreeEdges
//purpose  : 
//=======================================================================

 Standard_Boolean ShapeAnalysis_Shell::HasFreeEdges() const
{
  return (myFree.Extent() > 0);
}

//=======================================================================
//function : FreeEdges
//purpose  : 
//=======================================================================

 TopoDS_Compound ShapeAnalysis_Shell::FreeEdges() const
{
  TopoDS_Compound C;
  BRep_Builder B;
  B.MakeCompound (C);
  Standard_Integer n = myFree.Extent();
  for (Standard_Integer i = 1; i <= n; i ++)  B.Add (C,myFree.FindKey(i));
  return C;
}

//=======================================================================
//function : HasConnectedEdges
//purpose  : 
//=======================================================================

 Standard_Boolean ShapeAnalysis_Shell::HasConnectedEdges() const
{
  return myConex;
}