Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions doc/doxygen_xml_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,16 @@ def classDoc(self, name):
class ClassDoc:
def __init__(self, filename):
self.tree = etree.parse(filename)
self.compound = self.tree.find("/compounddef")
self.compound = self.tree.find("./compounddef")
self.classname = self.compound.find("compoundname").text.strip()

@staticmethod
def _getDoc(el):
b = el.find("briefdescription")
d = el.find("detaileddescription")
return etree.tostring(b, method="text").strip(), d.text.strip()
brief = etree.tostring(b, method="text", encoding="unicode").strip()
detailed = d.text.strip() if d.text else ""
return brief, detailed

def _getMember(self, sectionKind, memberDefKind, name):
# return self.compound.xpath ("sectiondef[@kind='" + sectionKind
Expand Down Expand Up @@ -76,14 +78,16 @@ def getClassMethodDoc(self, methodname):
]
else:
args = []
args += [el.text.strip() for el in member.xpath("param/declname")]
args += [el.text.strip() for el in member.xpath("param/declname") if el.text]
for parameters in dd.xpath("para/parameterlist/parameteritem"):
pargs = [
el.text.strip()
for el in parameters.find("parameternamelist").findall("parametername")
if el.text
]
pns = " ".join(pargs)
pd = parameters.find("parameterdescription").find("para").text.strip()
para_el = parameters.find("parameterdescription").find("para")
pd = para_el.text.strip() if para_el is not None and para_el.text else ""
d += "\n:param " + pns + ":" + pd
return b, d, args

Expand Down
8 changes: 6 additions & 2 deletions src/pyhpp/constraints/by-substitution.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
#include <hpp/constraints/solver/by-substitution.hh>
#include <pyhpp/constraints/fwd.hh>

// DocNamespace(hpp::constraints)

using namespace boost::python;

