00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 #ifndef __OBJREADER_HH__
00035 #define __OBJREADER_HH__
00036
00037
00038
00039
00040
00041 #include <iostream>
00042 #include <string>
00043 #include <vector>
00044 #include <map>
00045 #include <stdio.h>
00046
00047 #include <OpenMesh/Core/System/config.h>
00048 #include <OpenMesh/Core/Utils/SingletonT.hh>
00049 #include <OpenMesh/Core/IO/importer/BaseImporter.hh>
00050 #include <OpenMesh/Core/IO/reader/BaseReader.hh>
00051
00052
00053
00054
00055
00056 namespace OpenMesh {
00057 namespace IO {
00058
00059
00060
00061
00062
00067 class _OBJReader_ : public BaseReader
00068 {
00069 public:
00070
00071 _OBJReader_();
00072
00073 virtual ~_OBJReader_() { }
00074
00075 std::string get_description() const { return "Alias/Wavefront"; }
00076 std::string get_extensions() const { return "obj"; }
00077
00078 bool read(const std::string& _filename,
00079 BaseImporter& _bi,
00080 Options& _opt);
00081
00082 private:
00083
00084 #ifndef DOXY_IGNORE_THIS
00085 class Material
00086 {
00087 public:
00088
00089 Material() { cleanup(); }
00090
00091 void cleanup()
00092 {
00093 Kd_is_set_ = false;
00094 Ka_is_set_ = false;
00095 Ks_is_set_ = false;
00096 Tr_is_set_ = false;
00097 }
00098
00099 bool is_valid(void) const
00100 { return Kd_is_set_ || Ka_is_set_ || Ks_is_set_ || Tr_is_set_; }
00101
00102 bool has_Kd(void) { return Kd_is_set_; }
00103 bool has_Ka(void) { return Ka_is_set_; }
00104 bool has_Ks(void) { return Ks_is_set_; }
00105 bool has_Tr(void) { return Tr_is_set_; }
00106
00107 void set_Kd( float r, float g, float b )
00108 { Kd_=Vec3f(r,g,b); Kd_is_set_=true; }
00109
00110 void set_Ka( float r, float g, float b )
00111 { Ka_=Vec3f(r,g,b); Ka_is_set_=true; }
00112
00113 void set_Ks( float r, float g, float b )
00114 { Ks_=Vec3f(r,g,b); Ks_is_set_=true; }
00115
00116 void set_Tr( float t )
00117 { Tr_=t; Tr_is_set_=true; }
00118
00119 const Vec3f& Kd( void ) const { return Kd_; }
00120 const Vec3f& Ka( void ) const { return Ka_; }
00121 const Vec3f& Ks( void ) const { return Ks_; }
00122 float Tr( void ) const { return Tr_; }
00123
00124 private:
00125
00126 Vec3f Kd_; bool Kd_is_set_;
00127 Vec3f Ka_; bool Ka_is_set_;
00128 Vec3f Ks_; bool Ks_is_set_;
00129 float Tr_; bool Tr_is_set_;
00130 };
00131 #endif
00132
00133 typedef std::map<std::string, Material> MaterialList;
00134
00135 MaterialList materials_;
00136
00137 bool read_mtl( FILE* _in );
00138
00139 private:
00140
00141 bool read(FILE* _in, BaseImporter& _bi, Options& _opt);
00142
00143 std::string path_;
00144
00145 };
00146
00147
00148
00149
00150
00152 typedef SingletonT<_OBJReader_> OBJReader;
00153
00154
00155
00156 }
00157 }
00158
00159 #endif
00160