1 // Created on: 1993-06-17
2 // Created by: Jean Yves LEBEY
3 // Copyright (c) 1993-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 <TopOpeBRepBuild_ShellFaceClassifier.ixx>
24 #include <Precision.hxx>
26 #include <TopoDS_Vertex.hxx>
27 #include <TopoDS_Face.hxx>
28 #include <TopoDS_Shell.hxx>
29 #include <TopExp_Explorer.hxx>
30 #include <BRep_Tool.hxx>
31 #include <Standard_ProgramError.hxx>
32 #include <BRepAdaptor_Surface.hxx>
35 Standard_IMPORT Standard_Boolean TopOpeBRepBuild_GettraceCHK();
38 //=======================================================================
39 //function : TopOpeBRepBuild_ShellFaceClassifier
41 //=======================================================================
43 TopOpeBRepBuild_ShellFaceClassifier::TopOpeBRepBuild_ShellFaceClassifier
44 (const TopOpeBRepBuild_BlockBuilder& BB) :
45 TopOpeBRepBuild_CompositeClassifier(BB)
49 //=======================================================================
52 //=======================================================================
54 void TopOpeBRepBuild_ShellFaceClassifier::Clear()
56 mySolidClassifier.Clear();
57 myFaceShellMap.Clear();
60 //=======================================================================
61 //function : CompareShapes
63 //=======================================================================
65 TopAbs_State TopOpeBRepBuild_ShellFaceClassifier::CompareShapes
66 (const TopoDS_Shape& B1, const TopoDS_Shape& B2)
69 // const TopAbs_ShapeEnum t1 = B1.ShapeType();
70 // const TopAbs_ShapeEnum t2 = B2.ShapeType();
74 myShell = TopoDS::Shell(B2);
75 mySolidClassifier.LoadShell(myShell);
76 // myShell.Free(Standard_True);
77 TopAbs_State state = State();
82 //=======================================================================
83 //function : CompareElementToShape
85 //=======================================================================
87 TopAbs_State TopOpeBRepBuild_ShellFaceClassifier::CompareElementToShape
88 (const TopoDS_Shape& F, const TopoDS_Shape& SHE)
91 // const TopAbs_ShapeEnum t1 = F.ShapeType();
92 // const TopAbs_ShapeEnum t2 = SHE.ShapeType();
96 myShell = TopoDS::Shell(SHE);
97 mySolidClassifier.LoadShell(myShell);
98 // myShell.Free(Standard_True);
99 TopAbs_State state = State();
104 //=======================================================================
105 //function : ResetShape
107 //=======================================================================
109 void TopOpeBRepBuild_ShellFaceClassifier::ResetShape(const TopoDS_Shape& SHE)
112 // const TopAbs_ShapeEnum t1 = SHE.ShapeType();
115 TopExp_Explorer ex(SHE,TopAbs_FACE);
116 const TopoDS_Face& F = TopoDS::Face(ex.Current());
121 //=======================================================================
122 //function : ResetElement
124 //=======================================================================
126 void TopOpeBRepBuild_ShellFaceClassifier::ResetElement(const TopoDS_Shape& F)
128 const TopAbs_ShapeEnum t = F.ShapeType();
131 // initialize myPoint3d with first vertex of face <E>
132 myFirstCompare = Standard_True;
134 TopExp_Explorer ex(F,TopAbs_VERTEX);
136 const TopoDS_Vertex& V = TopoDS::Vertex(ex.Current());
137 myPoint3d = BRep_Tool::Pnt(V);
140 if(t == TopAbs_FACE) {
141 BRepAdaptor_Surface BAS(TopoDS::Face(F));
142 myPoint3d = BAS.Value(.5*(BAS.FirstUParameter()+BAS.LastUParameter()),
143 .5*(BAS.FirstVParameter()+BAS.LastVParameter()));
146 myPoint3d.SetCoord(0.,0.,0.);
152 //=======================================================================
153 //function : CompareElement
155 //=======================================================================
157 Standard_Boolean TopOpeBRepBuild_ShellFaceClassifier::CompareElement(const TopoDS_Shape& F)
160 // const TopAbs_ShapeEnum t = F.ShapeType();
162 Standard_Boolean bRet = Standard_True;
164 if (myFirstCompare) {
165 Standard_Boolean found = myFaceShellMap.IsBound(F);
167 // la face F est la premiere d'un bloc de faces
168 // la face F d'un bloc de faces (F est supposee n'appartenir qu'a
169 // un seul shell) n'a pas encore ete rencontree <=> le bloc de faces
170 // dont F fait partie n'a pas encore ete shellise
171 // on cree un shell et on l'attache a F
172 myBuilder.MakeShell(myShell);
173 myBuilder.Add(myShell,F);
174 myFaceShellMap.Bind(F,myShell);
177 // la face F est la premiere d'un bloc de faces
178 // on recupere le shell correspondant au bloc de faces (shellise)
179 // dont F fait partie.
180 TopoDS_Shape sbid = myFaceShellMap.Find(F);
181 myShell = TopoDS::Shell(sbid);
184 myFirstCompare = Standard_False;
187 // F n'est pas la premiere face d'un bloc.
188 // myShell est necessairement defini et represente le bloc de faces
189 // dont F fait partie
190 myBuilder.Add(myShell,F);
196 #include <BRepTools.hxx>
197 #include <BRep_Builder.hxx>
198 #include <TCollection_AsciiString.hxx>
199 static Standard_Integer STATIC_ishell = 0;
202 //=======================================================================
205 //=======================================================================
207 TopAbs_State TopOpeBRepBuild_ShellFaceClassifier::State()
210 Standard_Real tol3d = Precision::Confusion();
213 if (TopOpeBRepBuild_GettraceCHK()) {
215 TCollection_AsciiString home("/home/wb/mdl/gti/prod/TTOPOPE/src/test/data/");
216 TCollection_AsciiString sname("shell_"); sname = home + sname + STATIC_ishell;
217 TCollection_AsciiString vname("vertex_"); vname = home + vname + STATIC_ishell;
218 BRep_Builder B;TopoDS_Vertex V;B.MakeVertex(V,myPoint3d,tol3d);
219 cout<<"TopOpeBRepBuild_ShellFaceClassifier : write shell "<<sname;
220 cout<<" vertex "<<vname<<endl;
221 BRepTools::Write(myShell,sname.ToCString());
222 BRepTools::Write(V,vname.ToCString());
225 mySolidClassifier.Classify(myShell,myPoint3d,tol3d);
226 state = mySolidClassifier.State();