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 
26 namespace gazebo
27 {
28  namespace physics
29  {
32  {
35  public: explicit DARTCylinderShape(CollisionPtr _parent)
36  : CylinderShape(_parent) {}
37 
39  public: virtual ~DARTCylinderShape() {}
40 
41  // Documentation inerited.
42  public: void SetSize(double _radius, double _length)
43  {
44  if (_radius < 0)
45  {
46  gzerr << "Cylinder shape does not support negative radius\n";
47  return;
48  }
49 
50  if (_length < 0)
51  {
52  gzerr << "Cylinder shape does not support negative length\n";
53  return;
54  }
55 
56  if (math::equal(_radius, 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 cylinder shape's radius to zero not supported "
62  << "in DART, using 1e-4.\n";
63  _radius = 1e-4;
64  }
65 
66  if (math::equal(_length, 0.0))
67  {
68  gzwarn << "Setting cylinder shape's length to zero not supported "
69  << "in DART, using 1e-4.\n";
70  _length = 1e-4;
71  }
72 
73  CylinderShape::SetSize(_radius, _length);
74 
75  DARTCollisionPtr dartCollisionParent =
76  boost::dynamic_pointer_cast<DARTCollision>(this->collisionParent);
77 
78  if (dartCollisionParent->GetDARTCollisionShape() == NULL)
79  {
80  dart::dynamics::BodyNode *dtBodyNode =
81  dartCollisionParent->GetDARTBodyNode();
82  dart::dynamics::CylinderShape *dtCylinderShape =
83  new dart::dynamics::CylinderShape(_radius, _length);
84  dtBodyNode->addCollisionShape(dtCylinderShape);
85  dartCollisionParent->SetDARTCollisionShape(dtCylinderShape);
86  }
87  else
88  {
89  dart::dynamics::CylinderShape *dtCylinderShape =
90  dynamic_cast<dart::dynamics::CylinderShape*>(
91  dartCollisionParent->GetDARTCollisionShape());
92  dtCylinderShape->setRadius(_radius);
93  dtCylinderShape->setHeight(_length);
94  }
95  }
96  };
97  }
98 }
99 #endif