MeshManager.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012 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_COMMON_MESHMANAGER_HH_
18 #define GAZEBO_COMMON_MESHMANAGER_HH_
19 
20 #include <utility>
21 #include <string>
22 #include <vector>
23 
24 #include <ignition/math/Plane.hh>
25 #include <ignition/math/Pose3.hh>
26 #include <ignition/math/Vector2.hh>
27 #include <ignition/math/Vector3.hh>
28 
31 #include "gazebo/util/system.hh"
32 
34 GZ_SINGLETON_DECLARE(GZ_COMMON_VISIBLE, gazebo, common, MeshManager)
35 
36 namespace gazebo
37 {
38  namespace common
39  {
40  // Forward declarations.
41  class MeshManagerPrivate;
42  class Mesh;
43  class SubMesh;
44 
47 
50  class GZ_COMMON_VISIBLE MeshManager : public SingletonT<MeshManager>
51  {
53  private: MeshManager();
54 
58  private: virtual ~MeshManager();
59 
63  public: const Mesh *Load(const std::string &_filename);
64 
71  public: void Export(const Mesh *_mesh, const std::string &_filename,
72  const std::string &_extension, bool _exportTextures = false);
73 
76  public: bool IsValidFilename(const std::string &_filename);
77 
83  public: void GetMeshAABB(const Mesh *_mesh,
84  ignition::math::Vector3d &_center,
85  ignition::math::Vector3d &_min_xyz,
86  ignition::math::Vector3d &_max_xyz);
87 
91  public: void GenSphericalTexCoord(const Mesh *_mesh,
92  const ignition::math::Vector3d &_center);
93 
99  public: void AddMesh(Mesh *_mesh);
100 
104  public: const Mesh *GetMesh(const std::string &_name) const;
105 
108  public: bool HasMesh(const std::string &_name) const;
109 
115  public: void CreateSphere(const std::string &_name, float _radius,
116  int _rings, int _segments);
117 
122  public: void CreateBox(const std::string &_name,
123  const ignition::math::Vector3d &_sides,
124  const ignition::math::Vector2d &_uvCoords);
125 
138  public: void CreateExtrudedPolyline(const std::string &_name,
139  const std::vector<std::vector<ignition::math::Vector2d> >
140  &_vertices, double _height);
141 
148  public: void CreateCylinder(const std::string &_name,
149  float _radius,
150  float _height,
151  int _rings,
152  int _segments);
153 
160  public: void CreateCone(const std::string &_name,
161  float _radius,
162  float _height,
163  int _rings,
164  int _segments);
165 
177  public: void CreateTube(const std::string &_name,
178  float _innerRadius,
179  float _outterRadius,
180  float _height,
181  int _rings,
182  int _segments,
183  double _arc = 2.0 * M_PI);
184 
190  public: void CreatePlane(const std::string &_name,
191  const ignition::math::Planed &_plane,
192  const ignition::math::Vector2d &_segments,
193  const ignition::math::Vector2d &_uvTile);
194 
202  public: void CreatePlane(const std::string &_name,
203  const ignition::math::Vector3d &_normal,
204  const double _d,
205  const ignition::math::Vector2d &_size,
206  const ignition::math::Vector2d &_segments,
207  const ignition::math::Vector2d &_uvTile);
208 
216  private: void Tesselate2DMesh(SubMesh *_sm,
217  int _meshWidth,
218  int _meshHeight,
219  bool _doubleSided);
220 
224  public: void CreateCamera(const std::string &_name, float _scale);
225 
226 #ifdef HAVE_GTS
227  public: void CreateBoolean(const std::string &_name, const Mesh *_m1,
234  const Mesh *_m2, const int _operation,
235  const ignition::math::Pose3d &_offset = ignition::math::Pose3d::Zero);
236 #endif
237 
245  private: static void ConvertPolylinesToVerticesAndEdges(
246  const std::vector<std::vector<ignition::math::Vector2d> >
247  &_polys,
248  double _tol,
249  std::vector<ignition::math::Vector2d> &_vertices,
250  std::vector<ignition::math::Vector2i> &_edges);
251 
259  private: static size_t AddUniquePointToVerticesTable(
260  std::vector<ignition::math::Vector2d> &_vertices,
261  const ignition::math::Vector2d &_p,
262  double _tol);
263 
265  private: friend class SingletonT<MeshManager>;
266 
269  private: MeshManagerPrivate *dataPtr;
270  };
272  }
273 }
274 #endif
A 3D mesh.
Definition: Mesh.hh:42
Forward declarations for the common classes.
Definition: Animation.hh:26
Singleton template class.
Definition: SingletonT.hh:33
A child mesh.
Definition: Mesh.hh:214
common
Definition: MeshManager.hh:34
Maintains and manages all meshes.
Definition: MeshManager.hh:50
#define GZ_SINGLETON_DECLARE(visibility, n1, n2, singletonType)
Helper to declare typed SingletonT.
Definition: SingletonT.hh:61