+ implement Python interface to discretize wires or edge with given deflection or number of points
git-svn-id: https://free-cad.svn.sourceforge.net/svnroot/free-cad/trunk@5423 e8eeb9e2-ec13-0410-a4a9-efa5cf37419d
This commit is contained in:
parent
2fd3f1634e
commit
1aa7e55e92
|
@ -23,7 +23,7 @@
|
||||||
</Methode>
|
</Methode>
|
||||||
<Methode Name="discretize">
|
<Methode Name="discretize">
|
||||||
<Documentation>
|
<Documentation>
|
||||||
<UserDocu>Discretizes the curve using a given deflection and returns a list of points</UserDocu>
|
<UserDocu>Discretizes the curve using a given deflection or number of points and returns a list of points</UserDocu>
|
||||||
</Documentation>
|
</Documentation>
|
||||||
</Methode>
|
</Methode>
|
||||||
<Methode Name="value">
|
<Methode Name="value">
|
||||||
|
|
|
@ -108,22 +108,33 @@ PyObject* GeometryCurvePy::toShape(PyObject *args)
|
||||||
|
|
||||||
PyObject* GeometryCurvePy::discretize(PyObject *args)
|
PyObject* GeometryCurvePy::discretize(PyObject *args)
|
||||||
{
|
{
|
||||||
double d;
|
PyObject* defl_or_num;
|
||||||
if (!PyArg_ParseTuple(args, "d", &d))
|
if (!PyArg_ParseTuple(args, "O", &defl_or_num))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
try {
|
||||||
Handle_Geom_Geometry g = getGeometryPtr()->handle();
|
Handle_Geom_Geometry g = getGeometryPtr()->handle();
|
||||||
Handle_Geom_Curve c = Handle_Geom_Curve::DownCast(g);
|
Handle_Geom_Curve c = Handle_Geom_Curve::DownCast(g);
|
||||||
try {
|
|
||||||
if (!c.IsNull()) {
|
if (!c.IsNull()) {
|
||||||
GeomAdaptor_Curve curve_adaptator(c);
|
GeomAdaptor_Curve adapt(c);
|
||||||
GCPnts_UniformAbscissa discretizer;
|
GCPnts_UniformAbscissa discretizer;
|
||||||
discretizer.Initialize (curve_adaptator, d);
|
if (PyInt_Check(defl_or_num)) {
|
||||||
|
int num = PyInt_AsLong(defl_or_num);
|
||||||
|
discretizer.Initialize (adapt, num);
|
||||||
|
}
|
||||||
|
else if (PyFloat_Check(defl_or_num)) {
|
||||||
|
double defl = PyFloat_AsDouble(defl_or_num);
|
||||||
|
discretizer.Initialize (adapt, defl);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
PyErr_SetString(PyExc_TypeError, "Either int or float expected");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
if (discretizer.IsDone () && discretizer.NbPoints () > 0) {
|
if (discretizer.IsDone () && discretizer.NbPoints () > 0) {
|
||||||
Py::List points;
|
Py::List points;
|
||||||
int nbPoints = discretizer.NbPoints ();
|
int nbPoints = discretizer.NbPoints ();
|
||||||
for (int i=1; i<=nbPoints; i++) {
|
for (int i=1; i<=nbPoints; i++) {
|
||||||
gp_Pnt p = curve_adaptator.Value (discretizer.Parameter (i));
|
gp_Pnt p = adapt.Value (discretizer.Parameter (i));
|
||||||
points.append(Py::Vector(Base::Vector3d(p.X(),p.Y(),p.Z())));
|
points.append(Py::Vector(Base::Vector3d(p.X(),p.Y(),p.Z())));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -59,6 +59,11 @@
|
||||||
<UserDocu>Set the tolerance for the edge.</UserDocu>
|
<UserDocu>Set the tolerance for the edge.</UserDocu>
|
||||||
</Documentation>
|
</Documentation>
|
||||||
</Methode>
|
</Methode>
|
||||||
|
<Methode Name="discretize">
|
||||||
|
<Documentation>
|
||||||
|
<UserDocu>Discretizes the edge using a given deflection or number of points and returns a list of points</UserDocu>
|
||||||
|
</Documentation>
|
||||||
|
</Methode>
|
||||||
<Attribute Name="Tolerance">
|
<Attribute Name="Tolerance">
|
||||||
<Documentation>
|
<Documentation>
|
||||||
<UserDocu>Set or get the tolerance of the vertex</UserDocu>
|
<UserDocu>Set or get the tolerance of the vertex</UserDocu>
|
||||||
|
|
|
@ -53,6 +53,7 @@
|
||||||
#include <BRepGProp.hxx>
|
#include <BRepGProp.hxx>
|
||||||
#include <GProp_GProps.hxx>
|
#include <GProp_GProps.hxx>
|
||||||
#include <GCPnts_AbscissaPoint.hxx>
|
#include <GCPnts_AbscissaPoint.hxx>
|
||||||
|
#include <GCPnts_UniformAbscissa.hxx>
|
||||||
|
|
||||||
#include <Base/VectorPy.h>
|
#include <Base/VectorPy.h>
|
||||||
#include <Base/GeometryPyCXX.h>
|
#include <Base/GeometryPyCXX.h>
|
||||||
|
@ -396,6 +397,52 @@ PyObject* TopoShapeEdgePy::derivative3At(PyObject *args)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PyObject* TopoShapeEdgePy::discretize(PyObject *args)
|
||||||
|
{
|
||||||
|
PyObject* defl_or_num;
|
||||||
|
if (!PyArg_ParseTuple(args, "O", &defl_or_num))
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
try {
|
||||||
|
BRepAdaptor_Curve adapt(TopoDS::Edge(getTopoShapePtr()->_Shape));
|
||||||
|
GCPnts_UniformAbscissa discretizer;
|
||||||
|
if (PyInt_Check(defl_or_num)) {
|
||||||
|
int num = PyInt_AsLong(defl_or_num);
|
||||||
|
discretizer.Initialize (adapt, num);
|
||||||
|
}
|
||||||
|
else if (PyFloat_Check(defl_or_num)) {
|
||||||
|
double defl = PyFloat_AsDouble(defl_or_num);
|
||||||
|
discretizer.Initialize (adapt, defl);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
PyErr_SetString(PyExc_TypeError, "Either int or float expected");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
if (discretizer.IsDone () && discretizer.NbPoints () > 0) {
|
||||||
|
Py::List points;
|
||||||
|
int nbPoints = discretizer.NbPoints ();
|
||||||
|
for (int i=1; i<=nbPoints; i++) {
|
||||||
|
gp_Pnt p = adapt.Value (discretizer.Parameter (i));
|
||||||
|
points.append(Py::Vector(Base::Vector3d(p.X(),p.Y(),p.Z())));
|
||||||
|
}
|
||||||
|
|
||||||
|
return Py::new_reference_to(points);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
PyErr_SetString(PyExc_Exception, "Descretization of curve failed");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Standard_Failure) {
|
||||||
|
Handle_Standard_Failure e = Standard_Failure::Caught();
|
||||||
|
PyErr_SetString(PyExc_Exception, e->GetMessageString());
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
PyErr_SetString(PyExc_Exception, "Geometry is not a curve");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
PyObject* TopoShapeEdgePy::setTolerance(PyObject *args)
|
PyObject* TopoShapeEdgePy::setTolerance(PyObject *args)
|
||||||
{
|
{
|
||||||
double tol;
|
double tol;
|
||||||
|
|
|
@ -49,6 +49,11 @@
|
||||||
<UserDocu>Approximate B-Spline-curve from this wire</UserDocu>
|
<UserDocu>Approximate B-Spline-curve from this wire</UserDocu>
|
||||||
</Documentation>
|
</Documentation>
|
||||||
</Methode>
|
</Methode>
|
||||||
|
<Methode Name="discretize">
|
||||||
|
<Documentation>
|
||||||
|
<UserDocu>Discretizes the wire using a given deflection or number of points and returns a list of points</UserDocu>
|
||||||
|
</Documentation>
|
||||||
|
</Methode>
|
||||||
<Attribute Name="CenterOfMass" ReadOnly="true">
|
<Attribute Name="CenterOfMass" ReadOnly="true">
|
||||||
<Documentation>
|
<Documentation>
|
||||||
<UserDocu>Returns the center of mass of the current system.
|
<UserDocu>Returns the center of mass of the current system.
|
||||||
|
|
|
@ -37,6 +37,7 @@
|
||||||
|
|
||||||
#include <BRepGProp.hxx>
|
#include <BRepGProp.hxx>
|
||||||
#include <GProp_GProps.hxx>
|
#include <GProp_GProps.hxx>
|
||||||
|
#include <GCPnts_UniformAbscissa.hxx>
|
||||||
|
|
||||||
#include <Base/VectorPy.h>
|
#include <Base/VectorPy.h>
|
||||||
#include <Base/GeometryPyCXX.h>
|
#include <Base/GeometryPyCXX.h>
|
||||||
|
@ -320,6 +321,52 @@ PyObject* TopoShapeWirePy::approximate(PyObject *args)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PyObject* TopoShapeWirePy::discretize(PyObject *args)
|
||||||
|
{
|
||||||
|
PyObject* defl_or_num;
|
||||||
|
if (!PyArg_ParseTuple(args, "O", &defl_or_num))
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
try {
|
||||||
|
BRepAdaptor_CompCurve adapt(TopoDS::Wire(getTopoShapePtr()->_Shape));
|
||||||
|
GCPnts_UniformAbscissa discretizer;
|
||||||
|
if (PyInt_Check(defl_or_num)) {
|
||||||
|
int num = PyInt_AsLong(defl_or_num);
|
||||||
|
discretizer.Initialize (adapt, num);
|
||||||
|
}
|
||||||
|
else if (PyFloat_Check(defl_or_num)) {
|
||||||
|
double defl = PyFloat_AsDouble(defl_or_num);
|
||||||
|
discretizer.Initialize (adapt, defl);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
PyErr_SetString(PyExc_TypeError, "Either int or float expected");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
if (discretizer.IsDone () && discretizer.NbPoints () > 0) {
|
||||||
|
Py::List points;
|
||||||
|
int nbPoints = discretizer.NbPoints ();
|
||||||
|
for (int i=1; i<=nbPoints; i++) {
|
||||||
|
gp_Pnt p = adapt.Value (discretizer.Parameter (i));
|
||||||
|
points.append(Py::Vector(Base::Vector3d(p.X(),p.Y(),p.Z())));
|
||||||
|
}
|
||||||
|
|
||||||
|
return Py::new_reference_to(points);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
PyErr_SetString(PyExc_Exception, "Descretization of wire failed");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Standard_Failure) {
|
||||||
|
Handle_Standard_Failure e = Standard_Failure::Caught();
|
||||||
|
PyErr_SetString(PyExc_Exception, e->GetMessageString());
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
PyErr_SetString(PyExc_Exception, "Geometry is not a curve");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
Py::Object TopoShapeWirePy::getCenterOfMass(void) const
|
Py::Object TopoShapeWirePy::getCenterOfMass(void) const
|
||||||
{
|
{
|
||||||
GProp_GProps props;
|
GProp_GProps props;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user