CSpace.h
Go to the documentation of this file.
1 /*
2  * This file is part of ArmarX.
3  *
4  * Copyright (C) 2011-2016, High Performance Humanoid Technologies (H2T), Karlsruhe Institute of Technology (KIT), all rights reserved.
5  *
6  * ArmarX is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation.
9  *
10  * ArmarX is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  *
18  * @package RobotComponents
19  * @author Raphael Grimm ( raphael dot grimm at kit dot edu )
20  * @date 2015
21  * @copyright http://www.gnu.org/licenses/gpl.txt
22  * GNU General Public License
23  */
24 #pragma once
25 
26 #include <functional>
27 #include <random>
28 
30 
31 #include <RobotComponents/interface/components/MotionPlanning/CSpace/CSpace.h>
32 
33 namespace armarx
34 {
35  class CSpace;
36  /**
37  * @brief An ice handle for a CSpace
38  */
40 
41  /**
42  * @brief Implementation of the slice class \ref CSpaceBase.
43  * This is the base class for all planning cspaces.
44  *
45  * The cspace holds all problem specific data of the planning problem.
46  * These are:
47  * - The cspace's bounds.
48  * - information required for collision checking.
49  *
50  * The class provides a function to check whether a configuration is collision free.
51  */
52  class CSpace : virtual public CSpaceBase
53  {
54  public:
55  /**
56  * @param config The config to check.
57  * @return Whether the given configuration is inside the cspace's bounds.
58  */
59  bool isValidConfiguration(const ::std::pair<const Ice::Float*, const Ice::Float*>& config,
60  const Ice::Current& = Ice::emptyCurrent) const override;
61 
62  //noop functions (can be overwritten in derived classes)
63  /**
64  * @brief Initializes collision checking.
65  * The default implementation is noop.
66  */
67  void
68  initCollisionTest(const Ice::Current& = Ice::emptyCurrent) override
69  {
70  }
71 
72  /**
73  * @param config The config to check.
74  * @return Whether the given configuration is collision free.
75  */
76  bool isCollisionFree(const ::std::pair<const Ice::Float*, const Ice::Float*>& config,
77  const Ice::Current& = Ice::emptyCurrent) override = 0;
78 
79  /**
80  * @return A clone of this object.
81  */
82  CSpaceBasePtr clone(const Ice::Current& = Ice::emptyCurrent) override = 0;
83 
84  /**
85  * @param first The configuration's first element.
86  * @param last The configuration's last element.
87  * @return Whether the given configuration [first,last) is collision free.
88  */
89  virtual bool
90  isCollisionFree(const Ice::Float* first, const Ice::Float* last)
91  {
92  return isCollisionFree(std::make_pair(first, last));
93  }
94 
95  /**
96  * @param config The config to check. (as \ref armarx::VectorXf)
97  * @return Whether the given configuration is inside the cspace's bounds.
98  */
99  virtual bool
100  isValidConfiguration(const VectorXf& config) const
101  {
102  return isValidConfiguration(
103  std::make_pair(config.data(), config.data() + config.size()));
104  }
105 
106  /**
107  * @param config The config to check. (as \ref armarx::VectorXf)
108  * @return Whether the given configuration is collision free.
109  */
110  virtual bool
111  isCollisionFree(const VectorXf& config)
112  {
113  return isCollisionFree(std::make_pair(config.data(), config.data() + config.size()));
114  }
115 
116  /**
117  * @return Whether the cspaces scales some axis internally during planning
118  */
119  virtual bool
121  {
122  return false;
123  }
124  };
125 
126  class CSpaceAdaptor;
127  /**
128  * @brief An ice handle for a CSpace
129  */
131 
132  class CSpaceAdaptor : virtual public CSpace, virtual public CSpaceAdaptorBase
133  {
134  public:
135  CSpaceAdaptor(CSpaceBasePtr originalCSpace) : CSpaceAdaptorBase(originalCSpace)
136  {
137  if (!originalCSpace)
138  {
139  throw std::invalid_argument{"the original cspace can't be null"};
140  }
141  }
142 
143  CSpaceBasePtr
144  getOriginalCSpace(const Ice::Current& = Ice::emptyCurrent) const override
145  {
146  return originalCSpace;
147  }
148 
149  protected:
150  CSpaceAdaptor() = default;
151  };
152 } // namespace armarx
armarx::CSpaceAdaptor::CSpaceAdaptor
CSpaceAdaptor(CSpaceBasePtr originalCSpace)
Definition: CSpace.h:135
armarx::VariantType::Float
const VariantTypeId Float
Definition: Variant.h:919
armarx::CSpace::isValidConfiguration
bool isValidConfiguration(const ::std::pair< const Ice::Float *, const Ice::Float * > &config, const Ice::Current &=Ice::emptyCurrent) const override
Definition: CSpace.cpp:31
armarx::CSpaceAdaptor::CSpaceAdaptor
CSpaceAdaptor()=default
armarx::CSpace::isCollisionFree
bool isCollisionFree(const ::std::pair< const Ice::Float *, const Ice::Float * > &config, const Ice::Current &=Ice::emptyCurrent) override=0
armarx::CSpace::clone
CSpaceBasePtr clone(const Ice::Current &=Ice::emptyCurrent) override=0
armarx::CSpaceAdaptor::getOriginalCSpace
CSpaceBasePtr getOriginalCSpace(const Ice::Current &=Ice::emptyCurrent) const override
Definition: CSpace.h:144
armarx::CSpace::isValidConfiguration
virtual bool isValidConfiguration(const VectorXf &config) const
Definition: CSpace.h:100
armarx::CSpace
Implementation of the slice class CSpaceBase.
Definition: CSpace.h:52
IceInternal::Handle
Definition: forward_declarations.h:8
armarx::CSpace::isCollisionFree
virtual bool isCollisionFree(const Ice::Float *first, const Ice::Float *last)
Definition: CSpace.h:90
armarx::CSpaceAdaptor
Definition: CSpace.h:132
armarx::CSpace::initCollisionTest
void initCollisionTest(const Ice::Current &=Ice::emptyCurrent) override
Initializes collision checking.
Definition: CSpace.h:68
armarx::CSpace::usesInternalScaling
virtual bool usesInternalScaling()
Definition: CSpace.h:120
ExpressionException.h
armarx::CSpace::isCollisionFree
virtual bool isCollisionFree(const VectorXf &config)
Definition: CSpace.h:111
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:27