• 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/grid/io/grid_matlab_write.h

Go to the documentation of this file.
00001 #ifndef OPENTISSUE_CORE_CONTAINERS_GRID_IO_GRID_MATLAB_WRITE_H
00002 #define OPENTISSUE_CORE_CONTAINERS_GRID_IO_GRID_MATLAB_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 <iostream>
00013 #include <fstream>
00014 #include <string>
00015 
00016 namespace OpenTissue
00017 {
00018   namespace grid
00019   {
00020 
00029     template <typename grid_type>
00030     inline bool matlab_write(std::string const & mfile, grid_type const & grid)
00031     {
00032       typedef typename grid_type::value_type    value_type;
00033       typedef typename grid_type::math_types    math_types;
00034       typedef typename math_types::vector3_type vector3_type;
00035       typedef typename math_types::real_type    real_type;
00036 
00037       std::ofstream file(mfile.c_str());
00038       file.precision(30);
00039 
00040       value_type * value = grid.data();
00041       for (size_t k=0; k<grid.K(); ++k)
00042       {
00043         file << "mfile(:,:," << k+1 << ") = [ " ;
00044         for (size_t j=0; j<grid.J(); ++j)
00045         {
00046           file << "[ " ;
00047 
00048           for (size_t i=0; i<grid.I()-1; ++i, value++)
00049           {
00050             file << static_cast<double>(*value) << ", " ;
00051           }
00052           file << static_cast<double>(*value++) << "];" << std::endl;
00053         }
00054         file << "];" << std::endl;
00055       }
00056       file.flush();
00057       file.close();
00058       return true;
00059     }
00060 
00061   } // namespace grid
00062 } // namespace OpenTissue
00063 
00064 // OPENTISSUE_CORE_CONTAINERS_GRID_IO_GRID_MATLAB_WRITE_H
00065 #endif

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