43 #define STATUSATTRIBT_CC
45 #include "StatusAttrib.hh"
47 #include "../Core/TopologyKernel.hh"
48 #include "../Core/PropertyDefines.hh"
55 template<
typename std_API_Container_VHandlePointer,
56 typename std_API_Container_HHandlePointer,
57 typename std_API_Container_HFHandlePointer,
58 typename std_API_Container_CHandlePointer>
60 std_API_Container_HHandlePointer &hh_to_update,
61 std_API_Container_HFHandlePointer &hfh_to_update,
62 std_API_Container_CHandlePointer &ch_to_update,
63 bool _preserveManifoldness) {
81 bool track_vh = !vh_to_update.empty();
82 bool track_hh = !hh_to_update.empty();
83 bool track_hfh = !hfh_to_update.empty();
84 bool track_ch = !ch_to_update.empty();
90 std::map<int,int> vh_map;
91 std::map<int,int> hh_map;
92 std::map<int,int> hfh_map;
93 std::map<int,int> ch_map;
97 typename std_API_Container_VHandlePointer::iterator it = vh_to_update.begin();
98 typename std_API_Container_VHandlePointer::iterator end = vh_to_update.end();
100 for (; it != end; ++it) {
101 vh_map[(*it)->idx()] = (*it)->idx();
105 typename std_API_Container_HHandlePointer::iterator it = hh_to_update.begin();
106 typename std_API_Container_HHandlePointer::iterator end = hh_to_update.end();
108 for (; it != end; ++it) {
109 hh_map[(*it)->idx()] = (*it)->idx();
113 typename std_API_Container_HFHandlePointer::iterator it = hfh_to_update.begin();
114 typename std_API_Container_HFHandlePointer::iterator end = hfh_to_update.end();
116 for (; it != end; ++it) {
117 hfh_map[(*it)->idx()] = (*it)->idx();
121 typename std_API_Container_CHandlePointer::iterator it = ch_to_update.begin();
122 typename std_API_Container_CHandlePointer::iterator end = ch_to_update.end();
124 for (; it != end; ++it) {
125 ch_map[(*it)->idx()] = (*it)->idx();
131 mark_higher_dim_entities();
133 std::vector<int> vertexIndexMap(kernel_.
n_vertices(), -1);
136 bool v_bu = kernel_.has_vertex_bottom_up_incidences();
137 bool e_bu = kernel_.has_edge_bottom_up_incidences();
138 bool f_bu = kernel_.has_face_bottom_up_incidences();
140 kernel_.enable_bottom_up_incidences(
false);
142 std::vector<bool> tags(kernel_.
n_cells(),
false);
143 std::vector<bool>::iterator tag_it = tags.begin();
145 for(
CellIter c_it = kernel_.cells_begin(); c_it != kernel_.cells_end(); ++c_it, ++tag_it) {
146 *tag_it = c_status_[c_it->idx()].deleted();
149 if (c_status_[c_it->idx()].deleted()) {
151 if (ch_map.find(c_it->idx()) != ch_map.end())
152 ch_map[c_it->idx()] = -1;
154 if (ch_map.find(c_it->idx()) != ch_map.end())
155 ch_map[c_it->idx()] = c_it->idx() - offset_ch;
159 kernel_.delete_multiple_cells(tags);
161 tags.resize(kernel_.
n_faces(),
false);
162 tag_it = tags.begin();
164 for(
FaceIter f_it = kernel_.faces_begin(); f_it != kernel_.faces_end(); ++f_it, ++tag_it) {
165 *tag_it = f_status_[f_it->idx()].deleted();
168 int halfface_idx = f_it->idx() * 2;
169 if (f_status_[f_it->idx()].deleted()) {
171 if (hfh_map.find(halfface_idx) != hfh_map.end()) {
172 hfh_map[halfface_idx] = -1;
174 if (hfh_map.find(halfface_idx + 1) != hfh_map.end()) {
175 hfh_map[halfface_idx + 1] = -1;
178 if (hfh_map.find(halfface_idx) != hfh_map.end()) {
179 hfh_map[halfface_idx] = halfface_idx - offset_hfh;
181 if (hfh_map.find(halfface_idx + 1) != hfh_map.end()) {
182 hfh_map[halfface_idx + 1] = halfface_idx + 1 - offset_hfh;
187 kernel_.delete_multiple_faces(tags);
189 tags.resize(kernel_.
n_edges(),
false);
190 tag_it = tags.begin();
192 for(
EdgeIter e_it = kernel_.edges_begin(); e_it != kernel_.edges_end(); ++e_it, ++tag_it) {
193 *tag_it = e_status_[e_it->idx()].deleted();
196 int halfedge_idx = e_it->idx() * 2;
197 if (e_status_[e_it->idx()].deleted()) {
199 if (hh_map.find(halfedge_idx) != hh_map.end()) {
200 hh_map[halfedge_idx] = -1;
202 if (hh_map.find(halfedge_idx + 1) != hh_map.end()) {
203 hh_map[halfedge_idx + 1] = -1;
206 if (hh_map.find(halfedge_idx) != hh_map.end()) {
207 hh_map[halfedge_idx] = halfedge_idx - offset_hh;
209 if (hh_map.find(halfedge_idx + 1) != hh_map.end()) {
210 hh_map[halfedge_idx + 1] = halfedge_idx + 1 - offset_hh;
215 kernel_.delete_multiple_edges(tags);
218 tag_it = tags.begin();
220 for(
VertexIter v_it = kernel_.vertices_begin(); v_it != kernel_.vertices_end(); ++v_it, ++tag_it) {
221 *tag_it = v_status_[v_it->idx()].deleted();
224 if (v_status_[v_it->idx()].deleted()) {
225 if (vh_map.find(v_it->idx()) != vh_map.end()) {
227 vh_map[v_it->idx()] = -1;
230 if (vh_map.find(v_it->idx()) != vh_map.end()) {
231 vh_map[v_it->idx()] = v_it->idx() - offset_vh;
236 kernel_.delete_multiple_vertices(tags);
240 typename std_API_Container_VHandlePointer::iterator it = vh_to_update.begin();
241 typename std_API_Container_VHandlePointer::iterator end = vh_to_update.end();
243 for (; it != end; ++it) {
248 typename std_API_Container_HHandlePointer::iterator it = hh_to_update.begin();
249 typename std_API_Container_HHandlePointer::iterator end = hh_to_update.end();
251 for (; it != end; ++it) {
256 typename std_API_Container_HFHandlePointer::iterator it = hfh_to_update.begin();
257 typename std_API_Container_HFHandlePointer::iterator end = hfh_to_update.end();
259 for (; it != end; ++it) {
264 typename std_API_Container_CHandlePointer::iterator it = ch_to_update.begin();
265 typename std_API_Container_CHandlePointer::iterator end = ch_to_update.end();
267 for (; it != end; ++it) {
274 if(v_bu) kernel_.enable_vertex_bottom_up_incidences(
true);
275 if(e_bu) kernel_.enable_edge_bottom_up_incidences(
true);
276 if(f_bu) kernel_.enable_face_bottom_up_incidences(
true);
279 if(_preserveManifoldness) {
280 if(kernel_.has_full_bottom_up_incidences()) {
284 for(
FaceIter f_it = kernel_.faces_begin(); f_it != kernel_.faces_end(); ++f_it) {
291 if(kernel_.
incident_cell(hf0) == TopologyKernel::InvalidCellHandle &&
292 kernel_.
incident_cell(hf1) == TopologyKernel::InvalidCellHandle) {
294 f_status_[f_it->idx()].set_deleted(
true);
300 for(
EdgeIter e_it = kernel_.edges_begin(); e_it != kernel_.edges_end(); ++e_it) {
308 if(!hehf_it.valid()) {
310 e_status_[e_it->idx()].set_deleted(
true);
313 bool validFace =
false;
314 for(; hehf_it.valid(); ++hehf_it) {
315 if(!f_status_[kernel_.face_handle(*hehf_it).idx()].deleted()) {
321 e_status_[e_it->idx()].set_deleted(
true);
328 for(
VertexIter v_it = kernel_.vertices_begin(); v_it != kernel_.vertices_end(); ++v_it) {
333 if(!voh_it.valid()) {
335 v_status_[v_it->idx()].set_deleted(
true);
338 bool validEdge =
false;
339 for(; voh_it.valid(); ++voh_it) {
340 if(!e_status_[kernel_.
edge_handle(voh_it->idx())].deleted()) {
346 v_status_[v_it->idx()].set_deleted(
true);
356 std::cerr <<
"Preservation of three-manifoldness in garbage_collection() "
357 <<
"requires bottom-up incidences!" << std::endl;
virtual size_t n_cells() const
Get number of cells in mesh.
virtual size_t n_vertices() const
Get number of vertices in mesh.
void garbage_collection(bool _preserveManifoldness=false)
Delete all entities that have been marked as deleted.
CellHandle incident_cell(const HalfFaceHandle &_halfFaceHandle) const
Get cell that is incident to the given halfface.
virtual size_t n_edges() const
Get number of edges in mesh.
static HalfEdgeHandle halfedge_handle(const EdgeHandle &_h, const unsigned char _subIdx)
Conversion function.
static HalfFaceHandle halfface_handle(const FaceHandle &_h, const unsigned char _subIdx)
Conversion function.
static EdgeHandle edge_handle(const HalfEdgeHandle &_h)
Handle conversion.
virtual size_t n_faces() const
Get number of faces in mesh.