1 // Created on: 1993-06-17
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 <BRep_Tool.hxx>
19 #include <BRepAdaptor_Surface.hxx>
20 #include <Precision.hxx>
21 #include <Standard_ProgramError.hxx>
22 #include <TopExp_Explorer.hxx>
23 #include <TopoDS.hxx>
24 #include <TopoDS_Face.hxx>
25 #include <TopoDS_Shape.hxx>
26 #include <TopoDS_Shell.hxx>
27 #include <TopoDS_Vertex.hxx>
28 #include <TopOpeBRepBuild_BlockBuilder.hxx>
29 #include <TopOpeBRepBuild_ShellFaceClassifier.hxx>
30
31 #ifdef OCCT_DEBUG
32 extern Standard_Boolean TopOpeBRepBuild_GettraceCHK();
33 #endif
34
35 //=======================================================================
36 //function : TopOpeBRepBuild_ShellFaceClassifier
37 //purpose :
38 //=======================================================================
39
TopOpeBRepBuild_ShellFaceClassifier(const TopOpeBRepBuild_BlockBuilder & BB)40 TopOpeBRepBuild_ShellFaceClassifier::TopOpeBRepBuild_ShellFaceClassifier
41 (const TopOpeBRepBuild_BlockBuilder& BB) :
42 TopOpeBRepBuild_CompositeClassifier(BB)
43 {
44 }
45
46 //=======================================================================
47 //function : Clear
48 //purpose :
49 //=======================================================================
50
Clear()51 void TopOpeBRepBuild_ShellFaceClassifier::Clear()
52 {
53 mySolidClassifier.Clear();
54 myFaceShellMap.Clear();
55 }
56
57 //=======================================================================
58 //function : CompareShapes
59 //purpose :
60 //=======================================================================
61
CompareShapes(const TopoDS_Shape & B1,const TopoDS_Shape & B2)62 TopAbs_State TopOpeBRepBuild_ShellFaceClassifier::CompareShapes
63 (const TopoDS_Shape& B1, const TopoDS_Shape& B2)
64 {
65 #ifdef OCCT_DEBUG
66 // const TopAbs_ShapeEnum t1 = B1.ShapeType();
67 // const TopAbs_ShapeEnum t2 = B2.ShapeType();
68 #endif
69
70 ResetShape(B1);
71 myShell = TopoDS::Shell(B2);
72 mySolidClassifier.LoadShell(myShell);
73 // myShell.Free(Standard_True);
74 TopAbs_State state = State();
75 return state;
76 }
77
78
79 //=======================================================================
80 //function : CompareElementToShape
81 //purpose :
82 //=======================================================================
83
CompareElementToShape(const TopoDS_Shape & F,const TopoDS_Shape & SHE)84 TopAbs_State TopOpeBRepBuild_ShellFaceClassifier::CompareElementToShape
85 (const TopoDS_Shape& F, const TopoDS_Shape& SHE)
86 {
87 #ifdef OCCT_DEBUG
88 // const TopAbs_ShapeEnum t1 = F.ShapeType();
89 // const TopAbs_ShapeEnum t2 = SHE.ShapeType();
90 #endif
91
92 ResetElement(F);
93 myShell = TopoDS::Shell(SHE);
94 mySolidClassifier.LoadShell(myShell);
95 // myShell.Free(Standard_True);
96 TopAbs_State state = State();
97 return state;
98 }
99
100
101 //=======================================================================
102 //function : ResetShape
103 //purpose :
104 //=======================================================================
105
ResetShape(const TopoDS_Shape & SHE)106 void TopOpeBRepBuild_ShellFaceClassifier::ResetShape(const TopoDS_Shape& SHE)
107 {
108 #ifdef OCCT_DEBUG
109 // const TopAbs_ShapeEnum t1 = SHE.ShapeType();
110 #endif
111
112 TopExp_Explorer ex(SHE,TopAbs_FACE);
113 const TopoDS_Face& F = TopoDS::Face(ex.Current());
114 ResetElement(F);
115 }
116
117
118 //=======================================================================
119 //function : ResetElement
120 //purpose :
121 //=======================================================================
122
ResetElement(const TopoDS_Shape & F)123 void TopOpeBRepBuild_ShellFaceClassifier::ResetElement(const TopoDS_Shape& F)
124 {
125 const TopAbs_ShapeEnum t = F.ShapeType();
126
127
128 // initialize myPoint3d with first vertex of face <E>
129 myFirstCompare = Standard_True;
130
131 TopExp_Explorer ex(F,TopAbs_VERTEX);
132 if ( ex.More() ) {
133 const TopoDS_Vertex& V = TopoDS::Vertex(ex.Current());
134 myPoint3d = BRep_Tool::Pnt(V);
135 }
136 else {
137 if(t == TopAbs_FACE) {
138 BRepAdaptor_Surface BAS(TopoDS::Face(F));
139 myPoint3d = BAS.Value(.5*(BAS.FirstUParameter()+BAS.LastUParameter()),
140 .5*(BAS.FirstVParameter()+BAS.LastVParameter()));
141 }
142 else {
143 myPoint3d.SetCoord(0.,0.,0.);
144 }
145 }
146
147 }
148
149 //=======================================================================
150 //function : CompareElement
151 //purpose :
152 //=======================================================================
153
CompareElement(const TopoDS_Shape & F)154 Standard_Boolean TopOpeBRepBuild_ShellFaceClassifier::CompareElement(const TopoDS_Shape& F)
155 {
156 #ifdef OCCT_DEBUG
157 // const TopAbs_ShapeEnum t = F.ShapeType();
158 #endif
159 Standard_Boolean bRet = Standard_True;
160 //
161 if (myFirstCompare) {
162 Standard_Boolean found = myFaceShellMap.IsBound(F);
163 if ( !found ) {
164 // la face F est la premiere d'un bloc de faces
165 // la face F d'un bloc de faces (F est supposee n'appartenir qu'a
166 // un seul shell) n'a pas encore ete rencontree <=> le bloc de faces
167 // dont F fait partie n'a pas encore ete shellise
168 // on cree un shell et on l'attache a F
169 myBuilder.MakeShell(myShell);
170 myBuilder.Add(myShell,F);
171 myFaceShellMap.Bind(F,myShell);
172 }
173 else {
174 // la face F est la premiere d'un bloc de faces
175 // on recupere le shell correspondant au bloc de faces (shellise)
176 // dont F fait partie.
177 TopoDS_Shape sbid = myFaceShellMap.Find(F);
178 myShell = TopoDS::Shell(sbid);
179 bRet = !bRet;
180 }
181 myFirstCompare = Standard_False;
182 }
183 else {
184 // F n'est pas la premiere face d'un bloc.
185 // myShell est necessairement defini et represente le bloc de faces
186 // dont F fait partie
187 myBuilder.Add(myShell,F);
188 }
189 return bRet;
190 }
191
192 #ifdef OCCT_DEBUG
193 #include <BRepTools.hxx>
194 #include <BRep_Builder.hxx>
195 #include <TCollection_AsciiString.hxx>
196 static Standard_Integer STATIC_ishell = 0;
197 #endif
198
199 //=======================================================================
200 //function : State
201 //purpose :
202 //=======================================================================
203
State()204 TopAbs_State TopOpeBRepBuild_ShellFaceClassifier::State()
205 {
206 TopAbs_State state;
207 Standard_Real tol3d = Precision::Confusion();
208
209 #ifdef OCCT_DEBUG
210 if (TopOpeBRepBuild_GettraceCHK()) {
211 STATIC_ishell++;
212 TCollection_AsciiString home("/home/wb/mdl/gti/prod/TTOPOPE/src/test/data/");
213 TCollection_AsciiString sname("shell_"); sname = home + sname + STATIC_ishell;
214 TCollection_AsciiString vname("vertex_"); vname = home + vname + STATIC_ishell;
215 BRep_Builder B;TopoDS_Vertex V;B.MakeVertex(V,myPoint3d,tol3d);
216 std::cout<<"TopOpeBRepBuild_ShellFaceClassifier : write shell "<<sname;
217 std::cout<<" vertex "<<vname<<std::endl;
218 BRepTools::Write(myShell,sname.ToCString());
219 BRepTools::Write(V,vname.ToCString());
220 }
221 #endif
222 mySolidClassifier.Classify(myShell,myPoint3d,tol3d);
223 state = mySolidClassifier.State();
224 return state;
225 }
226