| 1 | // Created on: 1993-09-22 |
| 2 | // Created by: Didier PIFFAULT |
| 3 | // Copyright (c) 1993-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 | |
| 21 | |
| 22 | #include <Standard_Stream.hxx> |
| 23 | |
| 24 | #include <stdio.h> |
| 25 | |
| 26 | #include <MeshTest.ixx> |
| 27 | |
| 28 | #include <MeshTest_DrawableMesh.hxx> |
| 29 | #include <TopAbs_ShapeEnum.hxx> |
| 30 | #include <TopoDS.hxx> |
| 31 | #include <TopoDS_Edge.hxx> |
| 32 | #include <TopoDS_Face.hxx> |
| 33 | #include <TopoDS_Shape.hxx> |
| 34 | #include <TopoDS_Compound.hxx> |
| 35 | #include <TopExp_Explorer.hxx> |
| 36 | #include <TopTools_ListIteratorOfListOfShape.hxx> |
| 37 | #include <DBRep.hxx> |
| 38 | #include <BRepTest.hxx> |
| 39 | #include <GeometryTest.hxx> |
| 40 | #include <BRep_Tool.hxx> |
| 41 | #include <BRep_Builder.hxx> |
| 42 | #include <Draw_MarkerShape.hxx> |
| 43 | #include <Draw_Appli.hxx> |
| 44 | #include <Draw.hxx> |
| 45 | #include <DrawTrSurf.hxx> |
| 46 | #include <BRepMesh_Triangle.hxx> |
| 47 | #include <BRepMesh_DataStructureOfDelaun.hxx> |
| 48 | #include <BRepMesh_Delaun.hxx> |
| 49 | #include <BRepMesh_FastDiscret.hxx> |
| 50 | #include <BRepMesh_Array1OfVertexOfDelaun.hxx> |
| 51 | #include <BRepMesh_Vertex.hxx> |
| 52 | #include <BRepMesh_Edge.hxx> |
| 53 | #include <BRepMesh_IncrementalMesh.hxx> |
| 54 | #include <TColStd_ListIteratorOfListOfInteger.hxx> |
| 55 | #include <TColStd_MapIteratorOfMapOfInteger.hxx> |
| 56 | #include <Bnd_Box.hxx> |
| 57 | #include <Precision.hxx> |
| 58 | #include <Draw_Interpretor.hxx> |
| 59 | #include <IntPoly_PlaneSection.hxx> |
| 60 | #include <IntPoly_ShapeSection.hxx> |
| 61 | #include <Geom_Plane.hxx> |
| 62 | #include <Geom_Surface.hxx> |
| 63 | #include <Draw_Marker3D.hxx> |
| 64 | #include <Draw_Segment2D.hxx> |
| 65 | |
| 66 | #include <GCPnts_UniformAbscissa.hxx> |
| 67 | #include <GeomAdaptor_Curve.hxx> |
| 68 | #include <Geom_Curve.hxx> |
| 69 | #include <Extrema_LocateExtPC.hxx> |
| 70 | |
| 71 | #include <TopLoc_Location.hxx> |
| 72 | #include <gp_Trsf.hxx> |
| 73 | #include <Poly_Triangulation.hxx> |
| 74 | #include <Poly_Connect.hxx> |
| 75 | #include <TColgp_Array1OfPnt2d.hxx> |
| 76 | #include <TColStd_HArray1OfInteger.hxx> |
| 77 | #include <TopExp_Explorer.hxx> |
| 78 | #include <gp_Pln.hxx> |
| 79 | |
| 80 | #include <PLib.hxx> |
| 81 | #include <AppCont_ContMatrices.hxx> |
| 82 | #include <math_Vector.hxx> |
| 83 | #include <math_Matrix.hxx> |
| 84 | #include <math.hxx> |
| 85 | |
| 86 | #include <CSLib_DerivativeStatus.hxx> |
| 87 | #include <CSLib.hxx> |
| 88 | #include <BRepAdaptor_Surface.hxx> |
| 89 | #include <Bnd_Box.hxx> |
| 90 | #include <BRepBndLib.hxx> |
| 91 | |
| 92 | |
| 93 | //epa Memory leaks test |
| 94 | #include <BRepBuilderAPI_MakePolygon.hxx> |
| 95 | #include <TopoDS_Wire.hxx> |
| 96 | #include <BRepBuilderAPI_MakeFace.hxx> |
| 97 | #include <BRepTools.hxx> |
| 98 | |
| 99 | //OAN: for triepoints |
| 100 | #include <BRepBuilderAPI_MakeVertex.hxx> |
| 101 | #include <Poly_PolygonOnTriangulation.hxx> |
| 102 | #include <TopTools_MapIteratorOfMapOfShape.hxx> |
| 103 | |
| 104 | #ifdef WNT |
| 105 | Standard_IMPORT Draw_Viewer dout; |
| 106 | #endif |
| 107 | |
| 108 | #define MAX2(X, Y) ( Abs(X) > Abs(Y)? Abs(X) : Abs(Y) ) |
| 109 | #define MAX3(X, Y, Z) ( MAX2 ( MAX2(X,Y) , Z) ) |
| 110 | |
| 111 | |
| 112 | |
| 113 | #define ONETHIRD 0.333333333333333333333333333333333333333333333333333333333333 |
| 114 | #define TWOTHIRD 0.666666666666666666666666666666666666666666666666666666666666 |
| 115 | |
| 116 | #ifdef DEB_MESH_CHRONO |
| 117 | #include <OSD_Chronometer.hxx> |
| 118 | Standard_Integer D0Control, D0Internal, D0Unif, D0Edges, NbControls; |
| 119 | OSD_Chronometer chTotal, chInternal, chControl, chUnif, chAddPoint; |
| 120 | OSD_Chronometer chEdges, chMaillEdges, chEtuInter, chLastControl, chStock; |
| 121 | OSD_Chronometer chAdd11, chAdd12, chAdd2, chUpdate, chPointValid; |
| 122 | OSD_Chronometer chIsos, chPointsOnIsos; |
| 123 | #endif |
| 124 | |
| 125 | |
| 126 | |
| 127 | //======================================================================= |
| 128 | //function : shapesection |
| 129 | //purpose : |
| 130 | //======================================================================= |
| 131 | |
| 132 | static Standard_Integer shapesection(Draw_Interpretor&, Standard_Integer nbarg, const char** argv) |
| 133 | { |
| 134 | if (nbarg < 4) return 1; |
| 135 | |
| 136 | TopoDS_Shape S1 = DBRep::Get(argv[2]); |
| 137 | TopoDS_Shape S2 = DBRep::Get(argv[3]); |
| 138 | if (S1.IsNull() || S2.IsNull()) return 1; |
| 139 | |
| 140 | IntPoly_ShapeSection SECTION(S1,S2); |
| 141 | // char name[100]; |
| 142 | BRep_Builder B; |
| 143 | TopoDS_Compound C; |
| 144 | B.MakeCompound(C); |
| 145 | for (Standard_Integer i = 1 ; i <= SECTION.NbEdges() ; i++) { |
| 146 | TopoDS_Shape E = SECTION.Edge(i); |
| 147 | if (!E.IsNull()) B.Add(C,E); |
| 148 | } |
| 149 | |
| 150 | DBRep::Set(argv[1],C); |
| 151 | return 0; |
| 152 | } |
| 153 | |
| 154 | //======================================================================= |
| 155 | //function : planesection |
| 156 | //purpose : |
| 157 | //======================================================================= |
| 158 | |
| 159 | static Standard_Integer planesection(Draw_Interpretor&, Standard_Integer nbarg, const char** argv) |
| 160 | { |
| 161 | if (nbarg < 4) return 1; |
| 162 | |
| 163 | TopoDS_Shape S = DBRep::Get(argv[2]); |
| 164 | if (S.IsNull()) return 1; |
| 165 | Handle(Geom_Surface) Surf = DrawTrSurf::GetSurface(argv[3]); |
| 166 | |
| 167 | Handle(Geom_Plane) pl = Handle(Geom_Plane)::DownCast(Surf); |
| 168 | if (!pl.IsNull()) { |
| 169 | IntPoly_PlaneSection SECTION(S,pl->Pln()); |
| 170 | // char name[100]; |
| 171 | BRep_Builder B; |
| 172 | TopoDS_Compound C; |
| 173 | B.MakeCompound(C); |
| 174 | for (Standard_Integer i = 1 ; i <= SECTION.NbEdges() ; i++) { |
| 175 | TopoDS_Shape E = SECTION.Edge(i); |
| 176 | if (!E.IsNull()) B.Add(C,E); |
| 177 | } |
| 178 | |
| 179 | DBRep::Set(argv[1],C); |
| 180 | return 0; |
| 181 | } |
| 182 | else return 1; |
| 183 | } |
| 184 | |
| 185 | //======================================================================= |
| 186 | //function : incrementalmesh |
| 187 | //purpose : |
| 188 | //======================================================================= |
| 189 | |
| 190 | static Standard_Integer incrementalmesh(Draw_Interpretor& di, Standard_Integer nbarg, const char** argv) |
| 191 | { |
| 192 | if (nbarg < 3) { |
| 193 | di << " use incmesh shape deflection [inParallel (0/1) : 0 by default]\n"; |
| 194 | return 0; |
| 195 | } |
| 196 | |
| 197 | TopoDS_Shape aShape = DBRep::Get(argv[1]); |
| 198 | if (aShape.IsNull()) { |
| 199 | di << " null shapes is not allowed here\n"; |
| 200 | return 0; |
| 201 | } |
| 202 | Standard_Real aDeflection = Draw::Atof(argv[2]); |
| 203 | |
| 204 | Standard_Boolean isInParallel = Standard_False; |
| 205 | if (nbarg == 4) { |
| 206 | isInParallel = Draw::Atoi(argv[3]) == 1; |
| 207 | } |
| 208 | di << "Incremental Mesh, multi-threading " |
| 209 | << (isInParallel ? "ON\n" : "OFF\n"); |
| 210 | |
| 211 | Standard::SetReentrant(isInParallel); |
| 212 | |
| 213 | BRepMesh_IncrementalMesh MESH(aShape, aDeflection, Standard_False, 0.5, isInParallel); |
| 214 | Standard_Integer statusFlags = MESH.GetStatusFlags(); |
| 215 | |
| 216 | di << "Meshing statuses: "; |
| 217 | |
| 218 | if( !statusFlags ) |
| 219 | { |
| 220 | di << "NoError"; |
| 221 | } |
| 222 | else |
| 223 | { |
| 224 | Standard_Integer i; |
| 225 | for( i = 0; i < 4; i++ ) |
| 226 | { |
| 227 | if( (statusFlags >> i) & (Standard_Integer)1 ) |
| 228 | { |
| 229 | switch(i+1) |
| 230 | { |
| 231 | case 1: |
| 232 | di << "OpenWire "; |
| 233 | break; |
| 234 | case 2: |
| 235 | di << "SelfIntersectingWire "; |
| 236 | break; |
| 237 | case 3: |
| 238 | di << "Failure "; |
| 239 | break; |
| 240 | case 4: |
| 241 | di << "ReMesh "; |
| 242 | break; |
| 243 | } |
| 244 | } |
| 245 | } |
| 246 | } |
| 247 | |
| 248 | return 0; |
| 249 | } |
| 250 | |
| 251 | //======================================================================= |
| 252 | //function : MemLeakTest |
| 253 | //purpose : |
| 254 | //======================================================================= |
| 255 | |
| 256 | static Standard_Integer MemLeakTest(Draw_Interpretor&, Standard_Integer nbarg, const char** argv) |
| 257 | { |
| 258 | for(int i=0;i<10000;i++) |
| 259 | { |
| 260 | BRepBuilderAPI_MakePolygon w(gp_Pnt(0,0,0),gp_Pnt(0,100,0),gp_Pnt(20,100,0),gp_Pnt(20,0,0)); |
| 261 | w.Close(); |
| 262 | TopoDS_Wire wireShape( w.Wire()); |
| 263 | BRepBuilderAPI_MakeFace faceBuilder(wireShape); |
| 264 | TopoDS_Face f( faceBuilder.Face()); |
| 265 | BRepMesh_IncrementalMesh im(f,1); |
| 266 | BRepTools::Clean(f); |
| 267 | } |
| 268 | return 0; |
| 269 | } |
| 270 | |
| 271 | //======================================================================= |
| 272 | //function : fastdiscret |
| 273 | //purpose : |
| 274 | //======================================================================= |
| 275 | |
| 276 | static Standard_Integer fastdiscret(Draw_Interpretor& di, Standard_Integer nbarg, const char** argv) |
| 277 | { |
| 278 | if (nbarg < 3) return 1; |
| 279 | |
| 280 | TopoDS_Shape S = DBRep::Get(argv[1]); |
| 281 | if (S.IsNull()) return 1; |
| 282 | |
| 283 | const Standard_Real d = Draw::Atof(argv[2]); |
| 284 | |
| 285 | Standard_Boolean WithShare = Standard_True; |
| 286 | if (nbarg > 3) WithShare = Draw::Atoi(argv[3]); |
| 287 | |
| 288 | Bnd_Box B; |
| 289 | BRepBndLib::Add(S,B); |
| 290 | BRepMesh_FastDiscret MESH(d,0.5,B,WithShare,Standard_True,Standard_False,Standard_True); |
| 291 | |
| 292 | //Standard_Integer NbIterations = MESH.NbIterations(); |
| 293 | //if (nbarg > 4) NbIterations = Draw::Atoi(argv[4]); |
| 294 | //MESH.NbIterations() = NbIterations; |
| 295 | |
| 296 | di<<"Starting FastDiscret with :"<<"\n"; |
| 297 | di<<" Deflection="<<d<<"\n"; |
| 298 | di<<" Angle="<<0.5<<"\n"; |
| 299 | di<<" SharedMode="<< (Standard_Integer) WithShare<<"\n"; |
| 300 | //di<<" NbIterations="<<NbIterations<<"\n"; |
| 301 | |
| 302 | Handle(Poly_Triangulation) T; |
| 303 | BRep_Builder aBuilder; |
| 304 | TopExp_Explorer ex; |
| 305 | |
| 306 | // Clear existing triangulations |
| 307 | for (ex.Init(S, TopAbs_FACE); ex.More(); ex.Next()) |
| 308 | aBuilder.UpdateFace(TopoDS::Face(ex.Current()),T); |
| 309 | |
| 310 | MESH.Perform(S); |
| 311 | |
| 312 | TopoDS_Compound aCompGood, aCompFailed, aCompViolating; |
| 313 | |
| 314 | TopLoc_Location L; |
| 315 | Standard_Integer nbtriangles = 0, nbnodes = 0, nbfailed = 0, nbviolating = 0; |
| 316 | Standard_Real maxdef = 0.0; |
| 317 | for (ex.Init(S, TopAbs_FACE); ex.More(); ex.Next()) |
| 318 | { |
| 319 | T = BRep_Tool::Triangulation(TopoDS::Face(ex.Current()),L); |
| 320 | if (T.IsNull()) |
| 321 | { |
| 322 | nbfailed++; |
| 323 | if (aCompFailed.IsNull()) |
| 324 | aBuilder.MakeCompound(aCompFailed); |
| 325 | aBuilder.Add(aCompFailed,ex.Current()); |
| 326 | } |
| 327 | else |
| 328 | { |
| 329 | nbtriangles += T->NbTriangles(); |
| 330 | nbnodes += T->NbNodes(); |
| 331 | if (T->Deflection() > maxdef) maxdef = T->Deflection(); |
| 332 | if (T->Deflection() > d) |
| 333 | { |
| 334 | nbviolating++; |
| 335 | if (aCompViolating.IsNull()) |
| 336 | aBuilder.MakeCompound(aCompViolating); |
| 337 | aBuilder.Add(aCompViolating,ex.Current()); |
| 338 | } |
| 339 | else |
| 340 | { |
| 341 | if (aCompGood.IsNull()) |
| 342 | aBuilder.MakeCompound(aCompGood); |
| 343 | aBuilder.Add(aCompGood,ex.Current()); |
| 344 | } |
| 345 | } |
| 346 | } |
| 347 | |
| 348 | if (!aCompGood.IsNull()) |
| 349 | { |
| 350 | char name[256]; |
| 351 | strcpy(name,argv[1]); |
| 352 | strcat(name,"_good"); |
| 353 | DBRep::Set(name,aCompGood); |
| 354 | } |
| 355 | if (!aCompFailed.IsNull()) |
| 356 | { |
| 357 | char name[256]; |
| 358 | strcpy(name,argv[1]); |
| 359 | strcat(name,"_failed"); |
| 360 | DBRep::Set(name,aCompFailed); |
| 361 | } |
| 362 | if (!aCompViolating.IsNull()) |
| 363 | { |
| 364 | char name[256]; |
| 365 | strcpy(name,argv[1]); |
| 366 | strcat(name,"_violating"); |
| 367 | DBRep::Set(name,aCompViolating); |
| 368 | } |
| 369 | |
| 370 | di<<"FastDiscret completed with :"<<"\n"; |
| 371 | di<<" MaxDeflection="<<maxdef<<"\n"; |
| 372 | di<<" NbNodes="<<nbnodes<<"\n"; |
| 373 | di<<" NbTriangles="<<nbtriangles<<"\n"; |
| 374 | di<<" NbFailed="<<nbfailed<<"\n"; |
| 375 | di<<" NbViolating="<<nbviolating<<"\n"; |
| 376 | |
| 377 | return 0; |
| 378 | } |
| 379 | |
| 380 | |
| 381 | //======================================================================= |
| 382 | //function : triangule |
| 383 | //purpose : |
| 384 | //======================================================================= |
| 385 | |
| 386 | |
| 387 | class BRepMesh_Couple |
| 388 | { |
| 389 | public: |
| 390 | BRepMesh_Couple() { myI1 = myI2 = 0; } |
| 391 | BRepMesh_Couple(const Standard_Integer I1, |
| 392 | const Standard_Integer I2) |
| 393 | { myI1 = I1; myI2 = I2; } |
| 394 | |
| 395 | Standard_Integer myI1; |
| 396 | Standard_Integer myI2; |
| 397 | }; |
| 398 | |
| 399 | inline Standard_Boolean IsEqual(const BRepMesh_Couple& one, |
| 400 | const BRepMesh_Couple& other) |
| 401 | { |
| 402 | if (one.myI1 == other.myI1 && |
| 403 | one.myI2 == other.myI2) return Standard_True; |
| 404 | else return Standard_False; |
| 405 | } |
| 406 | |
| 407 | inline Standard_Integer HashCode(const BRepMesh_Couple& one, |
| 408 | const Standard_Integer Upper) |
| 409 | { |
| 410 | return ::HashCode((one.myI1+one.myI2), Upper); |
| 411 | } |
| 412 | |
| 413 | typedef NCollection_Map<BRepMesh_Couple> BRepMesh_MapOfCouple; |
| 414 | |
| 415 | |
| 416 | static void AddLink(BRepMesh_MapOfCouple& aMap, |
| 417 | Standard_Integer v1, |
| 418 | Standard_Integer v2) |
| 419 | { |
| 420 | Standard_Integer i1 = v1; |
| 421 | Standard_Integer i2 = v2; |
| 422 | if(i1 > i2) { |
| 423 | i1 = v2; |
| 424 | i2 = v1; |
| 425 | } |
| 426 | aMap.Add(BRepMesh_Couple(i1,i2)); |
| 427 | } |
| 428 | |
| 429 | static void MeshStats(const TopoDS_Shape& theSape, |
| 430 | Standard_Integer& theNbTri, |
| 431 | Standard_Integer& theNbEdges, |
| 432 | Standard_Integer& theNbNodes) |
| 433 | { |
| 434 | theNbTri = 0; |
| 435 | theNbEdges = 0; |
| 436 | theNbNodes = 0; |
| 437 | |
| 438 | Handle(Poly_Triangulation) T; |
| 439 | TopLoc_Location L; |
| 440 | |
| 441 | for ( TopExp_Explorer ex(theSape, TopAbs_FACE); ex.More(); ex.Next()) { |
| 442 | TopoDS_Face F = TopoDS::Face(ex.Current()); |
| 443 | T = BRep_Tool::Triangulation(F, L); |
| 444 | if (!T.IsNull()) { |
| 445 | theNbTri += T->NbTriangles(); |
| 446 | theNbNodes += T->NbNodes(); |
| 447 | |
| 448 | BRepMesh_MapOfCouple aMap; |
| 449 | //count number of links |
| 450 | Poly_Array1OfTriangle& Trian = T->ChangeTriangles(); |
| 451 | for(Standard_Integer i = 1; i<=Trian.Length();i++) { |
| 452 | Standard_Integer v1, v2, v3; |
| 453 | Trian(i).Get(v1,v2,v3); |
| 454 | |
| 455 | AddLink(aMap, v1, v2); |
| 456 | AddLink(aMap, v2, v3); |
| 457 | AddLink(aMap, v3, v1); |
| 458 | } |
| 459 | |
| 460 | theNbEdges+=aMap.Extent(); |
| 461 | } |
| 462 | } |
| 463 | } |
| 464 | |
| 465 | static Standard_Integer triangule(Draw_Interpretor& di, Standard_Integer nbarg, const char** argv) |
| 466 | { |
| 467 | if (nbarg < 4) return 1; |
| 468 | |
| 469 | Standard_Boolean save = Standard_False; |
| 470 | |
| 471 | const char *id1 = argv[2]; |
| 472 | TopoDS_Shape S = DBRep::Get(id1); |
| 473 | if (S.IsNull()) return 1; |
| 474 | di << argv[1] << " "; |
| 475 | Standard_Real Deflect=Draw::Atof(argv[3]); |
| 476 | if (Deflect<=0.) { |
| 477 | di << " Donner la fleche !" << "\n"; |
| 478 | return 1; |
| 479 | } |
| 480 | |
| 481 | if (nbarg >4) { |
| 482 | save = (Draw::Atoi(argv[4])==1); |
| 483 | } |
| 484 | |
| 485 | Standard_Boolean partage=Standard_True; |
| 486 | if (nbarg>5) { |
| 487 | partage=Draw::Atoi(argv[5])==1; |
| 488 | } |
| 489 | |
| 490 | Handle(MeshTest_DrawableMesh) DM = |
| 491 | new MeshTest_DrawableMesh(S,Deflect,partage, save); |
| 492 | |
| 493 | Draw::Set(argv[1],DM); |
| 494 | |
| 495 | Standard_Integer nbn, nbl, nbe; |
| 496 | MeshStats(S, nbe, nbl, nbn); |
| 497 | |
| 498 | di<<"(Resultat ("<<nbe<<" mailles) ("<<nbl<<" aretes) ("<<nbn<<" sommets))"<<"\n"; |
| 499 | |
| 500 | // passe de verification du maillage. |
| 501 | /*Standard_Integer nbc; |
| 502 | for (Standard_Integer iLi=1; iLi<= DM->Mesh()->NbEdges(); iLi++) { |
| 503 | const BRepMesh_Edge& ed=DM->Mesh()->Edge(iLi); |
| 504 | if (ed.Movability()!=BRepMesh_Deleted) { |
| 505 | nbc=struc->ElemConnectedTo(iLi).Extent(); |
| 506 | if (nbc != 1 && nbc != 2) di <<"ERROR MAILLAGE Edge no "<< iLi<<"\n"; |
| 507 | } |
| 508 | }*/ |
| 509 | |
| 510 | Bnd_Box bobo; |
| 511 | |
| 512 | for (Standard_Integer lepnt=1; lepnt<DM->Mesh()->NbPoint3d(); lepnt++) { |
| 513 | bobo.Add(DM->Mesh()->Point3d(lepnt)); |
| 514 | } |
| 515 | Standard_Real x,y,z,X,Y,Z; |
| 516 | bobo.Get(x,y,z,X,Y,Z); |
| 517 | Standard_Real delta=Max(X-x,Max(Y-y,Z-z)); |
| 518 | if (delta>0) delta=Deflect/delta; |
| 519 | di << " Fleche de " << delta << " fois la taille de l''objet." << "\n"; |
| 520 | |
| 521 | return 0; |
| 522 | } |
| 523 | |
| 524 | //======================================================================= |
| 525 | //function : addshape |
| 526 | //purpose : |
| 527 | //======================================================================= |
| 528 | |
| 529 | Standard_Integer addshape(Draw_Interpretor&, Standard_Integer n, const char** a) |
| 530 | { |
| 531 | if (n < 3) return 1; |
| 532 | Handle(MeshTest_DrawableMesh) D = |
| 533 | Handle(MeshTest_DrawableMesh)::DownCast(Draw::Get(a[1])); |
| 534 | if (D.IsNull()) return 1; |
| 535 | TopoDS_Shape S = DBRep::Get(a[2]); |
| 536 | if (S.IsNull()) return 1; |
| 537 | |
| 538 | D->Add(S); |
| 539 | Draw::Repaint(); |
| 540 | |
| 541 | return 0; |
| 542 | } |
| 543 | |
| 544 | |
| 545 | //======================================================================= |
| 546 | //function : smooth |
| 547 | //purpose : |
| 548 | //======================================================================= |
| 549 | |
| 550 | /*Standard_Integer smooth(Draw_Interpretor&, Standard_Integer n, const char** a) |
| 551 | { |
| 552 | if (n < 2) return 1; |
| 553 | Handle(MeshTest_DrawableMesh) D = |
| 554 | Handle(MeshTest_DrawableMesh)::DownCast(Draw::Get(a[1])); |
| 555 | if (D.IsNull()) return 1; |
| 556 | Handle(BRepMesh_DataStructureOfDelaun) struc= |
| 557 | D->Mesh()->Result(); |
| 558 | BRepMesh_Array1OfVertexOfDelaun toto(1,1); |
| 559 | BRepMesh_Delaun trial(struc, |
| 560 | toto, |
| 561 | Standard_True); |
| 562 | trial.SmoothMesh(0.1); |
| 563 | Draw::Repaint(); |
| 564 | return 0; |
| 565 | } |
| 566 | */ |
| 567 | |
| 568 | //======================================================================= |
| 569 | //function : edges |
| 570 | //purpose : |
| 571 | //======================================================================= |
| 572 | |
| 573 | /*static Standard_Integer edges (Draw_Interpretor&, Standard_Integer n, const char** a) |
| 574 | { |
| 575 | if (n < 3) return 1; |
| 576 | |
| 577 | Handle(MeshTest_DrawableMesh) D = |
| 578 | Handle(MeshTest_DrawableMesh)::DownCast(Draw::Get(a[1])); |
| 579 | if (D.IsNull()) return 1; |
| 580 | TopoDS_Shape S = DBRep::Get(a[2]); |
| 581 | if (S.IsNull()) return 1; |
| 582 | |
| 583 | TopExp_Explorer ex; |
| 584 | TColStd_SequenceOfInteger& eseq = D->Edges(); |
| 585 | Handle(BRepMesh_FastDiscret) M = D->Mesh(); |
| 586 | Handle(BRepMesh_DataStructureOfDelaun) DS = M->Result(); |
| 587 | Standard_Integer e1, e2, e3, iTri; |
| 588 | Standard_Boolean o1, o2, o3; |
| 589 | |
| 590 | // the faces |
| 591 | for (ex.Init(S,TopAbs_FACE);ex.More();ex.Next()) { |
| 592 | const BRepMesh_MapOfInteger& elems = DS->ElemOfDomain(); |
| 593 | BRepMesh_MapOfInteger::Iterator it; |
| 594 | for (it.Initialize(elems); it.More(); it.Next()) { |
| 595 | iTri = it.Key(); |
| 596 | const BRepMesh_Triangle& triang = M->Triangle(iTri); |
| 597 | if (triang.Movability()!=BRepMesh_Deleted) { |
| 598 | triang.Edges(e1, e2, e3, o1, o2, o3); |
| 599 | eseq.Append(e1); |
| 600 | eseq.Append(e2); |
| 601 | eseq.Append(e3); |
| 602 | } |
| 603 | } |
| 604 | } |
| 605 | |
| 606 | // the edges |
| 607 | //for (ex.Init(S,TopAbs_EDGE,TopAbs_FACE);ex.More();ex.Next()) { |
| 608 | //} |
| 609 | |
| 610 | Draw::Repaint(); |
| 611 | return 0; |
| 612 | } |
| 613 | */ |
| 614 | |
| 615 | //======================================================================= |
| 616 | //function : vertices |
| 617 | //purpose : |
| 618 | //======================================================================= |
| 619 | |
| 620 | static Standard_Integer vertices (Draw_Interpretor&, Standard_Integer n, const char** a) |
| 621 | { |
| 622 | if (n < 3) return 1; |
| 623 | |
| 624 | Handle(MeshTest_DrawableMesh) D = |
| 625 | Handle(MeshTest_DrawableMesh)::DownCast(Draw::Get(a[1])); |
| 626 | if (D.IsNull()) return 1; |
| 627 | TopoDS_Shape S = DBRep::Get(a[2]); |
| 628 | if (S.IsNull()) return 1; |
| 629 | |
| 630 | TopExp_Explorer ex; |
| 631 | TColStd_SequenceOfInteger& vseq = D->Vertices(); |
| 632 | Handle(BRepMesh_FastDiscret) M = D->Mesh(); |
| 633 | |
| 634 | // the faces |
| 635 | for (ex.Init(S,TopAbs_FACE);ex.More();ex.Next()) { |
| 636 | BRepMesh_MapOfInteger vtx; |
| 637 | M->VerticesOfDomain(vtx); |
| 638 | for (BRepMesh_MapOfInteger::Iterator it(vtx); it.More(); it.Next()) |
| 639 | vseq.Append(it.Key()); |
| 640 | } |
| 641 | |
| 642 | |
| 643 | // the edges |
| 644 | //for (ex.Init(S,TopAbs_EDGE,TopAbs_FACE);ex.More();ex.Next()) { |
| 645 | //} |
| 646 | |
| 647 | Draw::Repaint(); |
| 648 | return 0; |
| 649 | } |
| 650 | |
| 651 | //======================================================================= |
| 652 | //function : medge |
| 653 | //purpose : |
| 654 | //======================================================================= |
| 655 | |
| 656 | static Standard_Integer medge (Draw_Interpretor&, Standard_Integer n, const char** a) |
| 657 | { |
| 658 | if (n < 3) return 1; |
| 659 | |
| 660 | Handle(MeshTest_DrawableMesh) D = |
| 661 | Handle(MeshTest_DrawableMesh)::DownCast(Draw::Get(a[1])); |
| 662 | if (D.IsNull()) return 1; |
| 663 | |
| 664 | Standard_Integer i,j,e; |
| 665 | TColStd_SequenceOfInteger& eseq = D->Edges(); |
| 666 | for (i = 2; i < n; i++) { |
| 667 | e = Draw::Atoi(a[i]); |
| 668 | if (e > 0) |
| 669 | eseq.Append(e); |
| 670 | else if (e < 0) { |
| 671 | e = -e; |
| 672 | j = 1; |
| 673 | while (j <= eseq.Length()) { |
| 674 | if (eseq(j) == e) |
| 675 | eseq.Remove(j); |
| 676 | else |
| 677 | j++; |
| 678 | } |
| 679 | } |
| 680 | else |
| 681 | eseq.Clear(); |
| 682 | } |
| 683 | |
| 684 | Draw::Repaint(); |
| 685 | return 0; |
| 686 | } |
| 687 | |
| 688 | |
| 689 | //======================================================================= |
| 690 | //function : mvertex |
| 691 | //purpose : |
| 692 | //======================================================================= |
| 693 | |
| 694 | static Standard_Integer mvertex (Draw_Interpretor&, Standard_Integer n, const char** a) |
| 695 | { |
| 696 | if (n < 3) return 1; |
| 697 | |
| 698 | Handle(MeshTest_DrawableMesh) D = |
| 699 | Handle(MeshTest_DrawableMesh)::DownCast(Draw::Get(a[1])); |
| 700 | if (D.IsNull()) return 1; |
| 701 | |
| 702 | Standard_Integer i,j,v; |
| 703 | TColStd_SequenceOfInteger& vseq = D->Vertices(); |
| 704 | for (i = 2; i < n; i++) { |
| 705 | v = Draw::Atoi(a[i]); |
| 706 | if (v > 0) |
| 707 | vseq.Append(v); |
| 708 | else if (v < 0) { |
| 709 | v = -v; |
| 710 | j = 1; |
| 711 | while (j <= vseq.Length()) { |
| 712 | if (vseq(j) == v) |
| 713 | vseq.Remove(v); |
| 714 | else |
| 715 | j++; |
| 716 | } |
| 717 | } |
| 718 | else |
| 719 | vseq.Clear(); |
| 720 | } |
| 721 | Draw::Repaint(); |
| 722 | return 0; |
| 723 | } |
| 724 | |
| 725 | |
| 726 | //======================================================================= |
| 727 | //function : triangle |
| 728 | //purpose : |
| 729 | //======================================================================= |
| 730 | |
| 731 | static Standard_Integer triangle (Draw_Interpretor&, Standard_Integer n, const char** a) |
| 732 | { |
| 733 | if (n < 3) return 1; |
| 734 | |
| 735 | Handle(MeshTest_DrawableMesh) D = |
| 736 | Handle(MeshTest_DrawableMesh)::DownCast(Draw::Get(a[1])); |
| 737 | if (D.IsNull()) return 1; |
| 738 | |
| 739 | Standard_Integer i,j,v; |
| 740 | TColStd_SequenceOfInteger& tseq = D->Triangles(); |
| 741 | for (i = 2; i < n; i++) { |
| 742 | v = Draw::Atoi(a[i]); |
| 743 | if (v > 0) |
| 744 | tseq.Append(v); |
| 745 | else if (v < 0) { |
| 746 | v = -v; |
| 747 | j = 1; |
| 748 | while (j <= tseq.Length()) { |
| 749 | if (tseq(j) == v) |
| 750 | tseq.Remove(v); |
| 751 | else |
| 752 | j++; |
| 753 | } |
| 754 | } |
| 755 | else |
| 756 | tseq.Clear(); |
| 757 | } |
| 758 | Draw::Repaint(); |
| 759 | return 0; |
| 760 | } |
| 761 | |
| 762 | |
| 763 | //======================================================================= |
| 764 | //function : printdegree |
| 765 | //purpose : |
| 766 | //======================================================================= |
| 767 | |
| 768 | static void printdegree(BRepMesh_DegreeOfFreedom dof, Draw_Interpretor& di) |
| 769 | { |
| 770 | switch (dof) { |
| 771 | case BRepMesh_InVolume : |
| 772 | di << "InVolume"; |
| 773 | break; |
| 774 | case BRepMesh_OnSurface : |
| 775 | di << "OnSurface"; |
| 776 | break; |
| 777 | case BRepMesh_OnCurve : |
| 778 | di << "OnCurve"; |
| 779 | break; |
| 780 | case BRepMesh_Fixed : |
| 781 | di << "Fixed"; |
| 782 | break; |
| 783 | case BRepMesh_Frontier : |
| 784 | di << "Frontier"; |
| 785 | break; |
| 786 | case BRepMesh_Deleted : |
| 787 | di << "Deleted"; |
| 788 | break; |
| 789 | case BRepMesh_Free : |
| 790 | di << "Free"; |
| 791 | break; |
| 792 | } |
| 793 | } |
| 794 | |
| 795 | //======================================================================= |
| 796 | //function : dumpvertex |
| 797 | //purpose : |
| 798 | //======================================================================= |
| 799 | |
| 800 | /* |
| 801 | Standard_Integer dumpvertex(Draw_Interpretor& di, Standard_Integer argc, const char** argv) |
| 802 | { |
| 803 | if (argc < 2) return 1; |
| 804 | |
| 805 | Handle(MeshTest_DrawableMesh) D = |
| 806 | Handle(MeshTest_DrawableMesh)::DownCast(Draw::Get(argv[1])); |
| 807 | if (D.IsNull()) return 1; |
| 808 | |
| 809 | Handle(BRepMesh_DataStructureOfDelaun) struc = D->Mesh()->Result(); |
| 810 | |
| 811 | Standard_Integer in=1; |
| 812 | if (argc>=3) { |
| 813 | in=Draw::Atoi(argv[2]); |
| 814 | in=Max(1,in); |
| 815 | } |
| 816 | Standard_Integer nbn=in; |
| 817 | if (argc>=4) { |
| 818 | nbn=Draw::Atoi(argv[3]); |
| 819 | nbn=Min(nbn,struc->NbNodes()); |
| 820 | } |
| 821 | |
| 822 | for (; in<=nbn; in++) { |
| 823 | BRepMesh_Vertex nod=struc->GetNode(in); |
| 824 | di<<"(node "<<in<<" (uv "<<nod.Coord().X() |
| 825 | <<" "<<nod.Coord().Y()<<") (3d " |
| 826 | <<nod.Location3d()<<") "; |
| 827 | printdegree(nod.Movability(), di); |
| 828 | di<<" (edgeconex"; |
| 829 | BRepMesh_ListOfInteger::Iterator tati(struc->LinkNeighboursOf(in)); |
| 830 | for (; tati.More(); tati.Next()) di<<" "<<tati.Value(); |
| 831 | di << "))\n"; |
| 832 | } |
| 833 | di <<"\n"; |
| 834 | return 0; |
| 835 | } |
| 836 | |
| 837 | //======================================================================= |
| 838 | //function : dumpedge |
| 839 | //purpose : |
| 840 | //======================================================================= |
| 841 | |
| 842 | Standard_Integer dumpedge(Draw_Interpretor& di, Standard_Integer argc, const char** argv) |
| 843 | { |
| 844 | if (argc < 2) return 1; |
| 845 | |
| 846 | Handle(MeshTest_DrawableMesh) D = |
| 847 | Handle(MeshTest_DrawableMesh)::DownCast(Draw::Get(argv[1])); |
| 848 | if (D.IsNull()) return 1; |
| 849 | |
| 850 | Handle(BRepMesh_DataStructureOfDelaun) struc=D->Mesh()->Result(); |
| 851 | Standard_Integer il=1; |
| 852 | if (argc>=3) { |
| 853 | il=Draw::Atoi(argv[2]); |
| 854 | il=Max(1, il); |
| 855 | } |
| 856 | Standard_Integer nbl=il; |
| 857 | if (argc>=4) { |
| 858 | nbl=Draw::Atoi(argv[3]); |
| 859 | nbl=Min(nbl, struc->NbLinks()); |
| 860 | } |
| 861 | |
| 862 | for (; il<=nbl; il++) { |
| 863 | BRepMesh_Edge edg=struc->GetLink(il); |
| 864 | di << "(edge "<<il<<" ("<<edg.FirstNode()<<" "<<edg.LastNode() |
| 865 | <<" "; |
| 866 | printdegree(edg.Movability(), di); |
| 867 | di<<") (triconex"; |
| 868 | const BRepMesh_PairOfIndex& pair = struc->ElemConnectedTo(il); |
| 869 | for (Standard_Integer j = 1, jn = pair.Extent(); j <= jn; j++) |
| 870 | di<<" "<<pair.Index(j); |
| 871 | di << "))\n"; |
| 872 | } |
| 873 | di <<"\n"; |
| 874 | return 0; |
| 875 | } |
| 876 | |
| 877 | //======================================================================= |
| 878 | //function : dumptriangle |
| 879 | //purpose : |
| 880 | //======================================================================= |
| 881 | |
| 882 | Standard_Integer dumptriangle(Draw_Interpretor& di, Standard_Integer argc, const char** argv) |
| 883 | { |
| 884 | if (argc < 2) return 1; |
| 885 | |
| 886 | Handle(MeshTest_DrawableMesh) D = |
| 887 | Handle(MeshTest_DrawableMesh)::DownCast(Draw::Get(argv[1])); |
| 888 | if (D.IsNull()) return 1; |
| 889 | |
| 890 | Handle(BRepMesh_DataStructureOfDelaun) struc=D->Mesh()->Result(); |
| 891 | Standard_Integer ie=1; |
| 892 | if (argc>=3) { |
| 893 | ie=Draw::Atoi(argv[2]); |
| 894 | ie=Max(1, ie); |
| 895 | } |
| 896 | Standard_Integer nbe=ie; |
| 897 | if (argc>=4) { |
| 898 | nbe=Draw::Atoi(argv[3]); |
| 899 | nbe=Min(nbe, struc->NbElements()); |
| 900 | } |
| 901 | |
| 902 | Standard_Integer e1, e2, e3; |
| 903 | Standard_Boolean o1, o2, o3; |
| 904 | |
| 905 | for (; ie<=nbe; ie++) { |
| 906 | BRepMesh_Triangle tri=struc->GetElement(ie); |
| 907 | tri.Edges(e1, e2, e3, o1, o2, o3); |
| 908 | if (o1) e1=-e1; |
| 909 | if (o2) e2=-e2; |
| 910 | if (o3) e3=-e3; |
| 911 | di<<" (maille "<<ie<<" (links "<<e1<<" " |
| 912 | <<e2<<" "<<e3<<")"; |
| 913 | printdegree(tri.Movability(), di); |
| 914 | di<<")\n"; |
| 915 | } |
| 916 | di << "\n"; |
| 917 | return 0; |
| 918 | } |
| 919 | */ |
| 920 | |
| 921 | //======================================================================= |
| 922 | //function : trianglesinfo |
| 923 | //purpose : |
| 924 | //======================================================================= |
| 925 | static Standard_Integer trianglesinfo(Draw_Interpretor& di, Standard_Integer n, const char** a) |
| 926 | { |
| 927 | if (n != 2) return 1; |
| 928 | TopoDS_Shape S = DBRep::Get(a[1]); |
| 929 | if (S.IsNull()) return 1; |
| 930 | TopExp_Explorer ex; |
| 931 | Handle(Poly_Triangulation) T; |
| 932 | TopLoc_Location L; |
| 933 | |
| 934 | Standard_Real MaxDeflection = 0.0; |
| 935 | Standard_Integer nbtriangles = 0, nbnodes = 0; |
| 936 | for (ex.Init(S, TopAbs_FACE); ex.More(); ex.Next()) { |
| 937 | TopoDS_Face F = TopoDS::Face(ex.Current()); |
| 938 | T = BRep_Tool::Triangulation(F, L); |
| 939 | if (!T.IsNull()) { |
| 940 | nbtriangles += T->NbTriangles(); |
| 941 | nbnodes += T->NbNodes(); |
| 942 | if (T->Deflection() > MaxDeflection) |
| 943 | MaxDeflection = T->Deflection(); |
| 944 | } |
| 945 | } |
| 946 | |
| 947 | di<<"\n"; |
| 948 | di<<"This shape contains " <<nbtriangles<<" triangles."<<"\n"; |
| 949 | di<<" " <<nbnodes <<" nodes."<<"\n"; |
| 950 | di<<"Maximal deflection " <<MaxDeflection<<"\n"; |
| 951 | di<<"\n"; |
| 952 | #ifdef DEB_MESH_CHRONO |
| 953 | Standard_Real tot, addp, unif, contr, inter; |
| 954 | Standard_Real edges, mailledges, etuinter, lastcontrol, stock; |
| 955 | Standard_Real add11, add12, add2, upda, pointvalid; |
| 956 | Standard_Real isos, pointsisos; |
| 957 | chTotal.Show(tot); chAddPoint.Show(addp); chUnif.Show(unif); |
| 958 | chControl.Show(contr); chInternal.Show(inter); |
| 959 | chEdges.Show(edges); chMaillEdges.Show(mailledges); |
| 960 | chEtuInter.Show(etuinter); chLastControl.Show(lastcontrol); |
| 961 | chStock.Show(stock); |
| 962 | chAdd11.Show(add11); chAdd12.Show(add12); chAdd2.Show(add2); chUpdate.Show(upda); |
| 963 | chPointValid.Show(pointvalid); chIsos.Show(isos); chPointsOnIsos.Show(pointsisos); |
| 964 | |
| 965 | if (tot > 0.00001) { |
| 966 | di <<"temps total de maillage: "<<tot <<" seconds"<< "\n"; |
| 967 | di <<"dont: "<< "\n"; |
| 968 | di <<"discretisation des edges: "<<edges <<" seconds---> "<< 100*edges/tot <<" %"<<"\n"; |
| 969 | di <<"maillage des edges: "<<mailledges <<" seconds---> "<< 100*mailledges/tot <<" %"<<"\n"; |
| 970 | di <<"controle et points internes: "<<etuinter <<" seconds---> "<< 100*etuinter/tot <<" %"<<"\n"; |
| 971 | di <<"derniers controles: "<<lastcontrol<<" seconds---> "<< 100*lastcontrol/tot<<" %"<<"\n"; |
| 972 | di <<"stockage dans la S.D. "<<stock <<" seconds---> "<< 100*stock/tot <<" %"<<"\n"; |
| 973 | di << "\n"; |
| 974 | di <<"et plus precisement: "<<"\n"; |
| 975 | di <<"Add 11ere partie : "<<add11 <<" seconds---> "<<100*add11/tot <<" %"<<"\n"; |
| 976 | di <<"Add 12ere partie : "<<add12 <<" seconds---> "<<100*add12/tot <<" %"<<"\n"; |
| 977 | di <<"Add 2eme partie : "<<add2 <<" seconds---> "<<100*add2/tot <<" %"<<"\n"; |
| 978 | di <<"Update : "<<upda <<" seconds---> "<<100*upda/tot <<" %"<<"\n"; |
| 979 | di <<"AddPoint : "<<addp <<" seconds---> "<<100*addp/tot <<" %"<<"\n"; |
| 980 | di <<"UniformDeflection "<<unif <<" seconds---> "<<100*unif/tot <<" %"<<"\n"; |
| 981 | di <<"Controle : "<<contr <<" seconds---> "<<100*contr/tot <<" %"<<"\n"; |
| 982 | di <<"Points Internes: "<<inter <<" seconds---> "<<100*inter/tot <<" %"<<"\n"; |
| 983 | di <<"calcul des isos et du, dv: "<<isos <<" seconds---> "<<100*isos/tot <<" %"<<"\n"; |
| 984 | di <<"calcul des points sur isos: "<<pointsisos<<" seconds---> "<<100*pointsisos/tot <<" %"<<"\n"; |
| 985 | di <<"IsPointValid: "<<pointvalid<<" seconds---> "<<100*pointvalid/tot <<" %"<<"\n"; |
| 986 | di << "\n"; |
| 987 | |
| 988 | |
| 989 | di <<"nombre d'appels de controle apres points internes : "<< NbControls << "\n"; |
| 990 | di <<"nombre de points sur restrictions : "<< D0Edges << "\n"; |
| 991 | di <<"nombre de points calcules par UniformDeflection : "<< D0Unif << "\n"; |
| 992 | di <<"nombre de points calcules dans InternalVertices : "<< D0Internal << "\n"; |
| 993 | di <<"nombre de points calcules dans Control : "<< D0Control << "\n"; |
| 994 | if (nbnodes-D0Edges != 0) { |
| 995 | Standard_Real ratio = (Standard_Real)(D0Internal+D0Control)/ (Standard_Real)(nbnodes-D0Edges); |
| 996 | di <<"---> Ratio: (D0Internal+D0Control) / (nbNodes-nbOnEdges) : "<< ratio << "\n"; |
| 997 | } |
| 998 | |
| 999 | di << "\n"; |
| 1000 | |
| 1001 | chTotal.Reset(); chAddPoint.Reset(); chUnif.Reset(); |
| 1002 | chControl.Reset(); chInternal.Reset(); |
| 1003 | chEdges.Reset(); chMaillEdges.Reset(); |
| 1004 | chEtuInter.Reset(); chLastControl.Reset(); |
| 1005 | chStock.Reset(); |
| 1006 | chAdd11.Reset(); chAdd12.Reset(); chAdd2.Reset(); chUpdate.Reset(); |
| 1007 | chPointValid.Reset(); chIsos.Reset(); chPointsOnIsos.Reset(); |
| 1008 | |
| 1009 | } |
| 1010 | #endif |
| 1011 | return 0; |
| 1012 | } |
| 1013 | |
| 1014 | //======================================================================= |
| 1015 | //function : veriftriangles |
| 1016 | //purpose : |
| 1017 | //======================================================================= |
| 1018 | |
| 1019 | static Standard_Integer veriftriangles(Draw_Interpretor& di, Standard_Integer n, const char** a) |
| 1020 | { |
| 1021 | if (n < 2) return 1; |
| 1022 | Standard_Boolean quiet = 1; |
| 1023 | if (n == 3) quiet = 0; |
| 1024 | TopoDS_Shape Sh = DBRep::Get(a[1]); |
| 1025 | if (Sh.IsNull()) return 1; |
| 1026 | TopExp_Explorer ex; |
| 1027 | Handle(Poly_Triangulation) T; |
| 1028 | TopLoc_Location L; |
| 1029 | Standard_Integer i, n1, n2, n3; |
| 1030 | gp_Pnt2d mitri, v1, v2, v3, mi2d1, mi2d2, mi2d3; |
| 1031 | gp_XYZ vecEd1, vecEd2, vecEd3; |
| 1032 | // Standard_Real dipo, dm, dv, d1, d2, d3, defle; |
| 1033 | Standard_Real dipo, dv, d1, d2, d3, defle; |
| 1034 | Handle(Geom_Surface) S; |
| 1035 | Standard_Integer nbface = 0; |
| 1036 | gp_Pnt PP; |
| 1037 | |
| 1038 | for (ex.Init(Sh, TopAbs_FACE); ex.More(); ex.Next()) { |
| 1039 | TopoDS_Face F = TopoDS::Face(ex.Current()); |
| 1040 | nbface++; |
| 1041 | T = BRep_Tool::Triangulation(F, L); |
| 1042 | Standard_Real deflemax = 0, deflemin = 1.e100; |
| 1043 | if (!T.IsNull()) { |
| 1044 | Standard_Real defstock = T->Deflection(); |
| 1045 | const Poly_Array1OfTriangle& triangles = T->Triangles(); |
| 1046 | const TColgp_Array1OfPnt2d& Nodes2d = T->UVNodes(); |
| 1047 | const TColgp_Array1OfPnt& Nodes = T->Nodes(); |
| 1048 | |
| 1049 | S = BRep_Tool::Surface(F, L); |
| 1050 | |
| 1051 | for(i = 1; i <= triangles.Length(); i++) { |
| 1052 | if (F.Orientation() == TopAbs_REVERSED) |
| 1053 | triangles(i).Get(n1,n3,n2); |
| 1054 | else |
| 1055 | triangles(i).Get(n1,n2,n3); |
| 1056 | |
| 1057 | const gp_XY& xy1 = Nodes2d(n1).XY(); |
| 1058 | const gp_XY& xy2 = Nodes2d(n2).XY(); |
| 1059 | const gp_XY& xy3 = Nodes2d(n3).XY(); |
| 1060 | |
| 1061 | mi2d1.SetCoord((xy2.X()+xy3.X())*0.5, |
| 1062 | (xy2.Y()+xy3.Y())*0.5); |
| 1063 | mi2d2.SetCoord((xy1.X()+xy3.X())*0.5, |
| 1064 | (xy1.Y()+xy3.Y())*0.5); |
| 1065 | mi2d3.SetCoord((xy1.X()+xy2.X())*0.5, |
| 1066 | (xy1.Y()+xy2.Y())*0.5); |
| 1067 | |
| 1068 | gp_XYZ p1 = Nodes(n1).Transformed(L.Transformation()).XYZ(); |
| 1069 | gp_XYZ p2 = Nodes(n2).Transformed(L.Transformation()).XYZ(); |
| 1070 | gp_XYZ p3 = Nodes(n3).Transformed(L.Transformation()).XYZ(); |
| 1071 | |
| 1072 | vecEd1=p2-p1; |
| 1073 | vecEd2=p3-p2; |
| 1074 | vecEd3=p1-p3; |
| 1075 | d1=vecEd1.SquareModulus(); |
| 1076 | d2=vecEd2.SquareModulus(); |
| 1077 | d3=vecEd3.SquareModulus(); |
| 1078 | |
| 1079 | if (d1!=0. && d2!=0. && d3!=0.) { |
| 1080 | gp_XYZ equa(vecEd1^vecEd2); |
| 1081 | dv=equa.Modulus(); |
| 1082 | if (dv>0.) { |
| 1083 | equa.SetCoord(equa.X()/dv, equa.Y()/dv, equa.Z()/dv); |
| 1084 | dipo=equa*p1; |
| 1085 | |
| 1086 | |
| 1087 | mitri.SetCoord(ONETHIRD*(xy1.X()+xy2.X()+xy3.X()), |
| 1088 | ONETHIRD*(xy1.Y()+xy2.Y()+xy3.Y())); |
| 1089 | v1.SetCoord(ONETHIRD*mi2d1.X()+TWOTHIRD*xy1.X(), |
| 1090 | ONETHIRD*mi2d1.Y()+TWOTHIRD*xy1.Y()); |
| 1091 | v2.SetCoord(ONETHIRD*mi2d2.X()+TWOTHIRD*xy2.X(), |
| 1092 | ONETHIRD*mi2d2.Y()+TWOTHIRD*xy2.Y()); |
| 1093 | v3.SetCoord(ONETHIRD*mi2d3.X()+TWOTHIRD*xy3.X(), |
| 1094 | ONETHIRD*mi2d3.Y()+TWOTHIRD*xy3.Y()); |
| 1095 | |
| 1096 | S->D0(mi2d1.X(), mi2d1.Y(), PP); |
| 1097 | PP = PP.Transformed(L.Transformation()); |
| 1098 | defle = Abs((equa*PP.XYZ())-dipo); |
| 1099 | deflemax = Max(deflemax, defle); |
| 1100 | deflemin = Min(deflemin, defle); |
| 1101 | |
| 1102 | S->D0(mi2d2.X(), mi2d2.Y(), PP); |
| 1103 | PP = PP.Transformed(L.Transformation()); |
| 1104 | defle = Abs((equa*PP.XYZ())-dipo); |
| 1105 | deflemax = Max(deflemax, defle); |
| 1106 | deflemin = Min(deflemin, defle); |
| 1107 | |
| 1108 | S->D0(mi2d3.X(), mi2d3.Y(), PP); |
| 1109 | PP = PP.Transformed(L.Transformation()); |
| 1110 | defle = Abs((equa*PP.XYZ())-dipo); |
| 1111 | deflemax = Max(deflemax, defle); |
| 1112 | deflemin = Min(deflemin, defle); |
| 1113 | |
| 1114 | S->D0(v1.X(), v1.Y(), PP); |
| 1115 | PP = PP.Transformed(L.Transformation()); |
| 1116 | defle = Abs((equa*PP.XYZ())-dipo); |
| 1117 | deflemax = Max(deflemax, defle); |
| 1118 | deflemin = Min(deflemin, defle); |
| 1119 | |
| 1120 | S->D0(v2.X(), v2.Y(), PP); |
| 1121 | PP = PP.Transformed(L.Transformation()); |
| 1122 | defle = Abs((equa*PP.XYZ())-dipo); |
| 1123 | deflemax = Max(deflemax, defle); |
| 1124 | deflemin = Min(deflemin, defle); |
| 1125 | |
| 1126 | S->D0(v3.X(), v3.Y(), PP); |
| 1127 | PP = PP.Transformed(L.Transformation()); |
| 1128 | defle = Abs((equa*PP.XYZ())-dipo); |
| 1129 | deflemax = Max(deflemax, defle); |
| 1130 | deflemin = Min(deflemin, defle); |
| 1131 | |
| 1132 | S->D0(mitri.X(), mitri.Y(), PP); |
| 1133 | PP = PP.Transformed(L.Transformation()); |
| 1134 | defle = Abs((equa*PP.XYZ())-dipo); |
| 1135 | deflemax = Max(deflemax, defle); |
| 1136 | deflemin = Min(deflemin, defle); |
| 1137 | |
| 1138 | if (defle > defstock) { |
| 1139 | di <<"face "<< nbface <<" deflection = " << defle <<" pour "<<defstock <<" stockee."<<"\n"; |
| 1140 | } |
| 1141 | } |
| 1142 | } |
| 1143 | } |
| 1144 | if (!quiet) { |
| 1145 | di <<"face "<< nbface<<", deflemin = "<< deflemin<<", deflemax = "<<deflemax<<"\n"; |
| 1146 | } |
| 1147 | |
| 1148 | } |
| 1149 | } |
| 1150 | |
| 1151 | |
| 1152 | return 0; |
| 1153 | } |
| 1154 | |
| 1155 | |
| 1156 | |
| 1157 | |
| 1158 | //======================================================================= |
| 1159 | //function : tri2d |
| 1160 | //purpose : |
| 1161 | //======================================================================= |
| 1162 | |
| 1163 | Standard_Integer tri2d(Draw_Interpretor&, Standard_Integer n, const char** a) |
| 1164 | { |
| 1165 | |
| 1166 | if (n != 2) return 1; |
| 1167 | TopoDS_Shape aLocalShape = DBRep::Get(a[1]); |
| 1168 | TopoDS_Face F = TopoDS::Face(aLocalShape); |
| 1169 | // TopoDS_Face F = TopoDS::Face(DBRep::Get(a[1])); |
| 1170 | if (F.IsNull()) return 1; |
| 1171 | Handle(Poly_Triangulation) T; |
| 1172 | TopLoc_Location L; |
| 1173 | |
| 1174 | T = BRep_Tool::Triangulation(F, L); |
| 1175 | if (!T.IsNull()) { |
| 1176 | #ifdef DEB |
| 1177 | gp_Trsf tr = L.Transformation(); |
| 1178 | #else |
| 1179 | L.Transformation(); |
| 1180 | #endif |
| 1181 | |
| 1182 | // Build the connect tool |
| 1183 | Poly_Connect pc(T); |
| 1184 | |
| 1185 | Standard_Integer i,j, nFree, nInternal, nbTriangles = T->NbTriangles(); |
| 1186 | Standard_Integer t[3]; |
| 1187 | |
| 1188 | // count the free edges |
| 1189 | nFree = 0; |
| 1190 | for (i = 1; i <= nbTriangles; i++) { |
| 1191 | pc.Triangles(i,t[0],t[1],t[2]); |
| 1192 | for (j = 0; j < 3; j++) |
| 1193 | if (t[j] == 0) nFree++; |
| 1194 | } |
| 1195 | |
| 1196 | // allocate the arrays |
| 1197 | TColStd_Array1OfInteger Free(1,2*nFree); |
| 1198 | nInternal = (3*nbTriangles - nFree) / 2; |
| 1199 | TColStd_Array1OfInteger Internal(0,2*nInternal); |
| 1200 | |
| 1201 | Standard_Integer fr = 1, in = 1; |
| 1202 | const Poly_Array1OfTriangle& triangles = T->Triangles(); |
| 1203 | Standard_Integer nodes[3]; |
| 1204 | for (i = 1; i <= nbTriangles; i++) { |
| 1205 | pc.Triangles(i,t[0],t[1],t[2]); |
| 1206 | triangles(i).Get(nodes[0],nodes[1],nodes[2]); |
| 1207 | for (j = 0; j < 3; j++) { |
| 1208 | Standard_Integer k = (j+1) % 3; |
| 1209 | if (t[j] == 0) { |
| 1210 | Free(fr) = nodes[j]; |
| 1211 | Free(fr+1) = nodes[k]; |
| 1212 | fr += 2; |
| 1213 | } |
| 1214 | // internal edge if this triangle has a lower index than the adjacent |
| 1215 | else if (i < t[j]) { |
| 1216 | Internal(in) = nodes[j]; |
| 1217 | Internal(in+1) = nodes[k]; |
| 1218 | in += 2; |
| 1219 | } |
| 1220 | } |
| 1221 | } |
| 1222 | |
| 1223 | // Display the edges |
| 1224 | if (T->HasUVNodes()) { |
| 1225 | const TColgp_Array1OfPnt2d& Nodes2d = T->UVNodes(); |
| 1226 | |
| 1227 | Handle(Draw_Segment2D) Seg; |
| 1228 | |
| 1229 | // free edges |
| 1230 | Standard_Integer nn; |
| 1231 | nn = Free.Length() / 2; |
| 1232 | for (i = 1; i <= nn; i++) { |
| 1233 | Seg = new Draw_Segment2D(Nodes2d(Free(2*i-1)), |
| 1234 | Nodes2d(Free(2*i)), |
| 1235 | Draw_rouge); |
| 1236 | dout << Seg; |
| 1237 | } |
| 1238 | |
| 1239 | // internal edges |
| 1240 | |
| 1241 | nn = nInternal; |
| 1242 | for (i = 1; i <= nn; i++) { |
| 1243 | Seg = new Draw_Segment2D(Nodes2d(Internal(2*i-1)), |
| 1244 | Nodes2d(Internal(2*i)), |
| 1245 | Draw_bleu); |
| 1246 | dout << Seg; |
| 1247 | } |
| 1248 | } |
| 1249 | dout.Flush(); |
| 1250 | } |
| 1251 | |
| 1252 | return 0; |
| 1253 | } |
| 1254 | |
| 1255 | |
| 1256 | |
| 1257 | |
| 1258 | //======================================================================= |
| 1259 | //function : wavefront |
| 1260 | //purpose : |
| 1261 | //======================================================================= |
| 1262 | |
| 1263 | static Standard_Integer wavefront(Draw_Interpretor&, Standard_Integer nbarg, const char** argv) |
| 1264 | { |
| 1265 | if (nbarg < 2) return 1; |
| 1266 | |
| 1267 | TopoDS_Shape S = DBRep::Get(argv[1]); |
| 1268 | if (S.IsNull()) return 1; |
| 1269 | |
| 1270 | // creation du maillage s'il n'existe pas. |
| 1271 | |
| 1272 | Bnd_Box B; |
| 1273 | Standard_Real aXmin, aYmin, aZmin, aXmax, aYmax, aZmax; |
| 1274 | BRepBndLib::Add(S, B); |
| 1275 | B.Get(aXmin, aYmin, aZmin, aXmax, aYmax, aZmax); |
| 1276 | Standard_Real aDeflection = |
| 1277 | MAX3( aXmax-aXmin , aYmax-aYmin , aZmax-aZmin) * 0.004; |
| 1278 | |
| 1279 | BRepMesh_IncrementalMesh(S, aDeflection); |
| 1280 | |
| 1281 | |
| 1282 | TopLoc_Location L; |
| 1283 | TopExp_Explorer ex; |
| 1284 | |
| 1285 | Standard_Integer i, nbface = 0; |
| 1286 | Standard_Boolean OK = Standard_True; |
| 1287 | gp_Vec D1U,D1V; |
| 1288 | gp_Vec D2U,D2V,D2UV; |
| 1289 | gp_Dir Nor; |
| 1290 | gp_Pnt P; |
| 1291 | Standard_Real U, V; |
| 1292 | CSLib_DerivativeStatus Status; |
| 1293 | CSLib_NormalStatus NStat; |
| 1294 | Standard_Real x, y, z; |
| 1295 | Standard_Integer n1, n2, n3; |
| 1296 | Standard_Integer k1, k2, k3; |
| 1297 | |
| 1298 | char ffile[100]; |
| 1299 | |
| 1300 | if (nbarg == 3) { |
| 1301 | strcpy(ffile, argv[2]); |
| 1302 | strcat(ffile, ".obj"); |
| 1303 | } |
| 1304 | else strcpy(ffile, "wave.obj"); |
| 1305 | FILE* outfile = fopen(ffile, "w"); |
| 1306 | |
| 1307 | |
| 1308 | fprintf(outfile, "%s %s\n%s %s\n\n", "# CASCADE ","MATRA DATAVISION", "#", ffile); |
| 1309 | |
| 1310 | Standard_Integer nbNodes, totalnodes = 0, nbpolygons = 0; |
| 1311 | for (ex.Init(S, TopAbs_FACE); ex.More(); ex.Next()) { |
| 1312 | nbface++; |
| 1313 | TopoDS_Face F = TopoDS::Face(ex.Current()); |
| 1314 | Handle(Poly_Triangulation) Tr = BRep_Tool::Triangulation(F, L); |
| 1315 | |
| 1316 | if (!Tr.IsNull()) { |
| 1317 | nbNodes = Tr->NbNodes(); |
| 1318 | const TColgp_Array1OfPnt& Nodes = Tr->Nodes(); |
| 1319 | |
| 1320 | // les noeuds. |
| 1321 | for (i = 1; i <= nbNodes; i++) { |
| 1322 | gp_Pnt Pnt = Nodes(i).Transformed(L.Transformation()); |
| 1323 | x = Pnt.X(); |
| 1324 | y = Pnt.Y(); |
| 1325 | z = Pnt.Z(); |
| 1326 | fprintf(outfile, "%s %f %f %f\n", "v", x, y, z); |
| 1327 | } |
| 1328 | |
| 1329 | fprintf(outfile, "\n%s %d\n\n", "# number of vertex", nbNodes); |
| 1330 | |
| 1331 | |
| 1332 | // les normales. |
| 1333 | |
| 1334 | if (Tr->HasUVNodes()) { |
| 1335 | const TColgp_Array1OfPnt2d& UVNodes = Tr->UVNodes(); |
| 1336 | BRepAdaptor_Surface BS(F, Standard_False); |
| 1337 | |
| 1338 | for (i = 1; i <= nbNodes; i++) { |
| 1339 | U = UVNodes(i).X(); |
| 1340 | V = UVNodes(i).Y(); |
| 1341 | |
| 1342 | BS.D1(U,V,P,D1U,D1V); |
| 1343 | CSLib::Normal(D1U,D1V,Precision::Angular(),Status,Nor); |
| 1344 | if (Status != CSLib_Done) { |
| 1345 | BS.D2(U,V,P,D1U,D1V,D2U,D2V,D2UV); |
| 1346 | CSLib::Normal(D1U,D1V,D2U,D2V,D2UV,Precision::Angular(),OK,NStat,Nor); |
| 1347 | } |
| 1348 | if (F.Orientation() == TopAbs_REVERSED) Nor.Reverse(); |
| 1349 | |
| 1350 | fprintf(outfile, "%s %f %f %f\n", "vn", Nor.X(), Nor.Y(), Nor.Z()); |
| 1351 | } |
| 1352 | |
| 1353 | fprintf(outfile, "\n%s %d\n\n", "# number of vertex normals", nbNodes); |
| 1354 | } |
| 1355 | |
| 1356 | fprintf(outfile, "%s %d\n", "s", nbface); |
| 1357 | |
| 1358 | // les triangles. |
| 1359 | Standard_Integer nbTriangles = Tr->NbTriangles(); |
| 1360 | const Poly_Array1OfTriangle& triangles = Tr->Triangles(); |
| 1361 | |
| 1362 | |
| 1363 | for (i = 1; i <= nbTriangles; i++) { |
| 1364 | if (F.Orientation() == TopAbs_REVERSED) |
| 1365 | triangles(i).Get(n1, n3, n2); |
| 1366 | else |
| 1367 | triangles(i).Get(n1, n2, n3); |
| 1368 | k1 = n1+totalnodes; |
| 1369 | k2 = n2+totalnodes; |
| 1370 | k3 = n3+totalnodes; |
| 1371 | fprintf(outfile, "%s %d%s%d %d%s%d %d%s%d\n", "fo", k1,"//", k1, k2,"//", k2, k3,"//", k3); |
| 1372 | } |
| 1373 | nbpolygons += nbTriangles; |
| 1374 | totalnodes += nbNodes; |
| 1375 | |
| 1376 | fprintf(outfile, "\n%s %d\n", "# number of smooth groups", nbface); |
| 1377 | fprintf(outfile, "\n%s %d\n", "# number of polygons", nbpolygons); |
| 1378 | |
| 1379 | } |
| 1380 | } |
| 1381 | |
| 1382 | fclose(outfile); |
| 1383 | |
| 1384 | return 0; |
| 1385 | } |
| 1386 | |
| 1387 | |
| 1388 | //======================================================================= |
| 1389 | //function : onetriangulation |
| 1390 | //purpose : |
| 1391 | //======================================================================= |
| 1392 | |
| 1393 | Standard_Integer onetriangulation(Draw_Interpretor&, Standard_Integer nbarg, const char** argv) |
| 1394 | { |
| 1395 | |
| 1396 | /* |
| 1397 | |
| 1398 | if (nbarg < 2) return 1; |
| 1399 | |
| 1400 | TopoDS_Shape S = DBRep::Get(argv[1]); |
| 1401 | if (S.IsNull()) return 1; |
| 1402 | |
| 1403 | Handle(Poly_Triangulation) TFinale; |
| 1404 | char name[100]; |
| 1405 | Standard_Integer nbshell = 0; |
| 1406 | |
| 1407 | TopExp_Explorer ex, exs, ex2; |
| 1408 | |
| 1409 | for (ex.Init(S, TopAbs_SHELL); ex.More(); ex.Next()) { |
| 1410 | nbshell++; |
| 1411 | TopoDS_Shell Sh = TopoDS::Shell(ex.Current()); |
| 1412 | |
| 1413 | for (exs.Init(Sh, TopAbs_Face); exs.More(); exs.Next()) { |
| 1414 | TopoDS_Face F = TopoDS::Face(exs.Current()); |
| 1415 | Handle(Poly_Triangulation) T = BRep_Tool::Triangulation(F, L); |
| 1416 | |
| 1417 | for (ex2.Init(F, TopAbs_EDGE); ex2.More(); ex2.Next()) { |
| 1418 | TopoDS_Edge edge = TopoDS::Edge(ex2.Current()); |
| 1419 | const TColgp_Array1OfPnt& Nodes = T->Nodes(); |
| 1420 | const Poly_Array1OfTriangle& triangles = T->Triangles(); |
| 1421 | |
| 1422 | if (mapedges.IsBound(edge)) { |
| 1423 | const TColStd_ListOfTransient& L = edges.Find(edge); |
| 1424 | const Handle(Poly_PolygonOnTriangulation)& P = |
| 1425 | *(Handle(Poly_PolygonOnTriangulation)*)&(L.First()); |
| 1426 | const TColStd_Array1OfInteger& NOD = P->Nodes(); |
| 1427 | |
| 1428 | } |
| 1429 | } |
| 1430 | } |
| 1431 | |
| 1432 | Sprintf(name, "%s_%i", "tr", nbshell); |
| 1433 | DrawTrSurf::Set(name, TFinale); |
| 1434 | |
| 1435 | } |
| 1436 | |
| 1437 | */ |
| 1438 | return 0; |
| 1439 | } |
| 1440 | |
| 1441 | |
| 1442 | #if 0 |
| 1443 | |
| 1444 | //======================================================================= |
| 1445 | //function : vb |
| 1446 | //purpose : |
| 1447 | //======================================================================= |
| 1448 | |
| 1449 | Standard_Integer vb(Draw_Interpretor& di, Standard_Integer nbarg, const char** argv) |
| 1450 | { |
| 1451 | Standard_Integer NbPoints = 1, Deg = 1; |
| 1452 | |
| 1453 | for (Deg = 1; Deg <= 25; Deg++) { |
| 1454 | for (NbPoints = 1; NbPoints <= 24; NbPoints++) { |
| 1455 | |
| 1456 | math_Vector GaussP(1, NbPoints), GaussW(1, NbPoints); |
| 1457 | math_Vector TheWeights(1, NbPoints), VBParam(1, NbPoints); |
| 1458 | math_Matrix VB(1, Deg+1, 1, NbPoints); |
| 1459 | |
| 1460 | math::GaussPoints(NbPoints, GaussP); |
| 1461 | |
| 1462 | Standard_Integer i, j, classe = Deg+1, cl1 = Deg; |
| 1463 | |
| 1464 | // calcul et mise en ordre des parametres et des poids: |
| 1465 | for (i = 1; i <= NbPoints; i++) { |
| 1466 | if (i <= (NbPoints+1)/2) { |
| 1467 | VBParam(NbPoints-i+1) = 0.5*(1 + GaussP(i)); |
| 1468 | } |
| 1469 | else { |
| 1470 | VBParam(i-(NbPoints+1)/2) = 0.5*(1 + GaussP(i)); |
| 1471 | } |
| 1472 | } |
| 1473 | |
| 1474 | |
| 1475 | // Calcul du VB (Valeur des fonctions de Bernstein): |
| 1476 | for (i = 1; i <= classe; i++) { |
| 1477 | for (j = 1; j <= NbPoints; j++) { |
| 1478 | VB(i,j)=PLib::Binomial(cl1,i-1)*Pow((1-VBParam(j)),classe-i)*Pow(VBParam(j),i-1); |
| 1479 | } |
| 1480 | } |
| 1481 | |
| 1482 | |
| 1483 | for (i = 1; i <= classe; i++) { |
| 1484 | for (j = 1; j <= NbPoints; j++) { |
| 1485 | di<< VB(i, j) << ", "; |
| 1486 | } |
| 1487 | } |
| 1488 | di << "\n" << "\n"; |
| 1489 | } |
| 1490 | } |
| 1491 | return 0; |
| 1492 | } |
| 1493 | //======================================================================= |
| 1494 | //function : extrema |
| 1495 | //purpose : |
| 1496 | //======================================================================= |
| 1497 | |
| 1498 | Standard_Integer extrema(Draw_Interpretor& di, Standard_Integer nbarg, const char** argv) |
| 1499 | { |
| 1500 | |
| 1501 | |
| 1502 | Handle(Geom_Curve) C = DrawTrSurf::GetCurve(argv[1]); |
| 1503 | |
| 1504 | Standard_Real X, Y, Z, U0; |
| 1505 | X = Draw::Atof(argv[2]); |
| 1506 | Y = Draw::Atof(argv[3]); |
| 1507 | Z = Draw::Atof(argv[4]); |
| 1508 | U0 = Draw::Atof(argv[5]); |
| 1509 | |
| 1510 | gp_Pnt P(X, Y, Z); |
| 1511 | GeomAdaptor_Curve GC(C); |
| 1512 | Standard_Real tol = 1.e-09; |
| 1513 | Extrema_LocateExtPC ext(P, GC, U0, tol); |
| 1514 | |
| 1515 | if (ext.IsDone()) { |
| 1516 | gp_Pnt P1 = ext.Point().Value(); |
| 1517 | di <<"distance = "<<ext.Value() << "\n"; |
| 1518 | di <<"point = "<<P1.X()<<" "<<P1.Y()<<" "<< P1.Z()<< "\n"; |
| 1519 | di <<"parametre = "<<ext.Point().Parameter()<<"\n"; |
| 1520 | } |
| 1521 | |
| 1522 | return 0; |
| 1523 | } |
| 1524 | |
| 1525 | #endif |
| 1526 | |
| 1527 | |
| 1528 | //======================================================================= |
| 1529 | //function : triedgepoints |
| 1530 | //purpose : |
| 1531 | //======================================================================= |
| 1532 | |
| 1533 | Standard_Integer triedgepoints(Draw_Interpretor& di, Standard_Integer nbarg, const char** argv) |
| 1534 | { |
| 1535 | if( nbarg < 2 ) |
| 1536 | return 1; |
| 1537 | |
| 1538 | for( Standard_Integer i = 1; i < nbarg; i++ ) |
| 1539 | { |
| 1540 | TopoDS_Shape aShape = DBRep::Get(argv[i]); |
| 1541 | if ( aShape.IsNull() ) |
| 1542 | continue; |
| 1543 | |
| 1544 | Handle(Poly_PolygonOnTriangulation) aPoly; |
| 1545 | Handle(Poly_Triangulation) aT; |
| 1546 | TopLoc_Location aLoc; |
| 1547 | TopTools_MapOfShape anEdgeMap; |
| 1548 | TopTools_MapIteratorOfMapOfShape it; |
| 1549 | |
| 1550 | if( aShape.ShapeType() == TopAbs_EDGE ) |
| 1551 | { |
| 1552 | anEdgeMap.Add( aShape ); |
| 1553 | } |
| 1554 | else |
| 1555 | { |
| 1556 | TopExp_Explorer ex(aShape, TopAbs_EDGE); |
| 1557 | for(; ex.More(); ex.Next() ) |
| 1558 | anEdgeMap.Add( ex.Current() ); |
| 1559 | } |
| 1560 | |
| 1561 | if ( anEdgeMap.Extent() == 0 ) |
| 1562 | continue; |
| 1563 | |
| 1564 | char newname[1024]; |
| 1565 | strcpy(newname,argv[i]); |
| 1566 | char* p = newname; |
| 1567 | while (*p != '\0') p++; |
| 1568 | *p = '_'; |
| 1569 | p++; |
| 1570 | |
| 1571 | Standard_Integer nbEdge = 1; |
| 1572 | for(it.Initialize(anEdgeMap); it.More(); it.Next()) |
| 1573 | { |
| 1574 | BRep_Tool::PolygonOnTriangulation(TopoDS::Edge(it.Key()), aPoly, aT, aLoc); |
| 1575 | if ( aT.IsNull() || aPoly.IsNull() ) |
| 1576 | continue; |
| 1577 | |
| 1578 | const TColgp_Array1OfPnt& Nodes = aT->Nodes(); |
| 1579 | const TColStd_Array1OfInteger& Indices = aPoly->Nodes(); |
| 1580 | const Standard_Integer nbnodes = Indices.Length(); |
| 1581 | |
| 1582 | for( Standard_Integer j = 1; j <= nbnodes; j++ ) |
| 1583 | { |
| 1584 | gp_Pnt P3d = Nodes(Indices(j)); |
| 1585 | if( !aLoc.IsIdentity() ) |
| 1586 | P3d.Transform(aLoc.Transformation()); |
| 1587 | |
| 1588 | if( anEdgeMap.Extent() > 1 ) |
| 1589 | Sprintf(p,"%d_%d",nbEdge,j); |
| 1590 | else |
| 1591 | Sprintf(p,"%d",j); |
| 1592 | DBRep::Set( newname, BRepBuilderAPI_MakeVertex(P3d) ); |
| 1593 | di.AppendElement(newname); |
| 1594 | } |
| 1595 | nbEdge++; |
| 1596 | } |
| 1597 | } |
| 1598 | return 0; |
| 1599 | } |
| 1600 | |
| 1601 | //======================================================================= |
| 1602 | void MeshTest::Commands(Draw_Interpretor& theCommands) |
| 1603 | //======================================================================= |
| 1604 | { |
| 1605 | Draw::Commands(theCommands); |
| 1606 | BRepTest::AllCommands(theCommands); |
| 1607 | GeometryTest::AllCommands(theCommands); |
| 1608 | MeshTest::PluginCommands(theCommands); |
| 1609 | const char* g; |
| 1610 | |
| 1611 | g = "Mesh Commands"; |
| 1612 | |
| 1613 | theCommands.Add("shpsec","shpsec result shape shape",__FILE__, shapesection, g); |
| 1614 | theCommands.Add("plnsec","plnsec result shape plane",__FILE__, planesection, g); |
| 1615 | theCommands.Add("incmesh","incmesh shape deflection [inParallel (0/1) : 0 by default]",__FILE__, incrementalmesh, g); |
| 1616 | theCommands.Add("MemLeakTest","MemLeakTest",__FILE__, MemLeakTest, g); |
| 1617 | theCommands.Add("fastdiscret","fastdiscret shape deflection [shared [nbiter]]",__FILE__, fastdiscret, g); |
| 1618 | theCommands.Add("mesh","mesh result Shape deflection [save partage]",__FILE__, triangule, g); |
| 1619 | theCommands.Add("addshape","addshape meshname Shape [deflection]",__FILE__, addshape, g); |
| 1620 | //theCommands.Add("smooth","smooth meshname",__FILE__, smooth, g); |
| 1621 | //theCommands.Add("edges","edges mesh shape, highlight the edges",__FILE__,edges, g); |
| 1622 | theCommands.Add("vertices","vertices mesh shape, highlight the vertices",__FILE__,vertices, g); |
| 1623 | theCommands.Add("medge","medge mesh [-]index (0 to clear all)",__FILE__,medge, g); |
| 1624 | theCommands.Add("mvertex","mvertex mesh [-]index (0 to clear all)",__FILE__,mvertex, g); |
| 1625 | theCommands.Add("triangle","triangle mesh [-]index (0 to clear all)",__FILE__,triangle, g); |
| 1626 | //theCommands.Add("dumpvertex","dumpvertex mesh [index]",__FILE__,dumpvertex, g); |
| 1627 | //theCommands.Add("dumpedge","dumpedge mesh [index]",__FILE__,dumpedge, g); |
| 1628 | //theCommands.Add("dumptriangle","dumptriangle mesh [index]",__FILE__,dumptriangle, g); |
| 1629 | |
| 1630 | theCommands.Add("tri2d", "tri2d facename",__FILE__, tri2d, g); |
| 1631 | theCommands.Add("trinfo","trinfo name, print triangles information on objects",__FILE__,trianglesinfo,g); |
| 1632 | theCommands.Add("veriftriangles","veriftriangles name, verif triangles",__FILE__,veriftriangles,g); |
| 1633 | theCommands.Add("wavefront","wavefront name",__FILE__, wavefront, g); |
| 1634 | theCommands.Add("onetriangulation","onetriangulation name",__FILE__, onetriangulation, g); |
| 1635 | theCommands.Add("triepoints", "triepoints shape1 [shape2 ...]",__FILE__, triedgepoints, g); |
| 1636 | |
| 1637 | #if 0 |
| 1638 | theCommands.Add("extrema","extrema ",__FILE__, extrema, g); |
| 1639 | theCommands.Add("vb","vb ",__FILE__, vb, g); |
| 1640 | #endif |
| 1641 | } |