← Back to team overview

dolfin team mailing list archive

getting triangles

 

I need to export the vertices and the triangle from a dolfin::Mesh, but
I'm not sure that coordinates() and cells() do this, especially for the
latter function. I've written the following code:

dolfin::Mesh *mesh_obj = new dolfin::Mesh("tyre.xml");
dolfin::BoundaryMesh *bmesh_obj = new dolfin::BoundaryMesh( *mesh_obj );

NUM_TRIANGLES = bmesh_obj->numCells();
NUM_VERTICES = bmesh_obj->numVertices();
NUM_INDICES  = NUM_TRIANGLES * 3;

gVertices = new REAL[NUM_VERTICES * 3];
dolfin::real *vertices = new dolfin::real[NUM_VERTICES * 3];
vertices = bmesh_obj->coordinates();

for( int i = 0; i < NUM_VERTICES*3; i++ )
{
	gVertices[i] = vertices[i];
}

gIndices = new int*[NUM_TRIANGLES];
dolfin::uint *triangles = new dolfin::uint[NUM_TRIANGLES * 3];
triangles = bmesh_obj->cells();

for( int i = 0; i < NUM_TRIANGLES; i++ )
{
	gIndices[i] = new int[3];

	gIndices[i][0] = triangles[3*i + 0];
	gIndices[i][1] = triangles[3*i + 1];
	gIndices[i][2] = triangles[3*i + 2];
}

but I get a segmentation fault. Should I use some other function? I can't
find it in the programmer's reference.

Thanks,
Alessio