1 // Created on: 1994-08-04
2 // Created by: Christophe MARION
3 // Copyright (c) 1994-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
18 #include <BRep_Builder.hxx>
19 #include <BRepAdaptor_Curve.hxx>
20 #include <Contap_Contour.hxx>
21 #include <Extrema_ExtPC.hxx>
25 #include <HLRAlgo_Projector.hxx>
26 #include <HLRTopoBRep_Data.hxx>
27 #include <HLRTopoBRep_DSFiller.hxx>
28 #include <HLRTopoBRep_OutLiner.hxx>
29 #include <Standard_Type.hxx>
31 #include <TopExp_Explorer.hxx>
33 #include <TopoDS_Edge.hxx>
34 #include <TopoDS_Face.hxx>
35 #include <TopoDS_Shape.hxx>
36 #include <TopoDS_Shell.hxx>
37 #include <TopoDS_Wire.hxx>
38 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
39 #include <TopTools_ListIteratorOfListOfShape.hxx>
41 IMPLEMENT_STANDARD_RTTIEXT(HLRTopoBRep_OutLiner,Standard_Transient)
43 //=======================================================================
46 //=======================================================================
47 HLRTopoBRep_OutLiner::HLRTopoBRep_OutLiner ()
50 //=======================================================================
53 //=======================================================================
55 HLRTopoBRep_OutLiner::HLRTopoBRep_OutLiner(const TopoDS_Shape& OriS) :
59 //=======================================================================
62 //=======================================================================
64 HLRTopoBRep_OutLiner::HLRTopoBRep_OutLiner(const TopoDS_Shape& OriS,
65 const TopoDS_Shape& OutS) :
66 myOriginalShape(OriS),
70 //=======================================================================
73 //=======================================================================
75 void HLRTopoBRep_OutLiner::Fill(const HLRAlgo_Projector& P,
76 BRepTopAdaptor_MapOfShapeTool& MST,
77 const Standard_Integer nbIso)
79 if (!myOriginalShape.IsNull()) {
80 if (myOutLinedShape.IsNull()) {
81 gp_Vec Vecz (0., 0., 1.);
82 gp_Trsf Tr (P.Transformation ());
86 if (P.Perspective ()) {
88 Eye.SetXYZ (P.Focus ()*Vecz.XYZ ());
95 HLRTopoBRep_DSFiller::Insert(myOriginalShape,FO,myDS,MST,nbIso);
101 //=======================================================================
102 // Function : ProcessFace
103 // Purpose : Build a Face using myDS and add the new face to a shell
104 //=======================================================================
106 void HLRTopoBRep_OutLiner::ProcessFace(const TopoDS_Face& F,
108 BRepTopAdaptor_MapOfShapeTool& MST)
111 TopExp_Explorer exE, exW;
112 //Standard_Boolean splitted = Standard_False;
114 TopTools_IndexedDataMapOfShapeListOfShape aVEMap;
115 TopExp::MapShapesAndAncestors(F, TopAbs_VERTEX, TopAbs_EDGE, aVEMap);
117 TopoDS_Shape NF;// = F;
118 //NF.Free(Standard_True);
120 //for (exE.Init(F,TopAbs_EDGE); exE.More(); exE.Next()) {
121 //if (myDS.EdgeHasSplE(TopoDS::Edge(exE.Current()))) {
122 //splitted = Standard_True;
127 //if (splitted) { // the face contains a splitted edge :
128 // Make a copy with the new Edges
129 NF = F.EmptyCopied ();
132 for (exW.Init(F,TopAbs_WIRE); exW.More(); exW.Next()) {
136 for (exE.Init(exW.Current(),TopAbs_EDGE); exE.More(); exE.Next()) {
137 TopoDS_Edge E = TopoDS::Edge(exE.Current());
138 if (myDS.EdgeHasSplE(E)) {
140 TopTools_ListIteratorOfListOfShape itS;
141 for (itS.Initialize(myDS.EdgeSplE(E));
144 TopoDS_Edge newE = TopoDS::Edge(itS.Value());
145 newE.Orientation(E.Orientation());
146 myDS.AddOldS(newE,E);
154 B.Add(NF,W); // add the new wire in the new face.
158 TopTools_ListOfShape& OutL = myDS.AddOutL(F);
160 if (myDS.FaceHasIntL(F)) { // get the InternalOutLines on face F
163 TopTools_ListIteratorOfListOfShape itE;
164 for(itE.Initialize(myDS.FaceIntL(F));
167 TopoDS_Edge E = TopoDS::Edge(itE.Value());
168 E.Orientation(TopAbs_INTERNAL);
169 //Check, if outline edge coincides real edge
171 BRepAdaptor_Curve C(E);
172 Standard_Real par = 0.34*C.FirstParameter() + 0.66*C.LastParameter();
173 gp_Pnt P = C.Value(par);
174 TopoDS_Vertex V1, V2, aV1, aV2;
175 TopExp::Vertices(E, V1, V2);
177 Standard_Boolean SameEdge = Standard_False;
178 if(!V1.IsNull() && aVEMap.Contains(V1)) {
179 const TopTools_ListOfShape& aEList = aVEMap.FindFromKey(V1);
180 TopTools_ListIteratorOfListOfShape it(aEList);
181 for(; it.More(); it.Next()) {
182 const TopoDS_Edge& aE = TopoDS::Edge(it.Value());
183 TopExp::Vertices(aE, aV1, aV2);
185 if((V1.IsSame(aV1) && V2.IsSame(aV2)) || (V1.IsSame(aV2) && V2.IsSame(aV1))) {
186 BRepAdaptor_Curve aC(aE);
187 if((C.GetType() == GeomAbs_Line) &&
188 (aC.GetType() == GeomAbs_Line)) {
189 SameEdge = Standard_True;
193 //Try to project one point
194 Extrema_ExtPC anExt(P, aC);
196 Standard_Integer aNe = anExt.NbExt();
198 Standard_Real dist = RealLast();
200 for(ec = 1; ec <= aNe; ++ec) {
201 // dist = Min(dist, anExt.Value(ec));
202 dist = Min(dist, anExt.SquareDistance(ec));
205 // if(dist <= 1.e-7) {
207 SameEdge = Standard_True;
222 if (myDS.EdgeHasSplE(E)) {
224 TopTools_ListIteratorOfListOfShape itS;
225 for (itS.Initialize(myDS.EdgeSplE(E));
228 TopoDS_Shape newE = itS.Value();
229 newE.Orientation(TopAbs_INTERNAL);
230 if (W.IsNull()) B.MakeWire(W);
231 myDS.AddOldS(newE,F);
236 if (W.IsNull()) B.MakeWire(W);
241 if (!W.IsNull()) B.Add(NF,W); // add the new wire in the new face.
244 if (myDS.FaceHasIsoL(F)) { // get the IsoLines on face F
247 TopTools_ListIteratorOfListOfShape itE;
248 for(itE.Initialize(myDS.FaceIsoL(F));
251 TopoDS_Edge E = TopoDS::Edge(itE.Value());
252 E.Orientation(TopAbs_INTERNAL);
253 if (myDS.EdgeHasSplE(E)) { // normally IsoLines are never split.
255 TopTools_ListIteratorOfListOfShape itS;
256 for (itS.Initialize(myDS.EdgeSplE(E));
259 TopoDS_Shape newE = itS.Value();
260 newE.Orientation(TopAbs_INTERNAL);
261 if (W.IsNull()) B.MakeWire(W);
262 myDS.AddOldS(newE,F);
267 if (W.IsNull()) B.MakeWire(W);
272 if (!W.IsNull()) B.Add(NF,W); // add the new wire in the new face.
275 MST.Bind(NF, MST.ChangeFind(F));
277 B.Add(S,NF); // add the face in the shell.
280 //=======================================================================
281 //function : BuildShape
282 //purpose : Build the OutLinedShape
283 //=======================================================================
285 void HLRTopoBRep_OutLiner::BuildShape (BRepTopAdaptor_MapOfShapeTool& MST)
287 TopExp_Explorer exshell, exface, exedge;
289 B.MakeCompound(TopoDS::Compound(myOutLinedShape));
290 TopTools_MapOfShape ShapeMap;
292 for (exshell.Init (myOriginalShape, TopAbs_SHELL);
294 exshell.Next ()) { // faces in a shell (open or close)
295 TopoDS_Shell theShell;
296 B.MakeShell(theShell);
297 theShell.Closed(exshell.Current().Closed ());
299 for (exface.Init(exshell.Current(), TopAbs_FACE);
302 if (ShapeMap.Add(exface.Current()))
303 ProcessFace(TopoDS::Face(exface.Current()),theShell,MST);
305 B.Add(myOutLinedShape,theShell);
308 for (exface.Init(myOriginalShape, TopAbs_FACE, TopAbs_SHELL);
310 exface.Next()) { // faces not in a shell
311 if (ShapeMap.Add(exface.Current()))
312 ProcessFace (TopoDS::Face(exface.Current()),myOutLinedShape,MST);
315 for (exedge.Init(myOriginalShape, TopAbs_EDGE, TopAbs_FACE);
317 exedge.Next()) // edges not in a face
318 B.Add(myOutLinedShape,exedge.Current());