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