shape_volume.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2019 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 #pragma once
19 
20 #include <cmath>
21 #include <exception>
22 #include <memory>
23 #include <string>
24 #include <ignition/math/Pose3.hh>
25 #include <sdf/sdf.hh>
27 
28 namespace buoyancy
29 {
31  enum class ShapeType
32  {
33  None,
34  Box,
35  Sphere,
36  Cylinder
37  };
38 
40  struct ShapeVolume
41  {
43  virtual ~ShapeVolume() = default;
44 
47  static std::unique_ptr<ShapeVolume> makeShape(const sdf::ElementPtr sdf);
48 
50  virtual std::string Display();
51 
57  virtual Volume CalculateVolume(const ignition::math::Pose3d& pose,
58  double fluidLevel) = 0;
59 
62 
64  double volume;
65 
68  double averageLength;
69  };
70  typedef std::unique_ptr<ShapeVolume> ShapeVolumePtr;
71 
73  struct BoxVolume : public ShapeVolume
74  {
79  explicit BoxVolume(double x, double y, double z);
80 
82  std::string Display() override;
83 
84  // Documentation inherited.
85  Volume CalculateVolume(const ignition::math::Pose3d& pose,
86  double fluidLevel) override;
87 
89  double x;
90 
92  double y;
93 
95  double z;
96 
97  private:
100  };
101 
103  struct CylinderVolume : public ShapeVolume
104  {
108  explicit CylinderVolume(double r, double l);
109 
111  std::string Display() override;
112 
113  // Documentation inherited.
114  Volume CalculateVolume(const ignition::math::Pose3d& pose,
115  double fluidLevel) override;
116 
118  double r;
119 
121  double h;
122 
123  private:
126  };
127 
129  struct SphereVolume : public ShapeVolume
130  {
133  explicit SphereVolume(double r);
134 
136  std::string Display() override;
137 
138  // Documentation inherited.
139  Volume CalculateVolume(const ignition::math::Pose3d& pose,
140  double fluidLevel) override;
141 
143  double r;
144  };
145 
147  struct ParseException : public std::exception
148  {
149  ParseException(const char* shape, const char* message)
150  : output_("")
151  {
152  std::stringstream ss;
153  ss << "Parse error for <" << shape << ">: " << message;
154  // cppcheck-suppress useInitializationList
155  this->output_ = ss.str();
156  }
157 
158  const char* what() const throw()
159  {
160  return this->output_.c_str();
161  }
162 
163  private: std::string output_;
164  };
165 }
ShapeType
Type of geometry shape.
Definition: shape_volume.hh:31
Box shape volume.
Definition: shape_volume.hh:73
std::unique_ptr< ShapeVolume > ShapeVolumePtr
Definition: shape_volume.hh:70
TFSIMD_FORCE_INLINE const tfScalar & y() const
double r
Radius of sphere.
Polyhedron polyhedron
Polyhedron defining a cylinder.
double r
Radius of cylinder.
Submerged volume calculation using polyhedron based on: Exact Buoyancy for Polyhedra by Eric Catto...
Polyhedron polyhedron
Polyhedron defining a box.
Definition: shape_volume.hh:99
double x
Length.
Definition: shape_volume.hh:89
double volume
Full volume of object.
Definition: shape_volume.hh:64
double h
Height of cylinder.
Parent shape object for volume objects.
Definition: shape_volume.hh:40
Sphere shape volume.
TFSIMD_FORCE_INLINE const tfScalar & x() const
double y
Width.
Definition: shape_volume.hh:92
TFSIMD_FORCE_INLINE const tfScalar & z() const
double averageLength
Average length of object estimate used for drag torque calculation.
Definition: shape_volume.hh:68
Cylinder shape volume.
ShapeType type
Type of shape.
Definition: shape_volume.hh:61
Represents output volume with centroid.
Custom exception for parsing errors.
ParseException(const char *shape, const char *message)
const char * what() const
double z
Height.
Definition: shape_volume.hh:95


usv_gazebo_plugins
Author(s): Brian Bingham , Carlos Aguero
autogenerated on Thu May 7 2020 03:54:47