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