ViennaGrid - The Vienna Grid Library
2.1.0
|
00001 #ifndef VIENNAGRID_IO_VMESH_WRITER_HPP 00002 #define VIENNAGRID_IO_VMESH_WRITER_HPP 00003 00004 /* ======================================================================= 00005 Copyright (c) 2011-2014, Institute for Microelectronics, 00006 Institute for Analysis and Scientific Computing, 00007 TU Wien. 00008 00009 ----------------- 00010 ViennaGrid - The Vienna Grid Library 00011 ----------------- 00012 00013 License: MIT (X11), see file LICENSE in the base directory 00014 ======================================================================= */ 00015 00016 00017 #include <fstream> 00018 #include <sstream> 00019 #include <iostream> 00020 00021 #include "viennagrid/forwards.hpp" 00022 #include "viennagrid/mesh/segmentation.hpp" 00023 #include "viennagrid/mesh/mesh.hpp" 00024 #include "viennagrid/io/helper.hpp" 00025 #include "viennagrid/io/vtk_common.hpp" 00026 00031 namespace viennagrid 00032 { 00033 namespace io 00034 { 00035 00041 template < typename MeshType, typename SegmentationType = typename viennagrid::result_of::segmentation<MeshType>::type > 00042 class vmesh_writer 00043 { 00044 public: 00045 vmesh_writer() 00046 { 00047 empty_ = ""; 00048 indent_ = " "; 00049 } 00050 00059 void operator()(MeshType const & mesh_obj, SegmentationType const & segmentation, std::string const & inputfile, std::string const & outputfile) 00060 { 00061 std::stringstream ss; 00062 if(outputfile.substr( outputfile.rfind(".")+1 ) == "vmesh") 00063 ss << outputfile; 00064 else 00065 ss << outputfile << ".vmesh"; 00066 std::ofstream writer(ss.str().c_str()); 00067 00068 writer << "<mesh>" << std::endl; 00069 writer << indent_ << "<file>" << inputfile << "</file>" << std::endl; 00070 writer << indent_ << "<geomdim>" << typename viennagrid::result_of::point<MeshType>::type().size() << "</geomdim>" << std::endl; 00071 writer << indent_ << "<celltype>" << viennagrid::result_of::cell_tag<MeshType>::type::name() << "</celltype>" << std::endl; 00072 writer << indent_ << "<vertices>" << viennagrid::vertices(mesh_obj).size() << "</vertices>" << std::endl; 00073 writer << indent_ << "<cells>" << viennagrid::cells(mesh_obj).size() << "</cells>" << std::endl; 00074 writer << indent_ << "<segments>" << segmentation.size() << "</segments>" << std::endl; 00075 writer << indent_ << "<segmentation>" << std::endl; 00076 for (typename SegmentationType::const_iterator it = segmentation.begin(); it != segmentation.end(); ++it) 00077 { 00078 writer << indent_ << indent_ << "<segment>" << std::endl; 00079 writer << indent_ << indent_ << indent_ << "<id>" << it->id() << "</id>" << std::endl; 00080 writer << indent_ << indent_ << indent_ << "<name>" << empty_ << "</name>" << std::endl; 00081 writer << indent_ << indent_ << indent_ << "<vertices>" << viennagrid::vertices(*it).size() << "</vertices>" << std::endl; 00082 writer << indent_ << indent_ << indent_ << "<cells>" << viennagrid::cells(*it).size() << "</cells>" << std::endl; 00083 writer << indent_ << indent_ << "</segment>" << std::endl; 00084 } 00085 writer << indent_ << "</segmentation>" << std::endl; 00086 writer << "</mesh>" << std::endl; 00087 } 00088 00089 std::string empty_; 00090 std::string indent_; 00091 }; 00092 00093 } //namespace io 00094 } //namespace viennagrid 00095 00096 #endif 00097