All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
MeshManager.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012-2014 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 _MESHMANAGER_HH_
18 #define _MESHMANAGER_HH_
19 
20 #include <map>
21 #include <string>
22 #include <vector>
23 #include <boost/thread/mutex.hpp>
24 
25 #include "gazebo/math/Vector3.hh"
26 #include "gazebo/math/Vector2d.hh"
27 #include "gazebo/math/Pose.hh"
28 #include "gazebo/math/Plane.hh"
30 #include "gazebo/util/system.hh"
31 
32 namespace gazebo
33 {
34  namespace common
35  {
36  class ColladaLoader;
37  class ColladaExporter;
38  class STLLoader;
39  class Mesh;
40  class Plane;
41  class SubMesh;
42 
45 
48  class GAZEBO_VISIBLE MeshManager : public SingletonT<MeshManager>
49  {
51  private: MeshManager();
52 
56  private: virtual ~MeshManager();
57 
61  public: const Mesh *Load(const std::string &_filename);
62 
69  public: void Export(const Mesh *_mesh, const std::string &_filename,
70  const std::string &_extension, bool _exportTextures = false);
71 
74  public: bool IsValidFilename(const std::string &_filename);
75 
81  public: void GetMeshAABB(const Mesh *_mesh,
82  math::Vector3 &_center,
83  math::Vector3 &_min_xyz,
84  math::Vector3 &_max_xyz);
85 
87  public: void GenSphericalTexCoord(const Mesh *_mesh,
88  math::Vector3 _center);
89 
90 
96  public: void AddMesh(Mesh *_mesh);
97 
101  public: const Mesh *GetMesh(const std::string &_name) const;
102 
105  public: bool HasMesh(const std::string &_name) const;
106 
112  public: void CreateSphere(const std::string &_name, float _radius,
113  int _rings, int _segments);
114 
119  public: void CreateBox(const std::string &_name,
120  const math::Vector3 &_sides,
121  const math::Vector2d &_uvCoords);
122 
128  public: void CreateExtrudedPolyline(const std::string &_name,
129  const std::vector<math::Vector2d> &_vertices,
130  const double &_height,
131  const math::Vector2d &_uvCoords);
132 
139  public: void CreateCylinder(const std::string &_name,
140  float _radius,
141  float _height,
142  int _rings,
143  int _segments);
144 
151  public: void CreateCone(const std::string &_name,
152  float _radius,
153  float _height,
154  int _rings,
155  int _segments);
156 
167  public: void CreateTube(const std::string &_name,
168  float _innerRadius,
169  float _outterRadius,
170  float _height,
171  int _rings,
172  int _segments);
173 
179  public: void CreatePlane(const std::string &_name,
180  const math::Plane &_plane,
181  const math::Vector2d &_segments,
182  const math::Vector2d &_uvTile);
183 
191  public: void CreatePlane(const std::string &_name,
192  const math::Vector3 &_normal,
193  double _d,
194  const math::Vector2d &_size,
195  const math::Vector2d &_segments,
196  const math::Vector2d &_uvTile);
197 
205  private: void Tesselate2DMesh(SubMesh *_sm,
206  int _meshWidth,
207  int _meshHeight,
208  bool _doubleSided);
209 
213  public: void CreateCamera(const std::string &_name, float _scale);
214 
215 #ifdef HAVE_GTS
216  public: void CreateBoolean(const std::string &_name, const Mesh *_m1,
223  const Mesh *_m2, const int _operation,
224  const math::Pose &_offset = math::Pose::Zero);
225 #endif
226 
228  private: ColladaLoader *colladaLoader;
229 
231  private: ColladaExporter *colladaExporter;
232 
234  private: STLLoader *stlLoader;
235 
237  private: std::map<std::string, Mesh*> meshes;
238 
240  private: std::vector<std::string> fileExtensions;
241 
242  private: boost::mutex mutex;
243 
245  private: friend class SingletonT<MeshManager>;
246  };
248  }
249 }
250 #endif
A 3D mesh.
Definition: Mesh.hh:40
Encapsulates a position and rotation in three space.
Definition: Pose.hh:40
Generic double x, y vector.
Definition: Vector2d.hh:39
The Vector3 class represents the generic vector containing 3 elements.
Definition: Vector3.hh:43
Singleton template class.
Definition: SingletonT.hh:33
A child mesh.
Definition: Mesh.hh:209
A plane and related functions.
Definition: Plane.hh:33
Class used to load Collada mesh files.
Definition: ColladaLoader.hh:43
Maintains and manages all meshes.
Definition: MeshManager.hh:48
Class used to export Collada mesh files.
Definition: ColladaExporter.hh:43
static const Pose Zero
math::Pose(0, 0, 0, 0, 0, 0)
Definition: Pose.hh:43
#define GAZEBO_VISIBLE
Use to represent "symbol visible" if supported.
Definition: system.hh:48
Class used to load STL mesh files.
Definition: STLLoader.hh:40