43 #include "HexahedralMeshTopologyKernel.hh" 50 if(_halfedges.size() != 4) {
52 std::cerr <<
"HexahedralMeshTopologyKernel::add_face(): Face valence is not four! Returning" << std::endl;
53 std::cerr <<
"invalid handle." << std::endl;
55 return TopologyKernel::InvalidFaceHandle;
67 if(_vertices.size() != 4) {
69 std::cerr <<
"HexahedralMeshTopologyKernel::add_face(): Face valence is not four! Returning" << std::endl;
70 std::cerr <<
"invalid handle." << std::endl;
72 return TopologyKernel::InvalidFaceHandle;
84 if(_halffaces.size() != 6) {
87 std::cerr <<
"Cell valence is not six! Aborting." << std::endl;
89 return TopologyKernel::InvalidCellHandle;
91 for(std::vector<HalfFaceHandle>::const_iterator it = _halffaces.begin();
92 it != _halffaces.end(); ++it) {
95 std::cerr <<
"Incident face does not have valence four! Aborting." << std::endl;
97 return TopologyKernel::InvalidCellHandle;
102 std::vector<HalfFaceHandle> ordered_halffaces;
108 bool ordered = check_halfface_ordering(_halffaces);
113 std::cerr <<
"The specified half-faces are not in correct order. Trying automatic re-ordering." << std::endl;
117 const int orderTop[] = {2, 4, 3, 5};
120 ordered_halffaces.resize(6, TopologyKernel::InvalidHalfFaceHandle);
123 ordered_halffaces[0] = _halffaces[0];
127 unsigned int idx = 0;
128 for(std::vector<HalfEdgeHandle>::const_iterator he_it = hes.begin();
129 he_it != hes.end(); ++he_it) {
131 HalfFaceHandle ahfh = get_adjacent_halfface(ordered_halffaces[0], *he_it, _halffaces);
132 if(ahfh == TopologyKernel::InvalidHalfFaceHandle) {
134 std::cerr <<
"The current halfface is invalid!" << std::endl;
138 ordered_halffaces[orderTop[idx]] = ahfh;
145 cur_hf = get_adjacent_halfface(cur_hf, cur_he, _halffaces);
146 cur_he = TopologyKernel::opposite_halfedge_handle(cur_he);
149 cur_hf = get_adjacent_halfface(cur_hf, cur_he, _halffaces);
151 if(cur_hf != TopologyKernel::InvalidHalfFaceHandle) {
152 ordered_halffaces[1] = cur_hf;
155 std::cerr <<
"The current halfface is invalid!" << std::endl;
157 return TopologyKernel::InvalidCellHandle;
162 ordered_halffaces = _halffaces;
167 ordered_halffaces = _halffaces;
175 bool HexahedralMeshTopologyKernel::check_halfface_ordering(
const std::vector<HalfFaceHandle>& _hfs)
const {
200 const int orderTop[] = {2, 4, 3, 5};
201 const int orderBot[] = {3, 4, 2, 5};
213 for(std::vector<HalfEdgeHandle>::const_iterator it = halfedgesTop.begin();
214 it != halfedgesTop.end(); ++it) {
218 if(offsetTop == -1) {
219 if(ahfh == _hfs[2]) offsetTop = 0;
220 else if(ahfh == _hfs[4]) offsetTop = 1;
221 else if(ahfh == _hfs[3]) offsetTop = 2;
222 else if(ahfh == _hfs[5]) offsetTop = 3;
224 offsetTop = (offsetTop + 1) % 4;
225 if(ahfh != _hfs[orderTop[offsetTop]]) {
227 std::cerr <<
"Faces not in right order!" << std::endl;
234 if(offsetTop == -1) {
236 std::cerr <<
"Faces not in right order!" << std::endl;
242 for(std::vector<HalfEdgeHandle>::const_iterator it = halfedgesBot.begin();
243 it != halfedgesBot.end(); ++it) {
247 if(offsetBot == -1) {
248 if(ahfh == _hfs[3]) offsetBot = 0;
249 else if(ahfh == _hfs[4]) offsetBot = 1;
250 else if(ahfh == _hfs[2]) offsetBot = 2;
251 else if(ahfh == _hfs[5]) offsetBot = 3;
253 offsetBot = (offsetBot + 1) % 4;
254 if(ahfh != _hfs[orderBot[offsetBot]]) {
256 std::cerr <<
"Faces not in right order!" << std::endl;
263 if(offsetBot == -1) {
265 std::cerr <<
"Faces not in right order!" << std::endl;
279 assert(TopologyKernel::has_full_bottom_up_incidences());
280 assert(_vertices.size() == 8);
283 if(!TopologyKernel::has_full_bottom_up_incidences()) {
287 if(_vertices.size() != 8) {
293 std::vector<VertexHandle> vs;
296 vs.push_back(_vertices[3]);
297 vs.push_back(_vertices[2]);
298 vs.push_back(_vertices[1]);
299 vs.push_back(_vertices[0]);
303 vs.push_back(_vertices[7]);
304 vs.push_back(_vertices[6]);
305 vs.push_back(_vertices[5]);
306 vs.push_back(_vertices[4]);
310 vs.push_back(_vertices[1]);
311 vs.push_back(_vertices[2]);
312 vs.push_back(_vertices[6]);
313 vs.push_back(_vertices[7]);
317 vs.push_back(_vertices[4]);
318 vs.push_back(_vertices[5]);
319 vs.push_back(_vertices[3]);
320 vs.push_back(_vertices[0]);
324 vs.push_back(_vertices[1]);
325 vs.push_back(_vertices[7]);
326 vs.push_back(_vertices[4]);
327 vs.push_back(_vertices[0]);
331 vs.push_back(_vertices[2]);
332 vs.push_back(_vertices[3]);
333 vs.push_back(_vertices[5]);
334 vs.push_back(_vertices[6]);
337 if(!hf0.is_valid()) {
340 vs.push_back(_vertices[3]); vs.push_back(_vertices[2]);
341 vs.push_back(_vertices[1]); vs.push_back(_vertices[0]);
346 if(!hf1.is_valid()) {
349 vs.push_back(_vertices[7]); vs.push_back(_vertices[6]);
350 vs.push_back(_vertices[5]); vs.push_back(_vertices[4]);
355 if(!hf2.is_valid()) {
358 vs.push_back(_vertices[1]); vs.push_back(_vertices[2]);
359 vs.push_back(_vertices[6]); vs.push_back(_vertices[7]);
364 if(!hf3.is_valid()) {
367 vs.push_back(_vertices[4]); vs.push_back(_vertices[5]);
368 vs.push_back(_vertices[3]); vs.push_back(_vertices[0]);
373 if(!hf4.is_valid()) {
376 vs.push_back(_vertices[1]); vs.push_back(_vertices[7]);
377 vs.push_back(_vertices[4]); vs.push_back(_vertices[0]);
382 if(!hf5.is_valid()) {
385 vs.push_back(_vertices[2]); vs.push_back(_vertices[3]);
386 vs.push_back(_vertices[5]); vs.push_back(_vertices[6]);
391 assert(hf0.is_valid()); assert(hf1.is_valid()); assert(hf2.is_valid());
392 assert(hf3.is_valid()); assert(hf4.is_valid()); assert(hf5.is_valid());
395 std::vector<HalfFaceHandle> hfs;
396 hfs.push_back(hf0); hfs.push_back(hf1); hfs.push_back(hf2);
397 hfs.push_back(hf3); hfs.push_back(hf4); hfs.push_back(hf5);
399 if (_topologyCheck) {
408 std::set<HalfEdgeHandle> incidentHalfedges;
409 std::set<EdgeHandle> incidentEdges;
411 for(std::vector<HalfFaceHandle>::const_iterator it = hfs.begin(),
412 end = hfs.end(); it != end; ++it) {
415 for(std::vector<HalfEdgeHandle>::const_iterator he_it = hface.halfedges().begin(),
416 he_end = hface.halfedges().end(); he_it != he_end; ++he_it) {
417 incidentHalfedges.insert(*he_it);
422 if(incidentHalfedges.size() != (incidentEdges.size() * 2u)) {
424 std::cerr <<
"The specified halffaces are not connected!" << std::endl;
426 return InvalidCellHandle;
430 if(has_face_bottom_up_incidences()) {
432 for(std::vector<HalfFaceHandle>::const_iterator it = hfs.begin(),
433 end = hfs.end(); it != end; ++it) {
436 std::cerr <<
"Warning: One of the specified half-faces is already incident to another cell!" << std::endl;
438 return InvalidCellHandle;
453 const std::vector<HalfFaceHandle>& _halffaces)
const {
457 HalfEdgeHandle o_he = TopologyKernel::opposite_halfedge_handle(_heh);
459 for(std::vector<HalfFaceHandle>::const_iterator it = _halffaces.begin();
460 it != _halffaces.end(); ++it) {
461 if(*it == _hfh)
continue;
463 for(std::vector<HalfEdgeHandle>::const_iterator h_it = halfedges.begin();
464 h_it != halfedges.end(); ++h_it) {
465 if(*h_it == o_he)
return *it;
469 return TopologyKernel::InvalidHalfFaceHandle;
virtual FaceHandle add_face(const std::vector< HalfEdgeHandle > &_halfedges, bool _topologyCheck=false)
Add face via incident edges.
CellHandle add_cell(const std::vector< HalfFaceHandle > &_halffaces, bool _topologyCheck=false) override
Overridden function.
CellHandle incident_cell(const HalfFaceHandle &_halfFaceHandle) const
Get cell that is incident to the given halfface.
static EdgeHandle edge_handle(const HalfEdgeHandle &_h)
Handle conversion.
static HalfFaceHandle halfface_handle(const FaceHandle &_h, const unsigned char _subIdx)
Conversion function.
HalfEdgeHandle next_halfedge_in_halfface(const HalfEdgeHandle &_heh, const HalfFaceHandle &_hfh) const
Get next halfedge within a halfface.
FaceHandle add_face(const std::vector< HalfEdgeHandle > &_halfedges, bool _topologyCheck=false) override
Add face via incident edges.
Face halfface(const HalfFaceHandle &_halfFaceHandle) const
Get face that corresponds to halfface with handle _halfFaceHandle.
virtual CellHandle add_cell(const std::vector< HalfFaceHandle > &_halffaces, bool _topologyCheck=false)
Add cell via incident halffaces.
HalfFaceHandle halfface_extensive(const std::vector< VertexHandle > &_vs) const