DARTSphereShape.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2014-2015 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->setSize(Eigen::Vector3d(_radius*2.0,
81  _radius*2.0,
82  _radius*2.0));
83  }
84  }
85  };
86  }
87 }
88 #endif
#define gzwarn
Output a warning message.
Definition: Console.hh:46
#define gzerr
Output an error message.
Definition: Console.hh:49
default namespace for gazebo
bool equal(const T &_a, const T &_b, const T &_epsilon=1e-6)
check if two values are equal, within a tolerance
Definition: Helpers.hh:168
Base class for all DART collisions.
Definition: DARTCollision.hh:34
dart::dynamics::BodyNode * GetDARTBodyNode() const
Get DART body node.
virtual void SetRadius(double _radius)
Set the size.
Definition: DARTSphereShape.hh:42
#define NULL
Definition: CommonTypes.hh:30
virtual ~DARTSphereShape()
Destructor.
Definition: DARTSphereShape.hh:39
DARTSphereShape(DARTCollisionPtr _parent)
Constructor.
Definition: DARTSphereShape.hh:35
boost::shared_ptr< DARTCollision > DARTCollisionPtr
Definition: DARTTypes.hh:45
virtual void SetRadius(double _radius)
Set the size.
#define GAZEBO_VISIBLE
Use to represent "symbol visible" if supported.
Definition: system.hh:48
A DART sphere shape.
Definition: DARTSphereShape.hh:31
Sphere collision shape.
Definition: SphereShape.hh:38