HexahedralMeshIterators.cc 10.3 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
/*===========================================================================*\
 *                                                                           *
 *                            OpenVolumeMesh                                 *
 *        Copyright (C) 2011 by Computer Graphics Group, RWTH Aachen         *
 *                        www.openvolumemesh.org                             *
 *                                                                           *
 *---------------------------------------------------------------------------*
 *  This file is part of OpenVolumeMesh.                                     *
 *                                                                           *
 *  OpenVolumeMesh is free software: you can redistribute it and/or modify   *
 *  it under the terms of the GNU Lesser General Public License as           *
 *  published by the Free Software Foundation, either version 3 of           *
 *  the License, or (at your option) any later version with the              *
 *  following exceptions:                                                    *
 *                                                                           *
 *  If other files instantiate templates or use macros                       *
 *  or inline functions from this file, or you compile this file and         *
 *  link it with other files to produce an executable, this file does        *
 *  not by itself cause the resulting executable to be covered by the        *
 *  GNU Lesser General Public License. This exception does not however       *
 *  invalidate any other reasons why the executable file might be            *
 *  covered by the GNU Lesser General Public License.                        *
 *                                                                           *
 *  OpenVolumeMesh is distributed in the hope that it will be useful,        *
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of           *
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            *
 *  GNU Lesser General Public License for more details.                      *
 *                                                                           *
 *  You should have received a copy of the GNU LesserGeneral Public          *
 *  License along with OpenVolumeMesh.  If not,                              *
 *  see <http://www.gnu.org/licenses/>.                                      *
 *                                                                           *
\*===========================================================================*/

/*===========================================================================*\
 *                                                                           *
 *   $Revision$                                                         *
 *   $Date$                    *
 *   $LastChangedBy$                                                *
 *                                                                           *
\*===========================================================================*/

#include <set>

#include "HexahedralMeshIterators.hh"
#include "HexahedralMeshTopologyKernel.hh"
#include "../Core/Iterators.hh"

namespace OpenVolumeMesh {

//================================================================================================
// CellSheetCellIter
//================================================================================================

55 56 57

CellSheetCellIter::CellSheetCellIter(const CellHandle& _ref_h,
        const unsigned char _orthDir, const HexahedralMeshTopologyKernel* _mesh) :
58 59
BaseIter(_mesh, _ref_h) {

60
    if(!_mesh->has_face_bottom_up_incidences()) {
61
#ifndef NDEBUG
62
        std::cerr << "This iterator needs bottom-up incidences!" << std::endl;
63
#endif
64 65 66 67 68 69
        BaseIter::valid(false);
        return;
    }

	// First off, get all surrounding cells
	std::vector<HalfFaceHandle> halffaces = _mesh->cell(_ref_h).halffaces();
70
	for(std::vector<HalfFaceHandle>::const_iterator hf_it = halffaces.begin();
71 72 73 74 75
			hf_it != halffaces.end(); ++hf_it) {
		// Add those, that are perpendicular to the specified _orthDir
		if(_mesh->orientation(*hf_it, _ref_h) != _orthDir &&
				_mesh->orientation(*hf_it, _ref_h) != _mesh->opposite_orientation(_orthDir)) {
			CellHandle ch = _mesh->incident_cell(_mesh->opposite_halfface_handle(*hf_it));
76
			if(ch != TopologyKernel::InvalidCellHandle) {
77 78 79 80 81 82 83 84 85 86 87 88
				neighb_sheet_cell_hs_.insert(ch);
			}
		}
	}

	cur_it_ = neighb_sheet_cell_hs_.begin();
	BaseIter::valid(cur_it_ != neighb_sheet_cell_hs_.end());
	if(BaseIter::valid()) {
		BaseIter::cur_handle(*cur_it_);
	}
}

89 90

CellSheetCellIter& CellSheetCellIter::operator--() {
91 92 93 94 95 96 97 98 99 100

    if(cur_it_ == neighb_sheet_cell_hs_.begin()) {
        BaseIter::valid(false);
    } else {
        --cur_it_;
        BaseIter::cur_handle(*cur_it_);
    }
    return *this;
}

101 102

CellSheetCellIter& CellSheetCellIter::operator++() {
103 104 105 106 107 108 109 110 111 112 113 114 115 116

    ++cur_it_;
	if(cur_it_ != neighb_sheet_cell_hs_.end()) {
		BaseIter::cur_handle(*cur_it_);
	} else {
		BaseIter::valid(false);
	}
	return *this;
}

//================================================================================================
// HalfFaceSheetHalfFaceIter
//================================================================================================

117 118 119

HalfFaceSheetHalfFaceIter::HalfFaceSheetHalfFaceIter(const HalfFaceHandle& _ref_h,
        const HexahedralMeshTopologyKernel* _mesh) :
120 121
BaseIter(_mesh, _ref_h) {

122
	if(!_mesh->has_face_bottom_up_incidences()) {
123
#ifndef NDEBUG
124
        std::cerr << "This iterator needs bottom-up incidences!" << std::endl;
125
#endif
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
        BaseIter::valid(false);
        return;
    }

	/*
	 * Each halfface uniquely belongs to either a cell
	 * or the boundary. If the halfface belongs
	 * to a cell, it suffices to determine the local axis
	 * the halfface represents w.r.t. the cell and to
	 * iterate over all neighboring cells orthogonal to
	 * this direction. We have to find those halffaces
	 * of the neighboring cells that contain exactly one
	 * of the initial halfface's opposite halfedges.
	 */

	if(_mesh->is_boundary(_ref_h)) {
142
#ifndef NDEBUG
143
		std::cerr << "HalfFaceSheetHalfFaceIter: HalfFace is boundary!" << std::endl;
144
#endif
145 146 147 148 149 150 151 152 153 154
		BaseIter::valid(false);
        return;
	}

	CellHandle ch = _mesh->incident_cell(_ref_h);
	unsigned char orientation = _mesh->orientation(_ref_h, ch);
	std::vector<HalfEdgeHandle> hes_v = _mesh->opposite_halfface(_mesh->halfface(_ref_h)).halfedges();
	std::set<HalfEdgeHandle> hes;
	hes.insert(hes_v.begin(), hes_v.end());

155
	for(CellSheetCellIter csc_it = _mesh->csc_iter(ch, orientation);
156 157 158
			csc_it.valid(); ++csc_it) {

		std::vector<HalfFaceHandle> hfs = _mesh->cell(*csc_it).halffaces();
159
		for(std::vector<HalfFaceHandle>::const_iterator hf_it = hfs.begin();
160 161 162
				hf_it != hfs.end(); ++hf_it) {

			std::vector<HalfEdgeHandle> hf_hes = _mesh->halfface(*hf_it).halfedges();
163
			for(std::vector<HalfEdgeHandle>::const_iterator he_it = hf_hes.begin();
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183
					he_it != hf_hes.end(); ++he_it) {

				if(hes.count(*he_it) > 0) {
					// Found halfface that lies on the same sheet
					adjacent_halffaces_.push_back(*hf_it);
					common_edges_.push_back(_mesh->edge_handle(*he_it));
					break;
				}
			}
		}
	}

	cur_it_ = adjacent_halffaces_.begin();
	edge_it_ = common_edges_.begin();
    BaseIter::valid(cur_it_ != adjacent_halffaces_.end());
    if(BaseIter::valid()) {
    	BaseIter::cur_handle(*cur_it_);
    }
}

184 185

HalfFaceSheetHalfFaceIter& HalfFaceSheetHalfFaceIter::operator--() {
186 187 188 189 190 191 192 193 194 195 196

    --cur_it_;
    --edge_it_;
    if(cur_it_ >= adjacent_halffaces_.begin()) {
		BaseIter::cur_handle(*cur_it_);
	} else {
		BaseIter::valid(false);
	}
    return *this;
}

197 198

HalfFaceSheetHalfFaceIter& HalfFaceSheetHalfFaceIter::operator++() {
199 200 201 202 203 204 205 206 207 208 209

    ++cur_it_;
    ++edge_it_;
	if(cur_it_ != adjacent_halffaces_.end()) {
		BaseIter::cur_handle(*cur_it_);
	} else {
		BaseIter::valid(false);
	}
	return *this;
}

210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295
//================================================================================================
// HexVertexIter
//================================================================================================


HexVertexIter::HexVertexIter(const CellHandle& _ref_h,
        const HexahedralMeshTopologyKernel* _mesh) :
BaseIter(_mesh, _ref_h) {

    assert(_ref_h.is_valid());
    assert(_mesh->cell(_ref_h).halffaces().size() == 6);

    // Get first half-face
    HalfFaceHandle curHF = *_mesh->cell(_ref_h).halffaces().begin();
    assert(curHF.is_valid());

    // Get first half-edge
    assert(_mesh->halfface(curHF).halfedges().size() == 4);
    HalfEdgeHandle curHE = *_mesh->halfface(curHF).halfedges().begin();
    assert(curHE.is_valid());

    vertices_.push_back(_mesh->halfedge(curHE).from_vertex());

    curHE = _mesh->prev_halfedge_in_halfface(curHE, curHF);

    vertices_.push_back(_mesh->halfedge(curHE).from_vertex());

    curHE = _mesh->prev_halfedge_in_halfface(curHE, curHF);

    vertices_.push_back(_mesh->halfedge(curHE).from_vertex());

    curHE = _mesh->prev_halfedge_in_halfface(curHE, curHF);

    vertices_.push_back(_mesh->halfedge(curHE).from_vertex());

    curHE = _mesh->prev_halfedge_in_halfface(curHE, curHF);
    curHF = _mesh->adjacent_halfface_in_cell(curHF, curHE);
    curHE = _mesh->opposite_halfedge_handle(curHE);
    curHE = _mesh->next_halfedge_in_halfface(curHE, curHF);
    curHE = _mesh->next_halfedge_in_halfface(curHE, curHF);
    curHF = _mesh->adjacent_halfface_in_cell(curHF, curHE);
    curHE = _mesh->opposite_halfedge_handle(curHE);

    vertices_.push_back(_mesh->halfedge(curHE).to_vertex());

    curHE = _mesh->prev_halfedge_in_halfface(curHE, curHF);

    vertices_.push_back(_mesh->halfedge(curHE).to_vertex());

    curHE = _mesh->prev_halfedge_in_halfface(curHE, curHF);

    vertices_.push_back(_mesh->halfedge(curHE).to_vertex());

    vertices_.push_back(_mesh->halfedge(curHE).from_vertex());

    cur_it_ = vertices_.begin();
    BaseIter::valid(cur_it_ != vertices_.end());
    if(BaseIter::valid()) {
        BaseIter::cur_handle(*cur_it_);
    }
}


HexVertexIter& HexVertexIter::operator--() {

    --cur_it_;
    if(cur_it_ >= vertices_.begin()) {
        BaseIter::cur_handle(*cur_it_);
    } else {
        BaseIter::valid(false);
    }
    return *this;
}


HexVertexIter& HexVertexIter::operator++() {

    ++cur_it_;
    if(cur_it_ != vertices_.end()) {
        BaseIter::cur_handle(*cur_it_);
    } else {
        BaseIter::valid(false);
    }
    return *this;
}

296
} // Namespace OpenVolumeMesh