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

OBJReader.hh

00001 /*===========================================================================*\
00002  *                                                                           *
00003  *                               OpenMesh                                    *
00004  *        Copyright (C) 2003 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.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 //== NAMESPACES ===============================================================
00054 
00055 
00056 namespace OpenMesh {
00057 namespace IO {
00058 
00059 
00060 //== IMPLEMENTATION ===========================================================
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_; // diffuse
00127     Vec3f Ka_;         bool Ka_is_set_; // ambient
00128     Vec3f Ks_;         bool Ks_is_set_; // specular
00129     float Tr_;         bool Tr_is_set_; // transperency
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 //== TYPE DEFINITION ==========================================================
00149 
00150 
00152 typedef SingletonT<_OBJReader_> OBJReader;
00153 
00154 
00155 //=============================================================================
00156 } // namespace IO
00157 } // namespace OpenMesh
00158 //=============================================================================
00159 #endif
00160 //=============================================================================

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