Main Page | Modules | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

OBJReader.hh

00001 /*===========================================================================*\
00002  *                                                                           *
00003  *                               OpenMesh                                    *
00004  *      Copyright (C) 2001-2005 by Computer Graphics Group, RWTH Aachen      *
00005  *                           www.openmesh.org                                *
00006  *                                                                           *
00007  *---------------------------------------------------------------------------* 
00008  *                                                                           *
00009  *                                License                                    *
00010  *                                                                           *
00011  *  This library is free software; you can redistribute it and/or modify it  *
00012  *  under the terms of the GNU Library General Public License as published   *
00013  *  by the Free Software Foundation, version 2.                              *
00014  *                                                                           *
00015  *  This library is distributed in the hope that it will be useful, but      *
00016  *  WITHOUT ANY WARRANTY; without even the implied warranty of               *
00017  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU        *
00018  *  Library General Public License for more details.                         *
00019  *                                                                           *
00020  *  You should have received a copy of the GNU Library General Public        *
00021  *  License along with this library; if not, write to the Free Software      *
00022  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.                *
00023  *                                                                           *
00024 \*===========================================================================*/
00025 
00026 
00027 //=============================================================================
00028 //
00029 //  Implements an reader module for OBJ files
00030 //
00031 //=============================================================================
00032 
00033 
00034 #ifndef __OBJREADER_HH__
00035 #define __OBJREADER_HH__
00036 
00037 
00038 //=== INCLUDES ================================================================
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 //== NAMESPACES ===============================================================
00054 
00055 
00056 namespace OpenMesh {
00057 namespace IO {
00058 
00059 
00060 //== IMPLEMENTATION ===========================================================
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_; // diffuse
00126     Vec3f Ka_;         bool Ka_is_set_; // ambient
00127     Vec3f Ks_;         bool Ks_is_set_; // specular
00128     float Tr_;         bool Tr_is_set_; // transperency
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 //== TYPE DEFINITION ==========================================================
00148 
00149 
00150 extern _OBJReader_  __OBJReaderInstance;
00151 _OBJReader_& OBJReader();
00152 
00153 
00154 //=============================================================================
00155 } // namespace IO
00156 } // namespace OpenMesh
00157 //=============================================================================
00158 #endif
00159 //=============================================================================

acg pic Project OpenMesh, ©  Computer Graphics Group, RWTH Aachen. Documentation generated using doxygen .