1
// Copyright (C) 2010 Anders Logg.
2
// Licensed under the GNU LGPL Version 2.1.
4
// First added: 2010-11-17
5
// Last changed: 2010-11-17
7
#ifndef __SUBSET_ITERATOR_H
8
#define __SUBSET_ITERATOR_H
12
#include <dolfin/common/types.h>
13
#include <dolfin/log/log.h>
14
#include "MeshFunction.h"
16
#include "MeshEntity.h"
21
/// A _SubsetIterator_ is similar to a _MeshEntityIterator_ but
22
/// iterates over a specified subset of the range of entities as
23
/// specified by a _MeshFunction_ that labels the entites.
29
/// Create iterator for given mesh function. The iterator visits
30
/// all entities that match the given label.
31
SubsetIterator(const MeshFunction<uint>& labels, uint label)
32
: entity(labels.mesh(), labels.dim(), 0)
36
for (MeshEntityIterator entity(labels.mesh(), labels.dim()); !entity.end(); ++entity)
38
if (labels[*entity] == label)
39
subset.push_back(entity->index());
41
info("Iterating over subset, found %d entities out of %d.",
42
subset.size(), labels.size());
49
virtual ~SubsetIterator() {}
51
/// Step to next mesh entity (prefix increment)
52
SubsetIterator& operator++()
58
/// Dereference operator
59
MeshEntity& operator*()
60
{ return *operator->(); }
62
/// Member access operator
63
MeshEntity* operator->()
64
{ entity._index = *it; return &entity; }
66
/// Check if iterator has reached the end
68
{ return it == subset.end(); }
76
std::vector<uint> subset;
79
std::vector<uint>::iterator it;