Skip to content

Commit

Permalink
problem-on-manifold.hh: add getter for manifold's shared_ptr
Browse files Browse the repository at this point in the history
  • Loading branch information
Benjamin Chrétien committed Nov 20, 2015
1 parent d0bab6c commit 94a713f
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 12 deletions.
Expand Up @@ -52,8 +52,13 @@ namespace roboptim

virtual ~ProblemOnManifold();

/// \brief Get a reference to the global manifold.
/// TODO: deprecate this method (to only keep one getter).
const mnf::Manifold& getManifold() const;

/// \brief Get a shared pointer to the global manifold.
const std::shared_ptr<const mnf::Manifold>& manifold() const;

protected:
/// \brief Global manifold.
std::shared_ptr<const mnf::Manifold> manifold_;
Expand Down
Expand Up @@ -49,5 +49,12 @@ namespace roboptim
{
return *manifold_;
}

template<typename T>
const std::shared_ptr<const mnf::Manifold>&
ProblemOnManifold<T>::manifold() const
{
return manifold_;
}
}
#endif //!ROBOPTIM_CORE_MANIFOLD_MAP_DECORATOR_PROBLEM_ON_MANIFOLD_HXX
26 changes: 14 additions & 12 deletions tests/problem-factory.cc
Expand Up @@ -19,6 +19,7 @@
#include "shared-tests/fixture.hh"

#include <iostream>
#include <memory>

#include <roboptim/core/differentiable-function.hh>

Expand Down Expand Up @@ -218,9 +219,9 @@ BOOST_AUTO_TEST_CASE_TEMPLATE (manifold_factory_test_single_cstr, T, functionTyp
factory.getProblem());
std::cout << "Problem created!!!" << std::endl;

BOOST_CHECK(manifoldProblem->getManifold().representationDim() == 10);
std::cout << manifoldProblem->getManifold().name() << std::endl;
BOOST_CHECK(manifoldProblem->getManifold().name() == "R10");
BOOST_CHECK(manifoldProblem->manifold()->representationDim() == 10);
std::cout << manifoldProblem->manifold()->name() << std::endl;
BOOST_CHECK(manifoldProblem->manifold()->name() == "R10");
}

BOOST_AUTO_TEST_CASE_TEMPLATE (manifold_factory_test, T, functionTypes_t)
Expand Down Expand Up @@ -323,9 +324,9 @@ BOOST_AUTO_TEST_CASE_TEMPLATE (manifold_factory_test, T, functionTypes_t)

std::unique_ptr<roboptim::ProblemOnManifold<T>> manifoldProblem(factory.getProblem());

BOOST_CHECK(manifoldProblem->getManifold().representationDim() == 22 + 42 + 39);
std::cout << manifoldProblem->getManifold().name() << std::endl;
BOOST_CHECK(manifoldProblem->getManifold().name() == "SO3xR10xR3xR39xR42");
BOOST_CHECK(manifoldProblem->manifold()->representationDim() == 22 + 42 + 39);
std::cout << manifoldProblem->manifold()->name() << std::endl;
BOOST_CHECK(manifoldProblem->manifold()->name() == "SO3xR10xR3xR39xR42");

size_t i = 0;

Expand All @@ -338,8 +339,9 @@ BOOST_AUTO_TEST_CASE_TEMPLATE (manifold_factory_test, T, functionTypes_t)
<< std::endl;
}

const mnf::CartesianProduct* globalMnf
= dynamic_cast<const mnf::CartesianProduct*>(&manifoldProblem->getManifold());
std::shared_ptr<const mnf::CartesianProduct> globalMnf
= std::dynamic_pointer_cast<const mnf::CartesianProduct>
(manifoldProblem->manifold());
BOOST_CHECK(!!globalMnf);

size_t globalIdx = 0;
Expand Down Expand Up @@ -408,7 +410,7 @@ BOOST_AUTO_TEST_CASE_TEMPLATE (manifold_factory_no_objective_test, T, functionTy

std::unique_ptr<roboptim::ProblemOnManifold<T>> manifoldProblem(factory.getProblem());

BOOST_CHECK(manifoldProblem->getManifold().representationDim() == 19);
BOOST_CHECK(manifoldProblem->manifold()->representationDim() == 19);
}

BOOST_AUTO_TEST_CASE_TEMPLATE(manifold_problem_factory_no_constraints, T, functionTypes_t)
Expand Down Expand Up @@ -483,17 +485,17 @@ BOOST_AUTO_TEST_CASE_TEMPLATE (sum_on_manifold_test, T, functionTypes_t)

std::unique_ptr<roboptim::ProblemOnManifold<T>> manifoldProblem(factory.getProblem());

manifoldProblem->getManifold().display();
manifoldProblem->manifold()->display();

BOOST_CHECK(manifoldProblem->getManifold().representationDim() == 12 + 39);
BOOST_CHECK(manifoldProblem->manifold()->representationDim() == 12 + 39);

Func fF;
Gunc gF;
Iunc iF;

std::shared_ptr<roboptim::FunctionOnManifold<T>> sum = adder.getFunction(manifoldProblem->getManifold());

Eigen::VectorXd input(manifoldProblem->getManifold().representationDim());
Eigen::VectorXd input(manifoldProblem->manifold()->representationDim());

input = 42 * Eigen::VectorXd::Ones(input.size());

Expand Down

0 comments on commit 94a713f

Please sign in to comment.