dune-grid 3.0-git
corneriterator.hh
Go to the documentation of this file.
1// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2// vi: set et ts=4 sw=2 sts=2:
3
4#ifndef DUNE_GRID_IO_FILE_VTK_CORNERITERATOR_HH
5#define DUNE_GRID_IO_FILE_VTK_CORNERITERATOR_HH
6
7#include <iterator>
8
9#include <dune/common/iteratorfacades.hh>
10#include <dune/common/typetraits.hh>
11
12#include <dune/geometry/referenceelements.hh>
13
15
16namespace Dune
17{
20
21 namespace VTK {
22
24
28 template<typename CellIterator>
30 : public ForwardIteratorFacade
31 < CornerIterator<CellIterator>,
32 const Corner<typename std::remove_const<typename std::iterator_traits<
33 CellIterator>::value_type>::type>,
34 const Corner<typename std::remove_const<typename std::iterator_traits<
35 CellIterator>::value_type>::type>&,
36 typename std::iterator_traits<CellIterator>::difference_type>
37 {
38 public:
39 // reiterate the facades typedefs here
41 typedef VTK::Corner<typename std::remove_const<typename std::iterator_traits<
42 CellIterator>::value_type>::type> Corner;
43 typedef const Corner Value;
44 typedef Value& Reference;
45 typedef typename std::iterator_traits<CellIterator>::difference_type
47
48 typedef typename std::iterator_traits<CellIterator>::value_type::Geometry::ctype
50 static const unsigned dim = std::iterator_traits<CellIterator>::
51 value_type::mydimension;
52 typedef ReferenceElements<ctype, dim> Refelems;
53
54 private:
55 typedef ForwardIteratorFacade<DerivedType, Value, Reference,
56 DifferenceType> Facade;
57
58 CellIterator cellit;
59 CellIterator cellend;
60 Corner corner;
61
62 public:
64 return corner;
65 }
66
67 bool isDereferencable() const {
68 return cellit != cellend;
69 }
70
71 bool equals(const DerivedType& other) const {
72 bool mePassedTheEnd = !isDereferencable();
73 bool otherPassedTheEnd = !other.isDereferencable();
74 // both are passed the end => return true
75 if(mePassedTheEnd && otherPassedTheEnd) return true;
76 // one is passed the end => return false
77 if(mePassedTheEnd || otherPassedTheEnd) return false;
78 // none is passed the end, do their iterators and indices match?
79 return cellit == other.cellit &&
80 corner.duneIndex() == other.corner.duneIndex();
81 }
82
83 void increment() {
84 int index = corner.vtkIndex();
85 ++index;
86 if(index == Refelems::general(cellit->type()).size(dim)) {
87 ++cellit;
88 if(cellit != cellend) {
89 corner.cell(*cellit);
90 corner.vtkIndex(0);
91 }
92 }
93 else
94 corner.vtkIndex(index);
95 }
96
98
103 CornerIterator(const CellIterator& cellit_, const CellIterator& cellend_,
104 unsigned vtkIndex = 0)
105 : cellit(cellit_), cellend(cellend_)
106 {
107 if(cellit != cellend) {
108 corner.cell(*cellit);
109 corner.vtkIndex(vtkIndex);
110 }
111 }
113
116 CornerIterator(const CellIterator& cellend_)
117 : cellit(cellend_), cellend(cellend_)
118 { }
119 };
120
121 } // namespace VTK
122
124
125} // namespace Dune
126
127#endif // DUNE_GRID_IO_FILE_VTK_CORNERITERATOR_HH
Include standard header files.
Definition agrid.hh:60
simple class representing a corner of a cell
Definition corner.hh:23
unsigned vtkIndex() const
get the index of the corner within the cell in VTK-numbering
Definition corner.hh:61
unsigned duneIndex() const
get the index of the corner within the cell in Dune-numbering
Definition corner.hh:53
const Cell & cell() const
get reference to the cell
Definition corner.hh:44
iterate over the corners of some cell range
Definition corneriterator.hh:37
Value & Reference
Definition corneriterator.hh:44
VTK::Corner< typename std::remove_const< typename std::iterator_traits< CellIterator >::value_type >::type > Corner
Definition corneriterator.hh:42
void increment()
Definition corneriterator.hh:83
Reference dereference() const
Definition corneriterator.hh:63
std::iterator_traits< CellIterator >::difference_type DifferenceType
Definition corneriterator.hh:46
static const unsigned dim
Definition corneriterator.hh:50
ReferenceElements< ctype, dim > Refelems
Definition corneriterator.hh:52
const Corner Value
Definition corneriterator.hh:43
CornerIterator(const CellIterator &cellit_, const CellIterator &cellend_, unsigned vtkIndex=0)
construct a CornerIterator
Definition corneriterator.hh:103
CornerIterator(const CellIterator &cellend_)
construct a CornerIterator
Definition corneriterator.hh:116
bool equals(const DerivedType &other) const
Definition corneriterator.hh:71
CornerIterator< CellIterator > DerivedType
Definition corneriterator.hh:40
std::iterator_traits< CellIterator >::value_type::Geometry::ctype ctype
Definition corneriterator.hh:49
bool isDereferencable() const
Definition corneriterator.hh:67