Hello Gerhard,
Thank you for your reply. The call to Triangulation seems to work but exception occurs when I try to get count of triangles. The goal is to create 2 lists, one with vertices and one with triangles defined by those vertices (an indexed mesh). I have tried to convert C++ samples found in this forum to your C# wrapper. Complete code below:
------
using System;
using System.Collections.Generic;
using System.Text;
namespace OpenCASCADE
{
class Point3D
{
public double X;
public double Y;
public double Z;
}
class Mesh
{
public static void CreateMesh()
{
// The resulting lists containing vertices and triangle definition by index pointers to vertices
List vertices = new List();
List indecies = new List();
TopoDS.Shape topoShape = new BRepPrimAPI.MakeBox(200, 40, 40).Shape();
//BRepMesh.General.Mesh(topoShape, 0.1);
TopExp.Explorer ex = new TopExp.Explorer(topoShape, TopAbs.ShapeEnum.FACE, TopAbs.ShapeEnum.SHAPE);
// Loop all faces
while (ex.More())
{
// Triangulate current face
TopoDS.Face F = TopoDS.General.Face(ex.Current());
TopLoc.Location L = new TopLoc.Location();
Poly.Triangulation facing = BRep.Tool.Triangulation(F, L);
if (facing != null)
{
int nbtris = facing.NbTriangles();
//Poly.Array1OfTriangle tris = new Poly.Array1OfTriangle(1, nbtris);
Poly.Array1OfTriangle tris = facing.Triangles();
for (int i = 1; i <= nbtris; i++)
{
Poly.Triangle tri = tris.Value(i);
int index0 = 0, index1 = 0, index2 = 0;
tri.Get(ref index0, ref index1, ref index2);
indecies.Add(index0);
indecies.Add(index1);
indecies.Add(index2);
}
int nbnodes = facing.NbNodes();
//TColgp.Array1OfPnt nodes = new TColgp.Array1OfPnt(1, nbnodes);
TColgp.Array1OfPnt nodes = facing.Nodes();
for (int i = 1; i <= nbnodes; i++)
{
gp.Pnt node = nodes.Value(i);
Point3D p = new Point3D();
p.X = node.x;
p.Y = node.y;
p.Z = node.z;
vertices.Add(p);
}
}
ex.Next();
}
}
}
}
-----
The exception is "Access violation in OpenCascade" in the line "int nbtris = facing.NbTriangles();". I think I am using a pointer in the wrong way or something?