OpenMesh
|
00001 /*===========================================================================*\ 00002 * * 00003 * OpenMesh * 00004 * Copyright (C) 2001-2011 by Computer Graphics Group, RWTH Aachen * 00005 * www.openmesh.org * 00006 * * 00007 *---------------------------------------------------------------------------* 00008 * This file is part of OpenMesh. * 00009 * * 00010 * OpenMesh is free software: you can redistribute it and/or modify * 00011 * it under the terms of the GNU Lesser General Public License as * 00012 * published by the Free Software Foundation, either version 3 of * 00013 * the License, or (at your option) any later version with the * 00014 * following exceptions: * 00015 * * 00016 * If other files instantiate templates or use macros * 00017 * or inline functions from this file, or you compile this file and * 00018 * link it with other files to produce an executable, this file does * 00019 * not by itself cause the resulting executable to be covered by the * 00020 * GNU Lesser General Public License. This exception does not however * 00021 * invalidate any other reasons why the executable file might be * 00022 * covered by the GNU Lesser General Public License. * 00023 * * 00024 * OpenMesh is distributed in the hope that it will be useful, * 00025 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00026 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00027 * GNU Lesser General Public License for more details. * 00028 * * 00029 * You should have received a copy of the GNU LesserGeneral Public * 00030 * License along with OpenMesh. If not, * 00031 * see <http://www.gnu.org/licenses/>. * 00032 * * 00033 \*===========================================================================*/ 00034 00035 /*===========================================================================*\ 00036 * * 00037 * $Revision: 362 $ * 00038 * $Date: 2011-01-26 10:21:12 +0100 (Mi, 26 Jan 2011) $ * 00039 * * 00040 \*===========================================================================*/ 00041 00042 00043 //============================================================================= 00044 // 00045 // Implements an exporter module for arbitrary OpenMesh meshes 00046 // 00047 //============================================================================= 00048 00049 00050 #ifndef __EXPORTERT_HH__ 00051 #define __EXPORTERT_HH__ 00052 00053 00054 //=== INCLUDES ================================================================ 00055 00056 // C++ 00057 #include <vector> 00058 00059 // OpenMesh 00060 #include <OpenMesh/Core/System/config.h> 00061 #include <OpenMesh/Core/Geometry/VectorT.hh> 00062 #include <OpenMesh/Core/Utils/GenProg.hh> 00063 #include <OpenMesh/Core/Utils/vector_cast.hh> 00064 #include <OpenMesh/Core/Utils/color_cast.hh> 00065 #include <OpenMesh/Core/IO/exporter/BaseExporter.hh> 00066 00067 00068 //=== NAMESPACES ============================================================== 00069 00070 namespace OpenMesh { 00071 namespace IO { 00072 00073 00074 //=== EXPORTER CLASS ========================================================== 00075 00079 template <class Mesh> 00080 class ExporterT : public BaseExporter 00081 { 00082 public: 00083 00084 // Constructor 00085 ExporterT(const Mesh& _mesh) : mesh_(_mesh) {} 00086 00087 00088 // get vertex data 00089 00090 Vec3f point(VertexHandle _vh) const 00091 { 00092 return vector_cast<Vec3f>(mesh_.point(_vh)); 00093 } 00094 00095 Vec3f normal(VertexHandle _vh) const 00096 { 00097 return (mesh_.has_vertex_normals() 00098 ? vector_cast<Vec3f>(mesh_.normal(_vh)) 00099 : Vec3f(0.0f, 0.0f, 0.0f)); 00100 } 00101 00102 Vec3uc color(VertexHandle _vh) const 00103 { 00104 return (mesh_.has_vertex_colors() 00105 ? color_cast<Vec3uc>(mesh_.color(_vh)) 00106 : Vec3uc(0, 0, 0)); 00107 } 00108 00109 Vec4uc colorA(VertexHandle _vh) const 00110 { 00111 return (mesh_.has_vertex_colors() 00112 ? color_cast<Vec4uc>(mesh_.color(_vh)) 00113 : Vec4uc(0, 0, 0, 0)); 00114 } 00115 00116 Vec2f texcoord(VertexHandle _vh) const 00117 { 00118 #if defined(OM_CC_GCC) && (OM_CC_VERSION<30000) 00119 // Workaround! 00120 // gcc 2.95.3 exits with internal compiler error at the 00121 // code below!??? **) 00122 if (mesh_.has_vertex_texcoords2D()) 00123 return vector_cast<Vec2f>(mesh_.texcoord2D(_vh)); 00124 return Vec2f(0.0f, 0.0f); 00125 #else // **) 00126 return (mesh_.has_vertex_texcoords2D() 00127 ? vector_cast<Vec2f>(mesh_.texcoord2D(_vh)) 00128 : Vec2f(0.0f, 0.0f)); 00129 #endif 00130 } 00131 00132 // get edge data 00133 00134 Vec3uc color(EdgeHandle _eh) const 00135 { 00136 return (mesh_.has_edge_colors() 00137 ? color_cast<Vec3uc>(mesh_.color(_eh)) 00138 : Vec3uc(0, 0, 0)); 00139 } 00140 00141 Vec4uc colorA(EdgeHandle _eh) const 00142 { 00143 return (mesh_.has_edge_colors() 00144 ? color_cast<Vec4uc>(mesh_.color(_eh)) 00145 : Vec4uc(0, 0, 0, 0)); 00146 } 00147 00148 00149 // get face data 00150 00151 unsigned int get_vhandles(FaceHandle _fh, 00152 std::vector<VertexHandle>& _vhandles) const 00153 { 00154 unsigned int count(0); 00155 _vhandles.clear(); 00156 for (typename Mesh::CFVIter fv_it=mesh_.cfv_iter(_fh); fv_it; ++fv_it) 00157 { 00158 _vhandles.push_back(fv_it.handle()); 00159 ++count; 00160 } 00161 return count; 00162 } 00163 00164 Vec3f normal(FaceHandle _fh) const 00165 { 00166 return (mesh_.has_face_normals() 00167 ? vector_cast<Vec3f>(mesh_.normal(_fh)) 00168 : Vec3f(0.0f, 0.0f, 0.0f)); 00169 } 00170 00171 Vec3uc color(FaceHandle _fh) const 00172 { 00173 return (mesh_.has_face_colors() 00174 ? color_cast<Vec3uc>(mesh_.color(_fh)) 00175 : Vec3uc(0, 0, 0)); 00176 } 00177 00178 Vec4uc colorA(FaceHandle _fh) const 00179 { 00180 return (mesh_.has_face_colors() 00181 ? color_cast<Vec4uc>(mesh_.color(_fh)) 00182 : Vec4uc(0, 0, 0, 0)); 00183 } 00184 00185 virtual const BaseKernel* kernel() { return &mesh_; } 00186 00187 00188 // query number of faces, vertices, normals, texcoords 00189 size_t n_vertices() const { return mesh_.n_vertices(); } 00190 size_t n_faces() const { return mesh_.n_faces(); } 00191 size_t n_edges() const { return mesh_.n_edges(); } 00192 00193 00194 // property information 00195 bool is_triangle_mesh() const 00196 { return Mesh::is_triangles(); } 00197 00198 bool has_vertex_normals() const { return mesh_.has_vertex_normals(); } 00199 bool has_vertex_colors() const { return mesh_.has_vertex_colors(); } 00200 bool has_vertex_texcoords() const { return mesh_.has_vertex_texcoords2D(); } 00201 bool has_edge_colors() const { return mesh_.has_edge_colors(); } 00202 bool has_face_normals() const { return mesh_.has_face_normals(); } 00203 bool has_face_colors() const { return mesh_.has_face_colors(); } 00204 00205 private: 00206 00207 const Mesh& mesh_; 00208 }; 00209 00210 00211 //============================================================================= 00212 } // namespace IO 00213 } // namespace OpenMesh 00214 //============================================================================= 00215 #endif 00216 //=============================================================================