00001 #ifndef GRAL_GB_BASE_FACET_GRID_H
00002 #define GRAL_GB_BASE_FACET_GRID_H
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include "Gral/Base/common-grid-basics.h"
00019 #include "Gral/Subranges/enumerated-element-range.h"
00020
00021
00022 #include "Gral/Base/element-sequence-references.h"
00023
00024 namespace GrAL {
00025
00030 template<class FACETRANGE>
00031 struct grid_types_facet_grid : public grid_types_detail::grid_types_root {
00032 typedef grid_types<FACETRANGE> fgt;
00033
00034 typedef typename FACETRANGE::grid_type base_grid_type;
00035 typedef grid_types<base_grid_type> bgt;
00036
00037 typedef typename bgt::Facet Cell;
00038 typedef typename bgt::Vertex Vertex;
00039 typedef typename bgt::facet_handle cell_handle;
00040 typedef typename bgt::vertex_handle vertex_handle;
00041 typedef typename bgt::VertexOnFacetIterator VertexOnCellIterator;
00042
00043
00044 typedef typename FACETRANGE::FacetIterator CellIterator;
00045
00046
00047 enum { dim = ( bgt::dimension_tag::dim > 0
00048 ? bgt::dimension_tag::dim - 1
00049 : -1) };
00050 typedef grid_dim_tag<dim> dimension_tag;
00051 };
00052
00053
00060 template<class FACETRANGE>
00061 class facet_grid
00062 : public grid_types_facet_grid<FACETRANGE> {
00063 private:
00064 typedef facet_grid<FACETRANGE> self;
00065 typedef grid_types_facet_grid<FACETRANGE> gt;
00066 public:
00067 enum { dim = gt::dimension_tag::dim };
00068 typedef self grid_type;
00069 typedef grid_category_d<dim> category;
00070
00071 typedef typename gt::base_grid_type base_grid_type;
00072 typedef enumerated_vertex_range<base_grid_type> vertex_range_type;
00073 typedef FACETRANGE facet_range_type;
00074 typedef typename vertex_range_type::VertexIterator VertexIterator;
00075 typedef typename gt ::CellIterator CellIterator;
00076 private:
00077 FACETRANGE const* facets;
00078 vertex_range_type vertices;
00079
00080 public:
00081 facet_grid() : facets(0) {}
00082
00083 facet_grid(FACETRANGE const& f) : facets(&f), vertices(facets->TheGrid())
00084 {
00085 vertex_set_of_facets_iterator<FACETRANGE> v(*facets);
00086 while(! v.IsDone()) {
00087 vertices.push_back(*v);
00088 ++v;
00089 }
00090 }
00091
00092
00093
00094 unsigned NumOfCells() const { return facets->NumOfFacets();}
00095 unsigned NumOfVertices() const { return vertices.NumOfVertices();}
00096
00097 CellIterator FirstCell() const { return begin<CellIterator>(*facets);}
00098 CellIterator EndCell() const { return end <CellIterator>(*facets);}
00099
00100 VertexIterator FirstVertex() const { return vertices.FirstVertex();}
00101 VertexIterator EndVertex() const { return vertices.EndVertex();}
00102 };
00103
00104 template<class FACETRANGE>
00105 struct grid_types<facet_grid<FACETRANGE> >
00106 : public grid_types_facet_grid<FACETRANGE>
00107 {
00108 typedef typename facet_grid<FACETRANGE>::VertexIterator VertexIterator;
00109 };
00110
00111 #define gt typename grid_types<FACETRANGE>
00112
00113
00114 template<class FACETRANGE>
00115 inline gt::VertexIterator gral_begin(facet_grid<FACETRANGE> const& a,
00116 typename enumerated_vertex_range<typename FACETRANGE::grid_type>::VertexIterator)
00117 { return a.FirstVertex();}
00118
00119 template<class FACETRANGE>
00120 inline gt::VertexIterator gral_end (facet_grid<FACETRANGE> const& a,
00121 typename grid_types<FACETRANGE>::VertexIterator)
00122 { return a.EndVertex();}
00123
00124 template<class FACETRANGE>
00125 inline gt::VertexIterator gral_size (facet_grid<FACETRANGE> const& a,
00126 typename grid_types<FACETRANGE>::VertexIterator)
00127 { return a.NumOfVertices();}
00128
00129
00130
00131 template<class FACETRANGE>
00132 inline gt::CellIterator gral_begin(facet_grid<FACETRANGE> const& a,
00133 typename grid_types<FACETRANGE>::CellIterator)
00134 { return a.FirstCell();}
00135
00136 template<class FACETRANGE>
00137 inline gt::CellIterator gral_end (facet_grid<FACETRANGE> const& a,
00138 typename grid_types<FACETRANGE>::CellIterator)
00139 { return a.EndCell();}
00140
00141 template<class FACETRANGE>
00142 inline gt::CellIterator gral_size (facet_grid<FACETRANGE> const& a,
00143 typename grid_types<FACETRANGE>::CellIterator)
00144 { return a.NumOfCells();}
00145
00146
00147 #undef gt
00148
00149 }
00150
00151 #endif
00152