namespace pyhpp {
Expand All @@ -52,15 +54,17 @@ void exposeBySubstitution() {
.value("INFEASIBLE", HierarchicalIterative::INFEASIBLE)
.value("SUCCESS", HierarchicalIterative::SUCCESS);

// DocClass(solver::BySubstitution)
class_<BySubstitution, bases<HierarchicalIterative> >(
"BySubstitution", init<LiegroupSpacePtr_t>())
.def("explicitConstraintSetHasChanged",
&BySubstitution::explicitConstraintSetHasChanged)
&BySubstitution::explicitConstraintSetHasChanged,
DocClassMethod(explicitConstraintSetHasChanged))
.def("solve", &BySubstitution_solve)
.def("explicitConstraintSet",
static_cast<ExplicitConstraintSet& (BySubstitution::*)()>(
&BySubstitution::explicitConstraintSet),
return_internal_reference<>())
return_internal_reference<>(), DocClassMethod(explicitConstraintSet))
.add_property("errorThreshold",
static_cast<value_type (BySubstitution::*)() const>(
&BySubstitution::errorThreshold),
Expand Down
5 changes: 4 additions & 1 deletion src/pyhpp/constraints/explicit-constraint-set.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,20 @@
#include <pyhpp/constraints/fwd.hh>
#include <pyhpp/util.hh>

// DocNamespace(hpp::constraints)

using namespace boost::python;

namespace pyhpp {
namespace constraints {
using namespace hpp::constraints;

void exposeExplicitConstraintSet() {
// DocClass(ExplicitConstraintSet)
class_<ExplicitConstraintSet>("ExplicitConstraintSet",
init<LiegroupSpacePtr_t>())
.def("__str__", &to_str<ExplicitConstraintSet>)
.def("add", &ExplicitConstraintSet::add);
.def("add", &ExplicitConstraintSet::add, DocClassMethod(add));
}
} // namespace constraints
} // namespace pyhpp
21 changes: 16 additions & 5 deletions src/pyhpp/constraints/implicit.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
#include <pyhpp/util.hh>
#include <pyhpp/vector-indexing-suite.hh>

// DocNamespace(hpp::constraints)

using namespace boost::python;

namespace pyhpp {
Expand All @@ -53,13 +55,22 @@ void exposeImplicit() {
.value("EqualToZero", EqualToZero)
.value("Superior", Superior)
.value("Inferior", Inferior);
// DocClass(Implicit)
class_<Implicit, ImplicitPtr_t, boost::noncopyable>("Implicit", no_init)
.def("__init__", make_constructor(&Implicit::create))
.PYHPP_DEFINE_GETTER_SETTER_INTERNAL_REF(Implicit, comparisonType,
const ComparisonTypes_t&)
.PYHPP_DEFINE_METHOD_INTERNAL_REF(Implicit, function)
.def("parameterSize", &Implicit::parameterSize)
.def("rightHandSideSize", &Implicit::rightHandSideSize)
.def("comparisonType",
static_cast<const ComparisonTypes_t& (Implicit::*)() const>(
&Implicit::comparisonType),
return_internal_reference<>())
.def("comparisonType",
static_cast<void (Implicit::*)(const ComparisonTypes_t&)>(
&Implicit::comparisonType))
.def("function", &Implicit::function, return_internal_reference<>(),
DocClassMethod(function))
.def("parameterSize", &Implicit::parameterSize,
DocClassMethod(parameterSize))
.def("rightHandSideSize", &Implicit::rightHandSideSize,
DocClassMethod(rightHandSideSize))
.def("getFunctionOutputSize", &getFunctionOutputSize)
.staticmethod("getFunctionOutputSize");
}
Expand Down
5 changes: 4 additions & 1 deletion src/pyhpp/constraints/iterative-solver.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
#include <pyhpp/constraints/fwd.hh>
#include <pyhpp/util.hh>

// DocNamespace(hpp::constraints)

using namespace boost::python;

namespace pyhpp {
Expand All @@ -48,10 +50,11 @@ void exposeHierarchicalIterativeSolver() {
class_<ComparisonTypes_t>("ComparisonTypes")
.def(vector_indexing_suite<ComparisonTypes_t>());

// DocClass(solver::HierarchicalIterative)
class_<HierarchicalIterative>("HierarchicalIterative",
init<LiegroupSpacePtr_t>())
.def("__str__", &to_str<HierarchicalIterative>)
.def("add", &HierarchicalIterative::add)
.def("add", &HierarchicalIterative::add, DocClassMethod(add))

.add_property(
"errorThreshold",
Expand Down
37 changes: 26 additions & 11 deletions src/pyhpp/core/constraint.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
#include <pyhpp/core/fwd.hh>
#include <pyhpp/util.hh>

// DocNamespace(hpp::core)

using namespace boost::python;

namespace pyhpp {
Expand Down Expand Up @@ -85,41 +87,54 @@ static void setRightHandSideOfConstraint(
}

void exposeConstraint() {
// DocClass(Constraint)
class_<Constraint, ConstraintPtr_t, boost::noncopyable>("Constraint", no_init)
.def("__str__", &to_str_from_operator<Constraint>)
.PYHPP_DEFINE_METHOD_INTERNAL_REF(Constraint, name)
.PYHPP_DEFINE_METHOD(CWrapper, apply)
.def("name", &Constraint::name, return_internal_reference<>(),
DocClassMethod(name))
.def("apply", &CWrapper::apply)
.def("isSatisfied", &CWrapper::isSatisfied1)
.def("isSatisfied", &CWrapper::isSatisfied2)
.PYHPP_DEFINE_METHOD(CWrapper, copy);
.def("copy", &CWrapper::copy);

// DocClass(ConstraintSet)
class_<ConstraintSet, ConstraintSetPtr_t, boost::noncopyable,
bases<Constraint> >("ConstraintSet", no_init)
.def("__init__", make_constructor(&createConstraintSet))
.PYHPP_DEFINE_METHOD(ConstraintSet, addConstraint)
.PYHPP_DEFINE_METHOD(ConstraintSet, configProjector);
.def("addConstraint", &ConstraintSet::addConstraint,
DocClassMethod(addConstraint))
.def("configProjector", &ConstraintSet::configProjector,
DocClassMethod(configProjector));

// DocClass(ConfigProjector)
class_<ConfigProjector, ConfigProjectorPtr_t, boost::noncopyable,
bases<Constraint> >("ConfigProjector", no_init)
.def("__init__", make_constructor(&createConfigProjector))
.def("solver",
static_cast<BySubstitution& (ConfigProjector::*)()>(
&ConfigProjector::solver),
return_internal_reference<>())
.def("add", &ConfigProjector::add)
.PYHPP_DEFINE_GETTER_SETTER(ConfigProjector, lastIsOptional, bool)
.PYHPP_DEFINE_GETTER_SETTER(ConfigProjector, maxIterations, size_type)
return_internal_reference<>(), DocClassMethod(solver))
.def("add", &ConfigProjector::add, DocClassMethod(add))
.def("lastIsOptional", static_cast<bool (ConfigProjector::*)() const>(
&ConfigProjector::lastIsOptional))
.def("lastIsOptional", static_cast<void (ConfigProjector::*)(bool)>(
&ConfigProjector::lastIsOptional))
.def("maxIterations", static_cast<size_type (ConfigProjector::*)() const>(
&ConfigProjector::maxIterations))
.def("maxIterations", static_cast<void (ConfigProjector::*)(size_type)>(
&ConfigProjector::maxIterations))
.def("errorThreshold",
static_cast<void (ConfigProjector::*)(const value_type&)>(
&ConfigProjector::errorThreshold))
.def("errorThreshold",
static_cast<value_type (ConfigProjector::*)() const>(
&ConfigProjector::errorThreshold))
.PYHPP_DEFINE_METHOD(ConfigProjector, residualError)
.def("residualError", &ConfigProjector::residualError,
DocClassMethod(residualError))
.def("setRightHandSideFromConfig", &rightHandSideFromConfig)
.def("setRightHandSideOfConstraint", &setRightHandSideOfConstraint)
.def("sigma", &ConfigProjector::sigma,
return_value_policy<return_by_value>());
return_value_policy<return_by_value>(), DocClassMethod(sigma));
}
} // namespace core
} // namespace pyhpp
21 changes: 13 additions & 8 deletions src/pyhpp/core/node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
#include <pyhpp/core/fwd.hh>
#include <pyhpp/util.hh>

// DocNamespace(hpp::core)

using namespace boost::python;

namespace pyhpp {
Expand All @@ -42,23 +44,26 @@ namespace core {
using namespace hpp::core;

void exposeNode() {
// DocClass(Node)
class_<Node, boost::shared_ptr<Node>, boost::noncopyable>("Node", no_init)
.def(init<ConfigurationIn_t>())
.def(init<ConfigurationIn_t, ConnectedComponentPtr_t>())
.PYHPP_DEFINE_METHOD(Node, addOutEdge)
.PYHPP_DEFINE_METHOD(Node, addInEdge)
.def("addOutEdge", &Node::addOutEdge, DocClassMethod(addOutEdge))
.def("addInEdge", &Node::addInEdge, DocClassMethod(addInEdge))
.def("connectedComponent",
static_cast<ConnectedComponentPtr_t (Node::*)() const>(
&Node::connectedComponent))
.def("connectedComponent",
static_cast<void (Node::*)(const ConnectedComponentPtr_t&)>(
&Node::connectedComponent))
.PYHPP_DEFINE_METHOD_INTERNAL_REF(Node, outEdges)
.PYHPP_DEFINE_METHOD_INTERNAL_REF(Node, inEdges)
.PYHPP_DEFINE_METHOD(Node, isOutNeighbor)
.PYHPP_DEFINE_METHOD(Node, isInNeighbor)
.PYHPP_DEFINE_METHOD_INTERNAL_REF(Node, configuration)
.PYHPP_DEFINE_METHOD_INTERNAL_REF(Node, print);
.def("outEdges", &Node::outEdges, return_internal_reference<>(),
DocClassMethod(outEdges))
.def("inEdges", &Node::inEdges, return_internal_reference<>(),
DocClassMethod(inEdges))
.def("isOutNeighbor", &Node::isOutNeighbor, DocClassMethod(isOutNeighbor))
.def("isInNeighbor", &Node::isInNeighbor, DocClassMethod(isInNeighbor))
.def("configuration", &Node::configuration, return_internal_reference<>(),
DocClassMethod(configuration));
}
} // namespace core
} // namespace pyhpp
32 changes: 19 additions & 13 deletions src/pyhpp/core/path.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
#include <pyhpp/core/fwd.hh>
#include <pyhpp/util.hh>

// DocNamespace(hpp::core)

using namespace boost::python;

namespace pyhpp {
Expand Down Expand Up @@ -141,33 +143,37 @@ struct PathWrap : PathWrapper, wrapper<PathWrapper> {
};

void exposePath() {
// DocClass(Path)
class_<Path, hpp::shared_ptr<Path>, boost::noncopyable>("Path", no_init)
.def("__str__", &to_str_from_operator<Path>)

.def("__call__", &PathWrap::py_call1)
.def("__call__", &PathWrap::py_call2)
.def("eval", &PathWrap::py_call1)
.def("eval", &PathWrap::py_call2)
.PYHPP_DEFINE_METHOD(PathWrap, derivative)
.def("derivative", &PathWrap::derivative)

.def("copy", static_cast<PathPtr_t (Path::*)() const>(&Path::copy))
.def("copy", static_cast<PathPtr_t (Path::*)() const>(&Path::copy),
DocClassMethod(copy))
.def("extract",
static_cast<PathPtr_t (Path::*)(const value_type&, const value_type&)
const>(&Path::extract))
const>(&Path::extract),
DocClassMethod(extract))
.def("extract", static_cast<PathPtr_t (Path::*)(const interval_t&) const>(
&Path::extract))
// .PYHPP_DEFINE_METHOD (Path, timeRange)
.def("timeRange",
static_cast<const interval_t& (Path::*)() const>(&Path::timeRange),
return_internal_reference<>())
.def("reverse", &Path::reverse)
.PYHPP_DEFINE_METHOD_INTERNAL_REF(Path, paramRange)
.PYHPP_DEFINE_METHOD(Path, length)
.PYHPP_DEFINE_METHOD(Path, initial)
.PYHPP_DEFINE_METHOD(Path, end)
.PYHPP_DEFINE_METHOD(PathWrap, constraints)
.PYHPP_DEFINE_METHOD(Path, outputSize)
.PYHPP_DEFINE_METHOD(Path, outputDerivativeSize);
return_internal_reference<>(), DocClassMethod(timeRange))
.def("reverse", &Path::reverse, DocClassMethod(reverse))
.def("paramRange", &Path::paramRange, return_internal_reference<>(),
DocClassMethod(paramRange))
.def("length", &Path::length, DocClassMethod(length))
.def("initial", &Path::initial, DocClassMethod(initial))
.def("end", &Path::end, DocClassMethod(end))
.def("constraints", &PathWrap::constraints)
.def("outputSize", &Path::outputSize, DocClassMethod(outputSize))
.def("outputDerivativeSize", &Path::outputDerivativeSize,
DocClassMethod(outputDerivativeSize));

class_<PathWrap, bases<Path>, hpp::shared_ptr<PathWrap>, boost::noncopyable>(
"PathWrap", no_init)
Expand Down
35 changes: 34 additions & 1 deletion src/pyhpp/core/path/vector.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,13 @@

#include <boost/python.hpp>
#include <boost/python/suite/indexing/vector_indexing_suite.hpp>
#include <fstream>
#include <hpp/core/path-vector.hh>
#include <hpp/python/config.hh>
#include <hpp/util/serialization.hh>
#include <pyhpp/core/path/fwd.hh>
#include <pyhpp/util.hh>
#include <stdexcept>

using namespace boost::python;

Expand All @@ -41,6 +44,31 @@ namespace core {
namespace path {
using namespace hpp::core;

void savePathVector(PathVectorPtr_t pathVector, const std::string& filename) {
if (!pathVector) {
throw std::invalid_argument("Cannot save null PathVector");
}
std::ofstream ofs(filename, std::ios::binary);
if (!ofs.is_open()) {
throw std::runtime_error("Failed to open file for writing: " + filename);
}
hpp::serialization::binary_oarchive ar(ofs);
ar.initialize();
ar << hpp::serialization::make_nvp("pathVector", pathVector);
}

PathVectorPtr_t loadPathVector(const std::string& filename) {
std::ifstream ifs(filename, std::ios::binary);
if (!ifs.is_open()) {
throw std::runtime_error("Failed to open file for reading: " + filename);
}
hpp::serialization::binary_iarchive ar(ifs);
ar.initialize();
PathVectorPtr_t pathVector;
ar >> hpp::serialization::make_nvp("pathVector", pathVector);
return pathVector;
}

void exposeVector() {
class_<PathVector, PathVectorPtr_t, bases<Path>, boost::noncopyable>("Vector",
no_init)
Expand All @@ -52,7 +80,12 @@ void exposeVector() {
.PYHPP_DEFINE_METHOD(PathVector, rankAtParam)
.PYHPP_DEFINE_METHOD(PathVector, appendPath)
.PYHPP_DEFINE_METHOD(PathVector, concatenate)
.PYHPP_DEFINE_METHOD(PathVector, flatten);
.PYHPP_DEFINE_METHOD(PathVector, flatten)

// Serialization methods (binary format)
.def("save", &savePathVector, "Save PathVector to file (binary format)")
.def("load", &loadPathVector, "Load PathVector from file (binary format)")
.staticmethod("load");

class_<PathVectors_t>("Vectors").def(
vector_indexing_suite<PathVectors_t, true>());
Expand Down
Loading