| 1 | // Created on: 1994-02-07 |
| 2 | // Created by: Modelistation |
| 3 | // Copyright (c) 1994-1999 Matra Datavision |
| 4 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
| 5 | // |
| 6 | // This file is part of Open CASCADE Technology software library. |
| 7 | // |
| 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. |
| 13 | // |
| 14 | // Alternatively, this file may be used under the terms of Open CASCADE |
| 15 | // commercial license or contractual agreement. |
| 16 | |
| 17 | |
| 18 | #include <Bnd_Box.hxx> |
| 19 | #include <BndLib_Add3dCurve.hxx> |
| 20 | #include <BRepAdaptor_HSurface.hxx> |
| 21 | #include <BRepAdaptor_Surface.hxx> |
| 22 | #include <BRepBndLib.hxx> |
| 23 | #include <BRepIntCurveSurface_Inter.hxx> |
| 24 | #include <BRepTopAdaptor_TopolTool.hxx> |
| 25 | #include <Geom_Line.hxx> |
| 26 | #include <GeomAdaptor_Curve.hxx> |
| 27 | #include <GeomAdaptor_HCurve.hxx> |
| 28 | #include <gp_Lin.hxx> |
| 29 | #include <gp_Pnt.hxx> |
| 30 | #include <IntCurveSurface_IntersectionPoint.hxx> |
| 31 | #include <StdFail_NotDone.hxx> |
| 32 | #include <TopAbs_ShapeEnum.hxx> |
| 33 | #include <TopoDS.hxx> |
| 34 | #include <TopoDS_Face.hxx> |
| 35 | #include <TopoDS_Shape.hxx> |
| 36 | |
| 37 | //=========================================================================== |
| 38 | //function :BRepIntCurveSurface_Inter::BRepIntCurveSurface_Inte |
| 39 | //purpose : |
| 40 | //=========================================================================== |
| 41 | BRepIntCurveSurface_Inter::BRepIntCurveSurface_Inter() |
| 42 | { |
| 43 | myFastClass = new BRepTopAdaptor_TopolTool(); |
| 44 | Clear(); |
| 45 | } |
| 46 | |
| 47 | //=========================================================================== |
| 48 | //function :Init |
| 49 | //purpose : |
| 50 | //=========================================================================== |
| 51 | |
| 52 | void BRepIntCurveSurface_Inter::Init(const TopoDS_Shape& theShape, |
| 53 | const GeomAdaptor_Curve& theCurve, |
| 54 | const Standard_Real theTol) |
| 55 | { |
| 56 | Load(theShape, theTol); |
| 57 | Init(theCurve); |
| 58 | } |
| 59 | |
| 60 | //=========================================================================== |
| 61 | //function :Init |
| 62 | //purpose : |
| 63 | //=========================================================================== |
| 64 | |
| 65 | void BRepIntCurveSurface_Inter::Init(const TopoDS_Shape& theShape, |
| 66 | const gp_Lin& theLine, |
| 67 | const Standard_Real theTol) |
| 68 | { |
| 69 | |
| 70 | Handle(Geom_Line) geomline = new Geom_Line(theLine); |
| 71 | GeomAdaptor_Curve aCurve(geomline); |
| 72 | Load(theShape, theTol); |
| 73 | Init(aCurve); |
| 74 | |
| 75 | } |
| 76 | |
| 77 | //=========================================================================== |
| 78 | //function :Clear |
| 79 | //purpose : |
| 80 | //=========================================================================== |
| 81 | |
| 82 | void BRepIntCurveSurface_Inter::Clear() |
| 83 | { |
| 84 | myCurrentindex = 0; |
| 85 | myCurrentnbpoints = 0; |
| 86 | myIndFace = 0; |
| 87 | myCurrentstate = TopAbs_UNKNOWN; |
| 88 | myCurrentU = 0; |
| 89 | myCurrentV = 0; |
| 90 | |
| 91 | } |
| 92 | |
| 93 | //=========================================================================== |
| 94 | //function :Load |
| 95 | //purpose : |
| 96 | //=========================================================================== |
| 97 | |
| 98 | void BRepIntCurveSurface_Inter::Load(const TopoDS_Shape& theShape ,const Standard_Real theTol) |
| 99 | { |
| 100 | Clear(); |
| 101 | myFaces.Clear(); |
| 102 | myFaceBoxes.Nullify(); |
| 103 | myTolerance = theTol; |
| 104 | TopExp_Explorer explorer(theShape,TopAbs_FACE); |
| 105 | for( ; explorer.More(); explorer.Next()) |
| 106 | myFaces.Append(explorer.Current()); |
| 107 | |
| 108 | } |
| 109 | |
| 110 | //=========================================================================== |
| 111 | //function :Init |
| 112 | //purpose : |
| 113 | //=========================================================================== |
| 114 | |
| 115 | void BRepIntCurveSurface_Inter::Init(const GeomAdaptor_Curve& theCurve ) |
| 116 | { |
| 117 | Clear(); |
| 118 | myCurveBox.SetVoid(); |
| 119 | Standard_Real aFirst = theCurve.FirstParameter(); |
| 120 | Standard_Real aLast = theCurve.LastParameter(); |
| 121 | myCurve = new GeomAdaptor_HCurve(theCurve ); |
| 122 | if( !Precision::IsInfinite(aFirst) && !Precision::IsInfinite(aLast) ) |
| 123 | BndLib_Add3dCurve::Add(myCurve->Curve(),0., myCurveBox); |
| 124 | Find(); |
| 125 | } |
| 126 | |
| 127 | //=========================================================================== |
| 128 | //function :More |
| 129 | //purpose : |
| 130 | //=========================================================================== |
| 131 | Standard_Boolean BRepIntCurveSurface_Inter::More() const |
| 132 | { |
| 133 | return (myIndFace <= myFaces.Length() ); |
| 134 | } |
| 135 | |
| 136 | //=========================================================================== |
| 137 | //function :Next |
| 138 | //purpose : |
| 139 | //=========================================================================== |
| 140 | void BRepIntCurveSurface_Inter::Next() |
| 141 | { |
| 142 | if(myCurrentnbpoints) |
| 143 | myCurrentindex++; |
| 144 | Find(); |
| 145 | } |
| 146 | |
| 147 | //=========================================================================== |
| 148 | //function :Find |
| 149 | //purpose : |
| 150 | //=========================================================================== |
| 151 | void BRepIntCurveSurface_Inter::Find() |
| 152 | { |
| 153 | if(myCurrentnbpoints && myCurrentindex <= myCurrentnbpoints && FindPoint()) |
| 154 | return; |
| 155 | |
| 156 | myCurrentnbpoints = 0; |
| 157 | myCurrentindex = 0; |
| 158 | |
| 159 | Standard_Integer i = myIndFace +1; |
| 160 | for( ; i <= myFaces.Length(); i++) |
| 161 | { |
| 162 | TopoDS_Shape aCurface= myFaces(i); |
| 163 | if( myFaceBoxes.IsNull()) |
| 164 | myFaceBoxes = new Bnd_HArray1OfBox(1, myFaces.Length()); |
| 165 | Bnd_Box& aFaceBox = myFaceBoxes->ChangeValue(i); |
| 166 | if( aFaceBox.IsVoid()) |
| 167 | { |
| 168 | BRepBndLib::Add(aCurface, aFaceBox); |
| 169 | aFaceBox.SetGap(myTolerance);//Precision::Confusion()); |
| 170 | } |
| 171 | Standard_Boolean isOut = ( myCurve->GetType() == GeomAbs_Line ? aFaceBox.IsOut(myCurve->Line()) : |
| 172 | ( !myCurveBox.IsVoid() ? aFaceBox.IsOut(myCurveBox ) : Standard_False ) ); |
| 173 | if(isOut ) |
| 174 | continue; |
| 175 | Handle(BRepAdaptor_HSurface) aSurfForFastClass = new BRepAdaptor_HSurface(TopoDS::Face(aCurface)); |
| 176 | myIntcs.Perform(myCurve,aSurfForFastClass); |
| 177 | myCurrentnbpoints = myIntcs.NbPoints(); |
| 178 | if( !myCurrentnbpoints) |
| 179 | continue; |
| 180 | |
| 181 | const Handle(Adaptor3d_HSurface)& aSurf = aSurfForFastClass; // to avoid ambiguity |
| 182 | myFastClass->Initialize(aSurf); |
| 183 | myIndFace = i; |
| 184 | if(FindPoint()) |
| 185 | return; |
| 186 | myCurrentnbpoints = 0; |
| 187 | } |
| 188 | |
| 189 | if(!myCurrentnbpoints && i > myFaces.Length()) |
| 190 | { |
| 191 | myIndFace = i; |
| 192 | return; |
| 193 | } |
| 194 | } |
| 195 | |
| 196 | //=========================================================================== |
| 197 | //function :FindPoint |
| 198 | //purpose : |
| 199 | //=========================================================================== |
| 200 | Standard_Boolean BRepIntCurveSurface_Inter::FindPoint() |
| 201 | { |
| 202 | Standard_Integer j = (!myCurrentindex ? 1 : myCurrentindex); |
| 203 | |
| 204 | for( ; j <= myCurrentnbpoints; j++ ) |
| 205 | { |
| 206 | Standard_Real anU = myIntcs.Point(j).U(); |
| 207 | Standard_Real aV = myIntcs.Point(j).V(); |
| 208 | |
| 209 | gp_Pnt2d Puv( anU,aV ); |
| 210 | |
| 211 | myCurrentstate = myFastClass->Classify(Puv,myTolerance); |
| 212 | if(myCurrentstate == TopAbs_ON || myCurrentstate == TopAbs_IN) |
| 213 | { |
| 214 | myCurrentindex = j; |
| 215 | myCurrentU = anU; |
| 216 | myCurrentV = aV; |
| 217 | return Standard_True; |
| 218 | } |
| 219 | } |
| 220 | return Standard_False; |
| 221 | } |
| 222 | |
| 223 | //=========================================================================== |
| 224 | //function :Point |
| 225 | //purpose : |
| 226 | //=========================================================================== |
| 227 | |
| 228 | IntCurveSurface_IntersectionPoint BRepIntCurveSurface_Inter::Point() const |
| 229 | { |
| 230 | if(myCurrentindex==0) |
| 231 | throw StdFail_NotDone(); |
| 232 | const IntCurveSurface_IntersectionPoint& ICPS = myIntcs.Point(myCurrentindex); |
| 233 | return(IntCurveSurface_IntersectionPoint(ICPS.Pnt(), |
| 234 | myCurrentU, // ICPS.U(), |
| 235 | myCurrentV, // ICPS.V(), |
| 236 | ICPS.W(), |
| 237 | ICPS.Transition())); |
| 238 | //-- return(myIntcs.Point(myCurrentindex)); |
| 239 | } |
| 240 | |
| 241 | //=========================================================================== |
| 242 | //function :U |
| 243 | //purpose : |
| 244 | //=========================================================================== |
| 245 | Standard_Real BRepIntCurveSurface_Inter::U() const |
| 246 | { |
| 247 | if(myCurrentindex==0) |
| 248 | throw StdFail_NotDone(); |
| 249 | //-- return(myIntcs.Point(myCurrentindex).U()); |
| 250 | return(myCurrentU); |
| 251 | } |
| 252 | |
| 253 | //=========================================================================== |
| 254 | //function :V |
| 255 | //purpose : |
| 256 | //=========================================================================== |
| 257 | Standard_Real BRepIntCurveSurface_Inter::V() const |
| 258 | { |
| 259 | if(myCurrentindex==0) |
| 260 | throw StdFail_NotDone(); |
| 261 | //-- return(myIntcs.Point(myCurrentindex).V()); |
| 262 | return(myCurrentV); |
| 263 | } |
| 264 | |
| 265 | //=========================================================================== |
| 266 | //function :W |
| 267 | //purpose : |
| 268 | //=========================================================================== |
| 269 | Standard_Real BRepIntCurveSurface_Inter::W() const |
| 270 | { |
| 271 | if(myCurrentindex==0) |
| 272 | throw StdFail_NotDone(); |
| 273 | return(myIntcs.Point(myCurrentindex).W()); |
| 274 | } |
| 275 | |
| 276 | //=========================================================================== |
| 277 | //function :State |
| 278 | //purpose : |
| 279 | //=========================================================================== |
| 280 | TopAbs_State BRepIntCurveSurface_Inter::State() const |
| 281 | { |
| 282 | if(myCurrentindex==0) |
| 283 | throw StdFail_NotDone(); |
| 284 | //-- return(classifier.State()); |
| 285 | return(myCurrentstate); |
| 286 | } |
| 287 | |
| 288 | //=========================================================================== |
| 289 | //function :Transition |
| 290 | //purpose : |
| 291 | //=========================================================================== |
| 292 | IntCurveSurface_TransitionOnCurve BRepIntCurveSurface_Inter::Transition() const |
| 293 | { |
| 294 | if(myCurrentindex==0) |
| 295 | throw StdFail_NotDone(); |
| 296 | return(myIntcs.Point(myCurrentindex).Transition()); |
| 297 | } |
| 298 | |
| 299 | //=========================================================================== |
| 300 | //function :Face |
| 301 | //purpose : |
| 302 | //=========================================================================== |
| 303 | const TopoDS_Face& BRepIntCurveSurface_Inter::Face() const |
| 304 | { |
| 305 | return(TopoDS::Face(myFaces.Value(myIndFace))); |
| 306 | } |
| 307 | |
| 308 | //=========================================================================== |
| 309 | //function :Pnt |
| 310 | //purpose : |
| 311 | //=========================================================================== |
| 312 | const gp_Pnt& BRepIntCurveSurface_Inter::Pnt() const { |
| 313 | if(myCurrentindex==0) |
| 314 | throw StdFail_NotDone(); |
| 315 | return(myIntcs.Point(myCurrentindex).Pnt()); |
| 316 | } |
| 317 | |