All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
DARTBoxShape.hh
Go to the documentation of this file.
1 /*
2  * Copyright 2014 Open Source Robotics Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16 */
17 #ifndef _GAZEBO_DARTBOXSHAPE_HH_
18 #define _GAZEBO_DARTBOXSHAPE_HH_
19 
20 #include "gazebo/common/Console.hh"
21 
22 #include "gazebo/math/Vector3.hh"
23 
27 
30 #include "gazebo/util/system.hh"
31 
32 namespace gazebo
33 {
34  namespace physics
35  {
38  {
41  public: explicit DARTBoxShape(DARTCollisionPtr _parent)
42  : BoxShape(_parent) {}
43 
45  public: virtual ~DARTBoxShape() {}
46 
47  // Documentation inherited.
48  public: virtual void SetSize(const math::Vector3 &_size)
49  {
50  if (_size.x < 0 || _size.y < 0 || _size.z < 0)
51  {
52  gzerr << "Box shape does not support negative size\n";
53  return;
54  }
55  math::Vector3 size = _size;
56  if (math::equal(size.x, 0.0))
57  {
58  // Warn user, but still create shape with very small value
59  // otherwise later resize operations using setLocalScaling
60  // will not be possible
61  gzwarn << "Setting box shape's x to zero is not supported in DART, "
62  << "using 1e-4.\n";
63  size.x = 1e-4;
64  }
65 
66  if (math::equal(size.y, 0.0))
67  {
68  gzwarn << "Setting box shape's y to zero is not supported in DART, "
69  << "using 1e-4.\n";
70  size.y = 1e-4;
71  }
72 
73  if (math::equal(size.z, 0.0))
74  {
75  gzwarn << "Setting box shape's z to zero is not supported in DART "
76  << "using 1e-4.\n";
77  size.z = 1e-4;
78  }
79 
80  BoxShape::SetSize(size);
81 
82  DARTCollisionPtr dartCollisionParent =
83  boost::dynamic_pointer_cast<DARTCollision>(this->collisionParent);
84 
85  if (dartCollisionParent->GetDARTCollisionShape() == NULL)
86  {
87  dart::dynamics::BodyNode *dtBodyNode =
88  dartCollisionParent->GetDARTBodyNode();
89  dart::dynamics::BoxShape *dtBoxShape =
90  new dart::dynamics::BoxShape(DARTTypes::ConvVec3(size));
91  dtBodyNode->addCollisionShape(dtBoxShape);
92  dartCollisionParent->SetDARTCollisionShape(dtBoxShape);
93  }
94  else
95  {
96  dart::dynamics::BoxShape *dtBoxShape =
97  dynamic_cast<dart::dynamics::BoxShape*>(
98  dartCollisionParent->GetDARTCollisionShape());
99  dtBoxShape->setSize(DARTTypes::ConvVec3(size));
100  }
101  }
102  };
103  }
104 }
105 #endif
The Vector3 class represents the generic vector containing 3 elements.
Definition: Vector3.hh:43
virtual ~DARTBoxShape()
Destructor.
Definition: DARTBoxShape.hh:45
virtual void SetSize(const math::Vector3 &_size)
Set the size of the box.
Definition: DARTBoxShape.hh:48
virtual void SetSize(const math::Vector3 &_size)
Set the size of the box.
double x
X location.
Definition: Vector3.hh:302
#define gzwarn
Output a warning message.
Definition: Console.hh:44
double z
Z location.
Definition: Vector3.hh:308
#define gzerr
Output an error message.
Definition: Console.hh:47
default namespace for gazebo
bool equal(const T &_a, const T &_b, const T &_epsilon=1e-6)
check if two values are equal, within a tolerance
Definition: Helpers.hh:168
DART wrapper forward declarations and typedefs.
Base class for all DART collisions.
Definition: DARTCollision.hh:34
Box geometry primitive.
Definition: BoxShape.hh:37
DARTBoxShape(DARTCollisionPtr _parent)
Constructor.
Definition: DARTBoxShape.hh:41
dart::dynamics::BodyNode * GetDARTBodyNode() const
Get DART body node.
#define NULL
Definition: CommonTypes.hh:30
static Eigen::Vector3d ConvVec3(const math::Vector3 &_vec3)
Definition: DARTTypes.hh:57
boost::shared_ptr< DARTCollision > DARTCollisionPtr
Definition: DARTTypes.hh:45
DART Box shape.
Definition: DARTBoxShape.hh:37
#define GAZEBO_VISIBLE
Use to represent "symbol visible" if supported.
Definition: system.hh:48
double y
Y location.
Definition: Vector3.hh:305