1 // Created on: 1994-08-04
2 // Created by: Christophe MARION
3 // Copyright (c) 1994-1999 Matra Datavision
4 // Copyright (c) 1999-2012 OPEN CASCADE SAS
6 // The content of this file is subject to the Open CASCADE Technology Public
7 // License Version 6.5 (the "License"). You may not use the content of this file
8 // except in compliance with the License. Please obtain a copy of the License
9 // at http://www.opencascade.org and read it completely before using this file.
11 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
14 // The Original Code and all software distributed under the License is
15 // distributed on an "AS IS" basis, without warranty of any kind, and the
16 // Initial Developer hereby disclaims all such warranties, including without
17 // limitation, any warranties of merchantability, fitness for a particular
18 // purpose or non-infringement. Please see the License for the specific terms
19 // and conditions governing the rights and limitations under the License.
22 #include <HLRTopoBRep_OutLiner.ixx>
23 #include <HLRTopoBRep_DSFiller.hxx>
24 #include <Contap_Contour.hxx>
25 #include <BRep_Builder.hxx>
27 #include <TopoDS_Edge.hxx>
28 #include <TopoDS_Wire.hxx>
29 #include <TopoDS_Shell.hxx>
30 #include <TopExp_Explorer.hxx>
31 #include <TopTools_ListIteratorOfListOfShape.hxx>
35 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
37 #include <BRepAdaptor_Curve.hxx>
38 #include <Extrema_ExtPC.hxx>
40 //=======================================================================
43 //=======================================================================
45 HLRTopoBRep_OutLiner::HLRTopoBRep_OutLiner ()
48 //=======================================================================
51 //=======================================================================
53 HLRTopoBRep_OutLiner::HLRTopoBRep_OutLiner(const TopoDS_Shape& OriS) :
57 //=======================================================================
60 //=======================================================================
62 HLRTopoBRep_OutLiner::HLRTopoBRep_OutLiner(const TopoDS_Shape& OriS,
63 const TopoDS_Shape& OutS) :
64 myOriginalShape(OriS),
68 //=======================================================================
71 //=======================================================================
73 void HLRTopoBRep_OutLiner::Fill(const HLRAlgo_Projector& P,
74 BRepTopAdaptor_MapOfShapeTool& MST,
75 const Standard_Integer nbIso)
77 if (!myOriginalShape.IsNull()) {
78 if (myOutLinedShape.IsNull()) {
79 gp_Vec Vecz (0., 0., 1.);
80 gp_Trsf Tr (P.Transformation ());
84 if (P.Perspective ()) {
86 Eye.SetXYZ (P.Focus ()*Vecz.XYZ ());
93 HLRTopoBRep_DSFiller::Insert(myOriginalShape,FO,myDS,MST,nbIso);
99 //=======================================================================
100 // Function : ProcessFace
101 // Purpose : Build a Face using myDS and add the new face to a shell
102 //=======================================================================
104 void HLRTopoBRep_OutLiner::ProcessFace(const TopoDS_Face& F,
106 BRepTopAdaptor_MapOfShapeTool& MST)
109 TopExp_Explorer exE, exW;
110 //Standard_Boolean splitted = Standard_False;
112 TopTools_IndexedDataMapOfShapeListOfShape aVEMap;
113 TopExp::MapShapesAndAncestors(F, TopAbs_VERTEX, TopAbs_EDGE, aVEMap);
115 TopoDS_Shape NF;// = F;
116 //NF.Free(Standard_True);
118 //for (exE.Init(F,TopAbs_EDGE); exE.More(); exE.Next()) {
119 //if (myDS.EdgeHasSplE(TopoDS::Edge(exE.Current()))) {
120 //splitted = Standard_True;
125 //if (splitted) { // the face contains a splitted edge :
126 // Make a copy with the new Edges
127 NF = F.EmptyCopied ();
130 for (exW.Init(F,TopAbs_WIRE); exW.More(); exW.Next()) {
134 for (exE.Init(exW.Current(),TopAbs_EDGE); exE.More(); exE.Next()) {
135 TopoDS_Edge E = TopoDS::Edge(exE.Current());
136 if (myDS.EdgeHasSplE(E)) {
138 TopTools_ListIteratorOfListOfShape itS;
139 for (itS.Initialize(myDS.EdgeSplE(E));
142 TopoDS_Edge newE = TopoDS::Edge(itS.Value());
143 newE.Orientation(E.Orientation());
144 myDS.AddOldS(newE,E);
152 B.Add(NF,W); // add the new wire in the new face.
156 TopTools_ListOfShape& OutL = myDS.AddOutL(F);
158 if (myDS.FaceHasIntL(F)) { // get the InternalOutLines on face F
161 TopTools_ListIteratorOfListOfShape itE;
162 for(itE.Initialize(myDS.FaceIntL(F));
165 TopoDS_Edge E = TopoDS::Edge(itE.Value());
166 E.Orientation(TopAbs_INTERNAL);
167 //Check, if outline edge coincides real edge
169 BRepAdaptor_Curve C(E);
170 Standard_Real par = 0.34*C.FirstParameter() + 0.66*C.LastParameter();
171 gp_Pnt P = C.Value(par);
172 TopoDS_Vertex V1, V2, aV1, aV2;
173 TopExp::Vertices(E, V1, V2);
175 Standard_Boolean SameEdge = Standard_False;
176 if(!V1.IsNull() && aVEMap.Contains(V1)) {
177 const TopTools_ListOfShape& aEList = aVEMap.FindFromKey(V1);
178 TopTools_ListIteratorOfListOfShape it(aEList);
179 for(; it.More(); it.Next()) {
180 const TopoDS_Edge& aE = TopoDS::Edge(it.Value());
181 TopExp::Vertices(aE, aV1, aV2);
183 if((V1.IsSame(aV1) && V2.IsSame(aV2)) || (V1.IsSame(aV2) && V2.IsSame(aV1))) {
184 BRepAdaptor_Curve aC(aE);
185 if((C.GetType() == GeomAbs_Line) &&
186 (aC.GetType() == GeomAbs_Line)) {
187 SameEdge = Standard_True;
191 //Try to project one point
192 Extrema_ExtPC anExt(P, aC);
194 Standard_Integer aNe = anExt.NbExt();
196 Standard_Real dist = RealLast();
198 for(ec = 1; ec <= aNe; ++ec) {
199 // dist = Min(dist, anExt.Value(ec));
200 dist = Min(dist, anExt.SquareDistance(ec));
203 // if(dist <= 1.e-7) {
205 SameEdge = Standard_True;
220 if (myDS.EdgeHasSplE(E)) {
222 TopTools_ListIteratorOfListOfShape itS;
223 for (itS.Initialize(myDS.EdgeSplE(E));
226 TopoDS_Shape newE = itS.Value();
227 newE.Orientation(TopAbs_INTERNAL);
228 if (W.IsNull()) B.MakeWire(W);
229 myDS.AddOldS(newE,F);
234 if (W.IsNull()) B.MakeWire(W);
239 if (!W.IsNull()) B.Add(NF,W); // add the new wire in the new face.
242 if (myDS.FaceHasIsoL(F)) { // get the IsoLines on face F
245 TopTools_ListIteratorOfListOfShape itE;
246 for(itE.Initialize(myDS.FaceIsoL(F));
249 TopoDS_Edge E = TopoDS::Edge(itE.Value());
250 E.Orientation(TopAbs_INTERNAL);
251 if (myDS.EdgeHasSplE(E)) { // normaly IsoLines are never splitted.
253 TopTools_ListIteratorOfListOfShape itS;
254 for (itS.Initialize(myDS.EdgeSplE(E));
257 TopoDS_Shape newE = itS.Value();
258 newE.Orientation(TopAbs_INTERNAL);
259 if (W.IsNull()) B.MakeWire(W);
260 myDS.AddOldS(newE,F);
265 if (W.IsNull()) B.MakeWire(W);
270 if (!W.IsNull()) B.Add(NF,W); // add the new wire in the new face.
273 MST.Bind(NF, MST.ChangeFind(F));
275 B.Add(S,NF); // add the face in the shell.
278 //=======================================================================
279 //function : BuildShape
280 //purpose : Build the OutLinedShape
281 //=======================================================================
283 void HLRTopoBRep_OutLiner::BuildShape (BRepTopAdaptor_MapOfShapeTool& MST)
285 TopExp_Explorer exshell, exface, exedge;
287 B.MakeCompound(TopoDS::Compound(myOutLinedShape));
288 TopTools_MapOfShape ShapeMap;
290 for (exshell.Init (myOriginalShape, TopAbs_SHELL);
292 exshell.Next ()) { // faces in a shell (open or close)
293 TopoDS_Shell theShell;
294 B.MakeShell(theShell);
295 theShell.Closed(exshell.Current().Closed ());
297 for (exface.Init(exshell.Current(), TopAbs_FACE);
300 if (ShapeMap.Add(exface.Current()))
301 ProcessFace(TopoDS::Face(exface.Current()),theShell,MST);
303 B.Add(myOutLinedShape,theShell);
306 for (exface.Init(myOriginalShape, TopAbs_FACE, TopAbs_SHELL);
308 exface.Next()) { // faces not in a shell
309 if (ShapeMap.Add(exface.Current()))
310 ProcessFace (TopoDS::Face(exface.Current()),myOutLinedShape,MST);
313 for (exedge.Init(myOriginalShape, TopAbs_EDGE, TopAbs_FACE);
315 exedge.Next()) // edges not in a face
316 B.Add(myOutLinedShape,exedge.Current());