All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DARTSphereShape.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_DARTSPHERESHAPE_HH_
18 #define _GAZEBO_DARTSPHERESHAPE_HH_
19 
24 #include "gazebo/util/system.hh"
25 
26 namespace gazebo
27 {
28  namespace physics
29  {
32  {
35  public: explicit DARTSphereShape(DARTCollisionPtr _parent)
36  : SphereShape(_parent) {}
37 
39  public: virtual ~DARTSphereShape() {}
40 
41  // Documentation inherited.
42  public: virtual void SetRadius(double _radius)
43  {
44  if (_radius < 0)
45  {
46  gzerr << "Sphere shape does not support negative radius.\n";
47  return;
48  }
49  if (math::equal(_radius, 0.0))
50  {
51  // Warn user, but still create shape with very small value
52  // otherwise later resize operations using setLocalScaling
53  // will not be possible
54  gzwarn << "Setting sphere shape's radius to zero is not supported "
55  << "in DART, using 1e-4.\n";
56  _radius = 1e-4;
57  }
58 
59  SphereShape::SetRadius(_radius);
60 
61  DARTCollisionPtr dartCollisionParent =
62  boost::dynamic_pointer_cast<DARTCollision>(this->collisionParent);
63 
64  if (dartCollisionParent->GetDARTCollisionShape() == NULL)
65  {
66  dart::dynamics::BodyNode *dtBodyNode =
67  dartCollisionParent->GetDARTBodyNode();
68  dart::dynamics::EllipsoidShape *dtEllisoidShape =
69  new dart::dynamics::EllipsoidShape(Eigen::Vector3d(_radius*2.0,
70  _radius*2.0,
71  _radius*2.0));
72  dtBodyNode->addCollisionShape(dtEllisoidShape);
73  dartCollisionParent->SetDARTCollisionShape(dtEllisoidShape);
74  }
75  else
76  {
77  dart::dynamics::EllipsoidShape *dtEllipsoidShape =
78  dynamic_cast<dart::dynamics::EllipsoidShape*>(
79  dartCollisionParent->GetDARTCollisionShape());
80  dtEllipsoidShape->setDim(Eigen::Vector3d(_radius*2.0,
81  _radius*2.0,
82  _radius*2.0));
83  }
84  }
85  };
86  }
87 }
88 #endif