1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#include "meshkit/Mesh.hpp"

using namespace Jaal;

///////////////////////////////////////////////////////////////////////////////

void MeshImporter ::readTriNodes( const string &fname)
{
  string filename = fname + ".node";

  ifstream infile( filename.c_str(), ios::in);
  if( infile.fail() )  {
      cout << "Warning: cann't open node file " << filename << endl;
      return;
  }

  cout << "Reading node file " << filename << endl;

  int id, numnodes, ndim, numattrib, boundflag, bmark;

  infile >> numnodes >> ndim >> numattrib >> boundflag;

  assert( ndim == 2 );
  assert( numattrib == 0);

  mesh->reserve(numnodes, 0);

  double x, y, z = 0.0;
  Point3D xyz;
  for( int i = 0; i < numnodes; i++)  {
       infile >> id >> x >> y ;
       if( ndim == 3) infile >> z;
       if( boundflag ) infile >> bmark;
       global2local[id] = i;
       xyz[0] = x;
       xyz[1] = y;
       xyz[2] = z;
       Vertex *v = Vertex::newObject();
       v->setID(i);
       v->setXYZCoords(xyz);
       mesh->addNode( v );
  }
}
///////////////////////////////////////////////////////////////////////////////
void MeshImporter::readTriEdges( const string &fname)
{
/*
  string filename = fname + ".edge";
  ifstream infile( filename.c_str(), ios::in);
  if( infile.fail() ) {
      cout << "Warning: cann't open node file " << filename << endl;
      return;
  }

  cout << "Reading edge file " << filename << endl;

  int id, numedges, boundflag;
  int n0, n1;

  infile >> numedges >> boundflag;
  edges.resize( numedges );

  for( int i = 0; i < numedges; i++) {
       infile >> id >> n0 >> n1;
       if( boundflag ) infile >> edges[i].gid;
       n0 = global2local[n0];
       n1 = global2local[n1];
       edges[i].connect[0] = n0;
       edges[i].connect[1] = n1;
  }
  */
}

///////////////////////////////////////////////////////////////////////////////

void MeshImporter ::readTriFaces( const string &fname)
{
  string filename = fname + ".ele";
  ifstream infile( filename.c_str(), ios::in);
  if( infile.fail() ) {
      cout << "Warning: cann't open node file " << filename << endl;
      return;
  }

  int id, numfaces, numelemnodes, boundflag, bmark;
  int n0, n1, n2, n3, facetype;<--- The scope of the variable 'n3' can be reduced.
  (void) facetype;
  
  infile >> numfaces >> numelemnodes >> boundflag;

  mesh->reserve( numfaces, 2);

  vector<PNode> connect(3);
  Face *newface;
  
  if( numelemnodes == 3 ) {
      facetype = 3;
      connect.resize(3);
      for( int i = 0; i < numfaces; i++) {
           infile >> id >> n0 >> n1 >> n2;
           if( boundflag )  infile >> bmark;
           n0 = global2local[n0];
           n1 = global2local[n1];
           n2 = global2local[n2];

           connect[0] = mesh->getNodeAt(n0);
           connect[1] = mesh->getNodeAt(n1);
           connect[2] = mesh->getNodeAt(n2);
	   newface = new Face;
	   newface->setNodes(connect);
	   mesh->addFace( newface );
       }
  }

  if( numelemnodes == 4 ) {
      facetype = 4;<--- Variable 'facetype' is assigned a value that is never used.
      connect.resize(4);
      for( int i = 0; i < numfaces; i++)  {
           infile >> id >> n0 >> n1 >> n2 >> n3;
           if( boundflag )  infile >> bmark;
           n0 = global2local[n0];
           n1 = global2local[n1];
           n2 = global2local[n2];
           n3 = global2local[n3];
           connect[0] = mesh->getNodeAt(n0);
           connect[1] = mesh->getNodeAt(n1);
           connect[2] = mesh->getNodeAt(n2);
           connect[3] = mesh->getNodeAt(n3);
	   newface = new Face;
	   newface->setNodes(connect);
	   mesh->addFace( newface );
       }
  }
  
}

///////////////////////////////////////////////////////////////////////////////
int MeshImporter ::triangle_file( const string &fname)
{
   readTriNodes( fname );
   readTriEdges( fname );
   readTriFaces( fname );
   mesh->enumerate(2);
   global2local.clear();
   return 0;
}

///////////////////////////////////////////////////////////////////////////////