• Main Page
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

/export/development/ViennaGrid/release/ViennaGrid-1.0.0/viennagrid/io/vtk_common.hpp

Go to the documentation of this file.
00001 #ifndef VIENNAGRID_IO_VTK_COMMON_HPP
00002 #define VIENNAGRID_IO_VTK_COMMON_HPP
00003 
00004 /* =======================================================================
00005    Copyright (c) 2011, Institute for Microelectronics,
00006                        Institute for Analysis and Scientific Computing,
00007                        TU Wien.
00008 
00009                             -----------------
00010                      ViennaGrid - The Vienna Grid Library
00011                             -----------------
00012 
00013    Authors:      Karl Rupp                           rupp@iue.tuwien.ac.at
00014                  Josef Weinbub                    weinbub@iue.tuwien.ac.at
00015                
00016    (A list of additional contributors can be found in the PDF manual)
00017 
00018    License:      MIT (X11), see file LICENSE in the base directory
00019 ======================================================================= */
00020 
00021 
00022 #include <fstream>
00023 #include <iostream>
00024 #include "viennagrid/io/helper.hpp"
00025 #include "viennagrid/topology/all.hpp"
00026 #include "viennagrid/forwards.h"
00027 
00032 namespace viennagrid
00033 {
00034   namespace io
00035   {
00042     template <typename ElementTag>
00043     struct ELEMENT_TAG_TO_VTK_TYPE
00044     {
00045       enum{ ReturnValue = ElementTag::ERROR_ELEMENT_TYPE_NOT_SUPPORTED };
00046     };
00047 
00049     template <>
00050     struct ELEMENT_TAG_TO_VTK_TYPE<hexahedron_tag>
00051     {
00052       enum{ value = 12 };
00053     };
00054 
00056     template <>
00057     struct ELEMENT_TAG_TO_VTK_TYPE<tetrahedron_tag>
00058     {
00059       enum{ value = 10 };
00060     };
00061     
00063     template <>
00064     struct ELEMENT_TAG_TO_VTK_TYPE<quadrilateral_tag>
00065     {
00066       enum{ value = 9 };
00067     };
00068 
00070     template <>
00071     struct ELEMENT_TAG_TO_VTK_TYPE<triangle_tag>
00072     {
00073       enum{ value = 5 };
00074     };
00075 
00077     template <>
00078     struct ELEMENT_TAG_TO_VTK_TYPE<hypercube_tag<1> >
00079     {
00080       enum{ value = 3 };
00081     };
00082     
00084     template <>
00085     struct ELEMENT_TAG_TO_VTK_TYPE<simplex_tag<1> >
00086     {
00087       enum{ value = 3 };
00088     };
00089     
00094     template <typename CellTag>
00095     struct vtk_to_viennagrid_orientations
00096     {
00097       long operator()(long j) const { return j; }  //default case: do nothing
00098     };
00099 
00104     template <typename CellTag>
00105     struct viennagrid_to_vtk_orientations
00106     {
00107       long operator()(long j) const { return j; }  //default case: do nothing
00108     };
00109 
00111     template <>
00112     struct vtk_to_viennagrid_orientations<quadrilateral_tag>
00113     {
00114       long operator()(long j) const
00115       {
00116         switch (j)
00117         {
00118           case 2: return 3;
00119           case 3: return 2;
00120           default: return j;
00121         }
00122         return j;
00123       }
00124     };
00125     
00127     template <>
00128     struct viennagrid_to_vtk_orientations<quadrilateral_tag>
00129     {
00130       long operator()(long j) const
00131       {
00132         return vtk_to_viennagrid_orientations<quadrilateral_tag>()(j);
00133       }
00134     };
00135 
00136     // for hexahedra:
00138     template <>
00139     struct vtk_to_viennagrid_orientations<hexahedron_tag>
00140     {
00141       long operator()(long j) const
00142       {
00143         switch (j)
00144         {
00145           case 2: return 3;
00146           case 3: return 2;
00147           case 6: return 7;
00148           case 7: return 6;
00149           default: return j;
00150         }
00151         return j;
00152       }
00153     };
00154 
00156     template <>
00157     struct viennagrid_to_vtk_orientations<hexahedron_tag>
00158     {
00159       long operator()(long j) const
00160       {
00161         return vtk_to_viennagrid_orientations<hexahedron_tag>()(j);
00162       }
00163     };
00164 
00165 
00166 
00167 
00168 
00174     template <typename DomainSegmentType,
00175               typename IDHandler = typename viennagrid::result_of::element_id_handler<typename DomainSegmentType::config_type,
00176                                                                                       viennagrid::point_tag>::type
00177              >
00178     class vtk_vertex_id_repository //default case: This is a segment
00179     {
00180         typedef typename DomainSegmentType::config_type                      ConfigType;
00181         typedef typename viennagrid::result_of::segment<ConfigType>::type    SegmentType;
00182         typedef typename viennagrid::result_of::ncell<ConfigType, 0>::type   VertexType;
00183         
00184       public:
00185         vtk_vertex_id_repository(SegmentType const & seg) {}
00186       
00188         long operator()(VertexType const & v, SegmentType const & seg) const
00189         {
00190           return viennadata::access<segment_mapping_key<SegmentType>, long>(seg)(v);
00191         }
00192     };
00193     
00195     template <typename ConfigType>
00196     class vtk_vertex_id_repository< viennagrid::domain_t<ConfigType>, viennagrid::integral_id >
00197     {
00198         typedef typename viennagrid::result_of::domain<ConfigType>::type     DomainType;
00199         typedef typename viennagrid::result_of::ncell<ConfigType, 0>::type   VertexType;
00200         
00201       public:
00202         vtk_vertex_id_repository(DomainType const & seg) {}
00203       
00205         long operator()(VertexType const & v, DomainType const & seg) const
00206         {
00207           return v.id();
00208         }
00209     };
00210 
00212     template <typename ConfigType>
00213     class vtk_vertex_id_repository< viennagrid::domain_t<ConfigType>, viennagrid::pointer_id >
00214     {
00215         typedef typename viennagrid::domain_t<ConfigType>                    DomainType;
00216         typedef typename viennagrid::result_of::ncell<ConfigType, 0>::type   VertexType;
00217         
00218       public:
00219         vtk_vertex_id_repository(DomainType const & domain)
00220         {
00221           typedef typename viennagrid::result_of::const_ncell_range<DomainType, 0>::type    VertexRange;
00222           typedef typename viennagrid::result_of::iterator<VertexRange>::type               VertexIterator;
00223           
00224           VertexRange vertices = viennagrid::ncells(domain);
00225           long vertex_index = 0;
00226           for (VertexIterator vit = vertices.begin();
00227                               vit != vertices.end();
00228                             ++vit, ++vertex_index)
00229           {
00230             ptr_to_global_id[&(*vit)] = vertex_index;
00231           }
00232         }
00233       
00235         long operator()(VertexType const & v, DomainType const &)
00236         {
00237           return ptr_to_global_id[&v];
00238         }
00239         
00240       private:
00241         std::map<VertexType const *, long>  ptr_to_global_id;
00242     };
00243     
00244 
00245     
00246   } //namespace io
00247 } //namespace viennagrid
00248 
00249 #endif
00250 

Generated on Wed Sep 14 2011 19:21:30 for ViennaGrid by  doxygen 1.7.1