Commit 665b2fae authored by Chris Cantwell's avatar Chris Cantwell

Merge branch 'feature/MeshConvertPlyNormals' of /opt/gitlab/repositories/nektar

parents 472ab56c d8fd5ab9
......@@ -96,9 +96,9 @@ namespace Nektar
cout << "InputGmsh: Start reading file..." << endl;
}
while (!mshFile.eof())
while (!m_mshFile.eof())
{
getline(mshFile, line);
getline(m_mshFile, line);
stringstream s(line);
string word;
s >> word;
......@@ -106,13 +106,13 @@ namespace Nektar
// Process nodes.
if (word == "$Nodes")
{
getline(mshFile, line);
getline(m_mshFile, line);
stringstream s(line);
s >> nVertices;
int id = 0;
for (int i = 0; i < nVertices; ++i)
{
getline(mshFile, line);
getline(m_mshFile, line);
stringstream st(line);
double x = 0, y = 0, z = 0;
st >> id >> x >> y >> z;
......@@ -144,12 +144,12 @@ namespace Nektar
// Process elements
else if (word == "$Elements")
{
getline(mshFile, line);
getline(m_mshFile, line);
stringstream s(line);
s >> nEntities;
for (int i = 0; i < nEntities; ++i)
{
getline(mshFile, line);
getline(m_mshFile, line);
stringstream st(line);
int id = 0, num_tag = 0, num_nodes = 0;
......@@ -246,7 +246,7 @@ namespace Nektar
}
}
}
mshFile.close();
m_mshFile.close();
// Process rest of mesh.
ProcessVertices ();
......
......@@ -114,7 +114,7 @@ namespace Nektar
// Ignore first 3 lines. 4th line contains number of parameters.
for (i = 0; i < 4; ++i)
{
getline(mshFile, line);
getline(m_mshFile, line);
}
stringstream s(line);
......@@ -123,38 +123,38 @@ namespace Nektar
for (i = 0; i < nParam; ++i)
{
string tmp1, tmp2;
getline(mshFile, line);
getline(m_mshFile, line);
s.str(line);
s >> tmp1 >> tmp2;
}
// -- Read in passive scalars (ignore)
getline(mshFile, line);
getline(m_mshFile, line);
s.clear();
s.str(line);
s >> j;
for (i = 0; i < j; ++i)
{
getline(mshFile, line);
getline(m_mshFile, line);
}
// -- Read in logical switches (ignore)
getline(mshFile, line);
getline(m_mshFile, line);
s.clear();
s.str(line);
s >> j;
for (i = 0; i < j; ++i)
{
getline(mshFile, line);
getline(m_mshFile, line);
}
// -- Read in mesh data.
// First hunt for MESH tag
bool foundMesh = false;
while (!mshFile.eof())
while (!m_mshFile.eof())
{
getline(mshFile, line);
getline(m_mshFile, line);
if (line.find("MESH") != string::npos)
{
foundMesh = true;
......@@ -169,7 +169,7 @@ namespace Nektar
}
// Now read in number of elements and space dimension.
getline(mshFile, line);
getline(m_mshFile, line);
s.clear(); s.str(line);
s >> nElements >> m_mesh->m_expDim;
m_mesh->m_spaceDim = m_mesh->m_expDim;
......@@ -186,7 +186,7 @@ namespace Nektar
// Loop over and create elements.
for (i = 0; i < nElements; ++i)
{
getline(mshFile, line);
getline(m_mshFile, line);
if (m_mesh->m_expDim == 2)
{
......@@ -241,7 +241,7 @@ namespace Nektar
for (j = 0; j < m_mesh->m_expDim; ++j)
{
getline(mshFile,line);
getline(m_mshFile,line);
s.clear(); s.str(line);
for (k = 0; k < nNodes; ++k)
{
......@@ -326,7 +326,7 @@ namespace Nektar
}
// -- Read in curved data.
getline(mshFile, line);
getline(m_mshFile, line);
if (line.find("CURVE") == string::npos)
{
cerr << "Cannot find curved side data." << endl;
......@@ -334,7 +334,7 @@ namespace Nektar
}
// Read number of curves.
getline(mshFile, line);
getline(m_mshFile, line);
s.clear(); s.str(line);
s >> nCurves;
......@@ -344,14 +344,14 @@ namespace Nektar
for (i = 0; i < nCurves; ++i)
{
getline(mshFile, line);
getline(m_mshFile, line);
s.clear(); s.str(line);
s >> word;
if (word == "File")
{
// Next line contains filename and curve tag.
getline(mshFile, line);
getline(m_mshFile, line);
s.clear(); s.str(line);
s >> word >> curveTag;
curveTags[curveTag] = make_pair(eFile, word);
......@@ -359,7 +359,7 @@ namespace Nektar
else if (word == "Recon")
{
// Next line contains curve tag.
getline(mshFile, line);
getline(m_mshFile, line);
s.clear(); s.str(line);
s >> word >> curveTag;
curveTags[curveTag] = make_pair(eRecon, word);
......@@ -376,7 +376,7 @@ namespace Nektar
// Read in curve information. First line should contain number
// of curved sides.
getline(mshFile,line);
getline(m_mshFile,line);
if (line.find("side") == string::npos)
{
......@@ -396,7 +396,7 @@ namespace Nektar
// information in the HOSurfSet, then map this onto faces.
for (i = 0; i < nCurvedSides; ++i)
{
getline(mshFile, line);
getline(m_mshFile, line);
s.clear(); s.str(line);
s >> faceId >> elId >> word;
faceId--;
......@@ -446,21 +446,21 @@ namespace Nektar
}
// Read x/y/z coordinates.
getline(mshFile, line);
getline(m_mshFile, line);
s.clear(); s.str(line);
for (j = 0; j < tmp.size(); ++j)
{
s >> n[j].m_x;
}
getline(mshFile, line);
getline(m_mshFile, line);
s.clear(); s.str(line);
for (j = 0; j < tmp.size(); ++j)
{
s >> n[j].m_y;
}
getline(mshFile, line);
getline(m_mshFile, line);
s.clear(); s.str(line);
for (j = 0; j < tmp.size(); ++j)
{
......@@ -648,17 +648,17 @@ namespace Nektar
map<int,vector<pair<int,LibUtilities::ShapeType> > > surfaceCompMap;
// Skip boundary conditions line.
getline(mshFile, line);
getline(mshFile, line);
getline(m_mshFile, line);
getline(m_mshFile, line);
int nSurfaces = 0;
while (true)
{
getline(mshFile, line);
getline(m_mshFile, line);
// Break out of loop at end of boundary conditions section.
if (line.find("*") != string::npos || mshFile.eof() ||
if (line.find("*") != string::npos || m_mshFile.eof() ||
line.length() == 0)
{
break;
......@@ -703,7 +703,7 @@ namespace Nektar
{
for (i = 0; i < m_mesh->m_fields.size()-1; ++i)
{
getline(mshFile, line);
getline(m_mshFile, line);
size_t p = line.find_first_of('=');
vals.push_back(boost::algorithm::trim_copy(
line.substr(p+1)));
......@@ -905,7 +905,7 @@ namespace Nektar
nSurfaces++;
}
mshFile.close();
m_mshFile.close();
// -- Process rest of mesh.
ProcessEdges ();
......
......@@ -66,9 +66,23 @@ namespace Nektar
*/
void InputPly::Process()
{
// Open the file stream.
OpenStream();
ReadPly(m_mshFile);
m_mshFile.close();
ProcessVertices();
ProcessEdges();
ProcessFaces();
ProcessElements();
ProcessComposites();
}
void InputPly::ReadPly(std::ifstream &mshFile, NekDouble scale)
{
m_mesh->m_expDim = 0;
string line;
int nVertices = 0;
......@@ -132,6 +146,12 @@ namespace Nektar
{
m_mesh->m_spaceDim = 3;
}
x *= scale;
y *= scale;
z *= scale;
m_mesh->m_node.push_back(
boost::shared_ptr<Node>(new Node(i, x, y, z)));
......@@ -180,13 +200,7 @@ namespace Nektar
}
}
}
mshFile.close();
}
ProcessVertices();
ProcessEdges();
ProcessFaces();
ProcessElements();
ProcessComposites();
}
}
}
......@@ -57,7 +57,12 @@ namespace Nektar
/// Populate and validate required data structures.
virtual void Process();
void ReadPly(std::ifstream &mshFile, NekDouble scale = 1.0);
private:
};
typedef boost::shared_ptr<InputPly> InputPlySharedPtr;
}
}
......
......@@ -99,10 +99,10 @@ namespace Nektar
sectionMap["BCS"] = -1;
sectionMap["FIELDS"] = -1;
while (!mshFile.eof())
while (!m_mshFile.eof())
{
linePos = mshFile.tellg();
getline(mshFile, line);
linePos = m_mshFile.tellg();
getline(m_mshFile, line);
ss.clear();
ss.str(line);
ss >> word;
......@@ -119,8 +119,8 @@ namespace Nektar
}
// Clear eofbit and go back to the beginning of the file.
mshFile.clear();
mshFile.seekg(0);
m_mshFile.clear();
m_mshFile.seekg(0);
// Check that required sections exist in the file.
if (sectionMap["NODES"] == std::streampos(-1))
......@@ -171,8 +171,8 @@ namespace Nektar
// Begin by reading in list of nodes which define the linear
// elements.
mshFile.seekg(sectionMap["NODES"]);
getline(mshFile, line);
m_mshFile.seekg(sectionMap["NODES"]);
getline(m_mshFile, line);
ss.clear(); ss.str(line);
ss >> word;
......@@ -184,7 +184,7 @@ namespace Nektar
i = id = 0;
while (i < nVertices)
{
getline(mshFile, line);
getline(m_mshFile, line);
if (line.length() < 7) continue;
ss.clear(); ss.str(line);
double x = 0, y = 0, z = 0;
......@@ -204,8 +204,8 @@ namespace Nektar
}
// Now read in elements
mshFile.seekg(sectionMap["ELEMENTS"]);
getline(mshFile, line);
m_mshFile.seekg(sectionMap["ELEMENTS"]);
getline(m_mshFile, line);
ss.clear(); ss.str(line);
ss >> word;
......@@ -217,7 +217,7 @@ namespace Nektar
i = id = 0;
while (i < nEntities)
{
getline(mshFile, line);
getline(m_mshFile, line);
if (line.length() < 18)
{
continue;
......@@ -256,8 +256,8 @@ namespace Nektar
{
int np, nel, nodeId = m_mesh->m_node.size();
mshFile.seekg(sectionMap["CURVES"]);
getline(mshFile, line);
m_mshFile.seekg(sectionMap["CURVES"]);
getline(m_mshFile, line);
ss.clear(); ss.str(line);
ss >> word;
......@@ -314,7 +314,7 @@ namespace Nektar
i = id = 0;
while (i < nCurves)
{
getline(mshFile, line);
getline(m_mshFile, line);
if (line.length() < 18)
{
continue;
......@@ -416,9 +416,9 @@ namespace Nektar
// Process field names
if (sectionMap["FIELDS"] != std::streampos(-1))
{
mshFile.seekg(sectionMap["FIELDS"]);
getline(mshFile, line);
getline(mshFile, line);
m_mshFile.seekg(sectionMap["FIELDS"]);
getline(m_mshFile, line);
getline(m_mshFile, line);
ss.clear(); ss.str(line);
while (ss >> tag)
......@@ -435,8 +435,8 @@ namespace Nektar
int maxTag = -1;
// First read in list of groups, which defines each condition tag.
mshFile.seekg(sectionMap["GROUPS"]);
getline(mshFile, line);
m_mshFile.seekg(sectionMap["GROUPS"]);
getline(m_mshFile, line);
ss.clear(); ss.str(line);
ss >> word;
......@@ -448,7 +448,7 @@ namespace Nektar
i = id = 0;
while (i < nGroups)
{
getline(mshFile, line);
getline(m_mshFile, line);
ss.clear(); ss.str(line);
ss >> id >> tag;
conditionMap[tag] = i++;
......@@ -458,8 +458,8 @@ namespace Nektar
// Now read in actual values for boundary conditions from BCS
// section.
mshFile.seekg(sectionMap["BCS"]);
getline(mshFile, line);
m_mshFile.seekg(sectionMap["BCS"]);
getline(m_mshFile, line);
ss.clear(); ss.str(line);
ss >> word;
......@@ -474,7 +474,7 @@ namespace Nektar
int nF;
string tmp;
ConditionSharedPtr p;
getline(mshFile, line);
getline(m_mshFile, line);
ss.clear(); ss.str(line);
ss >> id >> tag >> nF;
......@@ -485,7 +485,7 @@ namespace Nektar
j = 0;
while (j < nF)
{
getline(mshFile, line);
getline(m_mshFile, line);
ss.clear(); ss.str(line);
ss >> tmp;
......@@ -541,8 +541,8 @@ namespace Nektar
}
// Finally read surface information.
mshFile.seekg(sectionMap["SURFACES"]);
getline(mshFile, line);
m_mshFile.seekg(sectionMap["SURFACES"]);
getline(m_mshFile, line);
ss.clear(); ss.str(line);
ss >> word;
......@@ -559,7 +559,7 @@ namespace Nektar
while (i < nSurf)
{
getline(mshFile, line);
getline(m_mshFile, line);
ss.clear(); ss.str(line);
ss >> id >> elmt >> side >> word;
elmt--;
......@@ -627,7 +627,7 @@ namespace Nektar
}
PrintSummary();
mshFile.close();
m_mshFile.close();
// Process rest of mesh.
ProcessVertices();
......
......@@ -97,9 +97,9 @@ namespace Nektar
int nComposite = 0;
// read first zone (Hopefully 3D)
while (!mshFile.eof())
while (!m_mshFile.eof())
{
getline(mshFile, line);
getline(m_mshFile, line);
if(line.find("ZONE") != string::npos)
{
ReadZone(nComposite);
......@@ -108,7 +108,7 @@ namespace Nektar
}
// read remaining 2D zones
while (!mshFile.eof())
while (!m_mshFile.eof())
{
if(line.find("ZONE") != string::npos)
{
......@@ -117,7 +117,7 @@ namespace Nektar
}
PrintSummary();
mshFile.close();
m_mshFile.close();
ProcessEdges();
ProcessFaces();
......@@ -138,18 +138,18 @@ namespace Nektar
// Read Zone Header
nnodes = nfaces = nelements = 0;
while (!mshFile.eof())
while (!m_mshFile.eof())
{
pos = mshFile.tellg();
pos = m_mshFile.tellg();
getline(mshFile, line);
getline(m_mshFile, line);
boost::to_upper(line);
// cehck to see if readable data.
if(sscanf(line.c_str(),"%lf",&value) == 1)
{
mshFile.seekg(pos);
m_mshFile.seekg(pos);
break;
}
......@@ -212,19 +212,19 @@ namespace Nektar
// Read in Nodes
for(i = 0; i < nnodes; ++i)
{
mshFile >> value;
m_mshFile >> value;
x.push_back(value);
}
for(i = 0; i < nnodes; ++i)
{
mshFile >> value;
m_mshFile >> value;
y.push_back(value);
}
for(i = 0; i < nnodes; ++i)
{
mshFile >> value;
m_mshFile >> value;
z.push_back(value);
}
......@@ -235,12 +235,12 @@ namespace Nektar
}
// Read Node count per face
getline(mshFile, line);
getline(m_mshFile, line);
if(line.find("node count per face") == string::npos)
{
if(line.find("face nodes") == string::npos)
{
getline(mshFile,line);
getline(m_mshFile,line);
}
}
......@@ -253,19 +253,19 @@ namespace Nektar
int nodes;
for(i = 0; i < nfaces; ++i)
{
mshFile>> nodes;
m_mshFile>> nodes;
ASSERTL0(nodes <= 4,"Can only handle meshes with "
"up to four nodes per face");
Nodes_per_face.push_back(nodes);
}
// Read next line
getline(mshFile, line);
getline(m_mshFile, line);
}
// Read face nodes;
if(line.find("face nodes") == string::npos)
{
getline(mshFile,line);
getline(m_mshFile,line);
}
s.clear();
s.str(line);
......@@ -286,7 +286,7 @@ namespace Nektar
for(int j = 0; j < nodes; ++j)
{
mshFile>> nodeID;
m_mshFile>> nodeID;
Fnodes.push_back(nodeID-1);
}
......@@ -304,10 +304,10 @@ names