All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MeshManager.hh
Go to the documentation of this file.
1 /*
2  * Copyright 2011 Nate Koenig
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 "math/Vector3.hh"
26 #include "math/Vector2d.hh"
27 #include "math/Plane.hh"
28 #include "common/SingletonT.hh"
29 
30 namespace gazebo
31 {
32  namespace common
33  {
34  class ColladaLoader;
35  class STLLoader;
36  class Mesh;
37  class Plane;
38  class SubMesh;
39 
42 
44  class MeshManager : public SingletonT<MeshManager>
45  {
47  private: MeshManager();
48 
52  private: virtual ~MeshManager();
53 
57  public: const Mesh *Load(const std::string &_filename);
58 
61  public: bool IsValidFilename(const std::string &_filename);
62 
68  public: void GetMeshAABB(const Mesh *_mesh,
69  math::Vector3 &_center,
70  math::Vector3 &_min_xyz,
71  math::Vector3 &_max_xyz);
72 
74  public: void GenSphericalTexCoord(const Mesh *_mesh,
75  math::Vector3 _center);
76 
77 
83  public: void AddMesh(Mesh *_mesh);
84 
88  public: const Mesh *GetMesh(const std::string &_name) const;
89 
92  public: bool HasMesh(const std::string &_name) const;
93 
99  public: void CreateSphere(const std::string &_name, float _radius,
100  int _rings, int _segments);
101 
106  public: void CreateBox(const std::string &_name,
107  const math::Vector3 &_sides,
108  const math::Vector2d &_uvCoords);
109 
116  public: void CreateCylinder(const std::string &_name,
117  float _radius,
118  float _height,
119  int _rings,
120  int _segments);
121 
128  public: void CreateCone(const std::string &_name,
129  float _radius,
130  float _height,
131  int _rings,
132  int _segments);
133 
144  public: void CreateTube(const std::string &_name,
145  float _innerRadius,
146  float _outterRadius,
147  float _height,
148  int _rings,
149  int _segments);
150 
156  public: void CreatePlane(const std::string &_name,
157  const math::Plane &_plane,
158  const math::Vector2d &_segments,
159  const math::Vector2d &_uvTile);
160 
168  public: void CreatePlane(const std::string &_name,
169  const math::Vector3 &_normal,
170  double _d,
171  const math::Vector2d &_size,
172  const math::Vector2d &_segments,
173  const math::Vector2d &_uvTile);
174 
182  private: void Tesselate2DMesh(SubMesh *_sm,
183  int _meshWidth,
184  int _meshHeight,
185  bool _doubleSided);
186 
190  public: void CreateCamera(const std::string &_name, float _scale);
191 
193  private: ColladaLoader *colladaLoader;
194 
196  private: STLLoader *stlLoader;
197 
199  private: std::map<std::string, Mesh*> meshes;
200 
202  private: std::vector<std::string> fileExtensions;
203 
204  private: boost::mutex mutex;
205 
207  private: friend class SingletonT<MeshManager>;
208  };
210  }
211 }
212 #endif
213 
214