Mesh.hh
Go to the documentation of this file.
1 /*
2  * Copyright 2018 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 SDF_MESH_HH_
18 #define SDF_MESH_HH_
19 
20 #include <string>
21 #include <optional>
22 
23 #include <gz/math/Vector3.hh>
24 #include <gz/math/Inertial.hh>
25 #include <gz/math/AxisAlignedBox.hh>
26 #include <gz/utils/ImplPtr.hh>
28 #include <sdf/Element.hh>
29 #include <sdf/Error.hh>
30 #include <sdf/sdf_config.h>
31 
32 namespace sdf
33 {
34  // Inline bracket to help doxygen filtering.
35  inline namespace SDF_VERSION_NAMESPACE {
36  //
37 
38  // Forward declarations.
39  class ParserConfig;
40 
42  enum class MeshOptimization
43  {
45  NONE,
50  };
51 
54  {
57 
64  public: Errors Load(ElementPtr _sdf);
65 
70  public: sdf::ElementPtr Element() const;
71 
74  public: unsigned int MaxConvexHulls() const;
75 
78  public: void SetMaxConvexHulls(unsigned int _maxConvexHulls);
79 
83  public: unsigned int VoxelResolution() const;
84 
88  public: void SetVoxelResolution(unsigned int _voxelResolution);
89 
91  GZ_UTILS_IMPL_PTR(dataPtr)
92  };
93 
97  {
98  public: using AxisAlignedBoxCalculator =
99  std::function<std::optional<gz::math::AxisAlignedBox>(
100  const sdf::Mesh &_sdfMesh)>;
101 
103  public: Mesh();
104 
111  public: Errors Load(ElementPtr _sdf);
112 
120  public: Errors Load(sdf::ElementPtr _sdf, const ParserConfig &_config);
121 
126 
130  public: std::string OptimizationStr() const;
131 
134  public: void SetOptimization(MeshOptimization _optimization);
135 
141  public: bool SetOptimization(const std::string &_optimizationStr);
142 
147 
151  const sdf::ConvexDecomposition &_convexDecomposition);
152 
155  public: std::string Uri() const;
156 
159  public: void SetUri(const std::string &_uri);
160 
163  public: const std::string &FilePath() const;
164 
167  public: void SetFilePath(const std::string &_filePath);
168 
171  public: gz::math::Vector3d Scale() const;
172 
175  public: void SetScale(const gz::math::Vector3d &_scale);
176 
181  public: std::string Submesh() const;
182 
186  public: void SetSubmesh(const std::string &_submesh);
187 
193  public: bool CenterSubmesh() const;
194 
198  public: void SetCenterSubmesh(const bool _center);
199 
208  public: std::optional<gz::math::Inertiald>
210  double _density,
211  const sdf::ElementPtr _autoInertiaParams,
212  const ParserConfig &_config);
213 
219  public: std::optional<gz::math::AxisAlignedBox>
220  AxisAlignedBox(const AxisAlignedBoxCalculator &_aabbCalc) const;
221 
225  public: sdf::ElementPtr Element() const;
226 
232  public: sdf::ElementPtr ToElement() const;
233 
240  public: sdf::ElementPtr ToElement(sdf::Errors &_errors) const;
241 
243  GZ_UTILS_IMPL_PTR(dataPtr)
244  };
245  }
246 }
247 #endif
Convex decomposition.
Definition: Mesh.hh:54
void SetVoxelResolution(unsigned int _voxelResolution)
Set the voxel resolution to use for representing the mesh.
Errors Load(ElementPtr _sdf)
Load the contact based on a element pointer.
void SetMaxConvexHulls(unsigned int _maxConvexHulls)
Set the maximum number of convex hulls that can be generated.
sdf::ElementPtr Element() const
Get a pointer to the SDF element that was used during load.
unsigned int VoxelResolution() const
Get the voxel resolution to use for representing the mesh.
unsigned int MaxConvexHulls() const
Get the maximum number of convex hulls that can be generated.
Mesh represents a mesh shape, and is usually accessed through a Geometry.
Definition: Mesh.hh:97
void SetFilePath(const std::string &_filePath)
Set the path to the file where this element was loaded from.
Errors Load(sdf::ElementPtr _sdf, const ParserConfig &_config)
Load the mesh geometry based on a element pointer.
void SetConvexDecomposition(const sdf::ConvexDecomposition &_convexDecomposition)
Set the associated ConvexDecomposition object.
Errors Load(ElementPtr _sdf)
Load the mesh geometry based on a element pointer.
std::optional< gz::math::AxisAlignedBox > AxisAlignedBox(const AxisAlignedBoxCalculator &_aabbCalc) const
Get the Axis-aligned box for this Mesh.
std::string Submesh() const
A submesh, contained with the mesh at the specified URI, may optionally be specified.
void SetUri(const std::string &_uri)
Set the mesh's URI.
sdf::ElementPtr ToElement() const
Create and return an SDF element filled with data from this mesh.
std::function< std::optional< gz::math::AxisAlignedBox >(const sdf::Mesh &_sdfMesh)> AxisAlignedBoxCalculator
Definition: Mesh.hh:100
bool CenterSubmesh() const
Get whether the submesh should be centered at 0,0,0.
std::optional< gz::math::Inertiald > CalculateInertial(sdf::Errors &_errors, double _density, const sdf::ElementPtr _autoInertiaParams, const ParserConfig &_config)
Calculate and return the Inertial values for the Mesh.
const sdf::ConvexDecomposition * ConvexDecomposition() const
Get the associated ConvexDecomposition object.
sdf::ElementPtr Element() const
Get a pointer to the SDF element that was used during load.
const std::string & FilePath() const
The path to the file where this element was loaded from.
bool SetOptimization(const std::string &_optimizationStr)
Set the mesh optimization method.
void SetSubmesh(const std::string &_submesh)
Set the mesh's submesh.
void SetOptimization(MeshOptimization _optimization)
Set the mesh optimization method.
void SetCenterSubmesh(const bool _center)
Set whether the submesh should be centered.
void SetScale(const gz::math::Vector3d &_scale)
Set the mesh's scale factor.
std::string Uri() const
Get the mesh's URI.
MeshOptimization Optimization() const
Get the mesh's optimization method.
std::string OptimizationStr() const
Get the mesh's optimization method.
sdf::ElementPtr ToElement(sdf::Errors &_errors) const
Create and return an SDF element filled with data from this mesh.
gz::math::Vector3d Scale() const
Get the mesh's scale factor.
This class contains configuration options for the libsdformat parser.
Definition: ParserConfig.hh:121
std::vector< Error > Errors
A vector of Error.
Definition: Types.hh:95
MeshOptimization
Mesh optimization method.
Definition: Mesh.hh:43
std::shared_ptr< Element > ElementPtr
Definition: Element.hh:55
namespace for Simulation Description Format parser
Definition: Actor.hh:35
#define SDFORMAT_VISIBLE
Use to represent "symbol visible" if supported.
Definition: system_util.hh:25