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 
29 #include <RobotComponents/interface/components/MotionPlanning/CSpace/CSpace.h>
31 
32 namespace armarx
33 {
34  class CSpace;
35  /**
36  * @brief An ice handle for a CSpace
37  */
39 
40  /**
41  * @brief Implementation of the slice class \ref CSpaceBase.
42  * This is the base class for all planning cspaces.
43  *
44  * The cspace holds all problem specific data of the planning problem.
45  * These are:
46  * - The cspace's bounds.
47  * - information required for collision checking.
48  *
49  * The class provides a function to check whether a configuration is collision free.
50  */
51  class CSpace :
52  virtual public CSpaceBase
53  {
54  public:
55 
56 
57 
58  /**
59  * @param config The config to check.
60  * @return Whether the given configuration is inside the cspace's bounds.
61  */
62  bool isValidConfiguration(const ::std::pair<const Ice::Float*, const Ice::Float*>& config, const Ice::Current& = Ice::emptyCurrent) const override;
63 
64  //noop functions (can be overwritten in derived classes)
65  /**
66  * @brief Initializes collision checking.
67  * The default implementation is noop.
68  */
69  void initCollisionTest(const Ice::Current& = Ice::emptyCurrent) override {}
70 
71  /**
72  * @param config The config to check.
73  * @return Whether the given configuration is collision free.
74  */
75  bool isCollisionFree(const ::std::pair<const Ice::Float*, const Ice::Float*>& config, const Ice::Current& = Ice::emptyCurrent) override = 0;
76 
77  /**
78  * @return A clone of this object.
79  */
80  CSpaceBasePtr clone(const Ice::Current& = Ice::emptyCurrent) override = 0;
81 
82  /**
83  * @param first The configuration's first element.
84  * @param last The configuration's last element.
85  * @return Whether the given configuration [first,last) is collision free.
86  */
87  virtual bool isCollisionFree(const Ice::Float* first, const Ice::Float* last)
88  {
89  return isCollisionFree(std::make_pair(first, last));
90  }
91 
92  /**
93  * @param config The config to check. (as \ref armarx::VectorXf)
94  * @return Whether the given configuration is inside the cspace's bounds.
95  */
96  virtual bool isValidConfiguration(const VectorXf& config) const
97  {
98  return isValidConfiguration(std::make_pair(config.data(), config.data() + config.size()));
99  }
100 
101  /**
102  * @param config The config to check. (as \ref armarx::VectorXf)
103  * @return Whether the given configuration is collision free.
104  */
105  virtual bool isCollisionFree(const VectorXf& config)
106  {
107  return isCollisionFree(std::make_pair(config.data(), config.data() + config.size()));
108  }
109 
110  /**
111  * @return Whether the cspaces scales some axis internally during planning
112  */
113  virtual bool usesInternalScaling()
114  {
115  return false;
116  }
117  };
118 
119  class CSpaceAdaptor;
120  /**
121  * @brief An ice handle for a CSpace
122  */
124 
126  virtual public CSpace,
127  virtual public CSpaceAdaptorBase
128  {
129  public:
130  CSpaceAdaptor(CSpaceBasePtr originalCSpace): CSpaceAdaptorBase(originalCSpace)
131  {
132  if (! originalCSpace)
133  {
134  throw std::invalid_argument {"the original cspace can't be null"};
135  }
136  }
137 
138  CSpaceBasePtr getOriginalCSpace(const Ice::Current& = Ice::emptyCurrent) const override
139  {
140  return originalCSpace;
141  }
142  protected:
143  CSpaceAdaptor() = default;
144  };
145 }
armarx::CSpaceAdaptor::CSpaceAdaptor
CSpaceAdaptor(CSpaceBasePtr originalCSpace)
Definition: CSpace.h:130
armarx::VariantType::Float
const VariantTypeId Float
Definition: Variant.h:918
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:30
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:138
armarx::CSpace::isValidConfiguration
virtual bool isValidConfiguration(const VectorXf &config) const
Definition: CSpace.h:96
armarx::CSpace
Implementation of the slice class CSpaceBase.
Definition: CSpace.h:51
IceInternal::Handle
Definition: forward_declarations.h:8
armarx::CSpace::isCollisionFree
virtual bool isCollisionFree(const Ice::Float *first, const Ice::Float *last)
Definition: CSpace.h:87
armarx::CSpaceAdaptor
Definition: CSpace.h:125
armarx::CSpace::initCollisionTest
void initCollisionTest(const Ice::Current &=Ice::emptyCurrent) override
Initializes collision checking.
Definition: CSpace.h:69
armarx::CSpace::usesInternalScaling
virtual bool usesInternalScaling()
Definition: CSpace.h:113
ExpressionException.h
armarx::CSpace::isCollisionFree
virtual bool isCollisionFree(const VectorXf &config)
Definition: CSpace.h:105
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28