| 1 | // File: BRepFill_NSections.cxx |
| 2 | // Created: Tue Dec 29 17:01:25 1998 |
| 3 | // Author: Joelle CHAUVET |
| 4 | // <jct@sgi64> |
| 5 | |
| 6 | #include <stdio.h> |
| 7 | |
| 8 | #include <BRepFill_NSections.ixx> |
| 9 | |
| 10 | #include <BRepFill.hxx> |
| 11 | #include <BRepTools_WireExplorer.hxx> |
| 12 | #include <BRep_Builder.hxx> |
| 13 | #include <BRep_Tool.hxx> |
| 14 | #include <BRepAdaptor_Curve.hxx> |
| 15 | #include <BRepLProp.hxx> |
| 16 | |
| 17 | #include <BRepLib_MakeWire.hxx> |
| 18 | #include <BRepLib_MakeEdge.hxx> |
| 19 | #include <TopExp.hxx> |
| 20 | #include <TopoDS.hxx> |
| 21 | #include <TopoDS_Vertex.hxx> |
| 22 | #include <TopoDS_Wire.hxx> |
| 23 | |
| 24 | #include <Geom_Curve.hxx> |
| 25 | #include <Geom_Line.hxx> |
| 26 | #include <Geom_TrimmedCurve.hxx> |
| 27 | #include <Geom_BSplineCurve.hxx> |
| 28 | #include <Geom_Conic.hxx> |
| 29 | #include <GeomFill_UniformSection.hxx> |
| 30 | #include <GeomFill_EvolvedSection.hxx> |
| 31 | #include <GeomFill_HArray1OfSectionLaw.hxx> |
| 32 | #include <GeomFill_NSections.hxx> |
| 33 | #include <TColGeom_SequenceOfCurve.hxx> |
| 34 | #include <GeomFill_SectionGenerator.hxx> |
| 35 | #include <GeomFill_Line.hxx> |
| 36 | #include <GeomFill_AppSurf.hxx> |
| 37 | #include <GeomConvert.hxx> |
| 38 | #include <GeomConvert_ApproxCurve.hxx> |
| 39 | #include <GeomConvert_CompCurveToBSplineCurve.hxx> |
| 40 | #include <Geom_BSplineSurface.hxx> |
| 41 | #include <BSplCLib.hxx> |
| 42 | |
| 43 | #include <TColgp_HArray1OfPnt.hxx> |
| 44 | #include <TColStd_HArray1OfReal.hxx> |
| 45 | #include <TColStd_HArray1OfInteger.hxx> |
| 46 | #include <Geom_BezierCurve.hxx> |
| 47 | #include <TopTools_Array1OfShape.hxx> |
| 48 | |
| 49 | #include <Precision.hxx> |
| 50 | |
| 51 | #ifdef DEB |
| 52 | static Standard_Boolean Affich = 0; |
| 53 | #endif |
| 54 | |
| 55 | #ifdef DRAW |
| 56 | #include <DrawTrSurf.hxx> |
| 57 | #include <DBRep.hxx> |
| 58 | #endif |
| 59 | |
| 60 | //======================================================================= |
| 61 | //function : totalsurf |
| 62 | //purpose : |
| 63 | //======================================================================= |
| 64 | |
| 65 | static Handle(Geom_BSplineSurface) totalsurf(const TopTools_Array2OfShape& shapes, |
| 66 | const Standard_Integer NbSects, |
| 67 | const Standard_Integer NbEdges, |
| 68 | const TColStd_SequenceOfReal& params, |
| 69 | const Standard_Boolean w1Point, |
| 70 | const Standard_Boolean w2Point, |
| 71 | const Standard_Boolean uClosed, |
| 72 | const Standard_Boolean vClosed, |
| 73 | const Standard_Real myPres3d) |
| 74 | { |
| 75 | Standard_Integer i,j,jdeb=1,jfin=NbSects; |
| 76 | TopoDS_Edge edge; |
| 77 | TopLoc_Location loc; |
| 78 | Standard_Real first, last; |
| 79 | TopoDS_Vertex vf,vl; |
| 80 | |
| 81 | GeomFill_SectionGenerator section; |
| 82 | Handle(Geom_BSplineSurface) surface; |
| 83 | Handle(Geom_BSplineCurve) BS, BS1; |
| 84 | Handle(Geom_TrimmedCurve) curvTrim; |
| 85 | Handle(Geom_BSplineCurve) curvBS; |
| 86 | |
| 87 | if (w1Point) { |
| 88 | jdeb++; |
| 89 | edge = TopoDS::Edge(shapes.Value(1,1)); |
| 90 | TopExp::Vertices(edge,vl,vf); |
| 91 | TColgp_Array1OfPnt Extremities(1,2); |
| 92 | Extremities(1) = BRep_Tool::Pnt(vf); |
| 93 | Extremities(2) = BRep_Tool::Pnt(vl); |
| 94 | TColStd_Array1OfReal Bounds(1,2); |
| 95 | Bounds(1) = 0.; |
| 96 | Bounds(2) = 1.; |
| 97 | Standard_Real Deg = 1; |
| 98 | TColStd_Array1OfInteger Mult(1,2); |
| 99 | Mult(1) = (Standard_Integer) Deg+1; |
| 100 | Mult(2) = (Standard_Integer) Deg+1; |
| 101 | Handle(Geom_BSplineCurve) BSPoint |
| 102 | = new Geom_BSplineCurve(Extremities,Bounds,Mult,(Standard_Integer ) Deg); |
| 103 | section.AddCurve(BSPoint); |
| 104 | } |
| 105 | |
| 106 | if (w2Point) { |
| 107 | jfin--; |
| 108 | } |
| 109 | |
| 110 | for (j=jdeb; j<=jfin; j++) { |
| 111 | |
| 112 | // cas des sections bouclantes |
| 113 | if (j==jfin && vClosed) { |
| 114 | section.AddCurve(BS1); |
| 115 | } |
| 116 | |
| 117 | else { |
| 118 | // read the first edge to initialise CompBS; |
| 119 | edge = TopoDS::Edge(shapes.Value(1,j)); |
| 120 | if (BRep_Tool::Degenerated(edge)) { |
| 121 | // edge degeneree : construction d'une courbe ponctuelle |
| 122 | TopExp::Vertices(edge,vl,vf); |
| 123 | TColgp_Array1OfPnt Extremities(1,2); |
| 124 | Extremities(1) = BRep_Tool::Pnt(vf); |
| 125 | Extremities(2) = BRep_Tool::Pnt(vl); |
| 126 | Handle(Geom_Curve) curv = new Geom_BezierCurve(Extremities); |
| 127 | curvTrim = new Geom_TrimmedCurve(curv, |
| 128 | curv->FirstParameter(), |
| 129 | curv->LastParameter()); |
| 130 | } |
| 131 | else { |
| 132 | // recuperation de la courbe sur l'edge |
| 133 | Handle(Geom_Curve) curv = BRep_Tool::Curve(edge, loc, first, last); |
| 134 | curvTrim = new Geom_TrimmedCurve(curv, first, last); |
| 135 | curvTrim->Transform(loc.Transformation()); |
| 136 | } |
| 137 | if (edge.Orientation() == TopAbs_REVERSED) { |
| 138 | curvTrim->Reverse(); |
| 139 | } |
| 140 | |
| 141 | // transformation en BSpline reparametree sur [i-1,i] |
| 142 | curvBS = Handle(Geom_BSplineCurve)::DownCast(curvTrim); |
| 143 | if (curvBS.IsNull()) { |
| 144 | Handle(Geom_Curve) theCurve = curvTrim->BasisCurve(); |
| 145 | if (theCurve->IsKind(STANDARD_TYPE(Geom_Conic))) |
| 146 | { |
| 147 | GeomConvert_ApproxCurve appr(curvTrim, Precision::Confusion(), GeomAbs_C1, 16, 14); |
| 148 | if (appr.HasResult()) |
| 149 | curvBS = appr.Curve(); |
| 150 | } |
| 151 | if (curvBS.IsNull()) |
| 152 | curvBS = GeomConvert::CurveToBSplineCurve(curvTrim); |
| 153 | } |
| 154 | TColStd_Array1OfReal BSK(1,curvBS->NbKnots()); |
| 155 | curvBS->Knots(BSK); |
| 156 | BSplCLib::Reparametrize(0.,1.,BSK); |
| 157 | curvBS->SetKnots(BSK); |
| 158 | |
| 159 | // initialisation |
| 160 | GeomConvert_CompCurveToBSplineCurve CompBS(curvBS); |
| 161 | |
| 162 | for (i=2; i<=NbEdges; i++) { |
| 163 | // read the edge |
| 164 | edge = TopoDS::Edge(shapes.Value(i,j)); |
| 165 | if (BRep_Tool::Degenerated(edge)) { |
| 166 | // edge degeneree : construction d'une courbe ponctuelle |
| 167 | TopExp::Vertices(edge,vl,vf); |
| 168 | TColgp_Array1OfPnt Extremities(1,2); |
| 169 | Extremities(1) = BRep_Tool::Pnt(vf); |
| 170 | Extremities(2) = BRep_Tool::Pnt(vl); |
| 171 | Handle(Geom_Curve) curv = new Geom_BezierCurve(Extremities); |
| 172 | curvTrim = new Geom_TrimmedCurve(curv, |
| 173 | curv->FirstParameter(), |
| 174 | curv->LastParameter()); |
| 175 | } |
| 176 | else { |
| 177 | // recuperation de la courbe sur l'edge |
| 178 | Handle(Geom_Curve) curv = BRep_Tool::Curve(edge, loc, first, last); |
| 179 | curvTrim = new Geom_TrimmedCurve(curv, first, last); |
| 180 | curvTrim->Transform(loc.Transformation()); |
| 181 | } |
| 182 | if (edge.Orientation() == TopAbs_REVERSED) { |
| 183 | curvTrim->Reverse(); |
| 184 | } |
| 185 | |
| 186 | // transformation en BSpline reparametree sur [i-1,i] |
| 187 | curvBS = Handle(Geom_BSplineCurve)::DownCast(curvTrim); |
| 188 | if (curvBS.IsNull()) { |
| 189 | Handle(Geom_Curve) theCurve = curvTrim->BasisCurve(); |
| 190 | if (theCurve->IsKind(STANDARD_TYPE(Geom_Conic))) |
| 191 | { |
| 192 | GeomConvert_ApproxCurve appr(curvTrim, Precision::Confusion(), GeomAbs_C1, 16, 14); |
| 193 | if (appr.HasResult()) |
| 194 | curvBS = appr.Curve(); |
| 195 | } |
| 196 | if (curvBS.IsNull()) |
| 197 | curvBS = GeomConvert::CurveToBSplineCurve(curvTrim); |
| 198 | } |
| 199 | TColStd_Array1OfReal BSK(1,curvBS->NbKnots()); |
| 200 | curvBS->Knots(BSK); |
| 201 | BSplCLib::Reparametrize(i-1,i,BSK); |
| 202 | curvBS->SetKnots(BSK); |
| 203 | |
| 204 | // concatenation |
| 205 | TopoDS_Vertex ComV; |
| 206 | Standard_Real epsV; |
| 207 | Standard_Boolean Bof = |
| 208 | TopExp::CommonVertex(TopoDS::Edge(shapes.Value(i-1,j)), edge, ComV); |
| 209 | if (Bof) epsV = BRep_Tool::Tolerance(ComV); |
| 210 | else epsV = Precision::Confusion(); |
| 211 | Bof = CompBS.Add(curvBS, epsV, Standard_True, Standard_False, 1); |
| 212 | if (!Bof) Bof = CompBS.Add(curvBS, 200*epsV, |
| 213 | Standard_True, Standard_False, 1); |
| 214 | } |
| 215 | |
| 216 | // recuperation de la section finale |
| 217 | BS = CompBS.BSplineCurve(); |
| 218 | section.AddCurve(BS); |
| 219 | |
| 220 | // cas des sections bouclantes |
| 221 | if (j==jdeb && vClosed) { |
| 222 | BS1 = BS; |
| 223 | } |
| 224 | |
| 225 | } |
| 226 | } |
| 227 | |
| 228 | if (w2Point) { |
| 229 | edge = TopoDS::Edge(shapes.Value(NbEdges,NbSects)); |
| 230 | TopExp::Vertices(edge,vl,vf); |
| 231 | TColgp_Array1OfPnt Extremities(1,2); |
| 232 | Extremities(1) = BRep_Tool::Pnt(vf); |
| 233 | Extremities(2) = BRep_Tool::Pnt(vl); |
| 234 | TColStd_Array1OfReal Bounds(1,2); |
| 235 | Bounds(1) = 0.; |
| 236 | Bounds(2) = 1.; |
| 237 | Standard_Real Deg = 1; |
| 238 | TColStd_Array1OfInteger Mult(1,2); |
| 239 | Mult(1) = (Standard_Integer) Deg+1; |
| 240 | Mult(2) = (Standard_Integer) Deg+1; |
| 241 | Handle(Geom_BSplineCurve) BSPoint |
| 242 | = new Geom_BSplineCurve(Extremities,Bounds,Mult,(Standard_Integer ) Deg); |
| 243 | section.AddCurve(BSPoint); |
| 244 | } |
| 245 | |
| 246 | Handle(TColStd_HArray1OfReal) HPar |
| 247 | = new TColStd_HArray1OfReal(1,params.Length()); |
| 248 | for (i=1; i<=params.Length(); i++) { |
| 249 | HPar->SetValue(i,params(i)); |
| 250 | } |
| 251 | section.SetParam(HPar); |
| 252 | section.Perform(Precision::PConfusion()); |
| 253 | Handle(GeomFill_Line) line = new GeomFill_Line(NbSects); |
| 254 | Standard_Integer nbIt = 0, degmin = 2, degmax = 6; |
| 255 | Standard_Boolean knownP = Standard_True; |
| 256 | GeomFill_AppSurf anApprox(degmin, degmax, myPres3d, myPres3d, nbIt, knownP); |
| 257 | Standard_Boolean SpApprox = Standard_True; |
| 258 | anApprox.Perform(line, section, SpApprox); |
| 259 | Standard_Boolean uperiodic = uClosed; |
| 260 | Standard_Boolean vperiodic = vClosed; |
| 261 | Standard_Integer nup = anApprox.SurfPoles().ColLength(), |
| 262 | nvp = anApprox.SurfPoles().RowLength(); |
| 263 | TColStd_Array1OfInteger Umults(1,anApprox.SurfUKnots().Length()); |
| 264 | Umults = anApprox.SurfUMults(); |
| 265 | TColStd_Array1OfInteger Vmults(1,anApprox.SurfVKnots().Length()); |
| 266 | Vmults = anApprox.SurfVMults(); |
| 267 | |
| 268 | if (uperiodic) { |
| 269 | Standard_Integer nbuk = anApprox.SurfUKnots().Length(); |
| 270 | Umults(1) --; |
| 271 | Umults(nbuk) --; |
| 272 | nup --; |
| 273 | } |
| 274 | |
| 275 | if (vperiodic) { |
| 276 | Standard_Integer nbvk = anApprox.SurfVKnots().Length(); |
| 277 | Vmults(1) --; |
| 278 | Vmults(nbvk) --; |
| 279 | nvp --; |
| 280 | } |
| 281 | |
| 282 | TColgp_Array2OfPnt poles (1, nup, 1, nvp); |
| 283 | TColStd_Array2OfReal weights(1, nup, 1, nvp); |
| 284 | for (j = 1; j <= nvp; j++) { |
| 285 | for (i = 1; i <= nup; i++) { |
| 286 | poles(i, j) = anApprox.SurfPoles()(i,j); |
| 287 | weights(i, j) = anApprox.SurfWeights()(i,j); |
| 288 | } |
| 289 | } |
| 290 | |
| 291 | // To create non-rational surface if possible |
| 292 | Standard_Real TolEps = 1.e-13; |
| 293 | Standard_Boolean Vrational = Standard_False, Urational = Standard_False; |
| 294 | for (j = 1; j <= weights.UpperCol(); j++) |
| 295 | if (!Vrational) |
| 296 | for (i = 1; i <= weights.UpperRow()-1; i++) |
| 297 | { |
| 298 | //Standard_Real signeddelta = weights(i,j) - weights(i+1,j); |
| 299 | Standard_Real delta = Abs( weights(i,j) - weights(i+1,j) ); |
| 300 | // Standard_Real eps = Epsilon( Abs(weights(i,j)) ); |
| 301 | if (delta > TolEps/* || delta > 3.*eps*/) |
| 302 | { |
| 303 | Vrational = Standard_True; |
| 304 | break; |
| 305 | } |
| 306 | } |
| 307 | for (i = 1; i <= weights.UpperRow(); i++) |
| 308 | if (!Urational) |
| 309 | for (j = 1; j <= weights.UpperCol()-1; j++) |
| 310 | { |
| 311 | //Standard_Real signeddelta = weights(i,j) - weights(i,j+1); |
| 312 | Standard_Real delta = Abs( weights(i,j) - weights(i,j+1) ); |
| 313 | // Standard_Real eps = Epsilon( Abs(weights(i,j)) ); |
| 314 | if (delta > TolEps/* || delta > 3.*eps*/) |
| 315 | { |
| 316 | Urational = Standard_True; |
| 317 | break; |
| 318 | } |
| 319 | } |
| 320 | if (!Vrational && !Urational) |
| 321 | { |
| 322 | Standard_Real theWeight = weights(1,1); |
| 323 | for (i = 1; i <= weights.UpperRow(); i++) |
| 324 | for (j = 1; j <= weights.UpperCol(); j++) |
| 325 | weights(i,j) = theWeight; |
| 326 | } |
| 327 | |
| 328 | surface = |
| 329 | new Geom_BSplineSurface(poles, weights, |
| 330 | anApprox.SurfUKnots(), anApprox.SurfVKnots(), |
| 331 | Umults, Vmults, |
| 332 | anApprox.UDegree(), anApprox.VDegree(), |
| 333 | uperiodic, vperiodic); |
| 334 | return surface; |
| 335 | |
| 336 | } |
| 337 | |
| 338 | |
| 339 | //======================================================================= |
| 340 | //function : Create |
| 341 | //purpose : WSeq |
| 342 | //======================================================================= |
| 343 | |
| 344 | BRepFill_NSections::BRepFill_NSections(const TopTools_SequenceOfShape& S, |
| 345 | const Standard_Boolean Build) |
| 346 | |
| 347 | { |
| 348 | myShapes = S; |
| 349 | VFirst = 0.; |
| 350 | VLast = 1.; |
| 351 | TColStd_SequenceOfReal par; |
| 352 | par.Clear(); |
| 353 | for (Standard_Integer i=1;i<=S.Length();i++) { |
| 354 | par.Append(i-1); |
| 355 | } |
| 356 | myParams = par; |
| 357 | Init(par,Build); |
| 358 | } |
| 359 | |
| 360 | //======================================================================= |
| 361 | //function : Create |
| 362 | //purpose : WSeq + Param |
| 363 | //======================================================================= |
| 364 | |
| 365 | BRepFill_NSections::BRepFill_NSections(const TopTools_SequenceOfShape& S, |
| 366 | const TColStd_SequenceOfReal & P, |
| 367 | const Standard_Real VF, |
| 368 | const Standard_Real VL, |
| 369 | const Standard_Boolean Build) |
| 370 | |
| 371 | { |
| 372 | #ifdef DEB |
| 373 | if ( Affich) { |
| 374 | #ifdef DRAW |
| 375 | Standard_Integer NBSECT = 0; |
| 376 | for (Standard_Integer i=1;i<=S.Length();i++) { |
| 377 | NBSECT++; |
| 378 | char name[256]; |
| 379 | sprintf(name,"WIRE_%d",NBSECT); |
| 380 | DBRep::Set(name,TopoDS::Wire(S.Value(i))); |
| 381 | } |
| 382 | #endif |
| 383 | } |
| 384 | #endif |
| 385 | Standard_Boolean ok = Standard_True; |
| 386 | for (Standard_Integer iseq=1;iseq<P.Length();iseq++) { |
| 387 | ok = ok && (P.Value(iseq)<P.Value(iseq+1)); |
| 388 | } |
| 389 | if (ok) { |
| 390 | myParams = P; |
| 391 | myShapes = S; |
| 392 | VFirst = VF; |
| 393 | VLast = VL; |
| 394 | Init(P,Build); |
| 395 | } |
| 396 | } |
| 397 | |
| 398 | //======================================================================= |
| 399 | //function : Init |
| 400 | //purpose : On cree une table de GeomFill_SectionLaw |
| 401 | //======================================================================= |
| 402 | void BRepFill_NSections::Init(const TColStd_SequenceOfReal & P, |
| 403 | const Standard_Boolean Build) |
| 404 | { |
| 405 | BRepTools_WireExplorer wexp; |
| 406 | // Class BRep_Tool without fields and without Constructor : |
| 407 | // BRep_Tool B; |
| 408 | TopoDS_Edge E; |
| 409 | Standard_Integer ii, NbEdge, jj, NbSects = P.Length(); |
| 410 | Standard_Integer ideb = 1, ifin = NbSects; |
| 411 | Standard_Boolean wClosed, w1Point = Standard_True, |
| 412 | w2Point = Standard_True; |
| 413 | Standard_Real First, Last; |
| 414 | TopoDS_Wire W; |
| 415 | |
| 416 | // On regarde si les wires debut et fin sont ponctuels |
| 417 | W = TopoDS::Wire(myShapes(1)); |
| 418 | for (wexp.Init(W); wexp.More(); wexp.Next()) |
| 419 | // w1Point = w1Point && B.Degenerated(wexp.Current()); |
| 420 | w1Point = w1Point && BRep_Tool::Degenerated(wexp.Current()); |
| 421 | if (w1Point) ideb++; |
| 422 | W = TopoDS::Wire(myShapes(NbSects)); |
| 423 | for (wexp.Init(W); wexp.More(); wexp.Next()) |
| 424 | // w2Point = w2Point && B.Degenerated(wexp.Current()); |
| 425 | w2Point = w2Point && BRep_Tool::Degenerated(wexp.Current()); |
| 426 | if (w2Point) ifin--; |
| 427 | |
| 428 | // On regarde si les wires debut et fin sont identiques |
| 429 | vclosed = myShapes(1).IsSame(myShapes(NbSects)); |
| 430 | |
| 431 | // On compte le nombre d'aretes non degenerees |
| 432 | W = TopoDS::Wire(myShapes(ideb)); |
| 433 | for (NbEdge=0, wexp.Init(W); wexp.More(); wexp.Next()) |
| 434 | // if (! B.Degenerated(wexp.Current())) NbEdge++; |
| 435 | if (! BRep_Tool::Degenerated(wexp.Current())) NbEdge++; |
| 436 | |
| 437 | |
| 438 | myEdges = new (TopTools_HArray2OfShape) (1, NbEdge, 1, NbSects); |
| 439 | |
| 440 | // On Remplit les tables |
| 441 | uclosed = Standard_True; |
| 442 | for (jj=ideb;jj<=ifin;jj++){ |
| 443 | |
| 444 | W = TopoDS::Wire(myShapes(jj)); |
| 445 | |
| 446 | for (ii=1, wexp.Init(W); ii<=NbEdge ; wexp.Next(), ii++) { |
| 447 | E = wexp.Current(); |
| 448 | |
| 449 | // if ( ! B.Degenerated(E)) { |
| 450 | if ( ! BRep_Tool::Degenerated(E)) { |
| 451 | myEdges->SetValue(ii,jj, E); |
| 452 | } |
| 453 | } |
| 454 | |
| 455 | // La loi est elle fermee en U ? |
| 456 | |
| 457 | wClosed = W.Closed(); |
| 458 | if (!wClosed) { |
| 459 | // le flag n'etant pas tres sur, on fait une verif |
| 460 | TopoDS_Edge Edge1, Edge2; |
| 461 | TopoDS_Vertex V1,V2; |
| 462 | Edge1 = TopoDS::Edge (myEdges->Value(NbEdge,jj)); |
| 463 | Edge2 = TopoDS::Edge (myEdges->Value(1,jj)); |
| 464 | |
| 465 | if ( Edge1.Orientation() == TopAbs_REVERSED) { |
| 466 | V1 = TopExp::FirstVertex(Edge1); |
| 467 | } |
| 468 | else { |
| 469 | V1 = TopExp::LastVertex(Edge1); |
| 470 | } |
| 471 | if ( Edge2.Orientation() == TopAbs_REVERSED) { |
| 472 | V2 = TopExp::LastVertex(Edge2); |
| 473 | } |
| 474 | else { |
| 475 | V2 = TopExp::FirstVertex(Edge2); |
| 476 | } |
| 477 | if (V1.IsSame(V2)) { |
| 478 | wClosed = Standard_True; |
| 479 | } |
| 480 | else { |
| 481 | BRepAdaptor_Curve Curve1(Edge1); |
| 482 | BRepAdaptor_Curve Curve2(Edge2); |
| 483 | Standard_Real U1 = BRep_Tool::Parameter(V1,Edge1); |
| 484 | Standard_Real U2 = BRep_Tool::Parameter(V2,Edge2); |
| 485 | Standard_Real Eps = BRep_Tool::Tolerance(V2) + |
| 486 | BRep_Tool::Tolerance(V1); |
| 487 | |
| 488 | wClosed = Curve1.Value(U1).IsEqual(Curve2.Value(U2), Eps); |
| 489 | } |
| 490 | } |
| 491 | if (!wClosed) uclosed = Standard_False; |
| 492 | } |
| 493 | |
| 494 | // sections en bout ponctuelles |
| 495 | if (w1Point) { |
| 496 | W = TopoDS::Wire(myShapes(1)); |
| 497 | wexp.Init(W); |
| 498 | E = wexp.Current(); |
| 499 | for (ii=1; ii<=NbEdge ; ii++) { |
| 500 | myEdges->SetValue(ii, 1, E); |
| 501 | } |
| 502 | } |
| 503 | |
| 504 | if (w2Point) { |
| 505 | W = TopoDS::Wire(myShapes(NbSects)); |
| 506 | wexp.Init(W); |
| 507 | E = wexp.Current(); |
| 508 | for (ii=1; ii<=NbEdge ; ii++) { |
| 509 | myEdges->SetValue(ii, NbSects, E); |
| 510 | } |
| 511 | } |
| 512 | |
| 513 | |
| 514 | myLaws = new (GeomFill_HArray1OfSectionLaw) (1, NbEdge); |
| 515 | |
| 516 | Standard_Real tol = Precision::Confusion(); |
| 517 | mySurface = totalsurf(myEdges->Array2(),myShapes.Length(),NbEdge, |
| 518 | myParams,w1Point,w2Point,uclosed,vclosed,tol); |
| 519 | |
| 520 | // On augmente le degre pour que le positionnement D2 |
| 521 | // sur les GeomFill_NSections soit correct |
| 522 | // cf commentaires dans GeomFill_NSections |
| 523 | if (mySurface->VDegree()<2) { |
| 524 | mySurface->IncreaseDegree(mySurface->UDegree(),2); |
| 525 | } |
| 526 | #ifdef DRAW |
| 527 | if ( Affich) { |
| 528 | char* name = new char[100]; |
| 529 | sprintf(name,"Ref_Surf"); |
| 530 | DrawTrSurf::Set(name,mySurface); |
| 531 | } |
| 532 | #endif |
| 533 | |
| 534 | // On Remplit les tables |
| 535 | if (Build) { |
| 536 | for (ii=1; ii<=NbEdge ; ii++) { |
| 537 | TColGeom_SequenceOfCurve NC; |
| 538 | NC.Clear(); |
| 539 | for (jj=1;jj<=NbSects;jj++) { |
| 540 | E = TopoDS::Edge (myEdges->Value(ii,jj)); |
| 541 | Handle(Geom_Curve) C; |
| 542 | // if (B.Degenerated(E)) { |
| 543 | if (BRep_Tool::Degenerated(E)) { |
| 544 | TopoDS_Vertex vf,vl; |
| 545 | TopExp::Vertices(E,vl,vf); |
| 546 | TColgp_Array1OfPnt Extremities(1,2); |
| 547 | Extremities(1) = BRep_Tool::Pnt(vf); |
| 548 | Extremities(2) = BRep_Tool::Pnt(vl); |
| 549 | TColStd_Array1OfReal Bounds(1,2); |
| 550 | Bounds(1) = 0.; |
| 551 | Bounds(2) = 1.; |
| 552 | TColStd_Array1OfInteger Mult(1,2); |
| 553 | Mult(1) = 2; |
| 554 | Mult(2) = 2; |
| 555 | Handle(Geom_BSplineCurve) BSPoint |
| 556 | = new Geom_BSplineCurve(Extremities,Bounds,Mult,1); |
| 557 | C = BSPoint; |
| 558 | } |
| 559 | else { |
| 560 | C = BRep_Tool::Curve(E,First,Last); |
| 561 | |
| 562 | if (E.Orientation() == TopAbs_REVERSED) { |
| 563 | Standard_Real aux; |
| 564 | Handle(Geom_Curve) CBis; |
| 565 | CBis = C->Reversed(); // Pour eviter de deteriorer la topologie |
| 566 | aux = C->ReversedParameter(First); |
| 567 | First = C->ReversedParameter(Last); |
| 568 | Last = aux; |
| 569 | C = CBis; |
| 570 | } |
| 571 | if ((ii>1) || (!E.Closed()) ) { // On trimme C |
| 572 | Handle(Geom_TrimmedCurve) TC = |
| 573 | new (Geom_TrimmedCurve) (C,First, Last); |
| 574 | C = TC; |
| 575 | } |
| 576 | // sinon On garde l'integrite de la courbe |
| 577 | } |
| 578 | NC.Append(C); |
| 579 | } |
| 580 | |
| 581 | Standard_Real Ufirst = ii-1; |
| 582 | Standard_Real Ulast = ii; |
| 583 | myLaws->ChangeValue(ii) = new (GeomFill_NSections)(NC,myParams, |
| 584 | Ufirst,Ulast, |
| 585 | VFirst,VLast, |
| 586 | mySurface); |
| 587 | } |
| 588 | |
| 589 | } |
| 590 | |
| 591 | } |
| 592 | |
| 593 | |
| 594 | //======================================================================= |
| 595 | //function : IsVertex |
| 596 | //purpose : |
| 597 | //======================================================================= |
| 598 | Standard_Boolean BRepFill_NSections::IsVertex() const |
| 599 | { |
| 600 | return Standard_False; |
| 601 | } |
| 602 | |
| 603 | //======================================================================= |
| 604 | //function : IsConstant |
| 605 | //purpose : |
| 606 | //======================================================================= |
| 607 | Standard_Boolean BRepFill_NSections::IsConstant() const |
| 608 | { |
| 609 | return Standard_False; |
| 610 | } |
| 611 | |
| 612 | //======================================================================= |
| 613 | //function : Vertex |
| 614 | //purpose : |
| 615 | //======================================================================= |
| 616 | TopoDS_Vertex |
| 617 | BRepFill_NSections::Vertex(const Standard_Integer Index, |
| 618 | const Standard_Real Param) const |
| 619 | { |
| 620 | BRep_Builder B; |
| 621 | TopoDS_Vertex V; |
| 622 | B.MakeVertex(V); |
| 623 | gp_Pnt P; |
| 624 | |
| 625 | if (Index <= myEdges->ColLength()) { |
| 626 | Handle(Geom_BSplineCurve) Curve |
| 627 | = Handle(Geom_BSplineCurve)::DownCast(myLaws->Value(Index)-> |
| 628 | BSplineSurface()->VIso(Param)); |
| 629 | Standard_Real first = Curve ->FirstParameter(); |
| 630 | Curve->D0(first, P); |
| 631 | B.UpdateVertex(V, P, Precision::Confusion()); |
| 632 | } |
| 633 | else if (Index == myEdges->ColLength()+1) { |
| 634 | Handle(Geom_BSplineCurve) Curve |
| 635 | = Handle(Geom_BSplineCurve)::DownCast(myLaws->Value(Index-1)-> |
| 636 | BSplineSurface()->VIso(Param)); |
| 637 | Standard_Real last = Curve ->LastParameter(); |
| 638 | Curve->D0(last, P); |
| 639 | B.UpdateVertex(V, P, Precision::Confusion()); |
| 640 | } |
| 641 | |
| 642 | return V; |
| 643 | } |
| 644 | |
| 645 | |
| 646 | ///======================================================================= |
| 647 | //function : VertexTol |
| 648 | //purpose : Evalue le trou entre 2 edges de la section |
| 649 | //======================================================================= |
| 650 | Standard_Real BRepFill_NSections::VertexTol(const Standard_Integer Index, |
| 651 | const Standard_Real Param) const |
| 652 | { |
| 653 | Standard_Real Tol = Precision::Confusion(); |
| 654 | Standard_Integer I1, I2; |
| 655 | if ( (Index==0) || (Index==myEdges->ColLength()) ) { |
| 656 | if (!uclosed) return Tol; //Le moins faux possible |
| 657 | I1 = myEdges->ColLength(); |
| 658 | I2 = 1; |
| 659 | } |
| 660 | else { |
| 661 | I1 = Index; |
| 662 | I2 = I1 +1; |
| 663 | } |
| 664 | |
| 665 | Handle(GeomFill_SectionLaw) Loi; |
| 666 | Standard_Integer NbPoles, NbKnots, Degree; |
| 667 | Handle(TColgp_HArray1OfPnt) Poles; |
| 668 | Handle(TColStd_HArray1OfReal) Knots, Weigth; |
| 669 | Handle(TColStd_HArray1OfInteger) Mults; |
| 670 | Handle(Geom_BSplineCurve) BS; |
| 671 | gp_Pnt PFirst; |
| 672 | |
| 673 | Loi = myLaws->Value(I1); |
| 674 | Loi->SectionShape( NbPoles, NbKnots, Degree); |
| 675 | Poles = new (TColgp_HArray1OfPnt) (1, NbPoles); |
| 676 | Weigth = new (TColStd_HArray1OfReal) (1, NbPoles); |
| 677 | Loi->D0(Param, Poles->ChangeArray1(), Weigth->ChangeArray1()); |
| 678 | Knots = new (TColStd_HArray1OfReal) (1, NbKnots); |
| 679 | Loi->Knots(Knots->ChangeArray1()); |
| 680 | Mults = new (TColStd_HArray1OfInteger) (1, NbKnots); |
| 681 | Loi->Mults(Mults->ChangeArray1()); |
| 682 | BS = new (Geom_BSplineCurve) (Poles->Array1(), |
| 683 | Weigth->Array1(), |
| 684 | Knots->Array1(), |
| 685 | Mults->Array1(), |
| 686 | Degree, |
| 687 | Loi->IsUPeriodic()); |
| 688 | PFirst = BS->Value( Knots->Value(Knots->Length()) ); |
| 689 | |
| 690 | Loi = myLaws->Value(I2); |
| 691 | Loi->SectionShape( NbPoles, NbKnots, Degree); |
| 692 | Poles = new (TColgp_HArray1OfPnt) (1, NbPoles); |
| 693 | Weigth = new (TColStd_HArray1OfReal) (1, NbPoles); |
| 694 | Loi->D0(Param, Poles->ChangeArray1(), Weigth->ChangeArray1()); |
| 695 | Knots = new (TColStd_HArray1OfReal) (1, NbKnots); |
| 696 | Loi->Knots(Knots->ChangeArray1()); |
| 697 | Mults = new (TColStd_HArray1OfInteger) (1, NbKnots); |
| 698 | Loi->Mults(Mults->ChangeArray1()); |
| 699 | BS = new (Geom_BSplineCurve) (Poles->Array1(), |
| 700 | Weigth->Array1(), |
| 701 | Knots->Array1(), |
| 702 | Mults->Array1(), |
| 703 | Degree, |
| 704 | Loi->IsUPeriodic()); |
| 705 | Tol += PFirst.Distance(BS->Value( Knots->Value(1))); |
| 706 | return Tol; |
| 707 | } |
| 708 | |
| 709 | //======================================================================= |
| 710 | //function : ConcatenedLaw |
| 711 | //purpose : |
| 712 | //======================================================================= |
| 713 | |
| 714 | Handle(GeomFill_SectionLaw) BRepFill_NSections::ConcatenedLaw() const |
| 715 | { |
| 716 | Handle(GeomFill_SectionLaw) Law; |
| 717 | if (myLaws->Length() == 1) |
| 718 | return myLaws->Value(1); |
| 719 | else { |
| 720 | Standard_Real Ufirst, Ulast, Vfirst, Vlast; |
| 721 | mySurface->Bounds(Ufirst, Ulast, Vfirst, Vlast); |
| 722 | TColGeom_SequenceOfCurve NCompo; |
| 723 | NCompo.Clear(); |
| 724 | for (Standard_Integer jj=1; jj<=myShapes.Length(); jj++) { |
| 725 | NCompo.Append(mySurface->VIso(myParams(jj))); |
| 726 | } |
| 727 | Law = new (GeomFill_NSections)(NCompo, myParams, |
| 728 | Ufirst, Ulast, |
| 729 | Vfirst, Vlast, |
| 730 | mySurface); |
| 731 | } |
| 732 | return Law; |
| 733 | } |
| 734 | |
| 735 | //======================================================================= |
| 736 | //function : Continuity |
| 737 | //purpose : |
| 738 | //======================================================================= |
| 739 | GeomAbs_Shape BRepFill_NSections::Continuity(const Standard_Integer Index, |
| 740 | const Standard_Real TolAngular) const |
| 741 | { |
| 742 | |
| 743 | Standard_Integer jj; |
| 744 | GeomAbs_Shape cont_jj; |
| 745 | #ifndef DEB |
| 746 | GeomAbs_Shape cont = GeomAbs_C0; |
| 747 | #else |
| 748 | GeomAbs_Shape cont; |
| 749 | #endif |
| 750 | |
| 751 | for (jj=1; jj<=myShapes.Length(); jj++) { |
| 752 | |
| 753 | TopoDS_Edge Edge1, Edge2; |
| 754 | if ( (Index==0) || (Index==myEdges->ColLength()) ) { |
| 755 | if (!uclosed) return GeomAbs_C0; //Le moins faux possible |
| 756 | |
| 757 | Edge1 = TopoDS::Edge (myEdges->Value(myEdges->ColLength(),jj)); |
| 758 | Edge2 = TopoDS::Edge (myEdges->Value(1,jj)); |
| 759 | } |
| 760 | else { |
| 761 | Edge1 = TopoDS::Edge (myEdges->Value(Index,jj)); |
| 762 | Edge2 = TopoDS::Edge (myEdges->Value(Index+1,jj)); |
| 763 | } |
| 764 | |
| 765 | TopoDS_Vertex V1,V2; |
| 766 | if ( Edge1.Orientation() == TopAbs_REVERSED) { |
| 767 | V1 = TopExp::FirstVertex(Edge1); |
| 768 | } |
| 769 | else { |
| 770 | V1 = TopExp::LastVertex(Edge1); |
| 771 | } |
| 772 | if ( Edge2.Orientation() == TopAbs_REVERSED) { |
| 773 | V2 = TopExp::LastVertex(Edge2); |
| 774 | } |
| 775 | else { |
| 776 | V2 = TopExp::FirstVertex(Edge2); |
| 777 | } |
| 778 | |
| 779 | if (BRep_Tool::Degenerated(Edge1) || BRep_Tool::Degenerated(Edge2)) |
| 780 | cont_jj = GeomAbs_CN; |
| 781 | else |
| 782 | { |
| 783 | Standard_Real U1 = BRep_Tool::Parameter(V1,Edge1); |
| 784 | Standard_Real U2 = BRep_Tool::Parameter(V2,Edge2); |
| 785 | BRepAdaptor_Curve Curve1(Edge1); |
| 786 | BRepAdaptor_Curve Curve2(Edge2); |
| 787 | Standard_Real Eps = BRep_Tool::Tolerance(V2) + |
| 788 | BRep_Tool::Tolerance(V1); |
| 789 | cont_jj = BRepLProp::Continuity(Curve1,Curve2,U1,U2, Eps, TolAngular); |
| 790 | } |
| 791 | |
| 792 | if (jj==1) cont = cont_jj; |
| 793 | if (cont>cont_jj) cont = cont_jj; |
| 794 | |
| 795 | } |
| 796 | |
| 797 | return cont; |
| 798 | } |
| 799 | |
| 800 | //======================================================================= |
| 801 | //function : D0 |
| 802 | //purpose : |
| 803 | //======================================================================= |
| 804 | void BRepFill_NSections::D0(const Standard_Real V, TopoDS_Shape& S) |
| 805 | { |
| 806 | TopoDS_Wire W; |
| 807 | BRepLib_MakeWire MW; |
| 808 | Standard_Integer ii, NbEdge = myLaws->Length(); |
| 809 | for (ii=1; ii<=NbEdge ; ii++) { |
| 810 | Handle(Geom_BSplineCurve) Curve |
| 811 | = Handle(Geom_BSplineCurve)::DownCast(myLaws->Value(ii)->BSplineSurface()->VIso(V)); |
| 812 | Standard_Real first = Curve ->FirstParameter(), |
| 813 | last = Curve ->LastParameter(); |
| 814 | TopoDS_Edge E = BRepLib_MakeEdge(Curve,first,last); |
| 815 | MW.Add(E); |
| 816 | } |
| 817 | TopAbs_Orientation Orien = TopAbs_FORWARD; |
| 818 | TopoDS_Shape aLocalShape = MW.Wire().Oriented(Orien); |
| 819 | S = TopoDS::Wire(aLocalShape); |
| 820 | // S = TopoDS::Wire(MW.Wire().Oriented(Orien)); |
| 821 | |
| 822 | } |
| 823 | |