Developer Documentation
FaceFunctions.cc
1
2/*===========================================================================*\
3 * *
4 * OpenFlipper *
5 * Copyright (c) 2001-2015, RWTH-Aachen University *
6 * Department of Computer Graphics and Multimedia *
7 * All rights reserved. *
8 * www.openflipper.org *
9 * *
10 *---------------------------------------------------------------------------*
11 * This file is part of OpenFlipper. *
12 *---------------------------------------------------------------------------*
13 * *
14 * Redistribution and use in source and binary forms, with or without *
15 * modification, are permitted provided that the following conditions *
16 * are met: *
17 * *
18 * 1. Redistributions of source code must retain the above copyright notice, *
19 * this list of conditions and the following disclaimer. *
20 * *
21 * 2. Redistributions in binary form must reproduce the above copyright *
22 * notice, this list of conditions and the following disclaimer in the *
23 * documentation and/or other materials provided with the distribution. *
24 * *
25 * 3. Neither the name of the copyright holder nor the names of its *
26 * contributors may be used to endorse or promote products derived from *
27 * this software without specific prior written permission. *
28 * *
29 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
30 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
31 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
32 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
33 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
34 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
35 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
36 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
37 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
38 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
39 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
40 * *
41\*===========================================================================*/
42
43
44
45
46#include "MeshRepairPlugin.hh"
48
49//-----------------------------------------------------------------------------
50
51void
52MeshRepairPlugin::detectTriangleAspect(int _objectId, float _aspect) {
53
54 // get the target mesh
55 TriMesh* mesh = 0;
56
57 PluginFunctions::getMesh(_objectId, mesh);
58
59 if (mesh) {
60
61 unsigned int count(0);
62
63 // Clear current face selection
64 MeshSelection::clearFaceSelection(mesh);
65
66 TriMesh::FVIter fv_it;
67 TriMesh::FEIter fe_it;
68
69 for (auto f_it : mesh->faces()) {
70 fv_it = mesh->fv_iter(f_it);
71
72 const TriMesh::Point& p0 = mesh->point(*fv_it);
73 const TriMesh::Point& p1 = mesh->point(*(++fv_it));
74 const TriMesh::Point& p2 = mesh->point(*(++fv_it));
75
76 if (ACG::Geometry::aspectRatio(p0, p1, p2) > _aspect) {
77 mesh->status(f_it).set_selected(true);
78 ++count;
79 }
80 }
81 if (count > 0) {
82 emit updatedObject(_objectId, UPDATE_SELECTION);
83 emit createBackup(_objectId, "Select triangles", UPDATE_SELECTION);
84 emit scriptInfo( "detectTriangleAspect(" + QString::number(_objectId) + ", " + QString::number(_aspect) + ")" );
85 }
86 emit log(
87 "Selected " + QString::number(count) + " triangles on object " + QString::number(_objectId)
88 + " with aspect ratio greater than " + QString::number(_aspect) + ".");
89 } else {
90 emit log("Cannot detect skinny triangles on non-trimesh " + QString::number(_objectId) + ".");
91 }
92}
93
94//-----------------------------------------------------------------------------
95
96void
98
99 // get the target mesh
100 TriMesh* triMesh = 0;
101 PolyMesh* polyMesh = 0;
102
103 PluginFunctions::getMesh(_objectId,triMesh);
104 PluginFunctions::getMesh(_objectId,polyMesh);
105
106 if (triMesh)
107 flipOrientation(*triMesh);
108 else if (polyMesh)
109 flipOrientation(*polyMesh);
110 else
111 emit log( LOGERR,tr("Unsupported Object Type for normal flipping!") );
112
113
114 emit updatedObject(_objectId, UPDATE_ALL);
115 emit createBackup( _objectId, "Flipped Normals", UPDATE_ALL);
116 emit scriptInfo( "flipOrientation(" + QString::number(_objectId) + ")" );
117}
118
119
120//-----------------------------------------------------------------------------
@ LOGERR
Functions for selection on a mesh.
void flipOrientation(int _objectId)
Flips the normals of all selected faces by changing the vertex order.
void detectTriangleAspect(int _objectId, float _aspect)
Detect triangles with aspect ratio greater than _aspect and select them.
Kernel::Point Point
Coordinate type.
Definition: PolyMeshT.hh:112
const UpdateType UPDATE_ALL(UpdateTypeSet(1))
Identifier for all updates.
const UpdateType UPDATE_SELECTION(UpdateTypeSet(16))
Selection updated.
Scalar aspectRatio(const VectorT< Scalar, N > &_v0, const VectorT< Scalar, N > &_v1, const VectorT< Scalar, N > &_v2)
return aspect ratio (length/height) of triangle
Definition: Algorithms.cc:1256
bool getMesh(int _identifier, PolyMesh *&_mesh)
Get the Poly Mesh which has the given identifier.