00001 // This file is part of ff3d - http://www.freefem.org/ff3d 00002 // Copyright (C) 2001, 2002, 2003 Stéphane Del Pino 00003 00004 // This program is free software; you can redistribute it and/or modify 00005 // it under the terms of the GNU General Public License as published by 00006 // the Free Software Foundation; either version 2, or (at your option) 00007 // any later version. 00008 00009 // This program is distributed in the hope that it will be useful, 00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 // GNU General Public License for more details. 00013 00014 // You should have received a copy of the GNU General Public License 00015 // along with this program; if not, write to the Free Software Foundation, 00016 // Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00017 00018 // $Id: MeshReaderAM_FMTFormat.cpp,v 1.1 2006/09/15 06:55:11 delpinux Exp $ 00019 00020 #include <MeshReaderAM_FMTFormat.hpp> 00021 00022 #include <Stringify.hpp> 00023 00024 #include <set> 00025 #include <sstream> 00026 00027 void MeshReaderAM_FMTFormat:: 00028 __checkVertex(const size_t& n) 00029 { 00030 if ((n == 0) or (n > (*__vertices).numberOfVertices())) { 00031 throw MeshReaderAM_FMTFormat::VertexError(); 00032 } 00033 } 00034 00035 00036 size_t MeshReaderAM_FMTFormat:: 00037 __getVertexNumber() 00038 { 00039 size_t n = this->__getInteger(); 00040 this->__checkVertex(n); 00041 00042 return n; 00043 } 00044 00045 void MeshReaderAM_FMTFormat:: 00046 __readTriangles() 00047 { 00048 ffout(4) << " - reading triangles\n"; 00049 VerticesSet& V = *__vertices; 00050 Vector<Triangle>& T = *__triangles; 00051 00052 size_t i; 00053 try { 00054 for (i=0; i<T.size(); ++i) { 00055 const size_t a = __getVertexNumber() - 1; 00056 const size_t b = __getVertexNumber() - 1; 00057 const size_t c = __getVertexNumber() - 1; 00058 00059 T[i] = Triangle(V[a],V[b],V[c], 0); 00060 } 00061 } 00062 catch (MeshReaderAM_FMTFormat::VertexError e) { 00063 throw MeshReader::Error("invalid vertex number reading triangle "+stringify(i)); 00064 } 00065 } 00066 00067 void MeshReaderAM_FMTFormat:: 00068 __readTrianglesReferences() 00069 { 00070 ffout(4) << " - reading triangles'references\n"; 00071 Vector<Triangle>& T = *__triangles; 00072 for (size_t i=0; i<T.size(); ++i) { 00073 T[i].reference() = this->__getInteger(); 00074 } 00075 } 00076 00077 void MeshReaderAM_FMTFormat:: 00078 __readVertices() 00079 { 00080 ffout(4) << " - reading vertices\n"; 00081 VerticesSet& V = *__vertices; 00082 for (size_t i=0; i<V.numberOfVertices(); ++i) { 00083 const double x = __getReal(); 00084 const double y = __getReal(); 00085 V[i] = Vertex(x,y,0); 00086 } 00087 } 00088 00089 void MeshReaderAM_FMTFormat:: 00090 __readVerticesReferences() 00091 { 00092 ffout(4) << " - reading vertices'references\n"; 00093 VerticesSet& V = *__vertices; 00094 for (size_t i=0; i<V.numberOfVertices(); ++i) { 00095 V[i].reference() = this->__getInteger(); 00096 } 00097 } 00098 00099 MeshReaderAM_FMTFormat:: 00100 MeshReaderAM_FMTFormat(const std::string& s) 00101 : MeshReader(s) 00102 { 00103 00104 ffout(3) << "\n"; 00105 ffout(3) << "Reading file " << s << '\n'; 00106 00107 const size_t numberOfVertices = this->__getInteger(); 00108 const size_t numberOfTriangles = this->__getInteger(); 00109 00110 ffout(3) << "- Number of vertices: " << numberOfVertices << '\n'; 00111 ffout(3) << "- Number of triangles: " << numberOfTriangles << '\n'; 00112 00113 __vertices = new VerticesSet(numberOfVertices); 00114 __triangles= new Vector<Triangle>(numberOfTriangles); 00115 00116 this->__readTriangles(); 00117 this->__readVertices(); 00118 this->__readTrianglesReferences(); 00119 this->__readVerticesReferences(); 00120 00121 this->__createMesh(); 00122 }
1.5.6