common.hh

Go to the documentation of this file.
00001 // -*- tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
00002 // vi: set et ts=8 sw=2 sts=2:
00003 
00004 #ifndef DUNE_GRID_IO_FILE_VTK_COMMON_HH
00005 #define DUNE_GRID_IO_FILE_VTK_COMMON_HH
00006 
00007 #include <limits>
00008 #include <sstream>
00009 #include <string>
00010 
00011 #include <dune/common/deprecated.hh>
00012 #include <dune/common/exceptions.hh>
00013 #include <dune/common/geometrytype.hh>
00014 #include <dune/common/typetraits.hh>
00015 
00023 namespace Dune
00024 {
00027 
00028   namespace VTK {
00029 
00031     //
00032     //  VTKOptions
00033     //
00034 
00036 
00041     enum OutputType {
00043       ascii,
00045       base64,
00047       appendedraw,
00049       appendedbase64
00050       // //! Output to the file is compressed inline binary.
00051       // binarycompressed,
00052       // //! Ouput is compressed and appended to the file.
00053       // compressedappended
00054     };
00056 
00065     enum DataMode {
00067 
00071       conforming,
00073 
00079       nonconforming
00080     };
00081 
00082   } // namespace VTK
00083 
00085 
00092   struct DUNE_DEPRECATED VTKOptions {
00094 
00102     typedef DUNE_DEPRECATED VTK::OutputType OutputType;
00104 
00107     static const VTK::OutputType ascii = VTK::ascii;
00109 
00112     static const VTK::OutputType binary = VTK::base64;
00114 
00117     static const VTK::OutputType binaryappended = VTK::appendedraw;
00119 
00131     typedef DUNE_DEPRECATED VTK::DataMode DataMode;
00133 
00139     static const VTK::DataMode conforming = VTK::conforming;
00141 
00149     static const VTK::DataMode nonconforming = VTK::nonconforming;
00150   };
00151 
00152   namespace VTK {
00153 
00155     //
00156     //  PrintType
00157     //
00158 
00160 
00164     template<typename T>
00165     struct PrintType {
00167       typedef T Type;
00168     };
00169 
00170     template<>
00171     struct PrintType<unsigned char> {
00172       typedef unsigned Type;
00173     };
00174 
00175     template<>
00176     struct PrintType<signed char> {
00177       typedef int Type;
00178     };
00179 
00180     template<>
00181     struct PrintType<char> {
00182       typedef SelectType<std::numeric_limits<char>::is_signed,
00183                          int, unsigned>::Type
00184         Type;
00185     };
00186 
00188     //
00189     //  TypeName
00190     //
00191 
00193 
00196     template<typename T>
00197     class TypeName {
00198       static std::string getString() {
00199         static const unsigned int_sizes[] = { 8, 16, 32, 64, 0 };
00200         static const unsigned float_sizes[] = { 32, 64, 0 };
00201         const unsigned* sizes;
00202 
00203         std::ostringstream s;
00204         if(std::numeric_limits<T>::is_integer) {
00205           if(std::numeric_limits<T>::is_signed)
00206             s << "Int";
00207           else
00208             s << "UInt";
00209           sizes = int_sizes;
00210         }
00211         else {
00212           // assume float
00213           s << "Float";
00214           sizes = float_sizes;
00215         }
00216 
00217         static const unsigned size = 8*sizeof(T);
00218         while(*sizes != 0 && *sizes <= size) ++sizes;
00219         --sizes;
00220         s << *sizes;
00221 
00222         return s.str();
00223       }
00224 
00225     public:
00227 
00230       const std::string& operator()() const {
00231         static const std::string s = getString();
00232         return s;
00233       }
00234     };
00235 
00237     //
00238     //  VTK::GeometryType related stuff
00239     //
00240 
00242 
00251     enum GeometryType {
00252       vertex = 1,
00253       line = 3,
00254       triangle = 5,
00255       quadrilateral = 9,
00256       tetrahedron = 10,
00257       hexahedron = 12,
00258       prism = 13,
00259       pyramid = 14
00260     };
00261 
00263 
00268     inline GeometryType geometryType(const Dune::GeometryType& t)
00269     {
00270       if (t.isVertex())        return vertex;
00271       if (t.isLine())          return line;
00272       if (t.isTriangle())      return triangle;
00273       if (t.isQuadrilateral()) return quadrilateral;
00274       if (t.isTetrahedron())   return tetrahedron;
00275       if (t.isPyramid())       return pyramid;
00276       if (t.isPrism())         return prism;
00277       if (t.isHexahedron())    return hexahedron;
00278 
00279       DUNE_THROW(IOError,"VTKWriter: unsupported GeometryType " << t);
00280     }
00281 
00283     //
00284     //  Functions for transforming the index of a corner inside an entity
00285     //  between Dune and VTK
00286     //
00287 
00289 
00297     inline int renumber(const Dune::GeometryType &t, int i)
00298     {
00299       static const int quadRenumbering[4] = {0,1,3,2};
00300       static const int cubeRenumbering[8] = {0,1,3,2,4,5,7,6};
00301       static const int prismRenumbering[6] = {0,2,1,3,5,4};
00302       static const int pyramidRenumbering[5] = {0,1,3,2,4};
00303 
00304       if (t.isQuadrilateral()) return quadRenumbering[i];
00305       if (t.isPyramid())       return pyramidRenumbering[i];
00306       if (t.isPrism())         return prismRenumbering[i];
00307       if (t.isHexahedron())    return cubeRenumbering[i];
00308 
00309       return i;
00310     }
00311 
00313 
00327     template<typename T>
00328     int renumber(const T& t, int i)
00329     {
00330       return renumber(t.type(), i);
00331     }
00332 
00334     //
00335     //  Determine Endianness
00336     //
00337 
00339 
00343     inline std::string getEndiannessString()
00344     {
00345       short i = 1;
00346       if (reinterpret_cast<char*>(&i)[1] == 1)
00347         return "BigEndian";
00348       else
00349         return "LittleEndian";
00350     }
00351 
00353     //
00354     //  which type of vtkfile to write
00355     //
00356 
00358 
00363     enum FileType {
00365       polyData,
00367       unstructuredGrid
00368     };
00369 
00370   } // namespace VTK
00371 
00373 
00374 } // namespace Dune
00375 
00376 #endif // DUNE_GRID_IO_FILE_VTK_COMMON_HH

Generated on Fri Apr 29 2011 with Doxygen (ver 1.7.1) [doxygen-log,error-log].