37#include <BRep_Tool.hxx>
38#include <Geom2d_Curve.hxx>
39#include <GeomAPI_ProjectPointOnSurf.hxx>
56 m_s = BRep_Tool::Surface(TopoDS::Face(in));
64 if (in.Orientation() == TopAbs_REVERSED)
73 m_sas =
new ShapeAnalysis_Surface(m_s);
97 if (
m_sas->Adaptor3d()->GetType() == GeomAbs_Plane)
107 BRepMesh_IncrementalMesh brmsh(
m_shape, 0.005);
115 std::array<NekDouble, 6> ret;
116 B.Get(ret[0], ret[1], ret[2], ret[3], ret[4], ret[5]);
127 BRepMesh_IncrementalMesh brmsh(
m_shape, 0.005 * scale);
132 e =
min(e, 5e-3 * scale);
135 std::array<NekDouble, 6> ret;
136 B.Get(ret[0], ret[1], ret[2], ret[3], ret[4], ret[5]);
149 std::array<NekDouble, 2> uv;
153 gp_Pnt2d p2 =
m_sas->ValueOfUV(loc, Precision::Confusion());
159 BRepBuilderAPI_MakeVertex v(loc);
160 BRepExtrema_DistShapeShape dss(
161 BRepTools::OuterWire(TopoDS::Face(
m_shape)), v.Shape());
163 gp_Pnt np = dss.PointOnShape1(1);
164 p2 =
m_sas->ValueOfUV(np, Precision::Confusion());
170 gp_Pnt p3 =
m_sas->Value(p2);
176 GeomAPI_ProjectPointOnSurf proj(loc, m_s, Precision::Confusion());
178 ASSERTL1(proj.NbPoints() > 0,
"Unable to find a projection!");
179 proj.LowerDistanceParameters(uv[0], uv[1]);
192 std::array<NekDouble, 2> uv;
196 gp_Pnt2d p2 =
m_sas->ValueOfUV(loc, Precision::Confusion());
202 BRepBuilderAPI_MakeVertex v(loc);
203 BRepExtrema_DistShapeShape dss(
204 BRepTools::OuterWire(TopoDS::Face(
m_shape)), v.Shape());
206 gp_Pnt np = dss.PointOnShape1(1);
207 p2 =
m_sas->ValueOfUV(np, Precision::Confusion());
213 gp_Pnt p3 =
m_sas->Value(p2);
219 GeomAPI_ProjectPointOnSurf proj(loc, m_s, Umin, Usup, Vmin, Vsup,
220 Precision::Confusion(),
221 Extrema_ExtAlgo_Grad);
223 ASSERTL1(proj.NbPoints() > 0,
"Unable to find a projection!");
224 proj.LowerDistanceParameters(uv[0], uv[1]);
233#if defined(NEKTAR_DEBUG)
237 GeomLProp_SLProps d(m_s, 2, Precision::Confusion());
238 d.SetParameters(uv[0], uv[1]);
240 if (!d.IsCurvatureDefined())
245 NekDouble d1 = std::abs(d.MaxCurvature());
246 NekDouble d2 = std::abs(d.MinCurvature());
252 std::array<NekDouble, 3> &loc)
254#if defined(NEKTAR_DEBUG)
261 GeomLProp_SLProps d(m_s, 2, Precision::Confusion());
262 d.SetParameters(uv[0], uv[1]);
266 if (!d.IsCurvatureDefined())
271 NekDouble d1 = std::abs(d.MaxCurvature());
272 NekDouble d2 = std::abs(d.MinCurvature());
278 std::array<NekDouble, 2> guess,
285 return locuv(p, dist);
289 gp_Pnt2d p2 =
m_sas->NextValueOfUV(gp_Pnt2d(guess[0], guess[1]), loc,
290 Precision::Confusion());
292 TopAbs_State state =
m_2Dclass->Perform(p2);
294 if (state == TopAbs_OUT)
299 return locuv(p, dist);
302 gp_Pnt p3 =
m_sas->Value(p2);
305 return {p2.X(), p2.Y()};
317 auto oceCurve = std::dynamic_pointer_cast<CADCurveOCE>(curve);
321 const TopoDS_Edge &edge = oceCurve->GetOccEdge();
322 TopoDS_Face face = TopoDS::Face(
m_shape);
328 if (!BRep_Tool::IsClosed(edge, face))
330 Standard_Real first, last;
331 Handle(Geom2d_Curve) pcurve =
332 BRep_Tool::CurveOnSurface(edge, face, first, last);
334 if (!pcurve.IsNull())
336 gp_Pnt2d p = pcurve->Value(t);
337 return {p.X(), p.Y()};
347#if defined(NEKTAR_DEBUG)
357#if defined(NEKTAR_DEBUG)
369#if defined(NEKTAR_DEBUG)
373 GeomLProp_SLProps d(m_s, 2, Precision::Confusion());
374 d.SetParameters(uv[0], uv[1]);
376 std::array<NekDouble, 3> normal = {0.0, 0.0, 0.0};
378 if (!d.IsNormalDefined())
383 gp_Dir n = d.Normal();
399#if defined(NEKTAR_DEBUG)
403 std::array<NekDouble, 9> r;
406 m_s->D1(uv[0], uv[1], Loc, D1U, D1V);
412 r = {l[0], l[1], l[2],
414 dv[0], dv[1], dv[2]};
421#if defined(NEKTAR_DEBUG)
425 std::array<NekDouble, 18> r;
427 gp_Vec D1U, D1V, D2U, D2V, D2UV;
428 m_s->D2(uv[0], uv[1], Loc, D1U, D1V, D2U, D2V, D2UV);
437 r = {l[0], l[1], l[2],
440 duu[0], duu[1], duu[2],
441 dvv[0], dvv[1], dvv[2],
442 duv[0], duv[1], duv[2]};
451 error <<
"Point not within parameter plane: " << endl;
457 if (fabs(uv[0] -
m_bounds[0]) > 1E-6)
459 error <<
"U(" << uv[0] <<
") is less than Umin(" <<
m_bounds[0]
466 if (fabs(uv[0] -
m_bounds[1]) > 1E-6)
468 error <<
"U(" << uv[0] <<
") is greater than Umax(" <<
m_bounds[1]
475 if (fabs(uv[1] -
m_bounds[2]) > 1E-6)
477 error <<
"V(" << uv[1] <<
") is less than Vmin(" <<
m_bounds[2]
484 if (fabs(uv[1] -
m_bounds[3]) > 1E-6)
486 error <<
"V(" << uv[1] <<
") is greater than Vmax(" <<
m_bounds[3]
492 error <<
" On Surface: " <<
GetId();
493 WARNINGL1(passed,
"Warning: " + error.str());
#define WARNINGL1(condition, msg)
#define ASSERTL1(condition, msg)
Assert Level 1 – Debugging which is used whether in FULLDEBUG or DEBUG compilation mode....
A class that defines a transfinite surface defined by four curves.
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, std::string pDesc="")
Register a class with the factory.
CADOrientation::Orientation m_orientation
orientation of the CADObject
int GetId()
Return ID of the CAD object.
virtual std::array< NekDouble, 2 > locuv(std::array< NekDouble, 3 > p, NekDouble &dist)=0
Performs a reverse look up to find u,v and x,y,z. if xyz is off the surface it will return the closes...
bool IsPlanar() override
Is the surface defined by a planar surface (i.e not nurbs and is flat)
void Test(std::array< NekDouble, 2 > uv) override
Function which tests the the value of uv used is within the surface.
Handle(Geom_Surface) m_s
OpenCascade object for surface.
std::array< NekDouble, 2 > locuv(std::array< NekDouble, 3 > p, NekDouble &dist) override
Performs a reverse look up to find u,v and x,y,z. if xyz is off the surface it will return the closes...
NekDouble Curvature(std::array< NekDouble, 2 > uv) override
returns curvature at point uv
TopoDS_Shape m_shape
original shape
std::array< NekDouble, 6 > BoundingBox() override
Returns the bounding box of the surface.
std::array< NekDouble, 4 > m_bounds
parametric bounds
void Initialise(int i, TopoDS_Shape in)
NekDouble CurvatureAndPosition(std::array< NekDouble, 2 > uv, std::array< NekDouble, 3 > &loc) override
std::array< NekDouble, 3 > P(std::array< NekDouble, 2 > uv) override
Get the x,y,z at parametric point u,v.
std::array< NekDouble, 2 > locuvOnCurve(const CADCurveSharedPtr &curve, NekDouble t) override
std::array< NekDouble, 3 > N(std::array< NekDouble, 2 > uv) override
Get the normal vector at parametric point u,v.
std::array< NekDouble, 18 > D2(std::array< NekDouble, 2 > uv) override
Get the set of second derivatives at parametric point u,v.
ShapeAnalysis_Surface * m_sas
locuv object (stored because it gets faster with stored information)
std::array< NekDouble, 9 > D1(std::array< NekDouble, 2 > uv) override
Get the set of first derivatives at parametric point u,v.
static CADSurfSharedPtr create()
bool m_isTransfiniteSurf
True if we're a transfinite surface (used for Geo)
std::array< NekDouble, 2 > locuvFrom(std::array< NekDouble, 3 > p, std::array< NekDouble, 2 > guess, NekDouble &dist) override
Curvature and position at uv together.
std::array< NekDouble, 4 > GetBounds() override
Get the limits of the parametric space for the surface.
BRepTopAdaptor_FClass2d * m_2Dclass
gp_Pnt PntToCAD(const std::array< NekDouble, 3 > &p)
A point on its way into OpenCASCADE.
std::array< NekDouble, 3 > PntFromCAD(const gp_Pnt &p)
A point on its way out of OpenCASCADE.
std::array< NekDouble, 3 > VecFromCAD(const gp_Vec &v)
A vector on its way out of OpenCASCADE.
NekDouble CurvatureFromCAD(NekDouble curvature)
A curvature, one over a length, on its way out of OpenCASCADE.
NekDouble FromCAD(NekDouble length)
A length on its way out of OpenCASCADE.
std::shared_ptr< CADCurve > CADCurveSharedPtr
CADSurfFactory & GetCADSurfFactory()
scalarT< T > min(scalarT< T > lhs, scalarT< T > rhs)
scalarT< T > sqrt(scalarT< T > in)