|
| 1 | +/* |
| 2 | + * Copyright 2024 CogniPilot Foundation |
| 3 | + * Copyright 2024 Open Source Robotics Foundation |
| 4 | + * Copyright 2024 Rudis Laboratories |
| 5 | + * |
| 6 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | + * you may not use this file except in compliance with the License. |
| 8 | + * You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, software |
| 13 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | + * See the License for the specific language governing permissions and |
| 16 | + * limitations under the License. |
| 17 | + * |
| 18 | + */ |
| 19 | +#ifndef SDF_CONE_HH_ |
| 20 | +#define SDF_CONE_HH_ |
| 21 | + |
| 22 | +#include <optional> |
| 23 | + |
| 24 | +#include <gz/math/Cone.hh> |
| 25 | +#include <gz/math/Inertial.hh> |
| 26 | +#include <gz/utils/ImplPtr.hh> |
| 27 | +#include <sdf/Error.hh> |
| 28 | +#include <sdf/Element.hh> |
| 29 | +#include <sdf/sdf_config.h> |
| 30 | + |
| 31 | +namespace sdf |
| 32 | +{ |
| 33 | + // Inline bracket to help doxygen filtering. |
| 34 | + inline namespace SDF_VERSION_NAMESPACE { |
| 35 | + /// \brief Cone represents a cone shape, and is usually accessed |
| 36 | + /// through a Geometry. |
| 37 | + class SDFORMAT_VISIBLE Cone |
| 38 | + { |
| 39 | + /// \brief Constructor |
| 40 | + public: Cone(); |
| 41 | + |
| 42 | + /// \brief Load the cone geometry based on a element pointer. |
| 43 | + /// This is *not* the usual entry point. Typical usage of the SDF DOM is |
| 44 | + /// through the Root object. |
| 45 | + /// \param[in] _sdf The SDF Element pointer |
| 46 | + /// \return Errors, which is a vector of Error objects. Each Error includes |
| 47 | + /// an error code and message. An empty vector indicates no error. |
| 48 | + public: Errors Load(ElementPtr _sdf); |
| 49 | + |
| 50 | + /// \brief Get the cone's radius in meters. |
| 51 | + /// \return The radius of the cone in meters. |
| 52 | + public: double Radius() const; |
| 53 | + |
| 54 | + /// \brief Set the cone's radius in meters. |
| 55 | + /// \param[in] _radius The radius of the cone in meters. |
| 56 | + public: void SetRadius(double _radius); |
| 57 | + |
| 58 | + /// \brief Get the cone's length in meters. |
| 59 | + /// \return The length of the cone in meters. |
| 60 | + public: double Length() const; |
| 61 | + |
| 62 | + /// \brief Set the cone's length in meters. |
| 63 | + /// \param[in] _length The length of the cone in meters. |
| 64 | + public: void SetLength(double _length); |
| 65 | + |
| 66 | + /// \brief Get a pointer to the SDF element that was used during |
| 67 | + /// load. |
| 68 | + /// \return SDF element pointer. The value will be nullptr if Load has |
| 69 | + /// not been called. |
| 70 | + public: sdf::ElementPtr Element() const; |
| 71 | + |
| 72 | + /// \brief Get the Gazebo Math representation of this cone. |
| 73 | + /// \return A const reference to a gz::math::Sphered object. |
| 74 | + public: const gz::math::Coned &Shape() const; |
| 75 | + |
| 76 | + /// \brief Get a mutable Gazebo Math representation of this cone. |
| 77 | + /// \return A reference to a gz::math::Coned object. |
| 78 | + public: gz::math::Coned &Shape(); |
| 79 | + |
| 80 | + /// \brief Calculate and return the Inertial values for the cone. In |
| 81 | + /// order to calculate the inertial properties, the function mutates the |
| 82 | + /// object by updating its material properties. |
| 83 | + /// \param[in] _density Density of the cone in kg/m^3 |
| 84 | + /// \return A std::optional with gz::math::Inertiald object or std::nullopt |
| 85 | + public: std::optional<gz::math::Inertiald> |
| 86 | + CalculateInertial(double _density); |
| 87 | + |
| 88 | + /// \brief Create and return an SDF element filled with data from this |
| 89 | + /// cone. |
| 90 | + /// Note that parameter passing functionality is not captured with this |
| 91 | + /// function. |
| 92 | + /// \return SDF element pointer with updated cone values. |
| 93 | + public: sdf::ElementPtr ToElement() const; |
| 94 | + |
| 95 | + /// \brief Create and return an SDF element filled with data from this |
| 96 | + /// cone. |
| 97 | + /// Note that parameter passing functionality is not captured with this |
| 98 | + /// function. |
| 99 | + /// \param[out] _errors Vector of errors. |
| 100 | + /// \return SDF element pointer with updated cone values. |
| 101 | + public: sdf::ElementPtr ToElement(sdf::Errors &_errors) const; |
| 102 | + |
| 103 | + /// \brief Private data pointer. |
| 104 | + GZ_UTILS_IMPL_PTR(dataPtr) |
| 105 | + }; |
| 106 | + } |
| 107 | +} |
| 108 | +#endif |
0 commit comments