1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233
|
// File: TopClass_Classifier2d.gxx
// Created: Tue Nov 17 17:47:02 1992
// Author: Remi LEQUETTE
// <rle@phylox>
// Modified: Mon May 13 15:20:43 1996
// Author: Laurent BUCHARD
// <lbr@sherlox>
//-- Reinitialisation des transitions complexes
// Modified by skv - Wed Jul 12 15:20:58 2006 OCC12627
#include <IntRes2d_IntersectionSegment.hxx>
#include <IntRes2d_IntersectionPoint.hxx>
#include <gp_Vec2d.hxx>
//=======================================================================
//function : TopClass_Classifier2d
//purpose :
//=======================================================================
TopClass_Classifier2d::TopClass_Classifier2d() :
myIsSet(Standard_False),
myFirstCompare(Standard_True),
myIsHeadOrEnd(Standard_False), // skv OCC12627
myState(TopAbs_UNKNOWN) // skv OCC12627
{
}
//=======================================================================
//function : Reset
//purpose :
//=======================================================================
void TopClass_Classifier2d::Reset(const gp_Lin2d& L,
const Standard_Real P,
const Standard_Real Tol)
{
myLin = L;
myParam = P;
myTolerance = Tol;
myState = TopAbs_UNKNOWN;
myFirstCompare = Standard_True;
myFirstTrans = Standard_True;
myClosest = 0;
myIsSet = Standard_True;
// Modified by skv - Wed Jul 12 15:20:58 2006 OCC12627 Begin
myIsHeadOrEnd = Standard_False;
// Modified by skv - Wed Jul 12 15:20:58 2006 OCC12627 End
}
//=======================================================================
//function : Compare
//purpose :
//=======================================================================
void TopClass_Classifier2d::Compare(const TheEdge& E,
const TopAbs_Orientation Or)
{
// intersect the edge and the segment
myClosest = 0;
myIntersector.Perform(myLin,myParam,myTolerance,E);
if (!myIntersector.IsDone()) return;
if ((myIntersector.NbPoints() == 0)&&
(myIntersector.NbSegments() == 0)) return;
// find the closest point
Standard_Integer iPoint, iSegment, nbPoints, nbSegments;
#ifndef DEB
const IntRes2d_IntersectionPoint *PClosest = NULL;
#else
const IntRes2d_IntersectionPoint *PClosest;
#endif
Standard_Real dMin = RealLast();
nbPoints = myIntersector.NbPoints();
for (iPoint = 1; iPoint <= nbPoints; iPoint++) {
const IntRes2d_IntersectionPoint& PInter = myIntersector.Point(iPoint);
// test for ON
if (PInter.TransitionOfFirst().PositionOnCurve() == IntRes2d_Head) {
myClosest = iPoint;
myState = TopAbs_ON;
return;
}
Standard_Real paramfirst = PInter.ParamOnFirst();
if (paramfirst < dMin) {
myClosest = iPoint;
PClosest = &PInter;
dMin = paramfirst;
}
}
// for the segments we only test the first point
nbSegments = myIntersector.NbSegments();
for (iSegment = 1; iSegment <= nbSegments; iSegment++) {
const IntRes2d_IntersectionSegment& SegInter =
myIntersector.Segment(iSegment);
const IntRes2d_IntersectionPoint& PInter = SegInter.FirstPoint();
if (PInter.TransitionOfFirst().PositionOnCurve() == IntRes2d_Head) {
myClosest = nbPoints + iSegment+ iSegment - 1;
myState = TopAbs_ON;
return;
}
Standard_Real paramfirst = PInter.ParamOnFirst();
if (paramfirst < dMin) {
myClosest = nbPoints + iSegment+iSegment - 1;
PClosest = &PInter;
dMin = paramfirst;
}
}
// if no point was found return
if (myClosest == 0) return;
// if the Edge is INTERNAL or EXTERNAL, no problem
if (Or == TopAbs_INTERNAL) {
myState = TopAbs_IN;
return;
}
else if (Or == TopAbs_EXTERNAL) {
myState = TopAbs_OUT;
return;
}
if ( ! myFirstCompare ) {
Standard_Boolean b = (dMin > myParam);
if (b) {
// dMin > myParam : le point le plus proche (dMin) trouve dans CETTE
// intersection ligne,arete n'est pas le plus proche
// de TOUS les points d'intersection avec les autres aretes (myParam).
return;
}
}
// process the closest point PClosest, found at dMin on line.
myFirstCompare = Standard_False;
if(myParam > dMin) { //-- lbr le 13 mai 96
myFirstTrans = Standard_True;
}
myParam = dMin;
const IntRes2d_Transition& T2 = PClosest->TransitionOfSecond();
// Modified by skv - Wed Jul 12 15:20:58 2006 OCC12627 Begin
// Standard_Boolean isHeadorEnd = (T2.PositionOnCurve() == IntRes2d_Head) ||
// (T2.PositionOnCurve() == IntRes2d_End);
myIsHeadOrEnd = (T2.PositionOnCurve() == IntRes2d_Head) ||
(T2.PositionOnCurve() == IntRes2d_End);
// Modified by skv - Wed Jul 12 15:20:58 2006 OCC12627 End
// transition on the segment
#ifndef DEB
TopAbs_Orientation SegTrans = TopAbs_FORWARD;
#else
TopAbs_Orientation SegTrans;
#endif
const IntRes2d_Transition& T1 = PClosest->TransitionOfFirst();
switch (T1.TransitionType()) {
case IntRes2d_In :
if (Or == TopAbs_REVERSED) SegTrans = TopAbs_REVERSED;
else SegTrans = TopAbs_FORWARD;
break;
case IntRes2d_Out :
if (Or == TopAbs_REVERSED) SegTrans = TopAbs_FORWARD;
else SegTrans = TopAbs_REVERSED;
break;
case IntRes2d_Touch :
switch (T1.Situation()) {
case IntRes2d_Inside :
if (Or == TopAbs_REVERSED) SegTrans = TopAbs_EXTERNAL;
else SegTrans = TopAbs_INTERNAL;
break;
case IntRes2d_Outside :
if (Or == TopAbs_REVERSED) SegTrans = TopAbs_INTERNAL;
else SegTrans = TopAbs_EXTERNAL;
break;
case IntRes2d_Unknown : return;
}
break;
case IntRes2d_Undecided : return;
}
// are we inside the Edge ?
// const IntRes2d_Transition& T2 = PClosest->TransitionOfSecond();
if ( ! myIsHeadOrEnd ) {
// PClosest is inside the edge
switch (SegTrans) {
case TopAbs_FORWARD :
case TopAbs_EXTERNAL :
myState = TopAbs_OUT;
break;
case TopAbs_REVERSED :
case TopAbs_INTERNAL :
myState = TopAbs_IN;
break;
}
}
else {
// PClosest is Head or End of the edge : update the complex transition
gp_Dir2d Tang2d,Norm2d;
Standard_Real Curv;
myIntersector.LocalGeometry
(E,PClosest->ParamOnSecond(),Tang2d,Norm2d,Curv);
gp_Dir Tang(Tang2d.X(),Tang2d.Y(),0.);
gp_Dir Norm(Norm2d.X(),Norm2d.Y(),0.);
if (myFirstTrans) {
gp_Dir D(myLin.Direction().X(),myLin.Direction().Y(),0.);
myTrans.Reset(D);
myFirstTrans = Standard_False;
}
TopAbs_Orientation Ort;
if (T2.PositionOnCurve() == IntRes2d_Head) Ort = TopAbs_FORWARD;
else Ort = TopAbs_REVERSED;
myTrans.Compare(RealEpsilon(), Tang, Norm, Curv, SegTrans, Ort);
myState = myTrans.StateBefore();
}
}
|