Skip to content

Commit

Permalink
Base: Placement: expose ScLERP to python
Browse files Browse the repository at this point in the history
  • Loading branch information
DeepSOIC authored and wwmayer committed Oct 12, 2019
1 parent 63d0435 commit 23e7083
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 23 deletions.
23 changes: 22 additions & 1 deletion src/Base/PlacementPy.xml
Expand Up @@ -85,14 +85,35 @@ Placement(Base, Axis, Angle) -- define position and rotation
</UserDocu>
</Documentation>
</Methode>
<Methode Name="inverse" Const="true">
<Methode Name="inverse" Const="true">
<Documentation>
<UserDocu>
inverse() -> Placement
compute the inverse placement
</UserDocu>
</Documentation>
</Methode>
<Methode Name="pow" Const="true">
<Documentation>
<UserDocu>
pow(t, shorten = true): raise this placement to real power using ScLERP interpolation.
If 'shorten' is true, ensures rotation quaternion is net positive, to make the path shorter.
Also available as ** operator.
</UserDocu>
</Documentation>
</Methode>
<Methode Name="sclerp" Const="true">
<Documentation>
<UserDocu>
sclerp(t, placement2, shorten = True): interpolate between self and placement2.
Interpolation is a continuous motion along a helical path, made of equal transforms if discretized.
t = 0.0 - return self. t = 1.0 - return placement2. t can also be outside of 0..1 range, for extrapolation.
If quaternions of rotations of the two placements differ in sign, the interpolation will
take a long path. If 'shorten' is true, the signs are harmonized before interpolation, and the
interpolation takes the shorter path.
</UserDocu>
</Documentation>
</Methode>
<Methode Name="isIdentity" Const="true">
<Documentation>
<UserDocu>
Expand Down
57 changes: 35 additions & 22 deletions src/Base/PlacementPyImp.cpp
Expand Up @@ -229,6 +229,29 @@ PyObject* PlacementPy::inverse(PyObject * args)
return new PlacementPy(new Placement(p));
}

PyObject* PlacementPy::pow(PyObject* args)
{
double t;
PyObject* shorten = Py_True;
if (!PyArg_ParseTuple(args, "d|O!", &t, &(PyBool_Type), &shorten))
return nullptr;
Base::Placement ret = getPlacementPtr()->pow(t, PyObject_IsTrue(shorten));
return new PlacementPy(new Placement(ret));
}


PyObject* PlacementPy::sclerp(PyObject* args)
{
PyObject* pyplm2;
double t;
PyObject* shorten = Py_True;
if (!PyArg_ParseTuple(args, "dO!|O!", &t, &(PlacementPy::Type), &pyplm2, &(PyBool_Type), &shorten))
return nullptr;
Base::Placement plm2 = static_cast<Base::PlacementPy*>(pyplm2)->value();
Base::Placement ret = Base::Placement::sclerp(*getPlacementPtr(), plm2, t, PyObject_IsTrue(shorten));
return new PlacementPy(new Placement(ret));
}

PyObject* PlacementPy::isIdentity(PyObject *args)
{
if (!PyArg_ParseTuple(args, ""))
Expand Down Expand Up @@ -342,34 +365,24 @@ PyObject* PlacementPy::number_multiply_handler(PyObject *self, PyObject *other)

PyObject * PlacementPy::number_power_handler (PyObject* self, PyObject* other, PyObject* arg)
{
if (!PyObject_TypeCheck(self, &(PlacementPy::Type)) ||
Py::Object pw(other);
Py::Tuple tup(1);
tup[0] = pw;

#if PY_MAJOR_VERSION < 3
!PyInt_Check(other)
#else
!PyLong_Check(other)
#endif
|| arg != Py_None
)
double pw_v;
if (!PyArg_ParseTuple(tup.ptr(), "d", &pw_v)){
//PyErr_SetString(PyExc_NotImplementedError, "Wrong exponent type (expect float).");
return nullptr;
}
if (!PyObject_TypeCheck(self, &(PlacementPy::Type))
|| arg != Py_None)
{
PyErr_SetString(PyExc_NotImplementedError, "Not implemented");
return 0;
}

auto a = static_cast<PlacementPy*>(self)->value();

long b = Py::Int(other);
if(!b)
return new PlacementPy(Placement());

if(b < 0) {
b = -b;
a.invert();
}
auto res = a;
for(--b;b;--b)
res *= a;
return new PlacementPy(res);
Placement a = static_cast<PlacementPy*>(self)->value();
return new PlacementPy(a.pow(pw_v));
}

PyObject* PlacementPy::number_add_handler(PyObject * /*self*/, PyObject * /*other*/)
Expand Down

0 comments on commit 23e7083

Please sign in to comment.