Gazebo Common

API Reference

4.9.0
gz/common/MeshManager.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2016 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 IGNITION_COMMON_MESHMANAGER_HH_
18 #define IGNITION_COMMON_MESHMANAGER_HH_
19 
20 #include <map>
21 #include <utility>
22 #include <string>
23 #include <vector>
24 #include <memory>
25 
26 #include <gz/math/Plane.hh>
27 #include <gz/math/Matrix3.hh>
28 #include <gz/math/Matrix4.hh>
29 #include <gz/math/Vector2.hh>
30 #include <gz/math/Vector3.hh>
31 #include <gz/math/Pose3.hh>
32 
33 #include <ignition/utils/ImplPtr.hh>
34 
35 #include <gz/common/config.hh>
37 #include <gz/common/SingletonT.hh>
38 #include <gz/common/graphics/Export.hh>
39 
40 namespace ignition
41 {
42  namespace common
43  {
45  class Mesh;
46  class SubMesh;
47 
50  class IGNITION_COMMON_GRAPHICS_VISIBLE MeshManager
51  : public SingletonT<MeshManager>
52  {
54  private: MeshManager();
55 
59  private: virtual ~MeshManager();
60 
64  public: static MeshManager* Instance();
65 
71  public: const Mesh *Load(const std::string &_filename);
72 
79  public: void Export(const Mesh *_mesh, const std::string &_filename,
80  const std::string &_extension, bool _exportTextures = false);
81 
84  public: bool IsValidFilename(const std::string &_filename);
85 
91  public: void MeshAABB(const Mesh *_mesh,
92  ignition::math::Vector3d &_center,
93  ignition::math::Vector3d &_min_xyz,
94  ignition::math::Vector3d &_max_xyz);
95 
99  public: void GenSphericalTexCoord(const Mesh *_mesh,
100  const ignition::math::Vector3d &_center);
101 
111  public: void AddMesh(Mesh *_mesh);
112 
117  public: bool RemoveMesh(const std::string &_name);
118 
120  public: void RemoveAll();
121 
126  const std::string &_name) const;
127 
130  public: bool HasMesh(const std::string &_name) const;
131 
137  public: common::Mesh *CreateMesh(const std::string &_name);
138 
144  public: void CreateSphere(const std::string &_name, const float _radius,
145  const int _rings, const int _segments);
146 
151  public: void CreateBox(const std::string &_name,
152  const ignition::math::Vector3d &_sides,
153  const ignition::math::Vector2d &_uvCoords);
154 
167  public: void CreateExtrudedPolyline(const std::string &_name,
169  &_vertices, const double _height);
170 
177  public: void CreateCylinder(const std::string &_name,
178  const float _radius,
179  const float _height,
180  const int _rings,
181  const int _segments);
182 
188  public: void CreateEllipsoid(const std::string &_name,
189  const ignition::math::Vector3d &_radii,
190  const unsigned int _rings,
191  const unsigned int _segments);
192 
199  public: void CreateCapsule(const std::string &_name,
200  const double radius,
201  const double length,
202  const unsigned int _rings,
203  const unsigned int _segments);
204 
211  public: void CreateCone(const std::string &_name,
212  const float _radius,
213  const float _height,
214  const int _rings,
215  const int _segments);
216 
228  public: void CreateTube(const std::string &_name,
229  const float _innerRadius,
230  const float _outterRadius,
231  const float _height,
232  const int _rings,
233  const int _segments,
234  const double _arc = 2.0 * IGN_PI);
235 
241  public: void CreatePlane(const std::string &_name,
242  const ignition::math::Planed &_plane,
243  const ignition::math::Vector2d &_segments,
244  const ignition::math::Vector2d &_uvTile);
245 
253  public: void CreatePlane(const std::string &_name,
254  const ignition::math::Vector3d &_normal,
255  const double _d,
256  const ignition::math::Vector2d &_size,
257  const ignition::math::Vector2d &_segments,
258  const ignition::math::Vector2d &_uvTile);
259 
267  private: void Tesselate2DMesh(SubMesh *_sm,
268  const int _meshWidth,
269  const int _meshHeight,
270  const bool _doubleSided);
271 
275  public: void CreateCamera(const std::string &_name, const float _scale);
276 
283  public: void CreateBoolean(const std::string &_name, const Mesh *_m1,
284  const Mesh *_m2, const int _operation,
286 
294  private: static void ConvertPolylinesToVerticesAndEdges(
296  &_polys,
297  const double _tol,
300 
308  private: static size_t AddUniquePointToVerticesTable(
310  const ignition::math::Vector2d &_p,
311  const double _tol);
312 
314  IGN_UTILS_UNIQUE_IMPL_PTR(dataPtr)
315 
316 
317  private: friend class SingletonT<MeshManager>;
318  };
319  }
320 }
321 #endif
Maintains and manages all meshes.
Definition: gz/common/MeshManager.hh:52
void MeshAABB(const Mesh *_mesh, ignition::math::Vector3d &_center, ignition::math::Vector3d &_min_xyz, ignition::math::Vector3d &_max_xyz)
Get mesh aabb and center.
bool RemoveMesh(const std::string &_name)
Remove a mesh based on a name.
void CreateCamera(const std::string &_name, const float _scale)
Create a Camera mesh.
void CreateCapsule(const std::string &_name, const double radius, const double length, const unsigned int _rings, const unsigned int _segments)
Create a capsule mesh.
const Mesh * Load(const std::string &_filename)
Load a mesh from a file. The mesh will be searched on the global SystemPaths instance provided by Uti...
void CreateBoolean(const std::string &_name, const Mesh *_m1, const Mesh *_m2, const int _operation, const ignition::math::Pose3d &_offset=ignition::math::Pose3d::Zero)
Create a boolean mesh from two meshes.
void CreatePlane(const std::string &_name, const ignition::math::Planed &_plane, const ignition::math::Vector2d &_segments, const ignition::math::Vector2d &_uvTile)
Create mesh for a plane.
void AddMesh(Mesh *_mesh)
Add a mesh to the manager.
void CreatePlane(const std::string &_name, const ignition::math::Vector3d &_normal, const double _d, const ignition::math::Vector2d &_size, const ignition::math::Vector2d &_segments, const ignition::math::Vector2d &_uvTile)
Create mesh for a plane.
void Export(const Mesh *_mesh, const std::string &_filename, const std::string &_extension, bool _exportTextures=false)
Export a mesh to a file.
void CreateBox(const std::string &_name, const ignition::math::Vector3d &_sides, const ignition::math::Vector2d &_uvCoords)
Create a Box mesh.
common::Mesh * CreateMesh(const std::string &_name)
Create an empty mesh and register it by name. If the mesh already exists, returns nullptr.
const ignition::common::Mesh * MeshByName(const std::string &_name) const
Get a mesh by name.
static MeshManager * Instance()
void RemoveAll()
Remove all meshes.
bool IsValidFilename(const std::string &_filename)
Checks a path extension against the list of valid extensions.
bool HasMesh(const std::string &_name) const
Return true if the mesh exists.
void CreateExtrudedPolyline(const std::string &_name, const std::vector< std::vector< ignition::math::Vector2d > > &_vertices, const double _height)
Create an extruded mesh from polylines. The polylines are assumed to be closed and non-intersecting....
void CreateCylinder(const std::string &_name, const float _radius, const float _height, const int _rings, const int _segments)
Create a cylinder mesh.
void CreateCone(const std::string &_name, const float _radius, const float _height, const int _rings, const int _segments)
Create a cone mesh.
void CreateEllipsoid(const std::string &_name, const ignition::math::Vector3d &_radii, const unsigned int _rings, const unsigned int _segments)
Create a ellipsoid mesh.
void CreateTube(const std::string &_name, const float _innerRadius, const float _outterRadius, const float _height, const int _rings, const int _segments, const double _arc=2.0 *IGN_PI)
Create a tube mesh.
void GenSphericalTexCoord(const Mesh *_mesh, const ignition::math::Vector3d &_center)
generate spherical texture coordinates
void CreateSphere(const std::string &_name, const float _radius, const int _rings, const int _segments)
Create a sphere mesh.
A 3D mesh.
Definition: gz/common/Mesh.hh:43
Singleton template class.
Definition: gz/common/SingletonT.hh:30
A child mesh.
Definition: gz/common/SubMesh.hh:43
static const Pose3< T > Zero
Forward declarations for the common classes.