All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DARTCylinderShape.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 
18 #ifndef _GAZEBO_DARTCYLINDERSHAPE_HH_
19 #define _GAZEBO_DARTCYLINDERSHAPE_HH_
20 
21 #include "gazebo/common/Console.hh"
22 
25 #include "gazebo/util/system.hh"
26 
27 namespace gazebo
28 {
29  namespace physics
30  {
33  {
36  public: explicit DARTCylinderShape(CollisionPtr _parent)
37  : CylinderShape(_parent) {}
38 
40  public: virtual ~DARTCylinderShape() {}
41 
42  // Documentation inerited.
43  public: void SetSize(double _radius, double _length)
44  {
45  if (_radius < 0)
46  {
47  gzerr << "Cylinder shape does not support negative radius\n";
48  return;
49  }
50 
51  if (_length < 0)
52  {
53  gzerr << "Cylinder shape does not support negative length\n";
54  return;
55  }
56 
57  if (math::equal(_radius, 0.0))
58  {
59  // Warn user, but still create shape with very small value
60  // otherwise later resize operations using setLocalScaling
61  // will not be possible
62  gzwarn << "Setting cylinder shape's radius to zero not supported "
63  << "in DART, using 1e-4.\n";
64  _radius = 1e-4;
65  }
66 
67  if (math::equal(_length, 0.0))
68  {
69  gzwarn << "Setting cylinder shape's length to zero not supported "
70  << "in DART, using 1e-4.\n";
71  _length = 1e-4;
72  }
73 
74  CylinderShape::SetSize(_radius, _length);
75 
76  DARTCollisionPtr dartCollisionParent =
77  boost::dynamic_pointer_cast<DARTCollision>(this->collisionParent);
78 
79  if (dartCollisionParent->GetDARTCollisionShape() == NULL)
80  {
81  dart::dynamics::BodyNode *dtBodyNode =
82  dartCollisionParent->GetDARTBodyNode();
83  dart::dynamics::CylinderShape *dtCylinderShape =
84  new dart::dynamics::CylinderShape(_radius, _length);
85  dtBodyNode->addCollisionShape(dtCylinderShape);
86  dartCollisionParent->SetDARTCollisionShape(dtCylinderShape);
87  }
88  else
89  {
90  dart::dynamics::CylinderShape *dtCylinderShape =
91  dynamic_cast<dart::dynamics::CylinderShape*>(
92  dartCollisionParent->GetDARTCollisionShape());
93  dtCylinderShape->setRadius(_radius);
94  dtCylinderShape->setHeight(_length);
95  }
96  }
97  };
98  }
99 }
100 #endif