0031668: Visualization - WebGL sample doesn't work on Emscripten 1.39
[occt.git] / src / TopClass / TopClass_SolidClassifier.gxx
CommitLineData
b311480e 1// Copyright (c) 1995-1999 Matra Datavision
973c2be1 2// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 3//
973c2be1 4// This file is part of Open CASCADE Technology software library.
b311480e 5//
d5f74e42 6// This library is free software; you can redistribute it and/or modify it under
7// the terms of the GNU Lesser General Public License version 2.1 as published
973c2be1 8// by the Free Software Foundation, with special exception defined in the file
9// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
10// distribution for complete text of the license and disclaimer of any warranty.
b311480e 11//
973c2be1 12// Alternatively, this file may be used under the terms of Open CASCADE
13// commercial license or contractual agreement.
b311480e 14
7fd59977 15//-- TopClass_SolidClassifier.gxx
16
0797d9d3 17#ifdef OCCT_DEBUG
7fd59977 18Standard_EXPORT Standard_Boolean TopClass_GettraceFC();
19#endif
20
21#include <gp_Lin.hxx>
22
23//extern void DrawSegment(const gp_Pnt& P1,const gp_Lin& L,const Standard_Real par);
24//extern Standard_Boolean DebugDrawSegment;
25
26TopClass_SolidClassifier::TopClass_SolidClassifier()
27{
28}
29
30
31TopClass_SolidClassifier::TopClass_SolidClassifier(TheSolidExplorer& S,
32 const gp_Pnt& P,
33 const Standard_Real Tol) {
34 Perform(S,P,Tol);
35}
36
37
38void TopClass_SolidClassifier::Perform(TheSolidExplorer& SolidExplorer,
39 const gp_Pnt& P,
40 const Standard_Real Tol) {
0797d9d3 41#ifdef OCCT_DEBUG
7fd59977 42 Standard_Boolean trace = TopClass_GettraceFC();
43#endif
44
45 myState = 0;
46 if(SolidExplorer.Reject(P) == Standard_False) {
47
48 //-- There is no rejection between the Shape loaded in the SolidExplorer
49 //-- and the point P.
50
51 gp_Lin L;
52 Standard_Real Par;
53 //-- We compute the intersection betwwen the line builded in the Solid Explorer
54 //-- and the shape.
55
56 SolidExplorer.Segment(P,L,Par);
57
58 TheIntersection3d Intersector;
59
60 Standard_Real parmin = RealLast();
61
62 for(SolidExplorer.InitShell();
63 SolidExplorer.MoreShell();
64 SolidExplorer.NextShell()) {
65
66 if(SolidExplorer.RejectShell(L) == Standard_False) {
67
68 for(SolidExplorer.InitFace();
69 SolidExplorer.MoreFace();
70 SolidExplorer.NextFace()) {
71
72 if(SolidExplorer.RejectFace(L) == Standard_False) {
73
74 Intersector.Perform(L,Par,Tol,SolidExplorer.CurrentFace());
75
76 if(Intersector.IsDone()) {
77 if(Intersector.HasAPoint()) {
78 if(Intersector.WParameter() < parmin) {
79
80 parmin = Intersector.WParameter();
81 if(Abs(parmin)<=Tol) {
0797d9d3 82#ifdef OCCT_DEBUG
7fd59977 83 if (trace) {
84 //-- #########################################
04232180 85 std::cout<<" parmin = "<<parmin<< " avec Par = "<<Par;
86 std::cout<<" ds TopClass_SolidClassifier.gxx "<<std::endl;
7fd59977 87 //-- #########################################
88 }
89#endif
90 myState = 2;
91 myFace = Intersector.Face();
92 }
93 else if(Intersector.State()==TopAbs_IN) {
94
95 //-- The intersection point between the line and a face F
96 // -- of the solid is in the face F
97
98 if(Intersector.Transition() == IntCurveSurface_Out) {
99 //-- The line is going from inside the solid to outside
100 //-- the solid.
101 myState = 3; //-- IN --
102 }
103 else if(Intersector.Transition() == IntCurveSurface_In) {
104 myState = 4; //-- OUT --
105 }
106 else {
0797d9d3 107#ifdef OCCT_DEBUG
04232180 108 std::cout<<"*Probleme ds TopClass_SolidClassifier.gxx"<<std::endl;
7fd59977 109#endif
110 }
111 myFace = Intersector.Face();
112 }
113 else if(Intersector.State()==TopAbs_ON) {
114 //-- The intersection point between the line and a face F
115 //-- of the solid is in the face F
116
117 if(Intersector.Transition() == IntCurveSurface_Out) {
118 //-- The line is going from inside the solid to outside
119 //-- the solid.
120 myState = 3; //-- IN --
121 }
122 else if(Intersector.Transition() == IntCurveSurface_In) {
123 myState = 4; //-- OUT --
124 }
125 else {
0797d9d3 126#ifdef OCCT_DEBUG
04232180 127 std::cout<<"*Probleme ds TopClass_SolidClassifier.gxx "<<std::endl;
7fd59977 128#endif
129 }
0797d9d3 130#ifdef OCCT_DEBUG
7fd59977 131 //-- #########################################
132// cout<<" Intersector.State() == TopAbs_ON";
133// cout<<" ds TopClass_SolidClassifier.gxx "<<endl;
134// cout<<" Transition : ";
135// if(myState==3) { cout<<" IN "; }
136// else if(myState==4) { cout<<" OUT "; }
137// else { cout<<" PB "; }
138// cout<<endl;
139 //-- #########################################
140#endif
141 //-- myState = 2;
142 myFace = Intersector.Face();
143 }
144 }
145 else {
146 //-- No point has been found by the intersector.
147 //-- Or a Point has been found with a greater parameter.
148 }
149 } //-- Intersector Has a point
150 else {
151 //-- The intersector failed.
152 }
153 } //-- Face has not been rejected
154 else {
155 myState = 1;
156 }
157 }
158 } //-- Exploration of the faces
159 } //-- Shell has not been rejected
160 else {
161 myState=1;
162 }
163 } //-- Exploration of the shells
164
0797d9d3 165#ifdef OCCT_DEBUG
7fd59977 166 //#################################################
167 SolidExplorer.DumpSegment(P,L,parmin,State());
168 //#################################################
169#endif
170
171 } //-- Solid has not been rejected
172 else {
173 myState = 1;
174 }
175}
176
177
178TopAbs_State TopClass_SolidClassifier::State() const {
179 if(myState==2) return(TopAbs_ON);
180 if(myState==4) return(TopAbs_OUT); //--
181 else if(myState==3) return(TopAbs_IN); //--
182 return(TopAbs_OUT);
183}
184
185TopoDS_Face TopClass_SolidClassifier::Face() const {
186 return(myFace);
187}
188
189Standard_Boolean TopClass_SolidClassifier::Rejected() const {
190 return(myState==1);
191}
192
193
194Standard_Boolean TopClass_SolidClassifier::IsOnAFace() const {
195 return(myState==2);
196}