1 // Created on: 2016-05-31
2 // Created by: Mikhail Sazonov
3 // Copyright (c) 2016 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 #include <Draw_Segment3D.hxx>
17 #include <DrawTrSurf_Polygon3D.hxx>
19 #include <TCollection_AsciiString.hxx>
20 #include <TColgp_Array1OfPnt.hxx>
21 #include <Poly_Polygon3D.hxx>
22 #include <BRepMesh_Edge.hxx>
23 #include <BRepMesh_Vertex.hxx>
24 #include <BRepMesh_Triangle.hxx>
25 #include <BRepMesh_DataStructureOfDelaun.hxx>
27 // This file defines global functions not declared in any public header,
28 // intended for use from debugger prompt (Command Window in Visual Studio)
30 //=======================================================================
31 //function : MeshTest_DrawLinks
32 //purpose : Draw links from mesh data structure of type BRepMesh_FaceAttribute
33 //=======================================================================
34 Standard_EXPORT const char* MeshTest_DrawLinks(const char* theNameStr, void* theDataStruct)
36 if (theNameStr == 0 || theDataStruct == 0)
38 return "Error: name or face attribute is null";
41 const Handle(BRepMesh_DataStructureOfDelaun)& aMeshData = *(Handle(BRepMesh_DataStructureOfDelaun)*)theDataStruct;
42 if (aMeshData.IsNull())
43 return "Null mesh data structure";
44 Standard_Integer nbLinks = aMeshData->NbLinks();
45 std::cout << "nblink=" << nbLinks << std::endl;
46 TCollection_AsciiString aName(theNameStr);
47 for (Standard_Integer i = 1; i <= nbLinks; i++)
49 const BRepMesh_Edge& aLink = aMeshData->GetLink(i);
50 if (aLink.Movability() == BRepMesh_Deleted)
52 Standard_Integer n1 = aLink.FirstNode();
53 Standard_Integer n2 = aLink.LastNode();
54 const BRepMesh_Vertex& aV1 = aMeshData->GetNode(n1);
55 const BRepMesh_Vertex& aV2 = aMeshData->GetNode(n2);
56 Handle(Draw_Segment3D) aSeg = new Draw_Segment3D(gp_Pnt(aV1.Coord().X(), aV1.Coord().Y(), 0),
57 gp_Pnt(aV2.Coord().X(), aV2.Coord().Y(), 0),
59 Draw::Set((aName + "_" + i).ToCString(), aSeg);
63 catch (Standard_Failure const& anException)
65 return anException.GetMessageString();
69 //=======================================================================
70 //function : MeshTest_DrawTriangles
71 //purpose : Draw triangles from mesh data structure of type BRepMesh_FaceAttribute
72 //=======================================================================
73 Standard_EXPORT const char* MeshTest_DrawTriangles(const char* theNameStr, void* theDataStruct)
75 if (theNameStr == 0 || theDataStruct == 0)
77 return "Error: name or face attribute is null";
80 const Handle(BRepMesh_DataStructureOfDelaun)& aMeshData =
81 *(Handle(BRepMesh_DataStructureOfDelaun)*)theDataStruct;
83 if (aMeshData.IsNull())
84 return "Null mesh data structure";
85 Standard_Integer nbElem = aMeshData->NbElements();
86 std::cout << "nbelem=" << nbElem << std::endl;
87 TCollection_AsciiString aName(theNameStr);
88 for (Standard_Integer i = 1; i <= nbElem; i++)
90 const BRepMesh_Triangle& aTri = aMeshData->GetElement(i);
91 if (aTri.Movability() == BRepMesh_Deleted)
93 Standard_Integer n[3];
94 aMeshData->ElementNodes(aTri, n);
95 const BRepMesh_Vertex& aV1 = aMeshData->GetNode(n[0]);
96 const BRepMesh_Vertex& aV2 = aMeshData->GetNode(n[1]);
97 const BRepMesh_Vertex& aV3 = aMeshData->GetNode(n[2]);
98 gp_Pnt aP[4] = { gp_Pnt(aV1.Coord().X(), aV1.Coord().Y(), 0),
99 gp_Pnt(aV2.Coord().X(), aV2.Coord().Y(), 0),
100 gp_Pnt(aV3.Coord().X(), aV3.Coord().Y(), 0),
101 gp_Pnt(aV1.Coord().X(), aV1.Coord().Y(), 0) };
102 TColgp_Array1OfPnt aPnts(aP[0], 1, 4);
103 Handle(Poly_Polygon3D) aPoly = new Poly_Polygon3D(aPnts);
104 Handle(DrawTrSurf_Polygon3D) aDPoly = new DrawTrSurf_Polygon3D(aPoly);
105 Draw::Set((aName + "_" + i).ToCString(), aDPoly);
109 catch (Standard_Failure const& anException)
111 return anException.GetMessageString();