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.hh>
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
00066 class _OBJReader_ : public BaseReader
00067 {
00068 public:
00069
00070 _OBJReader_();
00071
00072 virtual ~_OBJReader_() { }
00073
00074 std::string get_description() const { return "Alias/Wavefront"; }
00075 std::string get_extensions() const { return "obj"; }
00076
00077 bool read(const std::string& _filename,
00078 BaseImporter& _bi,
00079 Options& _opt);
00080
00081 private:
00082
00083 #ifndef DOXY_IGNORE_THIS
00084 class Material
00085 {
00086 public:
00087
00088 Material() { cleanup(); }
00089
00090 void cleanup()
00091 {
00092 Kd_is_set_ = false;
00093 Ka_is_set_ = false;
00094 Ks_is_set_ = false;
00095 Tr_is_set_ = false;
00096 }
00097
00098 bool is_valid(void) const
00099 { return Kd_is_set_ || Ka_is_set_ || Ks_is_set_ || Tr_is_set_; }
00100
00101 bool has_Kd(void) { return Kd_is_set_; }
00102 bool has_Ka(void) { return Ka_is_set_; }
00103 bool has_Ks(void) { return Ks_is_set_; }
00104 bool has_Tr(void) { return Tr_is_set_; }
00105
00106 void set_Kd( float r, float g, float b )
00107 { Kd_=Vec3f(r,g,b); Kd_is_set_=true; }
00108
00109 void set_Ka( float r, float g, float b )
00110 { Ka_=Vec3f(r,g,b); Ka_is_set_=true; }
00111
00112 void set_Ks( float r, float g, float b )
00113 { Ks_=Vec3f(r,g,b); Ks_is_set_=true; }
00114
00115 void set_Tr( float t )
00116 { Tr_=t; Tr_is_set_=true; }
00117
00118 const Vec3f& Kd( void ) const { return Kd_; }
00119 const Vec3f& Ka( void ) const { return Ka_; }
00120 const Vec3f& Ks( void ) const { return Ks_; }
00121 float Tr( void ) const { return Tr_; }
00122
00123 private:
00124
00125 Vec3f Kd_; bool Kd_is_set_;
00126 Vec3f Ka_; bool Ka_is_set_;
00127 Vec3f Ks_; bool Ks_is_set_;
00128 float Tr_; bool Tr_is_set_;
00129 };
00130 #endif
00131
00132 typedef std::map<std::string, Material> MaterialList;
00133
00134 MaterialList materials_;
00135
00136 bool read_mtl( FILE* _in );
00137
00138 private:
00139
00140 bool read(FILE* _in, BaseImporter& _bi, Options& _opt);
00141
00142 std::string path_;
00143
00144 };
00145
00146
00147
00148
00149
00150 extern _OBJReader_ __OBJReaderInstance;
00151 _OBJReader_& OBJReader();
00152
00153
00154
00155 }
00156 }
00157
00158 #endif
00159