StatusAttrib.cc 7.64 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/*===========================================================================*\
 *                                                                           *
 *                            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 "StatusAttrib.hh"

#include "../Core/TopologyKernel.hh"
#include "../Core/PropertyDefines.hh"

namespace OpenVolumeMesh {

StatusAttrib::StatusAttrib(TopologyKernel& _kernel) :
kernel_(_kernel),
v_status_(_kernel.request_vertex_property<OpenVolumeMeshStatus>("vertex_status")),
e_status_(_kernel.request_edge_property<OpenVolumeMeshStatus>("edge_status")),
he_status_(_kernel.request_halfedge_property<OpenVolumeMeshStatus>("halfedge_status")),
f_status_(_kernel.request_face_property<OpenVolumeMeshStatus>("face_status")),
hf_status_(_kernel.request_halfface_property<OpenVolumeMeshStatus>("halfface_status")),
c_status_(_kernel.request_cell_property<OpenVolumeMeshStatus>("cell_status")),
m_status_(_kernel.request_mesh_property<OpenVolumeMeshStatus>("mesh_status")) {

}

//========================================================================================

StatusAttrib::~StatusAttrib() {

}

void StatusAttrib::garbage_collection(bool _preserveManifoldness) {

    /*
71
72
73
74
75
76
     * This is not a real garbage collection in its conventional
     * sense. What happens in this routine are the following steps:
     *
     * 1. Delete all entities marked as deleted from bottom to top.
     * 2. Preserve manifoldness (optionally) by deleting all
     *    isolated entities in a top-down fashion afterwards.
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
     */

    for(VertexIter v_it = kernel_.vertices_begin(); v_it != kernel_.vertices_end();) {

        if(!v_status_[v_it->idx()].deleted()) {
            ++v_it;
        } else {
            v_it = kernel_.delete_vertex(*v_it);
        }
    }

    for(EdgeIter e_it = kernel_.edges_begin(); e_it != kernel_.edges_end();) {

        if(!e_status_[e_it->idx()].deleted()) {
            ++e_it;
        } else {
            e_it = kernel_.delete_edge(*e_it);
        }
    }

    for(FaceIter f_it = kernel_.faces_begin(); f_it != kernel_.faces_end();) {

        if(!f_status_[f_it->idx()].deleted()) {
            ++f_it;
        } else {
            f_it = kernel_.delete_face(*f_it);
        }
    }

    for(CellIter c_it = kernel_.cells_begin(); c_it != kernel_.cells_end();) {

        if(!c_status_[c_it->idx()].deleted()) {
            ++c_it;
        } else {
            c_it = kernel_.delete_cell(*c_it);
        }
    }

    // Step 6
    if(_preserveManifoldness) {
117
        if(kernel_.has_full_bottom_up_incidences()) {
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170

            // Go over all faces and find those
            // that are not incident to any cell
            for(FaceIter f_it = kernel_.faces_begin(); f_it != kernel_.faces_end();) {

                // Get half-faces
                HalfFaceHandle hf0 = kernel_.halfface_handle(*f_it, 0);
                HalfFaceHandle hf1 = kernel_.halfface_handle(*f_it, 1);

                // If neither of the half-faces is incident to a cell, delete face
                if(kernel_.incident_cell(hf0) == TopologyKernel::InvalidCellHandle &&
                        kernel_.incident_cell(hf1) == TopologyKernel::InvalidCellHandle) {

                    f_it = kernel_.delete_face(*f_it);

                } else {
                    ++f_it;
                }
            }

            // Go over all edges and find those
            // whose half-edges are not incident to any half-face
            for(EdgeIter e_it = kernel_.edges_begin(); e_it != kernel_.edges_end();) {

                // Get half-edges
                HalfEdgeHandle he0 = kernel_.halfedge_handle(*e_it, 0);
                HalfEdgeHandle he1 = kernel_.halfedge_handle(*e_it, 1);

                // If neither of the half-edges is incident to a half-face, delete edge
                HalfEdgeHalfFaceIter he0hf_it = kernel_.hehf_iter(he0);
                HalfEdgeHalfFaceIter he1hf_it = kernel_.hehf_iter(he1);

                if(!he0hf_it.valid() && !he1hf_it.valid()) {

                    e_it = kernel_.delete_edge(*e_it);

                } else {
                     ++e_it;
                }
            }

            // Go over all vertices and find those
            // that are not incident to any edge
            for(VertexIter v_it = kernel_.vertices_begin(); v_it != kernel_.vertices_end();) {

                // If neither of the half-edges is incident to a half-face, delete edge
                VertexOHalfEdgeIter voh_it = kernel_.voh_iter(*v_it);

                if(!voh_it.valid()) {

                    v_it = kernel_.delete_vertex(*v_it);

                } else {
171
                    ++v_it;
172
173
174
175
176
                }
            }

        } else {
            std::cerr << "Preservation of three-manifoldness in garbage_collection() "
177
                    << "requires bottom-up incidences!" << std::endl;
178
179
180
181
182
183
            return;
        }
    }
}

} // Namespace OpenVolumeMesh