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 "StatusAttrib.hh"
48 
49 namespace OpenVolumeMesh {
50 
51 StatusAttrib::StatusAttrib(TopologyKernel& _kernel) :
52 kernel_(_kernel),
53 v_status_(_kernel.request_vertex_property<OpenVolumeMeshStatus>("vertex_status")),
54 e_status_(_kernel.request_edge_property<OpenVolumeMeshStatus>("edge_status")),
55 he_status_(_kernel.request_halfedge_property<OpenVolumeMeshStatus>("halfedge_status")),
56 f_status_(_kernel.request_face_property<OpenVolumeMeshStatus>("face_status")),
57 hf_status_(_kernel.request_halfface_property<OpenVolumeMeshStatus>("halfface_status")),
58 c_status_(_kernel.request_cell_property<OpenVolumeMeshStatus>("cell_status")),
59 m_status_(_kernel.request_mesh_property<OpenVolumeMeshStatus>("mesh_status")) {
60 
61 }
62 
63 //========================================================================================
64 
65 StatusAttrib::~StatusAttrib() {
66 
67 }
68 
69 //========================================================================================
70 
71 void StatusAttrib::mark_higher_dim_entities() {
72 
73  // Edges
74  if(kernel_.has_vertex_bottom_up_incidences()) {
75 
76  for(VertexIter v_it = kernel_.vertices_begin(); v_it != kernel_.vertices_end(); ++v_it) {
77  if(v_status_[*v_it].deleted()) {
78  for(VertexOHalfEdgeIter voh_it = kernel_.voh_iter(*v_it);
79  voh_it.valid(); ++voh_it) {
80  e_status_[kernel_.edge_handle(*voh_it)].set_deleted(true);
81  }
82  }
83  }
84  } else {
85 
86  for(EdgeIter e_it = kernel_.edges_begin(); e_it != kernel_.edges_end(); ++e_it) {
87  if(v_status_[kernel_.edge(*e_it).from_vertex()].deleted() ||
88  v_status_[kernel_.edge(*e_it).to_vertex()].deleted()) {
89  e_status_[*e_it].set_deleted(true);
90  }
91  }
92  }
93 
94  // Faces
95  if(kernel_.has_edge_bottom_up_incidences()) {
96 
97  for(EdgeIter e_it = kernel_.edges_begin(); e_it != kernel_.edges_end(); ++e_it) {
98  if(e_status_[*e_it].deleted()) {
99  for(HalfEdgeHalfFaceIter hehf_it = kernel_.hehf_iter(kernel_.halfedge_handle(*e_it, 0));
100  hehf_it.valid(); ++hehf_it) {
101  f_status_[kernel_.face_handle(*hehf_it)].set_deleted(true);
102  }
103  }
104  }
105  } else {
106 
107  for(FaceIter f_it = kernel_.faces_begin(); f_it != kernel_.faces_end(); ++f_it) {
108 
109  const std::vector<HalfEdgeHandle>& hes = kernel_.face(*f_it).halfedges();
110  for(std::vector<HalfEdgeHandle>::const_iterator he_it = hes.begin(),
111  he_end = hes.end(); he_it != he_end; ++he_it) {
112  if(e_status_[kernel_.edge_handle(*he_it)].deleted()) {
113  f_status_[*f_it].set_deleted(true);
114  break;
115  }
116  }
117  }
118  }
119 
120  // Cells
121  if(kernel_.has_face_bottom_up_incidences()) {
122 
123  for(FaceIter f_it = kernel_.faces_begin(); f_it != kernel_.faces_end(); ++f_it) {
124  if(f_status_[*f_it].deleted()) {
125  CellHandle c0 = kernel_.incident_cell(kernel_.halfface_handle(*f_it, 0));
126  CellHandle c1 = kernel_.incident_cell(kernel_.halfface_handle(*f_it, 1));
127  if(c0.is_valid()) {
128  c_status_[c0].set_deleted(true);
129  }
130  if(c1.is_valid()) {
131  c_status_[c1].set_deleted(true);
132  }
133  }
134  }
135  } else {
136 
137  for(CellIter c_it = kernel_.cells_begin(); c_it != kernel_.cells_end(); ++c_it) {
138 
139  const std::vector<HalfFaceHandle>& hfs = kernel_.cell(*c_it).halffaces();
140  for(std::vector<HalfFaceHandle>::const_iterator hf_it = hfs.begin(),
141  hf_end = hfs.end(); hf_it != hf_end; ++hf_it) {
142  if(f_status_[kernel_.face_handle(*hf_it)].deleted()) {
143  c_status_[*c_it].set_deleted(true);
144  break;
145  }
146  }
147  }
148  }
149 }
150 
151 //========================================================================================
152 
153 void StatusAttrib::garbage_collection(bool _preserveManifoldness) {
154  std::vector<VertexHandle*> vh_empty;
155  std::vector<HalfEdgeHandle*> hh_empty;
156  std::vector<HalfFaceHandle*> hfh_empty;
157  std::vector<CellHandle*> ch_empty;
158 
159  garbage_collection(vh_empty, hh_empty, hfh_empty, ch_empty, _preserveManifoldness);
160 }
161 
162 
163 } // Namespace OpenVolumeMesh
void garbage_collection(bool _preserveManifoldness=false)
Delete all entities that have been marked as deleted.