RcsPySim
A robot control and simulation library
PPDBoxExtents.cpp
Go to the documentation of this file.
1 /*******************************************************************************
2  Copyright (c) 2020, Fabio Muratore, Honda Research Institute Europe GmbH, and
3  Technical University of Darmstadt.
4  All rights reserved.
5 
6  Redistribution and use in source and binary forms, with or without
7  modification, are permitted provided that the following conditions are met:
8  1. Redistributions of source code must retain the above copyright
9  notice, this list of conditions and the following disclaimer.
10  2. Redistributions in binary form must reproduce the above copyright
11  notice, this list of conditions and the following disclaimer in the
12  documentation and/or other materials provided with the distribution.
13  3. Neither the name of Fabio Muratore, Honda Research Institute Europe GmbH,
14  or Technical University of Darmstadt, nor the names of its contributors may
15  be used to endorse or promote products derived from this software without
16  specific prior written permission.
17 
18  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
19  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21  DISCLAIMED. IN NO EVENT SHALL FABIO MURATORE, HONDA RESEARCH INSTITUTE EUROPE GMBH,
22  OR TECHNICAL UNIVERSITY OF DARMSTADT BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
25  OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
26  IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28  POSSIBILITY OF SUCH DAMAGE.
29 *******************************************************************************/
30 
31 #include "PPDBoxExtents.h"
32 #include "PPDSingleVar.h"
33 
34 #include <Rcs_typedef.h>
35 
36 #include <stdexcept>
37 
38 namespace Rcs
39 {
40 
41 #define DEF_EXTENT_PARAM(name, modflag, var) \
42  addChild(new PPDSingleVar<double>((name), (modflag), [this](BodyParamInfo& bpi) -> double& {return (var);}))
43 
45  unsigned int shapeIdx,
46  const bool includeLength,
47  const bool includeWidth,
48  const bool includeHeight) : shapeIdx(shapeIdx)
49 {
50  // Add the children of type PPDSingleVar
51  if (includeLength) {
52  DEF_EXTENT_PARAM("length", BodyParamInfo::MOD_SHAPE, bpi.body->shape[this->shapeIdx]->extents[0]);
53  }
54  if (includeWidth) {
55  DEF_EXTENT_PARAM("width", BodyParamInfo::MOD_SHAPE, bpi.body->shape[this->shapeIdx]->extents[1]);
56  }
57  if (includeHeight) {
58  DEF_EXTENT_PARAM("height", BodyParamInfo::MOD_SHAPE, bpi.body->shape[this->shapeIdx]->extents[2]);
59  }
60 
61  if (getChildren().empty()) {
62  throw std::invalid_argument("No position specified for PPDBoxExtents!");
63  }
64 }
65 
67 
69 {
70  PPDCompound::init(bpi);
71 
72  if (bpi->body->shape[this->shapeIdx]->type != RCSSHAPE_TYPE::RCSSHAPE_BOX) {
73  throw std::invalid_argument("Using the PPDBoxExtents on a non-box shape!");
74  }
75 }
76 
78 {
79  // Change the shape via the childrens' setValues() method without any other adaption
80  PPDCompound::setValues(inValues);
81 }
82 
83 
84 PPDCubeExtents::PPDCubeExtents(unsigned int shapeIdx) : shapeIdx(shapeIdx)
85 {
86  // Add the children of type PPDSingleVar
87  DEF_EXTENT_PARAM("size", BodyParamInfo::MOD_SHAPE, bpi.body->shape[this->shapeIdx]->extents[0]);
88  DEF_EXTENT_PARAM("size", BodyParamInfo::MOD_SHAPE, bpi.body->shape[this->shapeIdx]->extents[1]);
89  DEF_EXTENT_PARAM("size", BodyParamInfo::MOD_SHAPE, bpi.body->shape[this->shapeIdx]->extents[2]);
90 
91  if (getChildren().empty()) {
92  throw std::invalid_argument("No position specified for PPDBoxExtents!");
93  }
94 }
95 
97 
99 {
100  PPDCompound::init(bpi);
101 
102  if (bpi->body->shape[this->shapeIdx]->type != RCSSHAPE_TYPE::RCSSHAPE_BOX) {
103  throw std::invalid_argument("Using the PPDCubeExtents on a non-box shape!");
104  }
105 }
106 
108 {
109  // Change the shape via the childrens' setValues() method without any other adaption
110  PPDCompound::setValues(inValues);
111 }
112 
113 
114 } /* namespace Rcs */
virtual void setValues(PropertySource *inValues)
RcsBody * body
The body.
Definition: BodyParamInfo.h:64
const std::vector< PhysicsParameterDescriptor * > & getChildren() const
Definition: PPDCompound.cpp:72
virtual void init(BodyParamInfo *bpi)
virtual void init(BodyParamInfo *bodyParamInfo)
Definition: PPDCompound.cpp:64
PPDBoxExtents(unsigned int shapeIdx, bool includeLength, bool includeWidth, bool includeHeight)
virtual void setValues(PropertySource *inValues)
Definition: PPDCompound.cpp:52
virtual void init(BodyParamInfo *bpi)
virtual void setValues(PropertySource *inValues)
PPDCubeExtents(unsigned int shapeIdx)
unsigned int shapeIdx
The shape&#39;s index given the body. THis is given by the order of the shapes in the config xml-file...
Definition: PPDBoxExtents.h:58
#define DEF_EXTENT_PARAM(name, modflag, var)