OpenMesh

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
OBJReader.hh
1 /*===========================================================================*\
2 * *
3 * OpenMesh *
4 * Copyright (C) 2001-2014 by Computer Graphics Group, RWTH Aachen *
5 * www.openmesh.org *
6 * *
7 *---------------------------------------------------------------------------*
8 * This file is part of OpenMesh. *
9 * *
10 * OpenMesh is free software: you can redistribute it and/or modify *
11 * it under the terms of the GNU Lesser General Public License as *
12 * published by the Free Software Foundation, either version 3 of *
13 * the License, or (at your option) any later version with the *
14 * following exceptions: *
15 * *
16 * If other files instantiate templates or use macros *
17 * or inline functions from this file, or you compile this file and *
18 * link it with other files to produce an executable, this file does *
19 * not by itself cause the resulting executable to be covered by the *
20 * GNU Lesser General Public License. This exception does not however *
21 * invalidate any other reasons why the executable file might be *
22 * covered by the GNU Lesser General Public License. *
23 * *
24 * OpenMesh is distributed in the hope that it will be useful, *
25 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
27 * GNU Lesser General Public License for more details. *
28 * *
29 * You should have received a copy of the GNU LesserGeneral Public *
30 * License along with OpenMesh. If not, *
31 * see <http://www.gnu.org/licenses/>. *
32 * *
33 \*===========================================================================*/
34
35 /*===========================================================================*\
36 * *
37 * $Revision: 990 $ *
38 * $Date: 2014-02-05 10:01:07 +0100 (Mi, 05. Feb 2014) $ *
39 * *
40 \*===========================================================================*/
41
42
43 //=============================================================================
44 //
45 // Implements an reader module for OBJ files
46 //
47 //=============================================================================
48
49
50 #ifndef __OBJREADER_HH__
51 #define __OBJREADER_HH__
52
53
54 //=== INCLUDES ================================================================
55
56
57 #include <iostream>
58 #include <string>
59 #include <vector>
60 #include <map>
61 #include <fstream>
62
63 #include <OpenMesh/Core/System/config.h>
64 #include <OpenMesh/Core/Utils/SingletonT.hh>
65 #include <OpenMesh/Core/IO/importer/BaseImporter.hh>
66 #include <OpenMesh/Core/IO/reader/BaseReader.hh>
67
68
69 //== NAMESPACES ===============================================================
70
71
72 namespace OpenMesh {
73 namespace IO {
74
75
76 //== IMPLEMENTATION ===========================================================
77
78
82 class OPENMESHDLLEXPORT _OBJReader_ : public BaseReader
83 {
84 public:
85
86 _OBJReader_();
87
88 virtual ~_OBJReader_() { }
89
90 std::string get_description() const { return "Alias/Wavefront"; }
91 std::string get_extensions() const { return "obj"; }
92
93 bool read(const std::string& _filename,
94 BaseImporter& _bi,
95 Options& _opt);
96
97 bool read(std::istream& _in,
98 BaseImporter& _bi,
99 Options& _opt);
100
101 private:
102
103 #ifndef DOXY_IGNORE_THIS
104 class Material
105 {
106 public:
107
108 Material() { cleanup(); }
109
110 void cleanup()
111 {
112 Kd_is_set_ = false;
113 Ka_is_set_ = false;
114 Ks_is_set_ = false;
115 Tr_is_set_ = false;
116 map_Kd_is_set_ = false;
117 }
118
119 bool is_valid(void) const
120 { return Kd_is_set_ || Ka_is_set_ || Ks_is_set_ || Tr_is_set_; }
121
122 bool has_Kd(void) { return Kd_is_set_; }
123 bool has_Ka(void) { return Ka_is_set_; }
124 bool has_Ks(void) { return Ks_is_set_; }
125 bool has_Tr(void) { return Tr_is_set_; }
126 bool has_map_Kd(void) { return map_Kd_is_set_; }
127
128 void set_Kd( float r, float g, float b )
129 { Kd_=Vec3f(r,g,b); Kd_is_set_=true; }
130
131 void set_Ka( float r, float g, float b )
132 { Ka_=Vec3f(r,g,b); Ka_is_set_=true; }
133
134 void set_Ks( float r, float g, float b )
135 { Ks_=Vec3f(r,g,b); Ks_is_set_=true; }
136
137 void set_Tr( float t )
138 { Tr_=t; Tr_is_set_=true; }
139
140 void set_map_Kd( std::string _name, int _index_Kd )
141 { map_Kd_ = _name, index_Kd_ = _index_Kd; map_Kd_is_set_ = true; };
142
143 const Vec3f& Kd( void ) const { return Kd_; }
144 const Vec3f& Ka( void ) const { return Ka_; }
145 const Vec3f& Ks( void ) const { return Ks_; }
146 float Tr( void ) const { return Tr_; }
147 const std::string& map_Kd( void ) { return map_Kd_ ; }
148 const int& map_Kd_index( void ) { return index_Kd_ ; }
149
150 private:
151
152 Vec3f Kd_; bool Kd_is_set_; // diffuse
153 Vec3f Ka_; bool Ka_is_set_; // ambient
154 Vec3f Ks_; bool Ks_is_set_; // specular
155 float Tr_; bool Tr_is_set_; // transperency
156
157 std::string map_Kd_; int index_Kd_; bool map_Kd_is_set_; // Texture
158
159 };
160 #endif
161
162 typedef std::map<std::string, Material> MaterialList;
163
164 MaterialList materials_;
165
166 bool read_material( std::fstream& _in );
167
168 private:
169
170 std::string path_;
171
172 };
173
174
175 //== TYPE DEFINITION ==========================================================
176
177
178 extern _OBJReader_ __OBJReaderInstance;
179 OPENMESHDLLEXPORT _OBJReader_& OBJReader();
180
181
182 //=============================================================================
183 } // namespace IO
184 } // namespace OpenMesh
185 //=============================================================================
186 #endif
187 //=============================================================================
OpenMesh::IO::_OBJReader_::get_extensions
std::string get_extensions() const
Returns a string with the accepted file extensions separated by a whitespace and in small caps...
Definition: OBJReader.hh:91
OpenMesh::IO::Options
Set options for reader/writer modules.
Definition: Options.hh:88
OpenMesh::IO::BaseImporter
Base class for importer modules.
Definition: BaseImporter.hh:81
OpenMesh::IO::_OBJReader_
Implementation of the OBJ format reader.
Definition: OBJReader.hh:82
OpenMesh::IO::_OBJReader_::get_description
std::string get_description() const
Returns a brief description of the file type that can be parsed.
Definition: OBJReader.hh:90
OpenMesh::IO::BaseReader
Base class for reader modules.
Definition: BaseReader.hh:86