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 #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->setDim(DARTTypes::ConvVec3(size));
100  }
101  }
102  };
103  }
104 }
105 #endif