import_ts.h
Go to the documentation of this file.
00001 /****************************************************************************
00002 * MeshLab                                                           o o     *
00003 * An extendible mesh processor                                    o     o   *
00004 *                                                                _   O  _   *
00005 * Copyright(C) 2005, 2009                                          \/)\/    *
00006 * Visual Computing Lab                                            /\/|      *
00007 * ISTI - Italian National Research Council                           |      *
00008 *                                                                    \      *
00009 * All rights reserved.                                                      *
00010 *                                                                           *
00011 * This program is free software; you can redistribute it and/or modify      *
00012 * it under the terms of the GNU General Public License as published by      *
00013 * the Free Software Foundation; either version 2 of the License, or         *
00014 * (at your option) any later version.                                       *
00015 *                                                                           *
00016 * This program is distributed in the hope that it will be useful,           *
00017 * but WITHOUT ANY WARRANTY; without even the implied warranty of            *
00018 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             *
00019 * GNU General Public License (http://www.gnu.org/licenses/gpl.txt)          *
00020 * for more details.                                                         *
00021 *                                                                           *
00022 ****************************************************************************/
00023 
00024 #ifndef __VCGLIB_IMPORTERTS
00025 #define __VCGLIB_IMPORTERTS
00026 #define NULL 0
00027 #include <vcg/space/point3.h>
00028 #include <vcg/space/point4.h>
00029 
00030 namespace vcg {
00031 namespace tetra {
00032 namespace io {
00033 
00034 template <typename  MESHTYPE>
00035 class ImporterTS{
00036         typedef MESHTYPE Tetramesh;
00037         typedef typename Tetramesh::VertexPointer VertexPointer;
00038         typedef typename Tetramesh::VertexType VertexType;
00039         typedef typename Tetramesh::TetraType FaceType;
00040         typedef typename Tetramesh::VertexIterator VertexIterator;
00041         typedef typename Tetramesh::TetraIterator FaceIterator;
00042         typedef typename Tetramesh::ScalarType ScalarType;
00043         typedef Point3<ScalarType> Point3x;
00044 
00045         static FILE *& F(){static FILE * f; return f;}
00046 
00047         inline static void ReadPos( Point3<double> &p){
00048                 fscanf(F(),"%lg %lg %lg",&p[0],&p[1],&p[2]);
00049         }
00050         inline static void  ReadPos( Point3<float> &p){
00051                 fscanf(F(),"%f %f %f",&p[0],&p[1],&p[2]);
00052         }
00053         inline static void  ReadPos( Point4<ScalarType> &p){
00054                 fscanf(F(),"%g %g %g %g",&p[0],&p[1],&p[2],&p[3]);
00055         }
00056 public:
00057 static int Open( Tetramesh & m, const char * filename )
00058 {       
00059         int nvertex;
00060         int ntetra;
00061         int tp0;
00062         int tp1;
00063         int tp2;
00064         int tp3;
00065         typename Tetramesh::VertexType p1;
00066         F() = fopen(filename,"r");
00067         if(F() == NULL ) 
00068                 {
00069                         printf( "The file was not opened\n" );
00070                         return -1;
00071                 }
00072    else
00073    {
00074                 fscanf(F(), "%i", &nvertex );
00075                 fscanf(F(), "%i", &ntetra );
00076                 m.tetra.reserve(ntetra);
00077     m.vert.reserve(nvertex);
00078                 int j;
00079                 for (j=0;j<nvertex;j++)
00080                 {
00081                         m.vert.push_back(VertexType());
00082                         ReadPos(m.vert.back().P());
00083       m.vert.back().ClearFlags();
00084                 }
00085                 for (j=0;j<ntetra;j++)
00086                 {
00087                         fscanf(F(), "%i", &tp0 );
00088                         fscanf(F(), "%i", &tp1 );
00089                         fscanf(F(), "%i", &tp2 );
00090                         fscanf(F(), "%i", &tp3 );
00091                         
00092                         m.tetra.push_back(typename Tetramesh::TetraType());
00093                         m.tetra.back().V(0) = &m.vert[tp0];
00094                         m.tetra.back().V(1) = &m.vert[tp1];
00095                         m.tetra.back().V(2) = &m.vert[tp2];
00096                         m.tetra.back().V(3) = &m.vert[tp3];
00097                         m.tetra.back().Flags() = 0;
00098                 }
00099          }
00100          m.vn = nvertex;
00101          m.tn = ntetra;
00102 
00103                 return 0;
00104          }
00105         };// end class
00106 }// end of io
00107 }// end of tetra
00108 }// end of vcg
00109 #endif


shape_reconstruction
Author(s): Roberto Martín-Martín
autogenerated on Sat Jun 8 2019 18:31:58