summaryrefslogtreecommitdiff
path: root/src/HLRTopoBRep/HLRTopoBRep_OutLiner.cxx
blob: 84ff1563652f9eaa14ce2a76722f31b25037b4c9 (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
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
// File:	HLRTopoBRep_OutLiner.cxx
// Created:	Thu Aug  4 09:53:26 1994
// Author:	Christophe MARION
//		<cma@ecolox>

#include <HLRTopoBRep_OutLiner.ixx>
#include <HLRTopoBRep_DSFiller.hxx>
#include <Contap_Contour.hxx>
#include <BRep_Builder.hxx>
#include <TopoDS.hxx>
#include <TopoDS_Edge.hxx>
#include <TopoDS_Wire.hxx>
#include <TopoDS_Shell.hxx>
#include <TopExp_Explorer.hxx>
#include <TopTools_ListIteratorOfListOfShape.hxx>
#include <gp_Pnt.hxx>
#include <gp_Dir.hxx>
#include <gp_Vec.hxx>
#include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
#include <TopExp.hxx>
#include <BRepAdaptor_Curve.hxx>
#include <Extrema_ExtPC.hxx>

//=======================================================================
//function : OutLiner
//purpose  : 
//=======================================================================

HLRTopoBRep_OutLiner::HLRTopoBRep_OutLiner ()
{}

//=======================================================================
//function : OutLiner
//purpose  : 
//=======================================================================

HLRTopoBRep_OutLiner::HLRTopoBRep_OutLiner(const TopoDS_Shape& OriS) :
  myOriginalShape(OriS)
{}

//=======================================================================
//function : OutLiner
//purpose  : 
//=======================================================================

HLRTopoBRep_OutLiner::HLRTopoBRep_OutLiner(const TopoDS_Shape& OriS,
					   const TopoDS_Shape& OutS) :
  myOriginalShape(OriS),
  myOutLinedShape(OutS)
{}

//=======================================================================
//function : Fill
//purpose  : 
//=======================================================================

void HLRTopoBRep_OutLiner::Fill(const HLRAlgo_Projector& P,
				BRepTopAdaptor_MapOfShapeTool& MST,
				const Standard_Integer nbIso)
{
  if (!myOriginalShape.IsNull()) {
    if (myOutLinedShape.IsNull()) {
      gp_Vec Vecz (0., 0., 1.);
      gp_Trsf Tr (P.Transformation ());
      Tr.Invert ();
      Vecz.Transform (Tr);
      Contap_Contour FO;
      if (P.Perspective ()) {
	gp_Pnt Eye;
	Eye.SetXYZ (P.Focus ()*Vecz.XYZ ());
	FO.Init(Eye);
      }
      else {
	gp_Dir DirZ(Vecz);
	FO.Init(DirZ);
      }
      HLRTopoBRep_DSFiller::Insert(myOriginalShape,FO,myDS,MST,nbIso);
      BuildShape(MST);
    }
  }
}

//=======================================================================
// Function : ProcessFace
// Purpose  : Build a Face using myDS and add the new face to a shell
//=======================================================================

void HLRTopoBRep_OutLiner::ProcessFace(const TopoDS_Face& F,
				       TopoDS_Shape& S,
				       BRepTopAdaptor_MapOfShapeTool& MST)
{
  BRep_Builder B;
  TopExp_Explorer exE, exW;
 
  TopTools_IndexedDataMapOfShapeListOfShape aVEMap;
  TopExp::MapShapesAndAncestors(F, TopAbs_VERTEX, TopAbs_EDGE, aVEMap);

  TopoDS_Shape NF;// = F;
  //NF.Free(Standard_True);

  //for (exE.Init(F,TopAbs_EDGE); exE.More(); exE.Next()) {
    //if (myDS.EdgeHasSplE(TopoDS::Edge(exE.Current()))) {
      //splitted = Standard_True;
      //break;
    //}
  //}

  //if (splitted) { // the face contains a splitted edge :
                  // Make a copy with the new Edges
    NF = F.EmptyCopied ();
    
    
    for (exW.Init(F,TopAbs_WIRE); exW.More(); exW.Next()) {
      TopoDS_Wire W;
      B.MakeWire(W);
      
      for (exE.Init(exW.Current(),TopAbs_EDGE); exE.More(); exE.Next()) {
	TopoDS_Edge E = TopoDS::Edge(exE.Current());
	if (myDS.EdgeHasSplE(E)) {
	  
	  TopTools_ListIteratorOfListOfShape itS;
	  for (itS.Initialize(myDS.EdgeSplE(E));
	       itS.More();
	       itS.Next()) {
	    TopoDS_Edge newE = TopoDS::Edge(itS.Value());
	    newE.Orientation(E.Orientation());
	    myDS.AddOldS(newE,E);
	    B.Add(W,newE);
	  }
	}
	else {
	  B.Add(W,E);
	}
      }
      B.Add(NF,W); // add the new wire in the new face.
    }
  //}
  

  myDS.AddIntL(F);
  TopTools_ListOfShape& OutL = myDS.AddOutL(F);

  if (myDS.FaceHasIntL(F)) { // get the InternalOutLines on face F
    TopoDS_Wire W;
    
    TopTools_ListIteratorOfListOfShape itE;
    for(itE.Initialize(myDS.FaceIntL(F));
	itE.More();
	itE.Next()) {
      TopoDS_Edge E = TopoDS::Edge(itE.Value());
      E.Orientation(TopAbs_INTERNAL);
      //Check, if outline edge coincides real edge

      BRepAdaptor_Curve C(E);
      Standard_Real par = 0.34*C.FirstParameter() + 0.66*C.LastParameter();
      gp_Pnt P = C.Value(par);
      TopoDS_Vertex V1, V2, aV1, aV2;
      TopExp::Vertices(E, V1, V2);

      Standard_Boolean SameEdge = Standard_False;
      if(!V1.IsNull() && aVEMap.Contains(V1)) {
	const TopTools_ListOfShape& aEList = aVEMap.FindFromKey(V1);
	TopTools_ListIteratorOfListOfShape it(aEList);
	for(; it.More(); it.Next()) {
	  const TopoDS_Edge& aE = TopoDS::Edge(it.Value());
	  TopExp::Vertices(aE, aV1, aV2);

	  if((V1.IsSame(aV1) && V2.IsSame(aV2)) || (V1.IsSame(aV2) && V2.IsSame(aV1))) {
	    BRepAdaptor_Curve aC(aE);
	    if((C.GetType() == GeomAbs_Line) &&
	       (aC.GetType() == GeomAbs_Line)) {
	      SameEdge = Standard_True;
	      break;
	    }
	    else {
	      //Try to project one point
	      Extrema_ExtPC anExt(P, aC);
	      if(anExt.IsDone()) {
		Standard_Integer aNe = anExt.NbExt();
		if(aNe > 0) {
		  Standard_Real dist = RealLast();
		  Standard_Integer ec;
		  for(ec = 1; ec <= aNe; ++ec) {
//		    dist = Min(dist, anExt.Value(ec));
		    dist = Min(dist, anExt.SquareDistance(ec));
		  }

//		  if(dist <= 1.e-7) {
		  if(dist <= 1.e-14) {
		    SameEdge = Standard_True;
		    break;
		  }
		}
	      }
	    }
	  }
	}
      }

      if(SameEdge) {
	OutL.Append(E);
	continue;
      }
	      
      if (myDS.EdgeHasSplE(E)) { 
	
	TopTools_ListIteratorOfListOfShape itS;
	for (itS.Initialize(myDS.EdgeSplE(E));
	     itS.More();
	     itS.Next()) {
	  TopoDS_Shape newE = itS.Value();
	  newE.Orientation(TopAbs_INTERNAL);
	  if (W.IsNull()) B.MakeWire(W);
	  myDS.AddOldS(newE,F);
	  B.Add(W,newE);
	}
      }
      else {
	if (W.IsNull()) B.MakeWire(W);
	myDS.AddOldS(E,F);
	B.Add(W,E);
      }
    }
    if (!W.IsNull()) B.Add(NF,W); // add the new wire in the new face.
  }
  
  if (myDS.FaceHasIsoL(F)) { // get the IsoLines on face F
    TopoDS_Wire W;
    
    TopTools_ListIteratorOfListOfShape itE;
    for(itE.Initialize(myDS.FaceIsoL(F));
	itE.More();
	itE.Next()) {
      TopoDS_Edge E = TopoDS::Edge(itE.Value());
      E.Orientation(TopAbs_INTERNAL);
      if (myDS.EdgeHasSplE(E)) { // normaly IsoLines are never splitted.
	
	TopTools_ListIteratorOfListOfShape itS;
	for (itS.Initialize(myDS.EdgeSplE(E));
	     itS.More();
	     itS.Next()) {
	  TopoDS_Shape newE = itS.Value();
	  newE.Orientation(TopAbs_INTERNAL);
	  if (W.IsNull()) B.MakeWire(W);
	  myDS.AddOldS(newE,F);
	  B.Add(W,newE);
	}
      }
      else {
	if (W.IsNull()) B.MakeWire(W);
	myDS.AddOldS(E,F);
	B.Add(W,E);
      }
    }
    if (!W.IsNull()) B.Add(NF,W); // add the new wire in the new face.
  }
  myDS.AddOldS(NF,F);
  MST.Bind(NF, MST.ChangeFind(F));
  //
  B.Add(S,NF); // add the face in the shell.
}

//=======================================================================
//function : BuildShape
//purpose  : Build the OutLinedShape
//=======================================================================

void HLRTopoBRep_OutLiner::BuildShape (BRepTopAdaptor_MapOfShapeTool& MST)
{
  TopExp_Explorer exshell, exface, exedge;
  BRep_Builder B;
  B.MakeCompound(TopoDS::Compound(myOutLinedShape));
  TopTools_MapOfShape ShapeMap;

  for (exshell.Init (myOriginalShape, TopAbs_SHELL);
       exshell.More (); 
       exshell.Next ()) {             // faces in a shell (open or close)
    TopoDS_Shell theShell;
    B.MakeShell(theShell);
    theShell.Closed(exshell.Current().Closed ());

    for (exface.Init(exshell.Current(), TopAbs_FACE);
	 exface.More(); 
	 exface.Next()) {
      if (ShapeMap.Add(exface.Current()))
	ProcessFace(TopoDS::Face(exface.Current()),theShell,MST);
    }
    B.Add(myOutLinedShape,theShell);
  }
  
  for (exface.Init(myOriginalShape, TopAbs_FACE, TopAbs_SHELL);
       exface.More(); 
       exface.Next()) {                           // faces not in a shell
    if (ShapeMap.Add(exface.Current()))
      ProcessFace (TopoDS::Face(exface.Current()),myOutLinedShape,MST);
  }
  
  for (exedge.Init(myOriginalShape, TopAbs_EDGE, TopAbs_FACE);
       exedge.More();
       exedge.Next())                              // edges not in a face
    B.Add(myOutLinedShape,exedge.Current());
}