Commit 9803a5c4 authored by Alexander Dielen's avatar Alexander Dielen
Browse files

Added boundary iterators.

parent cd0a41ca
Pipeline #6351 failed with stage
in 2 minutes and 43 seconds
......@@ -804,68 +804,6 @@ BoundaryHalfFaceHalfFaceIter& BoundaryHalfFaceHalfFaceIter::operator++() {
return *this;
}
////================================================================================================
//// BoundaryFaceIter
////================================================================================================
BoundaryFaceIter::BoundaryFaceIter(const TopologyKernel* _mesh) :
BaseIter(_mesh),
bf_it_(_mesh->faces_begin()) {
if(!_mesh->has_face_bottom_up_incidences()) {
#ifndef NDEBUG
std::cerr << "This iterator needs bottom-up incidences!" << std::endl;
#endif
BaseIter::valid(false);
return;
}
while(bf_it_ != BaseIter::mesh()->faces_end() &&
!BaseIter::mesh()->is_boundary(*bf_it_) &&
BaseIter::mesh()->is_deleted(bf_it_.cur_handle())){
++bf_it_;
}
BaseIter::valid(bf_it_ != BaseIter::mesh()->faces_end());
if(BaseIter::valid()) {
BaseIter::cur_handle(*bf_it_);
}
}
BoundaryFaceIter& BoundaryFaceIter::operator--() {
--bf_it_;
while(bf_it_ >= BaseIter::mesh()->faces_begin() &&
!BaseIter::mesh()->is_boundary(*bf_it_) &&
BaseIter::mesh()->is_deleted(bf_it_.cur_handle())){
--bf_it_;
}
if(bf_it_ >= BaseIter::mesh()->faces_begin()) {
BaseIter::cur_handle(*bf_it_);
} else {
BaseIter::valid(false);
}
return *this;
}
BoundaryFaceIter& BoundaryFaceIter::operator++() {
++bf_it_;
while(bf_it_ != BaseIter::mesh()->faces_end() &&
!BaseIter::mesh()->is_boundary(*bf_it_) &&
BaseIter::mesh()->is_deleted(bf_it_.cur_handle())){
++bf_it_;
}
if(bf_it_ != BaseIter::mesh()->faces_end()) {
BaseIter::cur_handle(*bf_it_);
} else {
BaseIter::valid(false);
}
return *this;
}
////================================================================================================
//// VertexIter
////================================================================================================
......@@ -1124,4 +1062,71 @@ CellIter& CellIter::operator++() {
return *this;
}
////================================================================================================
//// BoundaryItemIter
////================================================================================================
template <>
size_t BoundaryItemIter<VertexIter, VertexHandle>::n_items() const {
return BaseIter::mesh()->n_vertices();
}
template <>
size_t BoundaryItemIter<HalfEdgeIter, HalfEdgeHandle>::n_items() const {
return BaseIter::mesh()->n_halfedges();
}
template <>
size_t BoundaryItemIter<EdgeIter, EdgeHandle>::n_items() const {
return BaseIter::mesh()->n_edges();
}
template <>
size_t BoundaryItemIter<HalfFaceIter, HalfFaceHandle>::n_items() const {
return BaseIter::mesh()->n_halffaces();
}
template <>
size_t BoundaryItemIter<FaceIter, FaceHandle>::n_items() const {
return BaseIter::mesh()->n_faces();
}
template <>
size_t BoundaryItemIter<CellIter, CellHandle>::n_items() const {
return BaseIter::mesh()->n_cells();
}
template <>
bool BoundaryItemIter<VertexIter, VertexHandle>::has_incidences() const {
return BaseIter::mesh()->has_full_bottom_up_incidences();
}
template <>
bool BoundaryItemIter<HalfEdgeIter, HalfEdgeHandle>::has_incidences() const {
const TopologyKernel *mesh = BaseIter::mesh();
return mesh->has_edge_bottom_up_incidences() && mesh->has_face_bottom_up_incidences();
}
template <>
bool BoundaryItemIter<EdgeIter, EdgeHandle>::has_incidences() const {
const TopologyKernel *mesh = BaseIter::mesh();
return mesh->has_edge_bottom_up_incidences() && mesh->has_face_bottom_up_incidences();
}
template <>
bool BoundaryItemIter<HalfFaceIter, HalfFaceHandle>::has_incidences() const {
return BaseIter::mesh()->has_face_bottom_up_incidences();
}
template <>
bool BoundaryItemIter<FaceIter, FaceHandle>::has_incidences() const {
return BaseIter::mesh()->has_face_bottom_up_incidences();
}
//template <>
//bool BoundaryItemIter<CellIter, CellHandle>::has_incidences() const {
// return true; // TODO
//}
} // Namespace OpenVolumeMesh
......@@ -1154,60 +1154,120 @@ private:
//===========================================================================
class BoundaryFaceIter : public BaseIterator<FaceHandle> {
template <class Iter, class Handle>
class BoundaryItemIter : public BaseIterator<Handle> {
public:
typedef BaseIterator<FaceHandle> BaseIter;
typedef BaseIterator<Handle> BaseIter;
explicit BoundaryItemIter(const TopologyKernel* _mesh) :
BaseIter(_mesh),
it_(_mesh, Handle(0)),
it_begin_(_mesh, Handle(0)),
it_end_(_mesh, Handle((int)n_items())) {
explicit BoundaryFaceIter(const TopologyKernel* _mesh);
if(!has_incidences()) {
#ifndef NDEBUG
std::cerr << "This iterator needs bottom-up incidences!" << std::endl;
#endif
BaseIter::valid(false);
return;
}
while(it_ != it_end_ && !BaseIter::mesh()->is_boundary(*it_)){
++it_;
}
BaseIter::valid(it_ != it_end_);
if(BaseIter::valid()) {
BaseIter::cur_handle(*it_);
}
}
// Post increment/decrement operator
BoundaryFaceIter operator++(int) {
BoundaryFaceIter cpy = *this;
BoundaryItemIter operator++(int) {
BoundaryItemIter cpy = *this;
++(*this);
return cpy;
}
BoundaryFaceIter operator--(int) {
BoundaryFaceIter cpy = *this;
BoundaryItemIter operator--(int) {
BoundaryItemIter cpy = *this;
--(*this);
return cpy;
}
BoundaryFaceIter operator+(int _n) {
BoundaryFaceIter cpy = *this;
BoundaryItemIter operator+(int _n) {
BoundaryItemIter cpy = *this;
for(int i = 0; i < _n; ++i) {
++cpy;
}
return cpy;
}
BoundaryFaceIter operator-(int _n) {
BoundaryFaceIter cpy = *this;
BoundaryItemIter operator-(int _n) {
BoundaryItemIter cpy = *this;
for(int i = 0; i < _n; ++i) {
--cpy;
}
return cpy;
}
BoundaryFaceIter& operator+=(int _n) {
BoundaryItemIter& operator+=(int _n) {
for(int i = 0; i < _n; ++i) {
++(*this);
}
return *this;
}
BoundaryFaceIter& operator-=(int _n) {
BoundaryItemIter& operator-=(int _n) {
for(int i = 0; i < _n; ++i) {
--(*this);
}
return *this;
}
BoundaryFaceIter& operator++();
BoundaryFaceIter& operator--();
BoundaryItemIter& operator--() {
--it_;
while(it_ >= it_begin_ && !BaseIter::mesh()->is_boundary(*it_)){
--it_;
}
if(it_ >= it_begin_) {
BaseIter::cur_handle(*it_);
} else {
BaseIter::valid(false);
}
return *this;
}
BoundaryItemIter& operator++() {
++it_;
while(it_ != it_end_ && !BaseIter::mesh()->is_boundary(*it_)){
++it_;
}
if(it_ != it_end_) {
BaseIter::cur_handle(*it_);
} else {
BaseIter::valid(false);
}
return *this;
}
private:
FaceIter bf_it_;
size_t n_items() const;
bool has_incidences() const;
private:
Iter it_;
const Iter it_begin_;
const Iter it_end_;
};
//===========================================================================
typedef BoundaryItemIter<VertexIter, VertexHandle> BoundaryVertexIter;
typedef BoundaryItemIter<HalfEdgeIter, HalfEdgeHandle> BoundaryHalfEdgeIter;
typedef BoundaryItemIter<EdgeIter, EdgeHandle> BoundaryEdgeIter;
typedef BoundaryItemIter<HalfFaceIter, HalfFaceHandle> BoundaryHalfFaceIter;
typedef BoundaryItemIter<FaceIter, FaceHandle> BoundaryFaceIter;
//typedef BoundaryItemIter<CellIter, CellHandle> BoundaryCellIter;
//===========================================================================
} // Namespace OpenVolumeMesh
#endif /* ITERATORS_HH_ */
......@@ -94,7 +94,6 @@ public:
friend class CellCellIter;
friend class HalfFaceVertexIter;
friend class BoundaryHalfFaceHalfFaceIter;
friend class BoundaryFaceIter;
friend class VertexIter;
friend class EdgeIter;
friend class HalfEdgeIter;
......@@ -214,10 +213,30 @@ public:
* Iterators
*/
BoundaryVertexIter bv_iter() const {
return BoundaryVertexIter(this);
}
BoundaryHalfEdgeIter bhe_iter() const {
return BoundaryHalfEdgeIter(this);
}
BoundaryEdgeIter be_iter() const {
return BoundaryEdgeIter(this);
}
BoundaryHalfFaceIter bhf_iter() const {
return BoundaryHalfFaceIter(this);
}
BoundaryFaceIter bf_iter() const {
return BoundaryFaceIter(this);
}
// BoundaryCellIter bc_iter() const {
// return BoundaryCellIter(this);
// }
VertexIter v_iter() const {
return VertexIter(this);
}
......
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