Commit b52c2935 authored by 's avatar
Browse files

working .geo reader for 2D geometries

parent a8fbc4da
......@@ -40,6 +40,9 @@
#include <NekMeshUtils/CADSystem/OCE/CADSurfOCE.h>
#include <NekMeshUtils/CADSystem/CADSurf.h>
#include <boost/filesystem.hpp>
#include <boost/algorithm/string.hpp>
using namespace std;
namespace Nektar
......@@ -55,16 +58,26 @@ bool CADSystemOCE::LoadCAD()
if (m_naca.size() == 0)
{
//not a naca profile behave normally
// Takes step file and makes OpenCascade shape
STEPControl_Reader reader;
reader = STEPControl_Reader();
reader.ReadFile(m_name.c_str());
reader.NbRootsForTransfer();
reader.TransferRoots();
shape = reader.OneShape();
if (shape.IsNull())
//could be a geo
string ext = boost::filesystem::extension(m_name);
if(boost::iequals(ext,".geo"))
{
shape = BuildGeo(m_name);
}
else
{
return false;
// Takes step file and makes OpenCascade shape
STEPControl_Reader reader;
reader = STEPControl_Reader();
reader.ReadFile(m_name.c_str());
reader.NbRootsForTransfer();
reader.TransferRoots();
shape = reader.OneShape();
if (shape.IsNull())
{
return false;
}
}
}
else
......@@ -476,5 +489,138 @@ TopoDS_Shape CADSystemOCE::BuildNACA(string naca)
return face.Face();
}
TopoDS_Shape CADSystemOCE::BuildGeo(string geo)
{
ifstream f;
f.open(geo.c_str());
map<int,string> points;
map<int,string> lines;
map<int,string> splines;
map<int,string> loops;
map<int,string> surfs;
string fline;
while( !f.eof() )
{
getline( f, fline );
if(fline.size() == 0)
{
continue;
}
vector<string> tmp1, tmp2;
boost::split(tmp1,fline,boost::is_any_of("="));
boost::split(tmp2,tmp1[0],boost::is_any_of("("));
string type = tmp2[0];
boost::erase_all(tmp2[1],")");
boost::erase_all(tmp2[1]," ");
int id = boost::lexical_cast<int>(tmp2[1]);
boost::erase_all(tmp1[1]," ");
boost::erase_all(tmp1[1],"{");
boost::erase_all(tmp1[1],"}");
boost::erase_all(tmp1[1],";");
string var = tmp1[1];
if(boost::iequals(type,"Point"))
{
points[id] = var;
}
else if(boost::iequals(type,"Line"))
{
lines[id] = var;
}
else if(boost::iequals(type,"Spline"))
{
splines[id] = var;
}
else if(boost::iequals(type,"Line Loop"))
{
loops[id] = var;
}
else if(boost::iequals(type,"Plane Surface"))
{
surfs[id] = var;
}
else
{
cout << "not sure " << type << endl;
}
}
map<int,string>::iterator it;
//build points
map<int,gp_Pnt> cPoints;
for(it = points.begin(); it != points.end(); it++)
{
vector<NekDouble> data;
ParseUtils::GenerateUnOrderedVector(it->second.c_str(), data);
cPoints[it->first] = gp_Pnt(data[0]*1000.0,data[1]*1000.0,data[2]*1000.0);
}
//build edges
map<int,TopoDS_Edge> cEdges;
for(it = lines.begin(); it != lines.end(); it++)
{
vector<NekDouble> data;
ParseUtils::GenerateUnOrderedVector(it->second.c_str(), data);
BRepBuilderAPI_MakeEdge em(cPoints[(int)data[0]],cPoints[(int)data[1]]);
cEdges[it->first] = em.Edge();
}
for(it = splines.begin(); it != splines.end(); it++)
{
vector<NekDouble> data;
ParseUtils::GenerateUnOrderedVector(it->second.c_str(), data);
TColgp_Array1OfPnt pointArray(0,data.size()-1);
for(int i = 0; i < data.size(); i++)
{
pointArray.SetValue(i,cPoints[(int)data[i]]);
}
GeomAPI_PointsToBSpline spline(pointArray);
Handle(Geom_BSplineCurve) curve = spline.Curve();
BRepBuilderAPI_MakeEdge em(curve);
cEdges[it->first] = em.Edge();
}
//build wires
map<int,TopoDS_Wire> cWires;
for(it = loops.begin(); it != loops.end(); it++)
{
vector<NekDouble> data;
ParseUtils::GenerateUnOrderedVector(it->second.c_str(), data);
BRepBuilderAPI_MakeWire wm;
for(int i = 0; i < data.size(); i++)
{
wm.Add(cEdges[(int)data[i]]);
}
cWires[it->first] = wm.Wire();
}
//make surface, at this point assuming its 2D (therefore only 1)
//also going to assume that the first loop in the list is the outer domain
ASSERTL0(surfs.size() == 1,"more than 1 surf");
it = surfs.begin();
vector<NekDouble> data;
ParseUtils::GenerateUnOrderedVector(it->second.c_str(), data);
BRepBuilderAPI_MakeFace face(cWires[(int)data[0]], true);
for(int i = 1; i < data.size(); i++)
{
face.Add(cWires[(int)data[i]]);
}
return face.Face();
}
}
}
......@@ -74,6 +74,7 @@ private:
void AddSurf(int i, TopoDS_Shape in, std::vector<EdgeLoop> ein);
TopoDS_Shape BuildNACA(std::string naca);
TopoDS_Shape BuildGeo(std::string geo);
/// OCC master object
TopoDS_Shape shape;
};
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment