0024166: Unable to create file with "Save" menu of voxeldemo Qt sample
[occt.git] / src / TopClass / TopClass_FaceClassifier.gxx
CommitLineData
b311480e 1// Created on: 1992-11-18
2// Created by: Remi LEQUETTE
3// Copyright (c) 1992-1999 Matra Datavision
4// Copyright (c) 1999-2012 OPEN CASCADE SAS
5//
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.
10//
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.
13//
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.
20
7fd59977 21
22// Modified by skv - Thu Jul 13 18:00:34 2006 OCC12627
23// The method Perform is totally rewroted.
24
25#include <IntRes2d_IntersectionSegment.hxx>
26#include <IntRes2d_IntersectionPoint.hxx>
27
28//=======================================================================
29//function : TopClass_FaceClassifier
30//purpose :
31//=======================================================================
32
33TopClass_FaceClassifier::TopClass_FaceClassifier()
34{
35}
36
37//=======================================================================
38//function : TopClass_FaceClassifier
39//purpose :
40//=======================================================================
41
42TopClass_FaceClassifier::TopClass_FaceClassifier(TheFaceExplorer& FExp,
43 const gp_Pnt2d& P,
44 const Standard_Real Tol)
45{
46 Perform(FExp,P,Tol);
47}
48
49//=======================================================================
50//function : Perform
51//purpose :
52//=======================================================================
53
54void TopClass_FaceClassifier::Perform(TheFaceExplorer& Fexp,
55 const gp_Pnt2d& P,
56 const Standard_Real Tol)
57{
58 // Test for rejection.
59 rejected = Fexp.Reject(P);
60
61 if (rejected)
62 return;
63
64 gp_Lin2d aLine;
65 Standard_Real aParam;
66 Standard_Boolean IsValidSegment = Fexp.Segment(P, aLine, aParam);
67 TheEdge anEdge;
68 TopAbs_Orientation anEdgeOri;
69 Standard_Integer aClosestInd;
70 IntRes2d_IntersectionPoint aPInter;
1d47d8d0 71 TopAbs_State aState = TopAbs_UNKNOWN;
7fd59977 72 Standard_Boolean IsWReject;
73 Standard_Boolean IsEReject;
74
75 nowires = Standard_True;
76
77 while (IsValidSegment) {
78 myClassifier.Reset(aLine, aParam, Tol);
79
80 for (Fexp.InitWires(); Fexp.MoreWires(); Fexp.NextWire()) {
81 nowires = Standard_False;
82 IsWReject = Fexp.RejectWire(aLine, myClassifier.Parameter());
83
84 if (!IsWReject) {
85 // test this wire
86 for (Fexp.InitEdges(); Fexp.MoreEdges(); Fexp.NextEdge()) {
87 IsEReject = Fexp.RejectEdge(aLine, myClassifier.Parameter());
88
89 if (!IsEReject) {
90 // test this edge
91 Fexp.CurrentEdge(anEdge, anEdgeOri);
92
93 if (anEdgeOri == TopAbs_FORWARD || anEdgeOri == TopAbs_REVERSED) {
94 myClassifier.Compare(anEdge, anEdgeOri);
95 aClosestInd = myClassifier.ClosestIntersection();
96
97 if (aClosestInd != 0) {
98 // save the closest edge
99 TheIntersection2d &anIntersector = myClassifier.Intersector();
100 Standard_Integer aNbPnts = anIntersector.NbPoints();
101
102 myEdge = anEdge;
103
104 if (aClosestInd <= aNbPnts) {
105 aPInter = anIntersector.Point(aClosestInd);
106 } else {
107 aClosestInd -= aNbPnts;
108
109 if (aClosestInd&1) {
110 aPInter = anIntersector.
111 Segment((aClosestInd + 1)/2).FirstPoint();
112 } else {
113 aPInter = anIntersector.
114 Segment((aClosestInd + 1)/2).LastPoint();
115 }
116 }
117
118 myPosition = aPInter.
119 TransitionOfSecond().PositionOnCurve();
120 myEdgeParameter = aPInter.ParamOnSecond();
121 }
122 // if we are ON, we stop
123 aState = myClassifier.State();
124
125 if (aState == TopAbs_ON)
126 return;
127 }
128 }
129 }
130
131 // if we are out of the wire we stop
132 aState = myClassifier.State();
133
134 if (aState == TopAbs_OUT)
135 return;
136 }
137 }
138
cf836671 139 if (!myClassifier.IsHeadOrEnd() && aState != TopAbs_UNKNOWN)
7fd59977 140 break;
141
142 // Bad case for classification. Trying to get another segment.
143 IsValidSegment = Fexp.OtherSegment(P, aLine, aParam);
144 }
145}
146
147//=======================================================================
148//function : State
149//purpose :
150//=======================================================================
151
152TopAbs_State TopClass_FaceClassifier::State() const
153{
154 if (rejected) return TopAbs_OUT;
155 else if (nowires) return TopAbs_IN;
156 else return myClassifier.State();
157}
158
159//=======================================================================
160//function : Edge
161//purpose :
162//=======================================================================
163
164const TheEdge& TopClass_FaceClassifier::Edge() const
165{
166 Standard_DomainError_Raise_if(rejected,
167 "TopClass_FaceClassifier::Edge:rejected");
168 return myEdge;
169}
170
171
172//=======================================================================
173//function : EdgeParameter
174//purpose :
175//=======================================================================
176
177Standard_Real TopClass_FaceClassifier::EdgeParameter() const
178{
179 Standard_DomainError_Raise_if(rejected,
180 "TopClass_FaceClassifier::EdgeParameter:rejected");
181 return myEdgeParameter;
182}
183