dune-grid
2.2.0
|
00001 // -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- 00002 // vi: set et ts=4 sw=2 sts=2: 00003 00004 #ifndef DUNE_GRID_IO_FILE_VTK_PVTUWRITER_HH 00005 #define DUNE_GRID_IO_FILE_VTK_PVTUWRITER_HH 00006 00007 #include <ostream> 00008 #include <string> 00009 00010 #include <dune/common/exceptions.hh> 00011 #include <dune/common/indent.hh> 00012 00013 #include <dune/grid/io/file/vtk/common.hh> 00014 00015 namespace Dune { 00016 00019 00020 namespace VTK { 00021 00023 00060 class PVTUWriter { 00061 std::ostream& stream; 00062 00063 std::string fileType; 00064 00065 Indent indent; 00066 00067 public: 00069 00076 inline PVTUWriter(std::ostream& stream_, FileType fileType_) 00077 : stream(stream_) 00078 { 00079 switch(fileType_) { 00080 case polyData: 00081 fileType = "PPolyData"; 00082 break; 00083 case unstructuredGrid: 00084 fileType = "PUnstructuredGrid"; 00085 break; 00086 default: 00087 DUNE_THROW(IOError, "PVTUWriter: Unknown fileType: " << fileType_); 00088 } 00089 const std::string& byteOrder = getEndiannessString(); 00090 00091 stream << indent << "<?xml version=\"1.0\"?>\n"; 00092 stream << indent << "<VTKFile" 00093 << " type=\"" << fileType << "\"" 00094 << " version=\"0.1\"" 00095 << " byte_order=\"" << byteOrder << "\">\n"; 00096 ++indent; 00097 } 00098 00100 inline ~PVTUWriter() { 00101 --indent; 00102 stream << indent << "</VTKFile>\n" 00103 << std::flush; 00104 } 00105 00107 00118 inline void beginPointData(const std::string& scalars = "", 00119 const std::string& vectors = "") { 00120 stream << indent << "<PPointData"; 00121 if(scalars != "") stream << " Scalars=\"" << scalars << "\""; 00122 if(vectors != "") stream << " Vectors=\"" << vectors << "\""; 00123 stream << ">\n"; 00124 ++indent; 00125 } 00127 inline void endPointData() { 00128 --indent; 00129 stream << indent << "</PPointData>\n"; 00130 } 00131 00133 00144 inline void beginCellData(const std::string& scalars = "", 00145 const std::string& vectors = "") { 00146 stream << indent << "<PCellData"; 00147 if(scalars != "") stream << " Scalars=\"" << scalars << "\""; 00148 if(vectors != "") stream << " Vectors=\"" << vectors << "\""; 00149 stream << ">\n"; 00150 ++indent; 00151 } 00153 inline void endCellData() { 00154 --indent; 00155 stream << indent << "</PCellData>\n"; 00156 } 00157 00159 00164 inline void beginPoints() { 00165 stream << indent << "<PPoints>\n"; 00166 ++indent; 00167 } 00169 inline void endPoints() { 00170 --indent; 00171 stream << indent << "</PPoints>\n"; 00172 } 00173 00175 00187 inline void beginMain(unsigned ghostLevel = 0) { 00188 stream << indent << "<" << fileType 00189 << " GhostLevel=\"" << ghostLevel << "\">\n"; 00190 ++indent; 00191 } 00193 inline void endMain() { 00194 --indent; 00195 stream << indent << "</" << fileType << ">\n"; 00196 } 00197 00199 00204 template<typename T> 00205 void addArray(const std::string& name, unsigned ncomps) { 00206 TypeName<T> tn; 00207 stream << indent << "<PDataArray" 00208 << " type=\"" << tn() << "\"" 00209 << " Name=\"" << name << "\"" 00210 << " NumberOfComponents=\"" << ncomps << "\"/>\n"; 00211 } 00212 00214 inline void addPiece(const std::string& filename) { 00215 stream << indent << "<Piece " 00216 << " Source=\"" << filename << "\"/>\n"; 00217 } 00218 }; 00219 00220 } // namespace VTK 00221 00223 00224 } // namespace Dune 00225 00226 #endif // DUNE_GRID_IO_FILE_VTK_PVTUWRITER_HH