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 a reader module for OFF files 00030 // 00031 //============================================================================= 00032 00033 00034 #ifndef __OFFREADER_HH__ 00035 #define __OFFREADER_HH__ 00036 00037 00038 //=== INCLUDES ================================================================ 00039 00040 00041 #include <iostream> 00042 #include <string> 00043 #include <stdio.h> 00044 00045 #include <OpenMesh/Core/System/config.hh> 00046 #include <OpenMesh/Core/Utils/SingletonT.hh> 00047 #include <OpenMesh/Core/IO/reader/BaseReader.hh> 00048 00049 00050 //== NAMESPACES =============================================================== 00051 00052 00053 namespace OpenMesh { 00054 namespace IO { 00055 00056 00057 //== FORWARDS ================================================================= 00058 00059 00060 class BaseImporter; 00061 00062 00063 //== IMPLEMENTATION =========================================================== 00064 00065 00070 class _OFFReader_ : public BaseReader 00071 { 00072 public: 00073 00074 _OFFReader_(); 00075 00076 std::string get_description() const { return "Object File Format"; } 00077 std::string get_extensions() const { return "off"; } 00078 std::string get_magic() const { return "OFF"; } 00079 00080 bool read(const std::string& _filename, 00081 BaseImporter& _bi, 00082 Options& _opt); 00083 00084 bool can_u_read(const std::string& _filename) const; 00085 00086 00087 00088 private: 00089 00090 bool can_u_read(std::istream& _is) const; 00091 00092 bool read(FILE* _in, BaseImporter& _bi, Options& _opt ) const; 00093 bool read_ascii(FILE* _in, BaseImporter& _bi) const; 00094 bool read_binary(FILE* _in, BaseImporter& _bi, bool swap) const; 00095 00097 mutable struct { 00098 unsigned vertex_dim:8; // allow up to 256 dimensional vectors 00099 unsigned vertex_has_normal:1; 00100 unsigned vertex_has_color:1; 00101 unsigned vertex_has_texcoord:1; 00102 unsigned vertex_has_hcoord:1; 00103 unsigned is_binary:1; 00104 } options_; 00105 }; 00106 00107 00108 //== TYPE DEFINITION ========================================================== 00109 00110 00112 extern _OFFReader_ __OFFReaderInstance; 00113 _OFFReader_& OFFReader(); 00114 00115 00116 //============================================================================= 00117 } // namespace IO 00118 } // namespace OpenMesh 00119 //============================================================================= 00120 #endif 00121 //=============================================================================