• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Classes
  • Files
  • Examples
  • File List
  • File Members

/home/hauberg/Dokumenter/Capture/humim-tracker-0.1/src/OpenTissue/OpenTissue/core/containers/mesh/common/io/mesh_default_write.h

Go to the documentation of this file.
00001 #ifndef OPENTISSUE_CORE_CONTAINERS_MESH_COMMON_IO_MESH_DEFAULT_WRITE_H
00002 #define OPENTISSUE_CORE_CONTAINERS_MESH_COMMON_IO_MESH_DEFAULT_WRITE_H
00003 //
00004 // OpenTissue Template Library
00005 // - A generic toolbox for physics-based modeling and simulation.
00006 // Copyright (C) 2008 Department of Computer Science, University of Copenhagen.
00007 //
00008 // OTTL is licensed under zlib: http://opensource.org/licenses/zlib-license.php
00009 //
00010 #include <OpenTissue/configuration.h>
00011 
00012 #include <cassert>
00013 #include <string>
00014 #include <fstream>
00015 #include <iostream>
00016 #include <vector>
00017 
00018 namespace OpenTissue
00019 {
00020   namespace mesh
00021   {
00031     template<typename mesh_type>
00032     bool default_write(std::string const & filename, mesh_type const & mesh)
00033     {
00034       typedef typename mesh_type::math_types                    math_types;
00035       typedef typename math_types::value_traits                 value_traits;
00036       typedef typename math_types::vector3_type                 vector3_type;
00037       typedef typename math_types::real_type                    real_type;
00038       typedef typename mesh_type::vertex_handle                 vertex_handle;
00039       typedef typename mesh_type::index_type                    index_type;
00040       typedef typename mesh_type::const_vertex_iterator         const_vertex_iterator;
00041       typedef typename mesh_type::const_face_iterator           const_face_iterator;
00042       typedef typename mesh_type::const_face_vertex_circulator  const_face_vertex_circulator;
00043 
00044       std::ofstream file(filename.c_str());
00045       file.precision(30);
00046 
00047       file << "NODES\n{\n";
00048       const_vertex_iterator vend = mesh.vertex_end();
00049       const_vertex_iterator v    = mesh.vertex_begin();
00050 
00051       index_type idx = 0;
00052       for(;v!=vend;++v,++idx)
00053       {
00054         assert(v->get_handle().get_idx() == idx || !"Oh no, vertices did not have consecutive indices???");
00055         file << '\t' << v->m_coord(0)
00056           << '\t' << v->m_coord(1)
00057           << '\t' << v->m_coord(2)
00058           << '\n';
00059       }
00060       file << "}\n";
00061 
00062       file << "FACES\n{\n";
00063       const_face_iterator fend = mesh.face_end();
00064       const_face_iterator f    = mesh.face_begin();
00065 
00066       for(;f!=fend;++f)
00067       {
00068         if(valency(*f)!=3)
00069         {
00070           std::cout << "mesh::default_write(): Warning, non-triangular face with " << valency(*f) << " vertices" << std::endl;
00071           continue;
00072         }
00073         const_face_vertex_circulator fvc(*f),end;
00074         for(;fvc!=end;++fvc)
00075         {
00076           file << '\t' << fvc->get_handle().get_idx();
00077         }
00078         file << '\n';
00079       }
00080       file << "}\n";
00081       std::cout << "mesh::default_write(...): written " << filename << std::endl;
00082       return true;
00083     }
00084 
00085   } // namespace mesh
00086 } // namespace OpenTissue
00087 
00088 //OPENTISSUE_CORE_CONTAINERS_MESH_COMMON_IO_MESH_DEFAULT_WRITE_H
00089 #endif

Generated on Thu Dec 1 2011 12:51:11 for HUMIM Tracker by  doxygen 1.7.1