Line data Source code
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 :
43 : /// \addtogroup ugbase_common_util
44 : /// \{
45 :
46 : class LoaderObj
47 : {
48 : public:
49 : class Object
50 : {
51 : public:
52 0 : Object() : m_iMaterialIndex(-1) {}
53 :
54 : std::string m_strName;
55 : std::string m_strMaterialName;
56 : int m_iMaterialIndex;
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 0 : class Material
65 : {
66 : public:
67 : std::string m_strName;
68 : std::string m_strTextureDiffuse;
69 : ug::vector4 m_vDiffuse;
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 0 : inline int num_materials() const {return m_vMaterials.size();}
87 0 : 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 0 : inline const ug::vector3* point(int index) const {return &m_vPoints[index];}
92 0 : 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 0 : 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 :
102 : ObjectVector m_vObjects;
103 : MaterialVector m_vMaterials;
104 :
105 : std::vector<ug::vector3> m_vPoints;
106 : std::vector<ug::vector2> m_vTexCoords;
107 : };
108 :
109 : // end group ugbase_common_util
110 : /// \}
111 :
112 : }
113 :
114 : #endif
|