MeshKit  1.0
tri_io.cpp
Go to the documentation of this file.
00001 #include "meshkit/Mesh.hpp"
00002 
00003 using namespace Jaal;
00004 
00006 
00007 void MeshImporter ::readTriNodes( const string &fname)
00008 {
00009   string filename = fname + ".node";
00010 
00011   ifstream infile( filename.c_str(), ios::in);
00012   if( infile.fail() )  {
00013       cout << "Warning: cann't open node file " << filename << endl;
00014       return;
00015   }
00016 
00017   cout << "Reading node file " << filename << endl;
00018 
00019   int id, numnodes, ndim, numattrib, boundflag, bmark;
00020 
00021   infile >> numnodes >> ndim >> numattrib >> boundflag;
00022 
00023   assert( ndim == 2 );
00024   assert( numattrib == 0);
00025 
00026   mesh->reserve(numnodes, 0);
00027 
00028   double x, y, z = 0.0;
00029   Point3D xyz;
00030   for( int i = 0; i < numnodes; i++)  {
00031        infile >> id >> x >> y ;
00032        if( ndim == 3) infile >> z;
00033        if( boundflag ) infile >> bmark;
00034        global2local[id] = i;
00035        xyz[0] = x;
00036        xyz[1] = y;
00037        xyz[2] = z;
00038        Vertex *v = Vertex::newObject();
00039        v->setID(i);
00040        v->setXYZCoords(xyz);
00041        mesh->addNode( v );
00042   }
00043 }
00045 void MeshImporter::readTriEdges( const string &fname)
00046 {
00047 /*
00048   string filename = fname + ".edge";
00049   ifstream infile( filename.c_str(), ios::in);
00050   if( infile.fail() ) {
00051       cout << "Warning: cann't open node file " << filename << endl;
00052       return;
00053   }
00054 
00055   cout << "Reading edge file " << filename << endl;
00056 
00057   int id, numedges, boundflag;
00058   int n0, n1;
00059 
00060   infile >> numedges >> boundflag;
00061   edges.resize( numedges );
00062 
00063   for( int i = 0; i < numedges; i++) {
00064        infile >> id >> n0 >> n1;
00065        if( boundflag ) infile >> edges[i].gid;
00066        n0 = global2local[n0];
00067        n1 = global2local[n1];
00068        edges[i].connect[0] = n0;
00069        edges[i].connect[1] = n1;
00070   }
00071   */
00072 }
00073 
00075 
00076 void MeshImporter ::readTriFaces( const string &fname)
00077 {
00078   string filename = fname + ".ele";
00079   ifstream infile( filename.c_str(), ios::in);
00080   if( infile.fail() ) {
00081       cout << "Warning: cann't open node file " << filename << endl;
00082       return;
00083   }
00084 
00085   int id, numfaces, numelemnodes, boundflag, bmark;
00086   int n0, n1, n2, n3, facetype;
00087   (void) facetype;
00088   
00089   infile >> numfaces >> numelemnodes >> boundflag;
00090 
00091   mesh->reserve( numfaces, 2);
00092 
00093   vector<PNode> connect(3);
00094   Face *newface;
00095   
00096   if( numelemnodes == 3 ) {
00097       facetype = 3;
00098       connect.resize(3);
00099       for( int i = 0; i < numfaces; i++) {
00100            infile >> id >> n0 >> n1 >> n2;
00101            if( boundflag )  infile >> bmark;
00102            n0 = global2local[n0];
00103            n1 = global2local[n1];
00104            n2 = global2local[n2];
00105 
00106            connect[0] = mesh->getNodeAt(n0);
00107            connect[1] = mesh->getNodeAt(n1);
00108            connect[2] = mesh->getNodeAt(n2);
00109            newface = new Face;
00110            newface->setNodes(connect);
00111            mesh->addFace( newface );
00112        }
00113   }
00114 
00115   if( numelemnodes == 4 ) {
00116       facetype = 4;
00117       connect.resize(4);
00118       for( int i = 0; i < numfaces; i++)  {
00119            infile >> id >> n0 >> n1 >> n2 >> n3;
00120            if( boundflag )  infile >> bmark;
00121            n0 = global2local[n0];
00122            n1 = global2local[n1];
00123            n2 = global2local[n2];
00124            n3 = global2local[n3];
00125            connect[0] = mesh->getNodeAt(n0);
00126            connect[1] = mesh->getNodeAt(n1);
00127            connect[2] = mesh->getNodeAt(n2);
00128            connect[3] = mesh->getNodeAt(n3);
00129            newface = new Face;
00130            newface->setNodes(connect);
00131            mesh->addFace( newface );
00132        }
00133   }
00134   
00135 }
00136 
00138 int MeshImporter ::triangle_file( const string &fname)
00139 {
00140    readTriNodes( fname );
00141    readTriEdges( fname );
00142    readTriFaces( fname );
00143    mesh->enumerate(2);
00144    global2local.clear();
00145    return 0;
00146 }
00147 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines