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 (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 STLLoader;
38  class Mesh;
39  class Plane;
40  class SubMesh;
41 
44 
47  class GAZEBO_VISIBLE MeshManager : public SingletonT<MeshManager>
48  {
50  private: MeshManager();
51 
55  private: virtual ~MeshManager();
56 
60  public: const Mesh *Load(const std::string &_filename);
61 
64  public: bool IsValidFilename(const std::string &_filename);
65 
71  public: void GetMeshAABB(const Mesh *_mesh,
72  math::Vector3 &_center,
73  math::Vector3 &_min_xyz,
74  math::Vector3 &_max_xyz);
75 
77  public: void GenSphericalTexCoord(const Mesh *_mesh,
78  math::Vector3 _center);
79 
80 
86  public: void AddMesh(Mesh *_mesh);
87 
91  public: const Mesh *GetMesh(const std::string &_name) const;
92 
95  public: bool HasMesh(const std::string &_name) const;
96 
102  public: void CreateSphere(const std::string &_name, float _radius,
103  int _rings, int _segments);
104 
109  public: void CreateBox(const std::string &_name,
110  const math::Vector3 &_sides,
111  const math::Vector2d &_uvCoords);
112 
119  public: void CreateCylinder(const std::string &_name,
120  float _radius,
121  float _height,
122  int _rings,
123  int _segments);
124 
131  public: void CreateCone(const std::string &_name,
132  float _radius,
133  float _height,
134  int _rings,
135  int _segments);
136 
147  public: void CreateTube(const std::string &_name,
148  float _innerRadius,
149  float _outterRadius,
150  float _height,
151  int _rings,
152  int _segments);
153 
159  public: void CreatePlane(const std::string &_name,
160  const math::Plane &_plane,
161  const math::Vector2d &_segments,
162  const math::Vector2d &_uvTile);
163 
171  public: void CreatePlane(const std::string &_name,
172  const math::Vector3 &_normal,
173  double _d,
174  const math::Vector2d &_size,
175  const math::Vector2d &_segments,
176  const math::Vector2d &_uvTile);
177 
185  private: void Tesselate2DMesh(SubMesh *_sm,
186  int _meshWidth,
187  int _meshHeight,
188  bool _doubleSided);
189 
193  public: void CreateCamera(const std::string &_name, float _scale);
194 
195 #ifdef HAVE_GTS
196  public: void CreateBoolean(const std::string &_name, const Mesh *_m1,
203  const Mesh *_m2, const int _operation,
204  const math::Pose &_offset = math::Pose::Zero);
205 #endif
206 
208  private: ColladaLoader *colladaLoader;
209 
211  private: STLLoader *stlLoader;
212 
214  private: std::map<std::string, Mesh*> meshes;
215 
217  private: std::vector<std::string> fileExtensions;
218 
219  private: boost::mutex mutex;
220 
222  private: friend class SingletonT<MeshManager>;
223  };
225  }
226 }
227 #endif