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
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_Tool.hxx>
19 #include <BRepAdaptor_Surface.hxx>
20 #include <Precision.hxx>
21 #include <Standard_ProgramError.hxx>
22 #include <TopExp_Explorer.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>
32 extern Standard_Boolean TopOpeBRepBuild_GettraceCHK();
35 //=======================================================================
36 //function : TopOpeBRepBuild_ShellFaceClassifier
38 //=======================================================================
40 TopOpeBRepBuild_ShellFaceClassifier::TopOpeBRepBuild_ShellFaceClassifier
41 (const TopOpeBRepBuild_BlockBuilder& BB) :
42 TopOpeBRepBuild_CompositeClassifier(BB)
46 //=======================================================================
49 //=======================================================================
51 void TopOpeBRepBuild_ShellFaceClassifier::Clear()
53 mySolidClassifier.Clear();
54 myFaceShellMap.Clear();
57 //=======================================================================
58 //function : CompareShapes
60 //=======================================================================
62 TopAbs_State TopOpeBRepBuild_ShellFaceClassifier::CompareShapes
63 (const TopoDS_Shape& B1, const TopoDS_Shape& B2)
66 // const TopAbs_ShapeEnum t1 = B1.ShapeType();
67 // const TopAbs_ShapeEnum t2 = B2.ShapeType();
71 myShell = TopoDS::Shell(B2);
72 mySolidClassifier.LoadShell(myShell);
73 // myShell.Free(Standard_True);
74 TopAbs_State state = State();
79 //=======================================================================
80 //function : CompareElementToShape
82 //=======================================================================
84 TopAbs_State TopOpeBRepBuild_ShellFaceClassifier::CompareElementToShape
85 (const TopoDS_Shape& F, const TopoDS_Shape& SHE)
88 // const TopAbs_ShapeEnum t1 = F.ShapeType();
89 // const TopAbs_ShapeEnum t2 = SHE.ShapeType();
93 myShell = TopoDS::Shell(SHE);
94 mySolidClassifier.LoadShell(myShell);
95 // myShell.Free(Standard_True);
96 TopAbs_State state = State();
101 //=======================================================================
102 //function : ResetShape
104 //=======================================================================
106 void TopOpeBRepBuild_ShellFaceClassifier::ResetShape(const TopoDS_Shape& SHE)
109 // const TopAbs_ShapeEnum t1 = SHE.ShapeType();
112 TopExp_Explorer ex(SHE,TopAbs_FACE);
113 const TopoDS_Face& F = TopoDS::Face(ex.Current());
118 //=======================================================================
119 //function : ResetElement
121 //=======================================================================
123 void TopOpeBRepBuild_ShellFaceClassifier::ResetElement(const TopoDS_Shape& F)
125 const TopAbs_ShapeEnum t = F.ShapeType();
128 // initialize myPoint3d with first vertex of face <E>
129 myFirstCompare = Standard_True;
131 TopExp_Explorer ex(F,TopAbs_VERTEX);
133 const TopoDS_Vertex& V = TopoDS::Vertex(ex.Current());
134 myPoint3d = BRep_Tool::Pnt(V);
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()));
143 myPoint3d.SetCoord(0.,0.,0.);
149 //=======================================================================
150 //function : CompareElement
152 //=======================================================================
154 Standard_Boolean TopOpeBRepBuild_ShellFaceClassifier::CompareElement(const TopoDS_Shape& F)
157 // const TopAbs_ShapeEnum t = F.ShapeType();
159 Standard_Boolean bRet = Standard_True;
161 if (myFirstCompare) {
162 Standard_Boolean found = myFaceShellMap.IsBound(F);
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);
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);
181 myFirstCompare = Standard_False;
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);
193 #include <BRepTools.hxx>
194 #include <BRep_Builder.hxx>
195 #include <TCollection_AsciiString.hxx>
196 static Standard_Integer STATIC_ishell = 0;
199 //=======================================================================
202 //=======================================================================
204 TopAbs_State TopOpeBRepBuild_ShellFaceClassifier::State()
207 Standard_Real tol3d = Precision::Confusion();
210 if (TopOpeBRepBuild_GettraceCHK()) {
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 cout<<"TopOpeBRepBuild_ShellFaceClassifier : write shell "<<sname;
217 cout<<" vertex "<<vname<<endl;
218 BRepTools::Write(myShell,sname.ToCString());
219 BRepTools::Write(V,vname.ToCString());
222 mySolidClassifier.Classify(myShell,myPoint3d,tol3d);
223 state = mySolidClassifier.State();