Commit 25ec535d authored by Michael Turner's avatar Michael Turner
Browse files

upgrade locuv, much faster

parent 391a369d
......@@ -52,7 +52,7 @@ void CADSurfOCE::Initialise(int i, TopoDS_Shape in)
m_s = BRep_Tool::Surface(TopoDS::Face(in));
if(in.Orientation() == 1)
if (in.Orientation() == 1)
{
m_orient = CADSystem::eBackwards;
}
......@@ -63,20 +63,19 @@ void CADSurfOCE::Initialise(int i, TopoDS_Shape in)
TopLoc_Location mv(transform);
in.Move(mv);
m_occSurface = BRepAdaptor_Surface(TopoDS::Face(in));
m_id = i;
m_occSurface = BRepAdaptor_Surface(TopoDS::Face(in));
m_id = i;
m_bounds = Array<OneD, NekDouble>(4);
BRepTools::UVBounds(TopoDS::Face(in), m_bounds[0], m_bounds[1], m_bounds[2],
m_bounds[3]);
m_sas = new ShapeAnalysis_Surface(m_s);
m_sas->SetDomain(m_bounds[0], m_bounds[1], m_bounds[2], m_bounds[3]);
}
Array<OneD, NekDouble> CADSurfOCE::GetBounds()
{
Array<OneD,NekDouble> b(4);
b[0] = m_occSurface.FirstUParameter();
b[1] = m_occSurface.LastUParameter();
b[2] = m_occSurface.FirstVParameter();
b[3] = m_occSurface.LastVParameter();
return b;
return m_bounds;
}
Array<OneD, NekDouble> CADSurfOCE::locuv(Array<OneD, NekDouble> p)
......@@ -84,66 +83,39 @@ Array<OneD, NekDouble> CADSurfOCE::locuv(Array<OneD, NekDouble> p)
// has to transfer back to mm
gp_Pnt loc(p[0] * 1000.0, p[1] * 1000.0, p[2] * 1000.0);
GeomAPI_ProjectPointOnSurf projection(
loc, m_s, m_occSurface.FirstUParameter(), m_occSurface.LastUParameter(),
m_occSurface.FirstVParameter(), m_occSurface.LastVParameter());
Array<OneD, NekDouble> uvr(2);
if (projection.NbPoints() == 0)
{
// alternative locuv methods
ShapeAnalysis_Surface sas(m_s);
sas.SetDomain(
m_occSurface.FirstUParameter(), m_occSurface.LastUParameter(),
m_occSurface.FirstVParameter(), m_occSurface.LastVParameter());
gp_Pnt2d p2 = sas.ValueOfUV(loc, 1e-3);
uvr[0] = p2.X();
uvr[1] = p2.Y();
gp_Pnt p3 = sas.Value(p2);
ASSERTL0(p3.Distance(loc) < 1e-3, "large locuv distance sas");
}
else
{
Quantity_Parameter ui;
Quantity_Parameter vi;
projection.Parameters(1, ui, vi);
uvr[0] = ui;
uvr[1] = vi;
gp_Pnt2d p2 = m_sas->ValueOfUV(loc, 1e-3);
uvr[0] = p2.X();
uvr[1] = p2.Y();
if (projection.Distance(1) > 1.0)
{
stringstream ss;
cerr << "large locuv distance " << projection.Distance(1) / 1000.0
<< endl;
}
gp_Pnt p3 = m_sas->Value(p2);
if (p3.Distance(loc) > 1.0)
{
cout << "large locuv distance " << p3.Distance(loc) << " " << m_id
<< endl;
}
// if the uv returned is slightly off the surface
//(which ShapeAnalysis_Surface can do sometimes)
if (uvr[0] < m_occSurface.FirstUParameter() ||
uvr[0] > m_occSurface.LastUParameter() ||
uvr[1] < m_occSurface.FirstVParameter() ||
uvr[1] > m_occSurface.LastVParameter())
if (uvr[0] < m_bounds[0] || uvr[0] > m_bounds[1] || uvr[1] < m_bounds[2] ||
uvr[1] > m_bounds[3])
{
if (uvr[0] < m_occSurface.FirstUParameter() )
if (uvr[0] < m_bounds[0])
{
uvr[0] = m_occSurface.FirstUParameter();
uvr[0] = m_bounds[0];
}
else if (uvr[0] > m_occSurface.LastUParameter() )
else if (uvr[0] > m_bounds[1])
{
uvr[0] = m_occSurface.LastUParameter();
uvr[0] = m_bounds[1];
}
else if (uvr[1] < m_occSurface.FirstVParameter())
else if (uvr[1] < m_bounds[2])
{
uvr[1] = m_occSurface.FirstVParameter();
uvr[1] = m_bounds[2];
}
else if (uvr[1] > m_occSurface.LastVParameter() )
else if (uvr[1] > m_bounds[3])
{
uvr[1] = m_occSurface.LastVParameter();
uvr[1] = m_bounds[3];
}
else
{
......@@ -203,9 +175,7 @@ NekDouble CADSurfOCE::DistanceTo(Array<OneD, NekDouble> p)
// alternative locuv methods
ShapeAnalysis_Surface sas(m_s);
sas.SetDomain(m_occSurface.FirstUParameter(), m_occSurface.LastUParameter(),
m_occSurface.FirstVParameter(),
m_occSurface.LastVParameter());
sas.SetDomain(m_bounds[0], m_bounds[1], m_bounds[2], m_bounds[3]);
gp_Pnt2d p2 = sas.ValueOfUV(loc, 1e-7);
......@@ -214,15 +184,14 @@ NekDouble CADSurfOCE::DistanceTo(Array<OneD, NekDouble> p)
return p3.Distance(loc);
}
void CADSurfOCE::ProjectTo(Array<OneD, NekDouble> &tp, Array<OneD, NekDouble> &uv)
void CADSurfOCE::ProjectTo(Array<OneD, NekDouble> &tp,
Array<OneD, NekDouble> &uv)
{
gp_Pnt loc(tp[0] * 1000.0, tp[1] * 1000.0, tp[2] * 1000.0);
// alternative locuv methods
ShapeAnalysis_Surface sas(m_s);
sas.SetDomain(m_occSurface.FirstUParameter(), m_occSurface.LastUParameter(),
m_occSurface.FirstVParameter(),
m_occSurface.LastVParameter());
sas.SetDomain(m_bounds[0], m_bounds[1], m_bounds[2], m_bounds[3]);
gp_Pnt2d p2 = sas.ValueOfUV(loc, 1e-7);
......@@ -258,11 +227,11 @@ Array<OneD, NekDouble> CADSurfOCE::N(Array<OneD, NekDouble> uv)
#endif
BRepLProp_SLProps slp(m_occSurface, 2, 1e-6);
slp.SetParameters(uv[0],uv[1]);
slp.SetParameters(uv[0], uv[1]);
if(!slp.IsNormalDefined())
if (!slp.IsNormalDefined())
{
return Array<OneD, NekDouble>(3,0.0);
return Array<OneD, NekDouble>(3, 0.0);
}
gp_Dir d = slp.Normal();
......@@ -316,21 +285,21 @@ Array<OneD, NekDouble> CADSurfOCE::D2(Array<OneD, NekDouble> uv)
gp_Vec D1U, D1V, D2U, D2V, D2UV;
m_occSurface.D2(uv[0], uv[1], Loc, D1U, D1V, D2U, D2V, D2UV);
r[0] = Loc.X(); // x
r[1] = Loc.Y(); // y
r[2] = Loc.Z(); // z
r[3] = D1U.X(); // dx/dx
r[4] = D1U.Y(); // dy/dy
r[5] = D1U.Z(); // dz/dz
r[6] = D1V.X(); // dx/dx
r[7] = D1V.Y(); // dy/dy
r[8] = D1V.Z(); // dz/dz
r[9] = D2U.X(); // d2x/du2
r[10] = D2U.Y(); // d2y/du2
r[11] = D2U.Z(); // d2z/du2
r[12] = D2V.X(); // d2x/dv2
r[13] = D2V.Y(); // d2y/dv2
r[14] = D2V.Z(); // d2z/dv2
r[0] = Loc.X(); // x
r[1] = Loc.Y(); // y
r[2] = Loc.Z(); // z
r[3] = D1U.X(); // dx/dx
r[4] = D1U.Y(); // dy/dy
r[5] = D1U.Z(); // dz/dz
r[6] = D1V.X(); // dx/dx
r[7] = D1V.Y(); // dy/dy
r[8] = D1V.Z(); // dz/dz
r[9] = D2U.X(); // d2x/du2
r[10] = D2U.Y(); // d2y/du2
r[11] = D2U.Z(); // d2z/du2
r[12] = D2V.X(); // d2x/dv2
r[13] = D2V.Y(); // d2y/dv2
r[14] = D2V.Z(); // d2z/dv2
r[15] = D2UV.X(); // d2x/dudv
r[16] = D2UV.Y(); // d2y/dudv
r[17] = D2UV.Z(); // d2z/dudv
......@@ -346,39 +315,39 @@ void CADSurfOCE::Test(Array<OneD, NekDouble> uv)
bool passed = true;
if (uv[0] < m_occSurface.FirstUParameter())
if (uv[0] < m_bounds[0])
{
if (fabs(uv[0] - m_occSurface.FirstUParameter()) > 1E-6)
if (fabs(uv[0] - m_bounds[0]) > 1E-6)
{
error << "U(" << uv[0] << ") is less than Umin("
<< m_occSurface.FirstUParameter() << ")";
error << "U(" << uv[0] << ") is less than Umin(" << m_bounds[0]
<< ")";
passed = false;
}
}
else if (uv[0] > m_occSurface.LastUParameter())
else if (uv[0] > m_bounds[1])
{
if (fabs(uv[0] - m_occSurface.LastUParameter()) > 1E-6)
if (fabs(uv[0] - m_bounds[1]) > 1E-6)
{
error << "U(" << uv[0] << ") is greater than Umax("
<< m_occSurface.LastUParameter() << ")";
error << "U(" << uv[0] << ") is greater than Umax(" << m_bounds[1]
<< ")";
passed = false;
}
}
else if (uv[1] < m_occSurface.FirstVParameter())
else if (uv[1] < m_bounds[2])
{
if (fabs(uv[1] - m_occSurface.FirstVParameter()) > 1E-6)
if (fabs(uv[1] - m_bounds[2]) > 1E-6)
{
error << "V(" << uv[1] << ") is less than Vmin("
<< m_occSurface.FirstVParameter() << ")";
error << "V(" << uv[1] << ") is less than Vmin(" << m_bounds[2]
<< ")";
passed = false;
}
}
else if (uv[1] > m_occSurface.LastVParameter())
else if (uv[1] > m_bounds[3])
{
if (fabs(uv[1] - m_occSurface.LastVParameter()) > 1E-6)
if (fabs(uv[1] - m_bounds[3]) > 1E-6)
{
error << "V(" << uv[1] << ") is greater than Vmax("
<< m_occSurface.LastVParameter() << ")";
error << "V(" << uv[1] << ") is greater than Vmax(" << m_bounds[3]
<< ")";
passed = false;
}
}
......
......@@ -83,6 +83,10 @@ private:
BRepAdaptor_Surface m_occSurface;
/// Alternate OpenCascade object for surface. Used by reverse lookup.
Handle(Geom_Surface) m_s;
/// parametric bounds
Array<OneD, NekDouble> m_bounds;
/// locuv object (stored because it gets faster with stored information)
ShapeAnalysis_Surface *m_sas;
};
typedef boost::shared_ptr<CADSurf> CADSurfSharedPtr;
......
......@@ -46,7 +46,6 @@
#include <TopTools_IndexedMapOfShape.hxx>
#include <BRepAdaptor_Curve.hxx>
#include <BRepAdaptor_Surface.hxx>
#include <GeomAPI_ProjectPointOnSurf.hxx>
#include <GeomAPI_ProjectPointOnCurve.hxx>
#include <GeomAbs_SurfaceType.hxx>
#include <BRepTools.hxx>
......@@ -73,7 +72,6 @@
#include <Standard_Macro.hxx>
#include <ShapeFix_Face.hxx>
#include <GeomAPI_PointsToBSpline.hxx>
#include <Geom_BSplineCurve.hxx>
#include <TColgp_Array1OfPnt.hxx>
......
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