Developer Documentation
StatusAttrib.cc
1 /*===========================================================================*\
2  * *
3  * OpenVolumeMesh *
4  * Copyright (C) 2011 by Computer Graphics Group, RWTH Aachen *
5  * www.openvolumemesh.org *
6  * *
7  *---------------------------------------------------------------------------*
8  * This file is part of OpenVolumeMesh. *
9  * *
10  * OpenVolumeMesh is free software: you can redistribute it and/or modify *
11  * it under the terms of the GNU Lesser General Public License as *
12  * published by the Free Software Foundation, either version 3 of *
13  * the License, or (at your option) any later version with the *
14  * following exceptions: *
15  * *
16  * If other files instantiate templates or use macros *
17  * or inline functions from this file, or you compile this file and *
18  * link it with other files to produce an executable, this file does *
19  * not by itself cause the resulting executable to be covered by the *
20  * GNU Lesser General Public License. This exception does not however *
21  * invalidate any other reasons why the executable file might be *
22  * covered by the GNU Lesser General Public License. *
23  * *
24  * OpenVolumeMesh is distributed in the hope that it will be useful, *
25  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
26  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
27  * GNU Lesser General Public License for more details. *
28  * *
29  * You should have received a copy of the GNU LesserGeneral Public *
30  * License along with OpenVolumeMesh. If not, *
31  * see <http://www.gnu.org/licenses/>. *
32  * *
33 \*===========================================================================*/
34 
35 /*===========================================================================*\
36  * *
37  * $Revision$ *
38  * $Date$ *
39  * $LastChangedBy$ *
40  * *
41 \*===========================================================================*/
42 
43 #ifndef NDEBUG
44 #include <iostream>
45 #endif
46 
47 #include "../Core/TopologyKernel.hh"
48 #include "StatusAttrib.hh"
49 
50 namespace OpenVolumeMesh {
51 
52 StatusAttrib::StatusAttrib(TopologyKernel& _kernel) :
53 kernel_(_kernel),
54 v_status_(_kernel.request_vertex_property<OpenVolumeMeshStatus>("vertex_status")),
55 e_status_(_kernel.request_edge_property<OpenVolumeMeshStatus>("edge_status")),
56 he_status_(_kernel.request_halfedge_property<OpenVolumeMeshStatus>("halfedge_status")),
57 f_status_(_kernel.request_face_property<OpenVolumeMeshStatus>("face_status")),
58 hf_status_(_kernel.request_halfface_property<OpenVolumeMeshStatus>("halfface_status")),
59 c_status_(_kernel.request_cell_property<OpenVolumeMeshStatus>("cell_status")),
60 m_status_(_kernel.request_mesh_property<OpenVolumeMeshStatus>("mesh_status")) {
61 
62 }
63 
64 //========================================================================================
65 
66 StatusAttrib::~StatusAttrib() {
67 
68 }
69 
70 //========================================================================================
71 
72 void StatusAttrib::mark_higher_dim_entities() {
73 
74  // Edges
75  if(kernel_.has_vertex_bottom_up_incidences()) {
76 
77  for(VertexIter v_it = kernel_.vertices_begin(); v_it != kernel_.vertices_end(); ++v_it) {
78  if(v_status_[*v_it].deleted()) {
79  for(VertexOHalfEdgeIter voh_it = kernel_.voh_iter(*v_it);
80  voh_it.valid(); ++voh_it) {
81  e_status_[kernel_.edge_handle(*voh_it)].set_deleted(true);
82  }
83  }
84  }
85  } else {
86 
87  for(EdgeIter e_it = kernel_.edges_begin(); e_it != kernel_.edges_end(); ++e_it) {
88  if(v_status_[kernel_.edge(*e_it).from_vertex()].deleted() ||
89  v_status_[kernel_.edge(*e_it).to_vertex()].deleted()) {
90  e_status_[*e_it].set_deleted(true);
91  }
92  }
93  }
94 
95  // Faces
96  if(kernel_.has_edge_bottom_up_incidences()) {
97 
98  for(EdgeIter e_it = kernel_.edges_begin(); e_it != kernel_.edges_end(); ++e_it) {
99  if(e_status_[*e_it].deleted()) {
100  for(HalfEdgeHalfFaceIter hehf_it = kernel_.hehf_iter(kernel_.halfedge_handle(*e_it, 0));
101  hehf_it.valid(); ++hehf_it) {
102  f_status_[kernel_.face_handle(*hehf_it)].set_deleted(true);
103  }
104  }
105  }
106  } else {
107 
108  for(FaceIter f_it = kernel_.faces_begin(); f_it != kernel_.faces_end(); ++f_it) {
109 
110  const std::vector<HalfEdgeHandle>& hes = kernel_.face(*f_it).halfedges();
111  for(std::vector<HalfEdgeHandle>::const_iterator he_it = hes.begin(),
112  he_end = hes.end(); he_it != he_end; ++he_it) {
113  if(e_status_[kernel_.edge_handle(*he_it)].deleted()) {
114  f_status_[*f_it].set_deleted(true);
115  break;
116  }
117  }
118  }
119  }
120 
121  // Cells
122  if(kernel_.has_face_bottom_up_incidences()) {
123 
124  for(FaceIter f_it = kernel_.faces_begin(); f_it != kernel_.faces_end(); ++f_it) {
125  if(f_status_[*f_it].deleted()) {
126  CellHandle c0 = kernel_.incident_cell(kernel_.halfface_handle(*f_it, 0));
127  CellHandle c1 = kernel_.incident_cell(kernel_.halfface_handle(*f_it, 1));
128  if(c0.is_valid()) {
129  c_status_[c0].set_deleted(true);
130  }
131  if(c1.is_valid()) {
132  c_status_[c1].set_deleted(true);
133  }
134  }
135  }
136  } else {
137 
138  for(CellIter c_it = kernel_.cells_begin(); c_it != kernel_.cells_end(); ++c_it) {
139 
140  const std::vector<HalfFaceHandle>& hfs = kernel_.cell(*c_it).halffaces();
141  for(std::vector<HalfFaceHandle>::const_iterator hf_it = hfs.begin(),
142  hf_end = hfs.end(); hf_it != hf_end; ++hf_it) {
143  if(f_status_[kernel_.face_handle(*hf_it)].deleted()) {
144  c_status_[*c_it].set_deleted(true);
145  break;
146  }
147  }
148  }
149  }
150 }
151 
152 //========================================================================================
153 
154 void StatusAttrib::garbage_collection(bool _preserveManifoldness) {
155  std::vector<VertexHandle*> vh_empty;
156  std::vector<HalfEdgeHandle*> hh_empty;
157  std::vector<HalfFaceHandle*> hfh_empty;
158  std::vector<CellHandle*> ch_empty;
159 
160  garbage_collection(vh_empty, hh_empty, hfh_empty, ch_empty, _preserveManifoldness);
161 }
162 
163 
164 } // Namespace OpenVolumeMesh
void garbage_collection(bool _preserveManifoldness=false)
Delete all entities that have been marked as deleted.