0031668: Visualization - WebGL sample doesn't work on Emscripten 1.39
[occt.git] / src / TopOpeBRepBuild / TopOpeBRepBuild_BuildEdges.cxx
1 // Created on: 1993-06-14
2 // Created by: Jean Yves LEBEY
3 // Copyright (c) 1993-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
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.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16
17
18 #include <gp_Pnt.hxx>
19 #include <Standard_NoSuchObject.hxx>
20 #include <TCollection_AsciiString.hxx>
21 #include <TColStd_HArray1OfInteger.hxx>
22 #include <TopoDS.hxx>
23 #include <TopoDS_Edge.hxx>
24 #include <TopoDS_Face.hxx>
25 #include <TopoDS_Shape.hxx>
26 #include <TopoDS_Vertex.hxx>
27 #include <TopOpeBRepBuild_Builder.hxx>
28 #include <TopOpeBRepBuild_define.hxx>
29 #include <TopOpeBRepBuild_EdgeBuilder.hxx>
30 #include <TopOpeBRepBuild_FaceBuilder.hxx>
31 #include <TopOpeBRepBuild_GTopo.hxx>
32 #include <TopOpeBRepBuild_HBuilder.hxx>
33 #include <TopOpeBRepBuild_PaveSet.hxx>
34 #include <TopOpeBRepBuild_ShapeSet.hxx>
35 #include <TopOpeBRepBuild_ShellFaceSet.hxx>
36 #include <TopOpeBRepBuild_SolidBuilder.hxx>
37 #include <TopOpeBRepBuild_WireEdgeSet.hxx>
38 #include <TopOpeBRepDS_BuildTool.hxx>
39 #include <TopOpeBRepDS_Curve.hxx>
40 #include <TopOpeBRepDS_CurveExplorer.hxx>
41 #include <TopOpeBRepDS_CurveIterator.hxx>
42 #include <TopOpeBRepDS_HDataStructure.hxx>
43 #include <TopOpeBRepDS_PointIterator.hxx>
44 #include <TopOpeBRepDS_SurfaceIterator.hxx>
45 #include <TopOpeBRepTool_ShapeExplorer.hxx>
46
47 #ifdef OCCT_DEBUG
48 extern Standard_Boolean TopOpeBRepBuild_GettraceCU();
49 #endif
50
51 //=======================================================================
52 //function : BuildEdges
53 //purpose  : 
54 //=======================================================================
55 void TopOpeBRepBuild_Builder::BuildEdges(const Standard_Integer iC,const Handle(TopOpeBRepDS_HDataStructure)& HDS)
56 {
57 #ifdef OCCT_DEBUG
58   if (TopOpeBRepBuild_GettraceCU()) std::cout<<"\nBuildEdges on C "<<iC<<std::endl;
59 #endif
60   const TopOpeBRepDS_Curve& C = HDS->Curve(iC);
61   const Handle(Geom_Curve)& C3D = C.Curve(); 
62   const Handle(TopOpeBRepDS_Interference)& I1 = C.GetSCI1();
63   const Handle(TopOpeBRepDS_Interference)& I2 = C.GetSCI2();
64   Standard_Boolean nnn = C3D.IsNull() && I1.IsNull() && I2.IsNull();
65   if (nnn) {
66     return;
67   }
68   
69   TopoDS_Shape anEdge;
70   const TopOpeBRepDS_Curve& curC = HDS->Curve(iC);
71   myBuildTool.MakeEdge(anEdge,curC,HDS->DS());
72   TopOpeBRepBuild_PaveSet PVS(anEdge);
73   TopOpeBRepDS_PointIterator CPIT(HDS->CurvePoints(iC));
74   FillVertexSet(CPIT,TopAbs_IN,PVS);
75   TopOpeBRepBuild_PaveClassifier VCL(anEdge);
76   Standard_Boolean equalpar = PVS.HasEqualParameters();
77   if (equalpar) VCL.SetFirstParameter(PVS.EqualParameters());
78   Standard_Boolean closvert = PVS.ClosedVertices();
79   VCL.ClosedVertices(closvert);  
80   PVS.InitLoop();
81   if ( !PVS.MoreLoop() ) {
82     return;
83   }
84   TopOpeBRepBuild_EdgeBuilder EDBU(PVS,VCL);
85   TopTools_ListOfShape& EL = ChangeNewEdges(iC);
86   MakeEdges(anEdge,EDBU,EL);
87   TopTools_ListIteratorOfListOfShape It(EL);
88   Standard_Integer inewC = -1;
89   for (; It.More(); It.Next()) {
90     TopoDS_Edge& newEdge = TopoDS::Edge(It.Value());
91     myBuildTool.RecomputeCurves(curC,TopoDS::Edge(anEdge),newEdge,inewC,HDS);
92     if (inewC != -1) ChangeNewEdges(inewC).Append(newEdge);
93   }
94   if (inewC != -1) {
95     HDS->RemoveCurve(iC);
96   }
97   else {
98     for (It.Initialize(EL);It.More();It.Next()) {
99       TopoDS_Edge& newEdge = TopoDS::Edge(It.Value());
100       myBuildTool.UpdateEdge(anEdge,newEdge);
101     }
102   }
103 }
104
105 //=======================================================================
106 //function : BuildEdges
107 //purpose  : 
108 //=======================================================================
109 void TopOpeBRepBuild_Builder::BuildEdges(const Handle(TopOpeBRepDS_HDataStructure)& HDS)
110 {
111   TopOpeBRepDS_DataStructure& BDS = HDS->ChangeDS();
112
113   myNewEdges.Clear();
114   TopOpeBRepDS_CurveExplorer cex;
115
116   Standard_Integer ick = 0;
117   for (cex.Init(BDS,Standard_False); cex.More(); cex.Next()) {
118     Standard_Integer ic = cex.Index();
119     Standard_Boolean ck = cex.IsCurveKeep(ic);
120     Standard_Integer im = cex.Curve(ic).Mother();
121     if (ck == 1 && im != 0 && ick == 0) { ick = ic; break; }
122   }
123   if (ick) {
124     for (cex.Init(BDS,Standard_True); cex.More(); cex.Next()) {
125       Standard_Integer ic = cex.Index();
126       BDS.RemoveCurve(ic);
127     }
128     BDS.ChangeNbCurves(ick-1);
129   }
130
131   for (cex.Init(BDS,Standard_False); cex.More(); cex.Next()) {
132     Standard_Integer ic = cex.Index();
133     Standard_Integer im = cex.Curve(ic).Mother();
134     if (im != 0 ) continue;
135     BuildEdges(ic,HDS);
136   }
137
138   Standard_Integer ip, np = HDS->NbPoints();
139   TColStd_HArray1OfInteger tp(0,np,0);
140   for (cex.Init(BDS); cex.More(); cex.Next()) {
141 #ifdef OCCT_DEBUG
142 //    const TopOpeBRepDS_Curve& C = cex.Curve();
143 #endif
144     Standard_Integer ic = cex.Index();
145     TopOpeBRepDS_ListIteratorOfListOfInterference it(BDS.CurveInterferences(ic));
146     for(;it.More();it.Next()) {
147       const Handle(TopOpeBRepDS_Interference)& I = it.Value();
148       {
149         Standard_Integer ig = I->Geometry();
150         TopOpeBRepDS_Kind kg = I->GeometryType();
151         if (kg == TopOpeBRepDS_POINT && ig <= np) tp.ChangeValue(ig) = tp.Value(ig) + 1;
152       }
153       {
154         Standard_Integer is = I->Support();
155         TopOpeBRepDS_Kind ks = I->SupportType();
156         if (ks == TopOpeBRepDS_POINT) tp.ChangeValue(is) = tp.Value(is) + 1;
157       }
158     }
159   }
160   Standard_Integer is, ns = BDS.NbShapes();
161   for (is = 1; is <= ns; is++ ) {
162     const TopoDS_Shape& S = BDS.Shape(is);
163     if(S.IsNull()) continue;
164     Standard_Boolean test = (S.ShapeType() == TopAbs_EDGE); 
165     if ( !test ) continue;
166     TopOpeBRepDS_ListIteratorOfListOfInterference it(BDS.ShapeInterferences(is));
167     for(;it.More();it.Next()) {
168       const Handle(TopOpeBRepDS_Interference)& I = it.Value(); 
169       {
170         Standard_Integer ig = I->Geometry();
171         TopOpeBRepDS_Kind kg = I->GeometryType();
172         if (kg == TopOpeBRepDS_POINT) tp.ChangeValue(ig) = tp.Value(ig) + 1;
173       }
174       {
175         Standard_Integer is1 = I->Support();
176         TopOpeBRepDS_Kind ks = I->SupportType();
177        if (ks == TopOpeBRepDS_POINT) tp.ChangeValue(is1) = tp.Value(is1) + 1;
178       }
179     }
180   }
181   for (ip = 1; ip <= np; ip++) if (tp.Value(ip) == 0) BDS.RemovePoint(ip);
182 }