Commit 33fc6210 authored by Alexander Dielen's avatar Alexander Dielen
Browse files

Added CellHalfFaceIter and CellFaceIter.

parent d1ca9145
......@@ -1059,6 +1059,100 @@ CellIter& CellIter::operator++() {
return *this;
}
namespace Internal {
////================================================================================================
//// CellHalfFaceIterImpl
////================================================================================================
CellHalfFaceIterImpl::CellHalfFaceIterImpl(const CellHandle& _ref_h, const TopologyKernel* _mesh, int _max_laps) :
BaseIter(_mesh, _ref_h, _max_laps),
hf_iter_(BaseIter::mesh()->cell(_ref_h).halffaces().begin())
{
BaseIter::valid(hf_iter_ != BaseIter::mesh()->cell(_ref_h).halffaces().end());
if (BaseIter::valid()) {
BaseIter::cur_handle(*hf_iter_);
}
}
CellHalfFaceIterImpl& CellHalfFaceIterImpl::operator--() {
const std::vector<HalfFaceHandle>& halffaces =
BaseIter::mesh()->cell(ref_handle_).halffaces();
if (hf_iter_ == halffaces.begin()) {
hf_iter_ == halffaces.end();
--lap_;
if (lap_ < 0)
BaseIter::valid(false);
}
else {
--hf_iter_;
}
BaseIter::cur_handle(*hf_iter_);
return *this;
}
CellHalfFaceIterImpl& CellHalfFaceIterImpl::operator++() {
++hf_iter_;
const std::vector<HalfFaceHandle>& halffaces =
BaseIter::mesh()->cell(ref_handle_).halffaces();
if (hf_iter_ == halffaces.end()) {
hf_iter_ = halffaces.begin();
++lap_;
if (lap_ >= max_laps_)
BaseIter::valid(false);
}
BaseIter::cur_handle(*hf_iter_);
return *this;
}
////================================================================================================
//// CellFaceIterImpl
////================================================================================================
CellFaceIterImpl::CellFaceIterImpl(const CellHandle& _ref_h, const TopologyKernel* _mesh, int _max_laps) :
BaseIter(_mesh, _ref_h, _max_laps),
hf_iter_(BaseIter::mesh()->cell(_ref_h).halffaces().begin())
{
BaseIter::valid(hf_iter_ != BaseIter::mesh()->cell(_ref_h).halffaces().end());
if (BaseIter::valid()) {
BaseIter::cur_handle(BaseIter::mesh()->face_handle(*hf_iter_));
}
}
CellFaceIterImpl& CellFaceIterImpl::operator--() {
const std::vector<HalfFaceHandle>& halffaces =
BaseIter::mesh()->cell(ref_handle_).halffaces();
if (hf_iter_ == halffaces.begin()) {
hf_iter_ == halffaces.end();
--lap_;
if (lap_ < 0)
BaseIter::valid(false);
}
else {
--hf_iter_;
}
BaseIter::cur_handle(BaseIter::mesh()->face_handle(*hf_iter_));
return *this;
}
CellFaceIterImpl& CellFaceIterImpl::operator++() {
++hf_iter_;
const std::vector<HalfFaceHandle>& halffaces =
BaseIter::mesh()->cell(ref_handle_).halffaces();
if (hf_iter_ == halffaces.end()) {
hf_iter_ = halffaces.begin();
++lap_;
if (lap_ >= max_laps_)
BaseIter::valid(false);
}
BaseIter::cur_handle(BaseIter::mesh()->face_handle(*hf_iter_));
return *this;
}
}
////================================================================================================
//// BoundaryItemIter
////================================================================================================
......
......@@ -1158,6 +1158,110 @@ private:
//===========================================================================
namespace Internal {
//===========================================================================
class CellHalfFaceIterImpl : public BaseCirculator<CellHandle, HalfFaceHandle> {
public:
typedef BaseCirculator<CellHandle, HalfFaceHandle> BaseIter;
CellHalfFaceIterImpl(const CellHandle& _ref_h, const TopologyKernel* _mesh, int _max_laps = 1);
CellHalfFaceIterImpl& operator++();
CellHalfFaceIterImpl& operator--();
private:
std::vector<HalfFaceHandle>::const_iterator hf_iter_;
};
//===========================================================================
class CellFaceIterImpl : public BaseCirculator<CellHandle, FaceHandle> {
public:
typedef BaseCirculator<CellHandle, FaceHandle> BaseIter;
CellFaceIterImpl(const CellHandle& _ref_h, const TopologyKernel* _mesh, int _max_laps = 1);
CellFaceIterImpl& operator++();
CellFaceIterImpl& operator--();
private:
std::vector<HalfFaceHandle>::const_iterator hf_iter_;
};
//===========================================================================
} // Namespace Internal
//===========================================================================
template <class CirculatorImpl>
class GenericCirculator : public CirculatorImpl {
public:
GenericCirculator(const CellHandle& _ref_h, const TopologyKernel* _mesh, int _max_laps = 1) :
CirculatorImpl(_ref_h, _mesh, _max_laps) {}
GenericCirculator& operator++() {
CirculatorImpl::operator++();
return *this;
}
GenericCirculator& operator--() {
CirculatorImpl::operator--();
return *this;
}
// Post increment/decrement operator
GenericCirculator operator++(int) {
GenericCirculator cpy = *this;
++(*this);
return cpy;
}
GenericCirculator operator--(int) {
GenericCirculator cpy = *this;
--(*this);
return cpy;
}
GenericCirculator operator+(int _n) {
GenericCirculator cpy = *this;
for(int i = 0; i < _n; ++i) {
++cpy;
}
return cpy;
}
GenericCirculator operator-(int _n) {
GenericCirculator cpy = *this;
for(int i = 0; i < _n; ++i) {
--cpy;
}
return cpy;
}
GenericCirculator& operator+=(int _n) {
for(int i = 0; i < _n; ++i) {
++(*this);
}
return *this;
}
GenericCirculator& operator-=(int _n) {
for(int i = 0; i < _n; ++i) {
--(*this);
}
return *this;
}
};
//===========================================================================
typedef GenericCirculator<Internal::CellHalfFaceIterImpl> CellHalfFaceIter;
typedef GenericCirculator<Internal::CellFaceIterImpl> CellFaceIter;
//===========================================================================
template <class Iter, class Handle>
class BoundaryItemIter : public BaseIterator<Handle> {
public:
......
......@@ -182,6 +182,24 @@ public:
return std::make_pair(begin, make_end_circulator(begin));
}
CellHalfFaceIter chf_iter(const CellHandle& _h, int _max_laps = 1) const {
return CellHalfFaceIter(_h, this, _max_laps);
}
std::pair<CellHalfFaceIter, CellHalfFaceIter> cell_halffaces(const CellHandle& _h, int _max_laps = 1) const {
CellHalfFaceIter begin = chf_iter(_h, _max_laps);
return std::make_pair(begin, make_end_circulator(begin));
}
CellFaceIter cf_iter(const CellHandle& _h, int _max_laps = 1) const {
return CellFaceIter(_h, this, _max_laps);
}
std::pair<CellFaceIter, CellFaceIter> cell_faces(const CellHandle& _h, int _max_laps = 1) const {
CellFaceIter begin = cf_iter(_h, _max_laps);
return std::make_pair(begin, make_end_circulator(begin));
}
CellCellIter cc_iter(const CellHandle& _h, int _max_laps = 1) const {
return CellCellIter(_h, this, _max_laps);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment