Developer Documentation
VertexFunctions.cc
1/*===========================================================================*\
2 * *
3 * OpenFlipper *
4 * Copyright (c) 2001-2015, RWTH-Aachen University *
5 * Department of Computer Graphics and Multimedia *
6 * All rights reserved. *
7 * www.openflipper.org *
8 * *
9 *---------------------------------------------------------------------------*
10 * This file is part of OpenFlipper. *
11 *---------------------------------------------------------------------------*
12 * *
13 * Redistribution and use in source and binary forms, with or without *
14 * modification, are permitted provided that the following conditions *
15 * are met: *
16 * *
17 * 1. Redistributions of source code must retain the above copyright notice, *
18 * this list of conditions and the following disclaimer. *
19 * *
20 * 2. Redistributions in binary form must reproduce the above copyright *
21 * notice, this list of conditions and the following disclaimer in the *
22 * documentation and/or other materials provided with the distribution. *
23 * *
24 * 3. Neither the name of the copyright holder nor the names of its *
25 * contributors may be used to endorse or promote products derived from *
26 * this software without specific prior written permission. *
27 * *
28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
29 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
30 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
31 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
32 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
33 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
34 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
35 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
36 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
37 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
38 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
39 * *
40\*===========================================================================*/
41
42
43
44#include "MeshRepairPlugin.hh"
46
47//-----------------------------------------------------------------------------
48
49
50void MeshRepairPlugin::detectFlatValence3Vertices(int _objectId, double _angle) {
51
52 unsigned int count(0);
53
54 // get the target mesh
55 TriMesh* mesh = 0;
56 PluginFunctions::getMesh(_objectId,mesh);
57
58 if ( mesh ) {
59
60 // Clear current triangle selection
61 MeshSelection::clearVertexSelection(mesh);
62
63 TriMesh::VVIter vv_it;
64 TriMesh::VFIter vf_it;
66 TriMesh::Scalar cosangle(cos(_angle/180.0*M_PI));
67
68 for (auto v_it : mesh->vertices())
69 {
70 if (!mesh->status(v_it).deleted() && !v_it.is_boundary() && v_it.valence() == 3)
71 {
72 vf_it = mesh->vf_iter(v_it);
73 const TriMesh::Normal& n0 = mesh->normal(*vf_it);
74 const TriMesh::Normal& n1 = mesh->normal(*(++vf_it));
75 const TriMesh::Normal& n2 = mesh->normal(*(++vf_it));
76
77 if ( (n0|n1) > cosangle &&
78 (n0|n2) > cosangle &&
79 (n1|n2) > cosangle )
80 {
81
82 mesh->status(v_it).set_selected(true);
83 ++count;
84 }
85 }
86 }
87 }
88 else {
89 emit log(LOGERR, "Cannot detect flat triangles on non-trimesh " + QString::number(_objectId) + ".");
90 }
91
92 if (count > 0) {
93 emit updatedObject(_objectId, UPDATE_SELECTION);
94 emit createBackup(_objectId, "Select vertices", UPDATE_SELECTION);
95 }
96
97 emit log (LOGINFO,"Selected " + QString::number(count) + " vertices on object " + QString::number(_objectId) + " with face angle difference smaller than " + QString::number(_angle) + ".");
98 emit scriptInfo( "detectFlatValence3Vertices(" + QString::number(_objectId) + ", " + QString::number(_angle) + ")" );
99
100}
101
102//-----------------------------------------------------------------------------
103
105
106 unsigned int count = 0;
107
108 // get the target mesh
109 TriMesh* mesh = 0;
110 PluginFunctions::getMesh(_objectId, mesh);
111
112 if (mesh) {
113
114 std::vector<TriMesh::VertexHandle> vh(3);
115
116 for(auto v_it : mesh->vertices()) {
117 if ((mesh->status(v_it).selected()) && !mesh->status(v_it).feature() && v_it.valence() == 3) {
118 int i = 0;
119 for (auto vv_it : v_it.vertices()) {
120 vh[2 - i] = vv_it;
121 i++;
122 }
123
124 mesh->delete_vertex(v_it, false);
125 mesh->add_face(vh);
126
127 ++count;
128 }
129 }
130 if (count > 0)
131 mesh->garbage_collection();
132 }
133
134 if (count > 0) {
135 emit updatedObject(_objectId, UPDATE_ALL);
136 emit createBackup(_objectId, "Delete/merge selected vertices", UPDATE_ALL);
137 }
138 emit log("Deleted " + QString::number(count) + " vertices on object " + QString::number(_objectId) + ".");
139}
140
141//-----------------------------------------------------------------------------
@ LOGERR
@ LOGINFO
Functions for selection on a mesh.
void removeSelectedVal3Vertices(int _objectId)
Remove all selected valence 3 vertices.
void detectFlatValence3Vertices(int _objectId, double _angle)
Detect valence 3 vertices with faces that lie in the plane of their adjacent triangles.
Kernel::Scalar Scalar
Scalar type.
Definition: PolyMeshT.hh:110
Kernel::Normal Normal
Normal type.
Definition: PolyMeshT.hh:114
Kernel::FaceHandle FaceHandle
Scalar type.
Definition: PolyMeshT.hh:139
const UpdateType UPDATE_ALL(UpdateTypeSet(1))
Identifier for all updates.
const UpdateType UPDATE_SELECTION(UpdateTypeSet(16))
Selection updated.
bool getMesh(int _identifier, PolyMesh *&_mesh)
Get the Poly Mesh which has the given identifier.