trimesh.cpp

Demonstration of Creation an Artificial Triangular Mesh

#include <iostream>
#include <bundle/Bundle.hpp>
#include <grid/CartesianChart.hpp>

using namespace Fiber;
using namespace std;
using namespace MemCore;
using namespace Eagle;

int main()
{
BundlePtr B; 

double  time = 0.0; 

Slice   &T0 = (*B)[time]; 

Grid    &G = T0[ "MySpecialTriangularMesh" ]; 

Skeleton&MeshVertices     = G[ SkeletonID(3,0) ]; 
Skeleton&MeshConnectivity = G[ SkeletonID(3,1) ]; 

RefPtr<Chart> myCartesianChart = G.makeChart( typeid(Fiber::CartesianChart3D) ); 

Representation&CartesianVertices = MeshVertices[ myCartesianChart ]; 
Representation&CellsAsVertices   = MeshConnectivity[ MeshVertices ]; 

RefPtr<MemArray<1, Vector<double,3> > >    Vertices = new MemArray<1, Vector<double,3> >(5); 
RefPtr<MemArray<1, Vector<int,3> > >   Connectivity = new MemArray<1, Vector<int,3> >(3); 

// Define the vertices of the mesh
        (*Vertices)[0] = 1.0, 3.4, 5.1;
        (*Vertices)[1] = 5.0, 1.3, 2.2;
        (*Vertices)[2] = 3.0, 2.8, 4.3;
        (*Vertices)[3] = 1.4, 8.9, 7.6;
        (*Vertices)[4] = 5.3, 2.1, 6.12; 

// Define the triangles of the mesh
        (*Connectivity)[0] = 0,1,2; 
        (*Connectivity)[1] = 3,2,4;
        (*Connectivity)[2] = 0,3,2; 

        CartesianVertices [ FIBER_POSITIONS ] = new Field(Vertices, Cache::MemCache() ); 
        CellsAsVertices.setPositions( new Field(Connectivity, Cache::MemCache() ) );

        B.save("MyMesh.f5");

        return 0;
}