Warning, /include/opencascade/TopClass_FaceClassifier.gxx is written in an unsupported language. File is not indexed.
0001 // Created on: 1992-11-18
0002 // Created by: Remi LEQUETTE
0003 // Copyright (c) 1992-1999 Matra Datavision
0004 // Copyright (c) 1999-2014 OPEN CASCADE SAS
0005 //
0006 // This file is part of Open CASCADE Technology software library.
0007 //
0008 // This library is free software; you can redistribute it and/or modify it under
0009 // the terms of the GNU Lesser General Public License version 2.1 as published
0010 // by the Free Software Foundation, with special exception defined in the file
0011 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
0012 // distribution for complete text of the license and disclaimer of any warranty.
0013 //
0014 // Alternatively, this file may be used under the terms of Open CASCADE
0015 // commercial license or contractual agreement.
0016
0017 // Modified by skv - Thu Jul 13 18:00:34 2006 OCC12627
0018 // The method Perform is totally rewroted.
0019
0020 #include <IntRes2d_IntersectionSegment.hxx>
0021 #include <IntRes2d_IntersectionPoint.hxx>
0022
0023 //=======================================================================
0024 //function : TopClass_FaceClassifier
0025 //purpose :
0026 //=======================================================================
0027
0028 TopClass_FaceClassifier::TopClass_FaceClassifier() :
0029 myEdgeParameter(0.0),
0030 rejected(Standard_False),
0031 nowires(Standard_True)
0032 {
0033 }
0034
0035 //=======================================================================
0036 //function : TopClass_FaceClassifier
0037 //purpose :
0038 //=======================================================================
0039
0040 TopClass_FaceClassifier::TopClass_FaceClassifier(TheFaceExplorer& FExp,
0041 const gp_Pnt2d& P,
0042 const Standard_Real Tol) :
0043 myEdgeParameter(0.0),
0044 rejected(Standard_False),
0045 nowires(Standard_True)
0046 {
0047 Perform(FExp,P,Tol);
0048 }
0049
0050 //=======================================================================
0051 //function : Perform
0052 //purpose :
0053 //=======================================================================
0054
0055 void TopClass_FaceClassifier::Perform(TheFaceExplorer& Fexp,
0056 const gp_Pnt2d& P,
0057 const Standard_Real Tol)
0058 {
0059 gp_Pnt2d aPoint(P);
0060 Standard_Boolean aResOfPointCheck = Standard_False;
0061 while (aResOfPointCheck == Standard_False)
0062 {
0063 aResOfPointCheck = Fexp.CheckPoint(aPoint);
0064 }
0065
0066 // Test for rejection.
0067 rejected = Fexp.Reject(aPoint);
0068
0069 if (rejected)
0070 return;
0071
0072 gp_Lin2d aLine;
0073 Standard_Real aParam;
0074 Standard_Boolean IsValidSegment = Fexp.Segment(aPoint, aLine, aParam);
0075 TheEdge anEdge;
0076 TopAbs_Orientation anEdgeOri;
0077 Standard_Integer aClosestInd;
0078 IntRes2d_IntersectionPoint aPInter;
0079 TopAbs_State aState = TopAbs_UNKNOWN;
0080 Standard_Boolean IsWReject;
0081 Standard_Boolean IsEReject;
0082
0083 nowires = Standard_True;
0084
0085 while (IsValidSegment) {
0086 myClassifier.Reset(aLine, aParam, Tol);
0087
0088 for (Fexp.InitWires(); Fexp.MoreWires(); Fexp.NextWire()) {
0089 nowires = Standard_False;
0090 IsWReject = Fexp.RejectWire(aLine, myClassifier.Parameter());
0091
0092 if (!IsWReject) {
0093 // test this wire
0094 for (Fexp.InitEdges(); Fexp.MoreEdges(); Fexp.NextEdge()) {
0095 IsEReject = Fexp.RejectEdge(aLine, myClassifier.Parameter());
0096
0097 if (!IsEReject) {
0098 // test this edge
0099 Fexp.CurrentEdge(anEdge, anEdgeOri);
0100
0101 if (anEdgeOri == TopAbs_FORWARD || anEdgeOri == TopAbs_REVERSED) {
0102 myClassifier.Compare(anEdge, anEdgeOri);
0103 aClosestInd = myClassifier.ClosestIntersection();
0104
0105 if (aClosestInd != 0) {
0106 // save the closest edge
0107 TheIntersection2d &anIntersector = myClassifier.Intersector();
0108 Standard_Integer aNbPnts = anIntersector.NbPoints();
0109
0110 myEdge = anEdge;
0111
0112 if (aClosestInd <= aNbPnts) {
0113 aPInter = anIntersector.Point(aClosestInd);
0114 } else {
0115 aClosestInd -= aNbPnts;
0116
0117 if (aClosestInd&1) {
0118 aPInter = anIntersector.
0119 Segment((aClosestInd + 1)/2).FirstPoint();
0120 } else {
0121 aPInter = anIntersector.
0122 Segment((aClosestInd + 1)/2).LastPoint();
0123 }
0124 }
0125
0126 myPosition = aPInter.
0127 TransitionOfSecond().PositionOnCurve();
0128 myEdgeParameter = aPInter.ParamOnSecond();
0129 }
0130 // if we are ON, we stop
0131 aState = myClassifier.State();
0132
0133 if (aState == TopAbs_ON)
0134 return;
0135 }
0136 }
0137 }
0138
0139 // if we are out of the wire we stop
0140 aState = myClassifier.State();
0141
0142 if (aState == TopAbs_OUT)
0143 return;
0144 }
0145 }
0146
0147 if (!myClassifier.IsHeadOrEnd() && aState != TopAbs_UNKNOWN)
0148 break;
0149
0150 // Bad case for classification. Trying to get another segment.
0151 IsValidSegment = Fexp.OtherSegment(aPoint, aLine, aParam);
0152 }
0153 }
0154
0155 //=======================================================================
0156 //function : State
0157 //purpose :
0158 //=======================================================================
0159
0160 TopAbs_State TopClass_FaceClassifier::State() const
0161 {
0162 if (rejected) return TopAbs_OUT;
0163 else if (nowires) return TopAbs_IN;
0164 else return myClassifier.State();
0165 }
0166
0167 //=======================================================================
0168 //function : Edge
0169 //purpose :
0170 //=======================================================================
0171
0172 const TheEdge& TopClass_FaceClassifier::Edge() const
0173 {
0174 Standard_DomainError_Raise_if(rejected,
0175 "TopClass_FaceClassifier::Edge:rejected");
0176 return myEdge;
0177 }
0178
0179
0180 //=======================================================================
0181 //function : EdgeParameter
0182 //purpose :
0183 //=======================================================================
0184
0185 Standard_Real TopClass_FaceClassifier::EdgeParameter() const
0186 {
0187 Standard_DomainError_Raise_if(rejected,
0188 "TopClass_FaceClassifier::EdgeParameter:rejected");
0189 return myEdgeParameter;
0190 }
0191