ug4
loader_obj.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2009-2015: G-CSC, Goethe University Frankfurt
3  * Author: Sebastian Reiter
4  *
5  * This file is part of UG4.
6  *
7  * UG4 is free software: you can redistribute it and/or modify it under the
8  * terms of the GNU Lesser General Public License version 3 (as published by the
9  * Free Software Foundation) with the following additional attribution
10  * requirements (according to LGPL/GPL v3 §7):
11  *
12  * (1) The following notice must be displayed in the Appropriate Legal Notices
13  * of covered and combined works: "Based on UG4 (www.ug4.org/license)".
14  *
15  * (2) The following notice must be displayed at a prominent place in the
16  * terminal output of covered works: "Based on UG4 (www.ug4.org/license)".
17  *
18  * (3) The following bibliography is recommended for citation and must be
19  * preserved in all covered files:
20  * "Reiter, S., Vogel, A., Heppner, I., Rupp, M., and Wittum, G. A massively
21  * parallel geometric multigrid solver on hierarchically distributed grids.
22  * Computing and visualization in science 16, 4 (2013), 151-164"
23  * "Vogel, A., Reiter, S., Rupp, M., Nägel, A., and Wittum, G. UG4 -- a novel
24  * flexible software system for simulating pde based models on high performance
25  * computers. Computing and visualization in science 16, 4 (2013), 165-179"
26  *
27  * This program is distributed in the hope that it will be useful,
28  * but WITHOUT ANY WARRANTY; without even the implied warranty of
29  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30  * GNU Lesser General Public License for more details.
31  */
32 
33 #ifndef __LIBMESH_LOADER_OBJ__
34 #define __LIBMESH_LOADER_OBJ__
35 
36 #include <vector>
37 #include <string>
38 #include "../../math/ugmath.h"
39 
40 namespace ug
41 {
42 
45 
46 class LoaderObj
47 {
48  public:
49  class Object
50  {
51  public:
53 
54  std::string m_strName;
55  std::string m_strMaterialName;
57  std::vector<int> m_vQuadList;
58  std::vector<int> m_vTriangleList;
59  std::vector<int> m_vQuadListTex;
60  std::vector<int> m_vTriangleListTex;
61  std::vector<int> m_vEdgeList;
62  };
63 
64  class Material
65  {
66  public:
67  std::string m_strName;
68  std::string m_strTextureDiffuse;
70  float m_fAlpha;
71  };
72 
73  typedef std::vector<Object*> ObjectVector;
74  typedef ObjectVector::iterator ObjectIterator;
75  typedef std::vector<Material> MaterialVector;
76 
77  ~LoaderObj();
78  bool load_file(const char* strFilename, bool convertQuadsToTris = true);
79  void clear();
80 
81  inline ObjectIterator objects_begin() {return m_vObjects.begin();}
82  inline ObjectIterator objects_end() {return m_vObjects.end();}
83  inline int num_objects() const {return m_vObjects.size();}
84  inline const Object* get_object(int index) const {return m_vObjects[index];};
85 
86  inline int num_materials() const {return m_vMaterials.size();}
87  inline const Material& get_material(int index) const {return m_vMaterials[index];}
88 
89  inline std::vector<ug::vector3>::const_iterator points_begin() {return m_vPoints.begin();}
90  inline std::vector<ug::vector3>::const_iterator points_end() {return m_vPoints.end();}
91  inline const ug::vector3* point(int index) const {return &m_vPoints[index];}
92  inline int num_points() {return m_vPoints.size();}
93 
94  inline std::vector<ug::vector2>::const_iterator uv_begin() {return m_vTexCoords.begin();}
95  inline std::vector<ug::vector2>::const_iterator uv_end() {return m_vTexCoords.end();}
96  inline const ug::vector2* uv(int index) const {return &m_vTexCoords[index];}
97  inline int num_uvs() {return m_vTexCoords.size();}
98 
99  protected:
100  int get_material_index_by_name(const char* name) const;
101 
104 
105  std::vector<ug::vector3> m_vPoints;
106  std::vector<ug::vector2> m_vTexCoords;
107 };
108 
109 // end group ugbase_common_util
111 
112 }
113 
114 #endif
location name
Definition: checkpoint_util.lua:128
Definition: loader_obj.h:65
float m_fAlpha
Definition: loader_obj.h:70
ug::vector4 m_vDiffuse
Definition: loader_obj.h:69
std::string m_strTextureDiffuse
Definition: loader_obj.h:68
std::string m_strName
Definition: loader_obj.h:67
Definition: loader_obj.h:50
std::vector< int > m_vTriangleListTex
Definition: loader_obj.h:60
std::string m_strName
Definition: loader_obj.h:54
Object()
Definition: loader_obj.h:52
std::vector< int > m_vQuadListTex
Definition: loader_obj.h:59
std::vector< int > m_vTriangleList
Definition: loader_obj.h:58
int m_iMaterialIndex
Definition: loader_obj.h:56
std::string m_strMaterialName
Definition: loader_obj.h:55
std::vector< int > m_vQuadList
Definition: loader_obj.h:57
std::vector< int > m_vEdgeList
Definition: loader_obj.h:61
Definition: loader_obj.h:47
std::vector< Object * > ObjectVector
Definition: loader_obj.h:73
std::vector< Material > MaterialVector
Definition: loader_obj.h:75
ObjectIterator objects_end()
Definition: loader_obj.h:82
bool load_file(const char *strFilename, bool convertQuadsToTris=true)
Definition: loader_obj.cpp:138
const Object * get_object(int index) const
Definition: loader_obj.h:84
std::vector< ug::vector2 >::const_iterator uv_begin()
Definition: loader_obj.h:94
std::vector< ug::vector2 >::const_iterator uv_end()
Definition: loader_obj.h:95
MaterialVector m_vMaterials
Definition: loader_obj.h:103
std::vector< ug::vector3 >::const_iterator points_begin()
Definition: loader_obj.h:89
int num_materials() const
Definition: loader_obj.h:86
std::vector< ug::vector3 >::const_iterator points_end()
Definition: loader_obj.h:90
ObjectIterator objects_begin()
Definition: loader_obj.h:81
~LoaderObj()
Definition: loader_obj.cpp:126
int num_objects() const
Definition: loader_obj.h:83
std::vector< ug::vector3 > m_vPoints
Definition: loader_obj.h:105
ObjectVector m_vObjects
Definition: loader_obj.h:102
ObjectVector::iterator ObjectIterator
Definition: loader_obj.h:74
std::vector< ug::vector2 > m_vTexCoords
Definition: loader_obj.h:106
int num_points()
Definition: loader_obj.h:92
int get_material_index_by_name(const char *name) const
Definition: loader_obj.cpp:449
const Material & get_material(int index) const
Definition: loader_obj.h:87
const ug::vector2 * uv(int index) const
Definition: loader_obj.h:96
void clear()
Definition: loader_obj.cpp:131
int num_uvs()
Definition: loader_obj.h:97
const ug::vector3 * point(int index) const
Definition: loader_obj.h:91
the ug namespace