Commit d7e16885 authored by Michael Turner's avatar Michael Turner
Browse files

fix comments and splie

parent 368a18f8
......@@ -34,14 +34,14 @@
////////////////////////////////////////////////////////////////////////////////
#include <LibUtilities/BasicUtils/ParseUtils.hpp>
#include <NekMeshUtils/CADSystem/OCE/CADSystemOCE.h>
#include <NekMeshUtils/CADSystem/OCE/CADVertOCE.h>
#include <NekMeshUtils/CADSystem/CADSurf.h>
#include <NekMeshUtils/CADSystem/OCE/CADCurveOCE.h>
#include <NekMeshUtils/CADSystem/OCE/CADSurfOCE.h>
#include <NekMeshUtils/CADSystem/CADSurf.h>
#include <NekMeshUtils/CADSystem/OCE/CADSystemOCE.h>
#include <NekMeshUtils/CADSystem/OCE/CADVertOCE.h>
#include <boost/filesystem.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/filesystem.hpp>
using namespace std;
......@@ -57,11 +57,11 @@ bool CADSystemOCE::LoadCAD()
{
if (m_naca.size() == 0)
{
//not a naca profile behave normally
//could be a geo
string ext = boost::filesystem::extension(m_name);
// not a naca profile behave normally
// could be a geo
string ext = boost::filesystem::extension(m_name);
if(boost::iequals(ext,".geo"))
if (boost::iequals(ext, ".geo"))
{
shape = BuildGeo(m_name);
}
......@@ -208,7 +208,8 @@ bool CADSystemOCE::LoadCAD()
// now we acutally analyse the loops for cad building
for (int j = 1; j <= mapOfWires.Extent(); j++)
{
EdgeLoopSharedPtr edgeloop = boost::shared_ptr<EdgeLoop>(new EdgeLoop);
EdgeLoopSharedPtr edgeloop =
boost::shared_ptr<EdgeLoop>(new EdgeLoop);
TopoDS_Shape wire = mapOfWires.FindKey(j);
......@@ -228,8 +229,8 @@ bool CADSystemOCE::LoadCAD()
BRepAdaptor_Surface(TopoDS::Face(face)).LastVParameter());
gp_Pnt2d p2 = sas.ValueOfUV(gPt, 1e-7);
Array<OneD, NekDouble> cen(2);
cen[0] = p2.X();
cen[1] = p2.Y();
cen[0] = p2.X();
cen[1] = p2.Y();
edgeloop->center = cen;
BRepTools_WireExplorer exp;
......@@ -287,7 +288,7 @@ bool CADSystemOCE::LoadCAD()
for (map<int, vector<int> >::iterator it = adjsurfmap.begin();
it != adjsurfmap.end(); it++)
{
if(!m_2d)
if (!m_2d)
{
ASSERTL0(it->second.size() == 2, "no three curve surfaces");
}
......@@ -351,7 +352,7 @@ Array<OneD, NekDouble> CADSystemOCE::GetBoundingBox()
for (int i = 1; i <= m_curves.size(); i++)
{
CADCurveSharedPtr c = GetCurve(i);
CADCurveSharedPtr c = GetCurve(i);
Array<OneD, NekDouble> ends = c->GetMinMax();
bound[0] = min(bound[0], min(ends[0], ends[3]));
......@@ -374,71 +375,69 @@ TopoDS_Shape CADSystemOCE::BuildNACA(string naca)
ParseUtils::GenerateUnOrderedVector(m_naca.c_str(), data);
ASSERTL0(data.size() == 5, "not a vaild domain");
int n = boost::lexical_cast<int>(naca);
NekDouble T = (n%100) / 100.0;
n/=100;
NekDouble P = (n%10)/10.0;
n/=10;
NekDouble M = (n%10)/100.0;
int n = boost::lexical_cast<int>(naca);
NekDouble T = (n % 100) / 100.0;
n /= 100;
NekDouble P = (n % 10) / 10.0;
n /= 10;
NekDouble M = (n % 10) / 100.0;
int np = 25;
Array<OneD, NekDouble> xc(np);
NekDouble dtheta = M_PI/(np-1);
for(int i = 0; i < np; i++)
NekDouble dtheta = M_PI / (np - 1);
for (int i = 0; i < np; i++)
{
xc[i] = (1.0 - cos(i*dtheta)) / 2.0;
xc[i] = (1.0 - cos(i * dtheta)) / 2.0;
}
Array<OneD, NekDouble> yc(np), dyc(np);
for(int i = 0; i < np; i++)
for (int i = 0; i < np; i++)
{
if(xc[i] < P)
if (xc[i] < P)
{
yc[i] = M / P / P * (2.0 * P * xc[i] - xc[i] * xc[i]);
yc[i] = M / P / P * (2.0 * P * xc[i] - xc[i] * xc[i]);
dyc[i] = 2.0 * M / P / P * (P - xc[i]);
}
else
{
yc[i] = M / (1.0 - P) / (1.0 - P) * (
1.0 - 2.0 * P + 2.0 * P * xc[i] - xc[i] * xc[i]);
yc[i] = M / (1.0 - P) / (1.0 - P) *
(1.0 - 2.0 * P + 2.0 * P * xc[i] - xc[i] * xc[i]);
dyc[i] = 2.0 * M / (1.0 - P) / (1.0 - P) * (P - xc[i]);
}
}
Array<OneD, NekDouble> yt(np);
for(int i = 0; i < np; i++)
for (int i = 0; i < np; i++)
{
yt[i] = T / 0.2 * ( 0.2969 * sqrt(xc[i])
-0.1260 * xc[i]
-0.3516 * xc[i] * xc[i]
+0.2843 * xc[i] * xc[i] * xc[i]
-0.1015 * xc[i] * xc[i] * xc[i] * xc[i]);
yt[i] =
T / 0.2 * (0.2969 * sqrt(xc[i]) - 0.1260 * xc[i] -
0.3516 * xc[i] * xc[i] + 0.2843 * xc[i] * xc[i] * xc[i] -
0.1015 * xc[i] * xc[i] * xc[i] * xc[i]);
}
Array<OneD, NekDouble> x(2*np-1), y(2*np-1);
Array<OneD, NekDouble> x(2 * np - 1), y(2 * np - 1);
int l = 0;
for(int i = np-1; i >= 0; i--, l++)
for (int i = np - 1; i >= 0; i--, l++)
{
NekDouble theta = atan(dyc[i]);
x[l] = xc[i] - yt[i] * sin(theta);
y[l] = yc[i] + yt[i] * cos(theta);
}
for(int i = 1; i < np; i++)
for (int i = 1; i < np; i++)
{
NekDouble theta = atan(dyc[i]);
x[i+np-1] = xc[i] + yt[i] * sin(theta);
y[i+np-1] = yc[i] - yt[i] * cos(theta);
x[i + np - 1] = xc[i] + yt[i] * sin(theta);
y[i + np - 1] = yc[i] - yt[i] * cos(theta);
}
TColgp_Array1OfPnt pointArray(0,2*np-2);
TColgp_Array1OfPnt pointArray(0, 2 * np - 2);
for(int i = 0; i < 2*np-1; i++)
for (int i = 0; i < 2 * np - 1; i++)
{
pointArray.SetValue(i,gp_Pnt(x[i]*1000.0,y[i]*1000.0,0.0));
pointArray.SetValue(i, gp_Pnt(x[i] * 1000.0, y[i] * 1000.0, 0.0));
}
GeomAPI_PointsToBSpline spline(pointArray);
......@@ -447,33 +446,37 @@ TopoDS_Shape CADSystemOCE::BuildNACA(string naca)
BRepBuilderAPI_MakeEdge areoEdgeBuilder(curve);
TopoDS_Edge aeroEdge = areoEdgeBuilder.Edge();
BRepBuilderAPI_MakeEdge aeroTEBuilder(
gp_Pnt(x[0]*1000.0, y[0]*1000.0, 0.0),
gp_Pnt(x[2*np-2]*1000.0, y[2*np-2]*1000.0, 0.0));
gp_Pnt(x[0] * 1000.0, y[0] * 1000.0, 0.0),
gp_Pnt(x[2 * np - 2] * 1000.0, y[2 * np - 2] * 1000.0, 0.0));
TopoDS_Edge TeEdge = aeroTEBuilder.Edge();
BRepBuilderAPI_MakeWire aeroWireBuilder(aeroEdge, TeEdge);
TopoDS_Wire aeroWire = aeroWireBuilder.Wire();
gp_Trsf transform;
gp_Ax1 rotAx(gp_Pnt(500.0,0.0,0.0),gp_Dir(gp_Vec(0.0,0.0,-1.0)));
transform.SetRotation(rotAx, data[4]/180.0*M_PI);
gp_Ax1 rotAx(gp_Pnt(500.0, 0.0, 0.0), gp_Dir(gp_Vec(0.0, 0.0, -1.0)));
transform.SetRotation(rotAx, data[4] / 180.0 * M_PI);
TopLoc_Location mv(transform);
aeroWire.Move(mv);
BRepBuilderAPI_MakeEdge domInlBuilder(gp_Pnt(data[0]*1000.0,data[1]*1000.0,0.0),
gp_Pnt(data[0]*1000.0,data[3]*1000.0,0.0));
BRepBuilderAPI_MakeEdge domInlBuilder(
gp_Pnt(data[0] * 1000.0, data[1] * 1000.0, 0.0),
gp_Pnt(data[0] * 1000.0, data[3] * 1000.0, 0.0));
TopoDS_Edge inlEdge = domInlBuilder.Edge();
BRepBuilderAPI_MakeEdge domTopBuilder(gp_Pnt(data[0]*1000.0,data[3]*1000.0,0.0),
gp_Pnt(data[2]*1000.0,data[3]*1000.0,0.0));
BRepBuilderAPI_MakeEdge domTopBuilder(
gp_Pnt(data[0] * 1000.0, data[3] * 1000.0, 0.0),
gp_Pnt(data[2] * 1000.0, data[3] * 1000.0, 0.0));
TopoDS_Edge topEdge = domTopBuilder.Edge();
BRepBuilderAPI_MakeEdge domOutBuilder(gp_Pnt(data[2]*1000.0,data[3]*1000.0,0.0),
gp_Pnt(data[2]*1000.0,data[1]*1000.0,0.0));
BRepBuilderAPI_MakeEdge domOutBuilder(
gp_Pnt(data[2] * 1000.0, data[3] * 1000.0, 0.0),
gp_Pnt(data[2] * 1000.0, data[1] * 1000.0, 0.0));
TopoDS_Edge outEdge = domOutBuilder.Edge();
BRepBuilderAPI_MakeEdge domBotBuilder(gp_Pnt(data[2]*1000.0,data[1]*1000.0,0.0),
gp_Pnt(data[0]*1000.0,data[1]*1000.0,0.0));
BRepBuilderAPI_MakeEdge domBotBuilder(
gp_Pnt(data[2] * 1000.0, data[1] * 1000.0, 0.0),
gp_Pnt(data[0] * 1000.0, data[1] * 1000.0, 0.0));
TopoDS_Edge botEdge = domBotBuilder.Edge();
BRepBuilderAPI_MakeWire domWireBuilder(inlEdge, topEdge, outEdge, botEdge);
......@@ -490,57 +493,63 @@ 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;
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() )
while (!f.eof())
{
getline( f, fline );
getline(f, fline);
if(fline.size() == 0)
if (fline.size() == 0)
{
continue;
}
if (boost::starts_with(fline, "//"))
{
continue;
}
vector<string> tmp1, tmp2;
boost::split(tmp1,fline,boost::is_any_of("="));
boost::split(tmp1, fline, boost::is_any_of("="));
boost::split(tmp2,tmp1[0],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]," ");
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],";");
boost::erase_all(tmp1[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"))
if (boost::iequals(type, "Point"))
{
points[id] = var;
}
else if(boost::iequals(type,"Line"))
else if (boost::iequals(type, "Line"))
{
lines[id] = var;
}
else if(boost::iequals(type,"Spline"))
else if (boost::iequals(type, "Spline"))
{
splines[id] = var;
}
else if(boost::iequals(type,"Line Loop"))
else if (boost::iequals(type, "Line Loop"))
{
loops[id] = var;
}
else if(boost::iequals(type,"Plane Surface"))
else if (boost::iequals(type, "Plane Surface"))
{
surfs[id] = var;
}
......@@ -550,37 +559,39 @@ TopoDS_Shape CADSystemOCE::BuildGeo(string geo)
}
}
map<int,string>::iterator it;
map<int, string>::iterator it;
//build points
map<int,gp_Pnt> cPoints;
for(it = points.begin(); it != points.end(); 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);
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++)
// 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]]);
BRepBuilderAPI_MakeEdge em(cPoints[(int)data[0]],
cPoints[(int)data[1]]);
cEdges[it->first] = em.Edge();
}
for(it = splines.begin(); it != splines.end(); it++)
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);
TColgp_Array1OfPnt pointArray(0, data.size() - 1);
for(int i = 0; i < data.size(); i++)
for (int i = 0; i < data.size(); i++)
{
pointArray.SetValue(i,cPoints[(int)data[i]]);
pointArray.SetValue(i, cPoints[(int)data[i]]);
}
GeomAPI_PointsToBSpline spline(pointArray);
Handle(Geom_BSplineCurve) curve = spline.Curve();
......@@ -589,34 +600,35 @@ TopoDS_Shape CADSystemOCE::BuildGeo(string geo)
cEdges[it->first] = em.Edge();
}
//build wires
map<int,TopoDS_Wire> cWires;
for(it = loops.begin(); it != loops.end(); it++)
// 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++)
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");
// 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++)
for (int i = 1; i < data.size(); i++)
{
face.Add(cWires[(int)data[i]]);
}
ASSERTL0(face.Error() == BRepBuilderAPI_FaceDone, "build geo failed");
return face.Face();
}
}
}
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