ScaledCSpace.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 
27 
28 #include <RobotComponents/interface/components/MotionPlanning/CSpace/ScaledCSpace.h>
29 
30 #include "CSpace.h"
31 
32 namespace armarx
33 {
34  class ScaledCSpace;
35  /**
36  * @brief An ice handle to a ScaledCSpace.
37  */
39 
40  /**
41  * @brief Takes an other cspace and scales its' dimensions.
42  * Can be used when lage translations and rotations are planned at the same time.
43  */
44  class ScaledCSpace : virtual public ScaledCSpaceBase, virtual public CSpaceAdaptor
45  {
46  public:
48 
49  /**
50  * @brief ctor.
51  * @param cspace The cspace to scale.
52  * @param scale The dimensions' scaling factors.
53  */
54  ScaledCSpace(const CSpaceBasePtr& cspace, const Ice::FloatSeq& scale);
55 
56  /**
57  * @return The dimensions' scaling factors.
58  */
59  Ice::FloatSeq
60  getScalingFactors(const ::Ice::Current& = Ice::emptyCurrent) override
61  {
62  return scalingFactors;
63  }
64 
65  /**
66  * @param cfg The configuration.
67  * @return Returns the unscaled version of the configuration.
68  */
69  virtual void unscaleConfig(VectorXf& config) const;
70 
71  virtual void unscalePath(Path& path) const;
72  virtual void unscalePath(PathWithCost& path) const;
73  virtual void unscalePath(VectorXfSeq& nodes) const;
74 
75  virtual void scaleConfig(VectorXf& config) const;
76  virtual void scalePath(Path& path) const;
77 
78  //CSpaceBase
79  /**
80  * @param cfg The configuration to check.
81  * @return Checks whether the given configuration is collision free.
82  */
83  bool isCollisionFree(const ::std::pair<const Ice::Float*, const Ice::Float*>& cfg,
84  const Ice::Current& = Ice::emptyCurrent) override;
85 
86  /**
87  * @brief Initializes the collision check.
88  */
89  void
90  initCollisionTest(const Ice::Current& = Ice::emptyCurrent) override
91  {
92  ARMARX_CHECK_EXPRESSION(static_cast<std::size_t>(originalCSpace->getDimensionality()) ==
93  scalingFactors.size());
94  unscaled.resize(scalingFactors.size());
95  originalCSpace->initCollisionTest();
96  }
97 
98  /**
99  * @return A clone of this object.
100  */
101  CSpaceBasePtr clone(const Ice::Current& = Ice::emptyCurrent) override;
102 
103  /**
104  * @return The cspace's dimensions.
105  */
106  FloatRangeSeq getDimensionsBounds(const Ice::Current& = Ice::emptyCurrent) const override;
107 
108  /**
109  * @return The cspace's dimensionality.
110  */
111  Ice::Long
112  getDimensionality(const Ice::Current& = Ice::emptyCurrent) const override
113  {
114  return scalingFactors.size();
115  }
116 
117  protected:
118  template <class IceBaseClass, class DerivedClass>
120 
121  /**
122  * @brief Default ctor. Used for ice factories.
123  */
124  ScaledCSpace() = default;
125 
126  /**
127  * @brief Unscales the given configuration to a buffer.
128  * @param cfg The scaled configuration.
129  * @param buffer The buffer to fill.
130  */
131  void unscaleToBuffer(const Ice::Float* cfg, VectorXf& buffer) const;
132 
133  private:
134  /**
135  * @brief Buffer for speed up.
136  */
137  VectorXf unscaled;
138  };
139 } // namespace armarx
armarx::ScaledCSpace::unscalePath
virtual void unscalePath(Path &path) const
Definition: ScaledCSpace.cpp:67
armarx::VariantType::Float
const VariantTypeId Float
Definition: Variant.h:919
armarx::CSpace::isCollisionFree
bool isCollisionFree(const ::std::pair< const Ice::Float *, const Ice::Float * > &config, const Ice::Current &=Ice::emptyCurrent) override=0
CSpace.h
FactoryCollectionBase.h
armarx::ScaledCSpace::scalePath
virtual void scalePath(Path &path) const
Definition: ScaledCSpace.cpp:98
armarx::ScaledCSpace::getScalingFactors
Ice::FloatSeq getScalingFactors(const ::Ice::Current &=Ice::emptyCurrent) override
Definition: ScaledCSpace.h:60
armarx::ScaledCSpace::initCollisionTest
void initCollisionTest(const Ice::Current &=Ice::emptyCurrent) override
Initializes the collision check.
Definition: ScaledCSpace.h:90
IceInternal::Handle
Definition: forward_declarations.h:8
armarx::ScaledCSpace::unscaleToBuffer
void unscaleToBuffer(const Ice::Float *cfg, VectorXf &buffer) const
Unscales the given configuration to a buffer.
Definition: ScaledCSpace.cpp:141
armarx::CSpaceAdaptor
Definition: CSpace.h:132
armarx::ScaledCSpace::clone
CSpaceBasePtr clone(const Ice::Current &=Ice::emptyCurrent) override
Definition: ScaledCSpace.cpp:118
armarx::VariantType::Long
const VariantTypeId Long
Definition: Variant.h:918
armarx::ScaledCSpace::getDimensionsBounds
FloatRangeSeq getDimensionsBounds(const Ice::Current &=Ice::emptyCurrent) const override
Definition: ScaledCSpace.cpp:127
armarx::ScaledCSpace
Takes an other cspace and scales its' dimensions.
Definition: ScaledCSpace.h:44
ARMARX_CHECK_EXPRESSION
#define ARMARX_CHECK_EXPRESSION(expression)
This macro evaluates the expression and if it turns out to be false it will throw an ExpressionExcept...
Definition: ExpressionException.h:73
armarx::ScaledCSpace::ScaledCSpace
ScaledCSpace()=default
Default ctor.
armarx::ScaledCSpace::scaleConfig
virtual void scaleConfig(VectorXf &config) const
Definition: ScaledCSpace.cpp:88
armarx::armem::server::ltm::detail::mixin::Path
std::filesystem::path Path
Definition: DiskStorageMixin.h:17
armarx::GenericFactory
Definition: FactoryCollectionBase.h:51
armarx::ScaledCSpace::isCollisionFree
bool isCollisionFree(const ::std::pair< const Ice::Float *, const Ice::Float * > &cfg, const Ice::Current &=Ice::emptyCurrent) override
Definition: ScaledCSpace.cpp:107
armarx::ScaledCSpace::unscaleConfig
virtual void unscaleConfig(VectorXf &config) const
Definition: ScaledCSpace.cpp:60
armarx::ScaledCSpace::getDimensionality
Ice::Long getDimensionality(const Ice::Current &=Ice::emptyCurrent) const override
Definition: ScaledCSpace.h:112
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:27