All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator 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 
31 namespace gazebo
32 {
33  namespace physics
34  {
36  class DARTBoxShape : public BoxShape
37  {
40  public: explicit DARTBoxShape(DARTCollisionPtr _parent)
41  : BoxShape(_parent) {}
42 
44  public: virtual ~DARTBoxShape() {}
45 
46  // Documentation inherited.
47  public: virtual void SetSize(const math::Vector3 &_size)
48  {
49  if (_size.x < 0 || _size.y < 0 || _size.z < 0)
50  {
51  gzerr << "Box shape does not support negative size\n";
52  return;
53  }
54  math::Vector3 size = _size;
55  if (math::equal(size.x, 0.0))
56  {
57  // Warn user, but still create shape with very small value
58  // otherwise later resize operations using setLocalScaling
59  // will not be possible
60  gzwarn << "Setting box shape's x to zero is not supported in DART, "
61  << "using 1e-4.\n";
62  size.x = 1e-4;
63  }
64 
65  if (math::equal(size.y, 0.0))
66  {
67  gzwarn << "Setting box shape's y to zero is not supported in DART, "
68  << "using 1e-4.\n";
69  size.y = 1e-4;
70  }
71 
72  if (math::equal(size.z, 0.0))
73  {
74  gzwarn << "Setting box shape's z to zero is not supported in DART "
75  << "using 1e-4.\n";
76  size.z = 1e-4;
77  }
78 
79  BoxShape::SetSize(size);
80 
81  DARTCollisionPtr dartCollisionParent =
82  boost::dynamic_pointer_cast<DARTCollision>(this->collisionParent);
83 
84  if (dartCollisionParent->GetDARTCollisionShape() == NULL)
85  {
86  dart::dynamics::BodyNode *dtBodyNode =
87  dartCollisionParent->GetDARTBodyNode();
88  dart::dynamics::BoxShape *dtBoxShape =
89  new dart::dynamics::BoxShape(DARTTypes::ConvVec3(size));
90  dtBodyNode->addCollisionShape(dtBoxShape);
91  dartCollisionParent->SetDARTCollisionShape(dtBoxShape);
92  }
93  else
94  {
95  dart::dynamics::BoxShape *dtBoxShape =
96  dynamic_cast<dart::dynamics::BoxShape*>(
97  dartCollisionParent->GetDARTCollisionShape());
98  dtBoxShape->setDim(DARTTypes::ConvVec3(size));
99  }
100  }
101  };
102  }
103 }
104 #endif