Developer Documentation

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

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
OBJReader.hh
1 /* ========================================================================= *
2 * *
3 * OpenMesh *
4 * Copyright (c) 2001-2015, RWTH-Aachen University *
5 * Department of Computer Graphics and Multimedia *
6 * All rights reserved. *
7 * www.openmesh.org *
8 * *
9 *---------------------------------------------------------------------------*
10 * This file is part of OpenMesh. *
11 *---------------------------------------------------------------------------*
12 * *
13 * Redistribution and use in source and binary forms, with or without *
14 * modification, are permitted provided that the following conditions *
15 * are met: *
16 * *
17 * 1. Redistributions of source code must retain the above copyright notice, *
18 * this list of conditions and the following disclaimer. *
19 * *
20 * 2. Redistributions in binary form must reproduce the above copyright *
21 * notice, this list of conditions and the following disclaimer in the *
22 * documentation and/or other materials provided with the distribution. *
23 * *
24 * 3. Neither the name of the copyright holder nor the names of its *
25 * contributors may be used to endorse or promote products derived from *
26 * this software without specific prior written permission. *
27 * *
28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
29 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
30 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
31 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
32 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
33 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
34 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
35 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
36 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
37 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
38 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
39 * *
40 * ========================================================================= */
41
42 /*===========================================================================*\
43 * *
44 * $Revision$ *
45 * $Date$ *
46 * *
47 \*===========================================================================*/
48
49
50 //=============================================================================
51 //
52 // Implements an reader module for OBJ files
53 //
54 //=============================================================================
55
56
57 #ifndef __OBJREADER_HH__
58 #define __OBJREADER_HH__
59
60
61 //=== INCLUDES ================================================================
62
63
64 #include <iosfwd>
65 #include <string>
66 #include <map>
67
68 #include <OpenMesh/Core/System/config.h>
69 #include <OpenMesh/Core/Utils/SingletonT.hh>
70 #include <OpenMesh/Core/IO/importer/BaseImporter.hh>
71 #include <OpenMesh/Core/IO/reader/BaseReader.hh>
72
73
74 //== NAMESPACES ===============================================================
75
76
77 namespace OpenMesh {
78 namespace IO {
79
80
81 //== IMPLEMENTATION ===========================================================
82
83
87 class OPENMESHDLLEXPORT _OBJReader_ : public BaseReader
88 {
89 public:
90
91 _OBJReader_();
92
93 virtual ~_OBJReader_() { }
94
95 std::string get_description() const { return "Alias/Wavefront"; }
96 std::string get_extensions() const { return "obj"; }
97
98 bool read(const std::string& _filename,
99 BaseImporter& _bi,
100 Options& _opt);
101
102 bool read(std::istream& _in,
103 BaseImporter& _bi,
104 Options& _opt);
105
106 private:
107
108 #ifndef DOXY_IGNORE_THIS
109 class Material
110 {
111 public:
112
113 Material() { cleanup(); }
114
115 void cleanup()
116 {
117 Kd_is_set_ = false;
118 Ka_is_set_ = false;
119 Ks_is_set_ = false;
120 Tr_is_set_ = false;
121 map_Kd_is_set_ = false;
122 }
123
124 bool is_valid(void) const
125 { return Kd_is_set_ || Ka_is_set_ || Ks_is_set_ || Tr_is_set_ || map_Kd_is_set_; }
126
127 bool has_Kd(void) { return Kd_is_set_; }
128 bool has_Ka(void) { return Ka_is_set_; }
129 bool has_Ks(void) { return Ks_is_set_; }
130 bool has_Tr(void) { return Tr_is_set_; }
131 bool has_map_Kd(void) { return map_Kd_is_set_; }
132
133 void set_Kd( float r, float g, float b )
134 { Kd_=Vec3f(r,g,b); Kd_is_set_=true; }
135
136 void set_Ka( float r, float g, float b )
137 { Ka_=Vec3f(r,g,b); Ka_is_set_=true; }
138
139 void set_Ks( float r, float g, float b )
140 { Ks_=Vec3f(r,g,b); Ks_is_set_=true; }
141
142 void set_Tr( float t )
143 { Tr_=t; Tr_is_set_=true; }
144
145 void set_map_Kd( std::string _name, int _index_Kd )
146 { map_Kd_ = _name, index_Kd_ = _index_Kd; map_Kd_is_set_ = true; };
147
148 const Vec3f& Kd( void ) const { return Kd_; }
149 const Vec3f& Ka( void ) const { return Ka_; }
150 const Vec3f& Ks( void ) const { return Ks_; }
151 float Tr( void ) const { return Tr_; }
152 const std::string& map_Kd( void ) { return map_Kd_ ; }
153 const int& map_Kd_index( void ) { return index_Kd_ ; }
154
155 private:
156
157 Vec3f Kd_; bool Kd_is_set_; // diffuse
158 Vec3f Ka_; bool Ka_is_set_; // ambient
159 Vec3f Ks_; bool Ks_is_set_; // specular
160 float Tr_; bool Tr_is_set_; // transperency
161
162 std::string map_Kd_; int index_Kd_; bool map_Kd_is_set_; // Texture
163
164 };
165 #endif
166
167 typedef std::map<std::string, Material> MaterialList;
168
169 MaterialList materials_;
170
171 bool read_material( std::fstream& _in );
172
173 private:
174
175 std::string path_;
176
177 };
178
179
180 //== TYPE DEFINITION ==========================================================
181
182
183 extern _OBJReader_ __OBJReaderInstance;
184 OPENMESHDLLEXPORT _OBJReader_& OBJReader();
185
186
187 //=============================================================================
188 } // namespace IO
189 } // namespace OpenMesh
190 //=============================================================================
191 #endif
192 //=============================================================================
OpenMesh
Definition: MeshItems.hh:64
OpenMesh::IO::Options
Set options for reader/writer modules.
Definition: Options.hh:95
OpenMesh::IO::BaseReader
Definition: BaseReader.hh:94
OpenMesh::IO::_OBJReader_
Definition: OBJReader.hh:87
config.h
OpenMesh::IO::_OBJReader_::get_extensions
std::string get_extensions() const
Definition: OBJReader.hh:96
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:95
OpenVolumeMesh::Geometry::VectorT
Definition: Vector11T.hh:78
OpenMesh::Vec3f
VectorT< float, 3 > Vec3f
Definition: Vector11T.hh:769
OpenMesh::IO::BaseImporter
Definition: BaseImporter.hh:88