Skip to content

Commit

Permalink
Part: [skip ci] add method to project point on surface
Browse files Browse the repository at this point in the history
  • Loading branch information
wwmayer committed Mar 5, 2020
1 parent cda6628 commit 9d311b2
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 1 deletion.
15 changes: 15 additions & 0 deletions src/Mod/Part/App/GeometrySurfacePy.xml
Expand Up @@ -40,6 +40,21 @@ Computes the tangent of parameter (u,v) on this geometry</UserDocu>
Computes the normal of parameter (u,v) on this geometry</UserDocu>
</Documentation>
</Methode>
<Methode Name="projectPoint" Const="true" Keyword="true">
<Documentation>
<UserDocu>
Computes the projection of a point on the surface

projectPoint(Point=Vector,[Method=\"NearestPoint\"])
projectPoint(Vector,\"NearestPoint\") -> Vector
projectPoint(Vector,\"LowerDistance\") -> float
projectPoint(Vector,\"LowerDistanceParameters\") -> tuple of floats (u,v)
projectPoint(Vector,\"Distance\") -> list of floats
projectPoint(Vector,\"Parameters\") -> list of tuples of floats
projectPoint(Vector,\"Point\") -> list of points
</UserDocu>
</Documentation>
</Methode>
<Methode Name="isUmbillic" Const="true">
<Documentation>
<UserDocu>isUmbillic(u,v) -> bool
Expand Down
82 changes: 81 additions & 1 deletion src/Mod/Part/App/GeometrySurfacePyImp.cpp
Expand Up @@ -34,6 +34,7 @@
# include <gp_Quaternion.hxx>
# include <Geom_Geometry.hxx>
# include <Geom_Surface.hxx>
# include <GeomAPI_ProjectPointOnSurf.hxx>
# include <GeomConvert_ApproxSurface.hxx>
# include <GeomLProp_SLProps.hxx>
# include <Precision.hxx>
Expand Down Expand Up @@ -356,7 +357,6 @@ PyObject* GeometrySurfacePy::normal(PyObject *args)
}
}
catch (Standard_Failure& e) {

PyErr_SetString(PartExceptionOCCError, e.GetMessageString());
return 0;
}
Expand All @@ -365,6 +365,86 @@ PyObject* GeometrySurfacePy::normal(PyObject *args)
return 0;
}

PyObject* GeometrySurfacePy::projectPoint(PyObject *args, PyObject* kwds)
{
PyObject* v;
const char* meth = "NearestPoint";
static char *kwlist[] = {"Point", "Method", NULL};
if (!PyArg_ParseTupleAndKeywords(args, kwds, "O!|s", kwlist,
&Base::VectorPy::Type, &v, &meth))
return nullptr;

try {
Base::Vector3d vec = Py::Vector(v, false).toVector();
gp_Pnt pnt(vec.x, vec.y, vec.z);
std::string method = meth;

Handle(Geom_Geometry) geom = getGeometryPtr()->handle();
Handle(Geom_Surface) surf = Handle(Geom_Surface)::DownCast(geom);

GeomAPI_ProjectPointOnSurf proj(pnt, surf);
if (method == "NearestPoint") {
pnt = proj.NearestPoint();
vec.Set(pnt.X(), pnt.Y(), pnt.Z());
return new Base::VectorPy(vec);
}
else if (method == "LowerDistance") {
Py::Float dist(proj.LowerDistance());
return Py::new_reference_to(dist);
}
else if (method == "LowerDistanceParameters") {
Standard_Real u, v;
proj.LowerDistanceParameters(u, v);
Py::Tuple par(2);
par.setItem(0, Py::Float(u));
par.setItem(1, Py::Float(v));
return Py::new_reference_to(par);
}
else if (method == "Distance") {
Standard_Integer num = proj.NbPoints();
Py::List list;
for (Standard_Integer i=1; i <= num; i++) {
list.append(Py::Float(proj.Distance(i)));
}
return Py::new_reference_to(list);
}
else if (method == "Parameters") {
Standard_Integer num = proj.NbPoints();
Py::List list;
for (Standard_Integer i=1; i <= num; i++) {
Standard_Real u, v;
proj.Parameters(i, u, v);
Py::Tuple par(2);
par.setItem(0, Py::Float(u));
par.setItem(1, Py::Float(v));
list.append(par);
}
return Py::new_reference_to(list);
}
else if (method == "Point") {
Standard_Integer num = proj.NbPoints();
Py::List list;
for (Standard_Integer i=1; i <= num; i++) {
gp_Pnt pnt = proj.Point(i);
Base::Vector3d vec(pnt.X(), pnt.Y(), pnt.Z());
list.append(Py::Vector(vec));
}
return Py::new_reference_to(list);
}
else {
PyErr_SetString(PartExceptionOCCError, "Unsupported method");
return nullptr;
}
}
catch (Standard_Failure& e) {
PyErr_SetString(PartExceptionOCCError, e.GetMessageString());
return nullptr;
}

PyErr_SetString(PartExceptionOCCError, "Geometry is not a surface");
return nullptr;
}

PyObject* GeometrySurfacePy::isUmbillic(PyObject *args)
{
try {
Expand Down

0 comments on commit 9d311b2

Please sign in to comment.