Commit 02d3dc2d authored by Joseph Mirabel's avatar Joseph Mirabel Committed by Joseph Mirabel
Browse files

SteeringMethod and Distance constructors take const Problem& instead of ProblemPtr_t

* This homogenizes the API.
parent fee326ce
...@@ -35,14 +35,14 @@ namespace hpp { ...@@ -35,14 +35,14 @@ namespace hpp {
{ {
public: public:
virtual DistancePtr_t clone () const; virtual DistancePtr_t clone () const;
static ReedsSheppPtr_t create (const ProblemPtr_t& problem); static ReedsSheppPtr_t create (const Problem& problem);
static ReedsSheppPtr_t create (const ProblemPtr_t& problem, static ReedsSheppPtr_t create (const Problem& problem,
const value_type& turningRadius, const value_type& turningRadius,
size_type xyRank, size_type rzRank); size_type xyRank, size_type rzRank);
static ReedsSheppPtr_t createCopy (const ReedsSheppPtr_t& distance); static ReedsSheppPtr_t createCopy (const ReedsSheppPtr_t& distance);
protected: protected:
ReedsShepp (const ProblemPtr_t& problem); ReedsShepp (const Problem& problem);
ReedsShepp (const ProblemPtr_t& problem, ReedsShepp (const Problem& problem,
const value_type& turningRadius, const value_type& turningRadius,
size_type xyRank, size_type rzRank); size_type xyRank, size_type rzRank);
ReedsShepp (const ReedsShepp& distance); ReedsShepp (const ReedsShepp& distance);
......
...@@ -48,9 +48,9 @@ namespace hpp { ...@@ -48,9 +48,9 @@ namespace hpp {
PathProjectorBuilder_t; PathProjectorBuilder_t;
typedef boost::function <ConfigurationShooterPtr_t (const DevicePtr_t&) > typedef boost::function <ConfigurationShooterPtr_t (const DevicePtr_t&) >
ConfigurationShooterBuilder_t; ConfigurationShooterBuilder_t;
typedef boost::function <DistancePtr_t (const ProblemPtr_t&) > typedef boost::function <DistancePtr_t (const Problem&) >
DistanceBuilder_t; DistanceBuilder_t;
typedef boost::function <SteeringMethodPtr_t (const ProblemPtr_t&) > typedef boost::function <SteeringMethodPtr_t (const Problem&) >
SteeringMethodBuilder_t; SteeringMethodBuilder_t;
typedef std::vector<CollisionObjectPtr_t > AffordanceObjects_t; typedef std::vector<CollisionObjectPtr_t > AffordanceObjects_t;
typedef vector3_t AffordanceConfig_t; typedef vector3_t AffordanceConfig_t;
......
...@@ -38,24 +38,13 @@ namespace hpp { ...@@ -38,24 +38,13 @@ namespace hpp {
{ {
public: public:
/// Create instance and return shared pointer /// Create instance and return shared pointer
static SteeringMethodStraightPtr_t create (const ProblemPtr_t& problem) static SteeringMethodStraightPtr_t create (const Problem& problem)
{ {
SteeringMethodStraight* ptr = new SteeringMethodStraight (problem); SteeringMethodStraight* ptr = new SteeringMethodStraight (problem);
SteeringMethodStraightPtr_t shPtr (ptr); SteeringMethodStraightPtr_t shPtr (ptr);
ptr->init (shPtr); ptr->init (shPtr);
return shPtr; return shPtr;
} }
/// Create instance and return shared pointer
static SteeringMethodStraightPtr_t create
(const DevicePtr_t& device, const WeighedDistancePtr_t& distance)
HPP_CORE_DEPRECATED
{
SteeringMethodStraight* ptr = new SteeringMethodStraight (device,
distance);
SteeringMethodStraightPtr_t shPtr (ptr);
ptr->init (shPtr);
return shPtr;
}
/// Copy instance and return shared pointer /// Copy instance and return shared pointer
static SteeringMethodStraightPtr_t createCopy static SteeringMethodStraightPtr_t createCopy
(const SteeringMethodStraightPtr_t& other) (const SteeringMethodStraightPtr_t& other)
...@@ -75,7 +64,7 @@ namespace hpp { ...@@ -75,7 +64,7 @@ namespace hpp {
virtual PathPtr_t impl_compute (ConfigurationIn_t q1, virtual PathPtr_t impl_compute (ConfigurationIn_t q1,
ConfigurationIn_t q2) const ConfigurationIn_t q2) const
{ {
value_type length = (*problem_->distance()) (q1, q2); value_type length = (*problem_.distance()) (q1, q2);
ConstraintSetPtr_t c; ConstraintSetPtr_t c;
if (constraints() && constraints()->configProjector ()) { if (constraints() && constraints()->configProjector ()) {
c = HPP_STATIC_PTR_CAST (ConstraintSet, constraints()->copy ()); c = HPP_STATIC_PTR_CAST (ConstraintSet, constraints()->copy ());
...@@ -84,23 +73,16 @@ namespace hpp { ...@@ -84,23 +73,16 @@ namespace hpp {
c = constraints (); c = constraints ();
} }
PathPtr_t path = StraightPath::create PathPtr_t path = StraightPath::create
(problem_->robot(), q1, q2, length, c); (problem_.robot(), q1, q2, length, c);
return path; return path;
} }
protected: protected:
/// Constructor with robot /// Constructor with robot
/// Weighed distance is created from robot /// Weighed distance is created from robot
SteeringMethodStraight (const ProblemPtr_t& problem) : SteeringMethodStraight (const Problem& problem) :
SteeringMethod (problem), weak_ () SteeringMethod (problem), weak_ ()
{ {
} }
/// Constructor with weighed distance
SteeringMethodStraight (const DevicePtr_t& device,
const WeighedDistancePtr_t& distance) :
SteeringMethod (new Problem (device)), weak_ ()
{
problem_->distance (distance);
}
/// Copy constructor /// Copy constructor
SteeringMethodStraight (const SteeringMethodStraight& other) : SteeringMethodStraight (const SteeringMethodStraight& other) :
SteeringMethod (other), weak_ () SteeringMethod (other), weak_ ()
......
...@@ -75,7 +75,7 @@ namespace hpp { ...@@ -75,7 +75,7 @@ namespace hpp {
protected: protected:
/// Constructor /// Constructor
SteeringMethod (ProblemPtr_t problem) : SteeringMethod (const Problem& problem) :
problem_ (problem), constraints_ (), weak_ () problem_ (problem), constraints_ (), weak_ ()
{ {
} }
...@@ -99,7 +99,7 @@ namespace hpp { ...@@ -99,7 +99,7 @@ namespace hpp {
weak_ = weak; weak_ = weak;
} }
ProblemPtr_t problem_; const Problem& problem_;
private: private:
/// Set of constraints to apply on the paths produced /// Set of constraints to apply on the paths produced
......
...@@ -45,7 +45,7 @@ namespace hpp { ...@@ -45,7 +45,7 @@ namespace hpp {
/// - the 2 following parameters corresponds to the RZ unbounded /// - the 2 following parameters corresponds to the RZ unbounded
/// rotation joint. /// rotation joint.
/// Use ReedsShepp::setWheelJoints to set the wheel joints. /// Use ReedsShepp::setWheelJoints to set the wheel joints.
static ReedsSheppPtr_t createWithGuess (const ProblemPtr_t& problem) static ReedsSheppPtr_t createWithGuess (const Problem& problem)
{ {
ReedsShepp* ptr = new ReedsShepp (problem); ReedsShepp* ptr = new ReedsShepp (problem);
ReedsSheppPtr_t shPtr (ptr); ReedsSheppPtr_t shPtr (ptr);
...@@ -56,7 +56,7 @@ namespace hpp { ...@@ -56,7 +56,7 @@ namespace hpp {
/// Create an instance /// Create an instance
/// ///
/// This constructor does no assumption. /// This constructor does no assumption.
static ReedsSheppPtr_t create (const ProblemPtr_t& problem, static ReedsSheppPtr_t create (const Problem& problem,
const value_type turningRadius, const value_type turningRadius,
size_type xyRank, size_type rzRank, size_type xyRank, size_type rzRank,
std::vector <JointPtr_t> wheels = std::vector<JointPtr_t>()) std::vector <JointPtr_t> wheels = std::vector<JointPtr_t>())
...@@ -108,10 +108,10 @@ namespace hpp { ...@@ -108,10 +108,10 @@ namespace hpp {
protected: protected:
/// Constructor /// Constructor
ReedsShepp (const ProblemPtr_t& problem); ReedsShepp (const Problem& problem);
/// Constructor /// Constructor
ReedsShepp (const ProblemPtr_t& problem, ReedsShepp (const Problem& problem,
const value_type turningRadius, const value_type turningRadius,
size_type xyRank, size_type rzRank, size_type xyRank, size_type rzRank,
std::vector <JointPtr_t> wheels); std::vector <JointPtr_t> wheels);
......
...@@ -33,7 +33,7 @@ namespace hpp { ...@@ -33,7 +33,7 @@ namespace hpp {
class HPP_CORE_DLLAPI WeighedDistance : public Distance { class HPP_CORE_DLLAPI WeighedDistance : public Distance {
public: public:
static WeighedDistancePtr_t createFromProblem static WeighedDistancePtr_t createFromProblem
(const ProblemPtr_t& problem); (const Problem& problem);
static WeighedDistancePtr_t create (const DevicePtr_t& robot); static WeighedDistancePtr_t create (const DevicePtr_t& robot);
static WeighedDistancePtr_t static WeighedDistancePtr_t
createWithWeight (const DevicePtr_t& robot, createWithWeight (const DevicePtr_t& robot,
...@@ -59,7 +59,7 @@ namespace hpp { ...@@ -59,7 +59,7 @@ namespace hpp {
return robot_; return robot_;
} }
protected: protected:
WeighedDistance (const ProblemPtr_t& problem); WeighedDistance (const Problem& problem);
WeighedDistance (const DevicePtr_t& robot); WeighedDistance (const DevicePtr_t& robot);
WeighedDistance (const DevicePtr_t& robot, WeighedDistance (const DevicePtr_t& robot,
const std::vector <value_type>& weights); const std::vector <value_type>& weights);
......
...@@ -28,14 +28,14 @@ namespace hpp { ...@@ -28,14 +28,14 @@ namespace hpp {
return createCopy (weak_.lock ()); return createCopy (weak_.lock ());
} }
ReedsSheppPtr_t ReedsShepp::create (const ProblemPtr_t& problem) ReedsSheppPtr_t ReedsShepp::create (const Problem& problem)
{ {
ReedsShepp* ptr (new ReedsShepp (problem)); ReedsShepp* ptr (new ReedsShepp (problem));
ReedsSheppPtr_t shPtr (ptr); ReedsSheppPtr_t shPtr (ptr);
ptr->init (shPtr); ptr->init (shPtr);
return shPtr; return shPtr;
} }
ReedsSheppPtr_t ReedsShepp::create (const ProblemPtr_t& problem, ReedsSheppPtr_t ReedsShepp::create (const Problem& problem,
const value_type& turningRadius, const value_type& turningRadius,
size_type xyRank, size_type rzRank) size_type xyRank, size_type rzRank)
{ {
...@@ -54,12 +54,12 @@ namespace hpp { ...@@ -54,12 +54,12 @@ namespace hpp {
return shPtr; return shPtr;
} }
ReedsShepp::ReedsShepp (const ProblemPtr_t& problem) : ReedsShepp::ReedsShepp (const Problem& problem) :
Distance (), sm_ (steeringMethod::ReedsShepp::createWithGuess (problem)) Distance (), sm_ (steeringMethod::ReedsShepp::createWithGuess (problem))
{ {
} }
ReedsShepp::ReedsShepp (const ProblemPtr_t& problem, ReedsShepp::ReedsShepp (const Problem& problem,
const value_type& turningRadius, const value_type& turningRadius,
size_type xyRank, size_type rzRank) : size_type xyRank, size_type rzRank) :
Distance (), sm_ (steeringMethod::ReedsShepp::create Distance (), sm_ (steeringMethod::ReedsShepp::create
......
...@@ -161,7 +161,7 @@ namespace hpp { ...@@ -161,7 +161,7 @@ namespace hpp {
add <DistanceBuilder_t> ("WeighedDistance", add <DistanceBuilder_t> ("WeighedDistance",
WeighedDistance::createFromProblem); WeighedDistance::createFromProblem);
add <SteeringMethodBuilder_t> ("SteeringMethodStraight", boost::bind( add <SteeringMethodBuilder_t> ("SteeringMethodStraight", boost::bind(
static_cast<SteeringMethodStraightPtr_t (*)(const ProblemPtr_t&)> static_cast<SteeringMethodStraightPtr_t (*)(const Problem&)>
(&SteeringMethodStraight::create), _1 (&SteeringMethodStraight::create), _1
)); ));
add <SteeringMethodBuilder_t> ("ReedsShepp", steeringMethod::ReedsShepp::createWithGuess); add <SteeringMethodBuilder_t> ("ReedsShepp", steeringMethod::ReedsShepp::createWithGuess);
...@@ -542,7 +542,7 @@ namespace hpp { ...@@ -542,7 +542,7 @@ namespace hpp {
{ {
if (!problem_) throw std::runtime_error ("The problem is not defined."); if (!problem_) throw std::runtime_error ("The problem is not defined.");
DistancePtr_t dist ( DistancePtr_t dist (
get <DistanceBuilder_t> (distanceType_) (problem_) get <DistanceBuilder_t> (distanceType_) (*problem_)
); );
problem_->distance (dist); problem_->distance (dist);
} }
...@@ -552,7 +552,7 @@ namespace hpp { ...@@ -552,7 +552,7 @@ namespace hpp {
{ {
if (!problem_) throw std::runtime_error ("The problem is not defined."); if (!problem_) throw std::runtime_error ("The problem is not defined.");
SteeringMethodPtr_t sm ( SteeringMethodPtr_t sm (
get <SteeringMethodBuilder_t> (steeringMethodType_) (problem_) get <SteeringMethodBuilder_t> (steeringMethodType_) (*problem_)
); );
problem_->steeringMethod (sm); problem_->steeringMethod (sm);
} }
...@@ -568,7 +568,7 @@ namespace hpp { ...@@ -568,7 +568,7 @@ namespace hpp {
// the problem constraints. // the problem constraints.
PathProjectorPtr_t pathProjector_ = PathProjectorPtr_t pathProjector_ =
createProjector (problem_->distance (), createProjector (problem_->distance (),
SteeringMethodStraight::create (problem_), SteeringMethodStraight::create (*problem_),
pathProjectorTolerance_); pathProjectorTolerance_);
problem_->pathProjector (pathProjector_); problem_->pathProjector (pathProjector_);
} }
...@@ -648,7 +648,7 @@ namespace hpp { ...@@ -648,7 +648,7 @@ namespace hpp {
// Create steering method using factory // Create steering method using factory
SteeringMethodPtr_t sm (get <SteeringMethodBuilder_t> SteeringMethodPtr_t sm (get <SteeringMethodBuilder_t>
(steeringMethodType_) (problem_)); (steeringMethodType_) (*problem_));
problem_->steeringMethod (sm); problem_->steeringMethod (sm);
PathPtr_t dp = (*sm) (start, end); PathPtr_t dp = (*sm) (start, end);
if (!dp) { if (!dp) {
......
...@@ -42,7 +42,7 @@ namespace hpp { ...@@ -42,7 +42,7 @@ namespace hpp {
robot_ (robot), robot_ (robot),
distance_ (WeighedDistance::create (robot)), distance_ (WeighedDistance::create (robot)),
initConf_ (), goalConfigurations_ (), target_ (), initConf_ (), goalConfigurations_ (), target_ (),
steeringMethod_ (SteeringMethodStraight::create (this)), steeringMethod_ (SteeringMethodStraight::create (*this)),
configValidations_ (), configValidations_ (),
pathValidation_ (DiscretizedCollisionChecking::create pathValidation_ (DiscretizedCollisionChecking::create
(robot, 0.05)), (robot, 0.05)),
......
...@@ -49,8 +49,8 @@ namespace hpp { ...@@ -49,8 +49,8 @@ namespace hpp {
hppDout (info, "rho_ = " << rho_); hppDout (info, "rho_ = " << rho_);
} }
ReedsShepp::ReedsShepp (const ProblemPtr_t& problem) : ReedsShepp::ReedsShepp (const Problem& problem) :
SteeringMethod (problem), device_ (problem->robot ()), SteeringMethod (problem), device_ (problem.robot ()),
rho_ (1.), xy_ (0), rz_(2), weak_ () rho_ (1.), xy_ (0), rz_(2), weak_ ()
{ {
DevicePtr_t d (device_.lock()); DevicePtr_t d (device_.lock());
...@@ -73,13 +73,13 @@ namespace hpp { ...@@ -73,13 +73,13 @@ namespace hpp {
computeRadius(); computeRadius();
} }
ReedsShepp::ReedsShepp (const ProblemPtr_t& problem, ReedsShepp::ReedsShepp (const Problem& problem,
const value_type turningRadius, const value_type turningRadius,
size_type xyRank, size_type rzRank, size_type xyRank, size_type rzRank,
std::vector <JointPtr_t> wheels) : std::vector <JointPtr_t> wheels) :
SteeringMethod (problem), device_ (problem->robot ()), SteeringMethod (problem), device_ (problem.robot ()),
rho_ (turningRadius), rho_ (turningRadius),
turningJoint_ (problem->robot ()->getJointAtConfigRank (rzRank)), turningJoint_ (problem.robot ()->getJointAtConfigRank (rzRank)),
xy_ (xyRank), xy_ (xyRank),
rz_ (rzRank), rz_ (rzRank),
wheels_ (wheels), weak_ () wheels_ (wheels), weak_ ()
......
...@@ -196,7 +196,7 @@ namespace hpp { ...@@ -196,7 +196,7 @@ namespace hpp {
} }
WeighedDistancePtr_t WeighedDistance::createFromProblem WeighedDistancePtr_t WeighedDistance::createFromProblem
(const ProblemPtr_t& problem) (const Problem& problem)
{ {
WeighedDistance* ptr = new WeighedDistance (problem); WeighedDistance* ptr = new WeighedDistance (problem);
WeighedDistancePtr_t shPtr (ptr); WeighedDistancePtr_t shPtr (ptr);
...@@ -284,8 +284,8 @@ namespace hpp { ...@@ -284,8 +284,8 @@ namespace hpp {
computeWeights (); computeWeights ();
} }
WeighedDistance::WeighedDistance (const ProblemPtr_t& problem) : WeighedDistance::WeighedDistance (const Problem& problem) :
robot_ (problem->robot()), weights_ () robot_ (problem.robot()), weights_ ()
{ {
computeWeights (); computeWeights ();
} }
......
...@@ -110,8 +110,8 @@ BOOST_AUTO_TEST_CASE (Roadmap1) { ...@@ -110,8 +110,8 @@ BOOST_AUTO_TEST_CASE (Roadmap1) {
robot->createGeomData(); robot->createGeomData();
// Create steering method // Create steering method
Problem p = Problem (robot); Problem p (robot);
SteeringMethodStraightPtr_t sm = SteeringMethodStraight::create (&p); SteeringMethodStraightPtr_t sm = SteeringMethodStraight::create (p);
// create roadmap // create roadmap
hpp::core::DistancePtr_t distance (WeighedDistance::createWithWeight hpp::core::DistancePtr_t distance (WeighedDistance::createWithWeight
(robot, boost::assign::list_of (1)(1))); (robot, boost::assign::list_of (1)(1)));
...@@ -356,7 +356,7 @@ BOOST_AUTO_TEST_CASE (nearestNeighbor) { ...@@ -356,7 +356,7 @@ BOOST_AUTO_TEST_CASE (nearestNeighbor) {
// Create steering method // Create steering method
Problem p (robot); Problem p (robot);
SteeringMethodStraightPtr_t sm = SteeringMethodStraight::create (&p); SteeringMethodStraightPtr_t sm = SteeringMethodStraight::create (p);
// create roadmap // create roadmap
hpp::core::DistancePtr_t distance (WeighedDistance::createWithWeight hpp::core::DistancePtr_t distance (WeighedDistance::createWithWeight
(robot, boost::assign::list_of (1)(1))); (robot, boost::assign::list_of (1)(1)));
......
...@@ -64,7 +64,7 @@ BOOST_AUTO_TEST_CASE (continuous_collision_checking) ...@@ -64,7 +64,7 @@ BOOST_AUTO_TEST_CASE (continuous_collision_checking)
ConfigurationShooterPtr_t shooter (BasicConfigurationShooter::create (robot)); ConfigurationShooterPtr_t shooter (BasicConfigurationShooter::create (robot));
// create steering method // create steering method
ProblemPtr_t problem (new Problem (robot)); Problem problem (robot);
SteeringMethodPtr_t sm (SteeringMethodStraight::create (problem)); SteeringMethodPtr_t sm (SteeringMethodStraight::create (problem));
// create path validation objects // create path validation objects
...@@ -154,7 +154,6 @@ BOOST_AUTO_TEST_CASE (continuous_collision_checking) ...@@ -154,7 +154,6 @@ BOOST_AUTO_TEST_CASE (continuous_collision_checking)
} }
} }
// delete problem // delete problem
delete problem;
} }
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment