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"
47 #include <MeshTools/MeshSelectionT.hh>
48
49 //-----------------------------------------------------------------------------
50
51 void
52 MeshRepairPlugin::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::FaceIter f_it, f_end(mesh->faces_end());
67 TriMesh::FVIter fv_it;
68 TriMesh::FEIter fe_it;
69
70 for (f_it = mesh->faces_begin(); f_it != f_end; ++f_it) {
71 fv_it = mesh->fv_iter(*f_it);
72
73 const TriMesh::Point& p0 = mesh->point(*fv_it);
74 const TriMesh::Point& p1 = mesh->point(*(++fv_it));
75 const TriMesh::Point& p2 = mesh->point(*(++fv_it));
76
77 if (ACG::Geometry::aspectRatio(p0, p1, p2) > _aspect) {
78 mesh->status(*f_it).set_selected(true);
79 ++count;
80 }
81 }
82 if (count > 0) {
83 emit updatedObject(_objectId, UPDATE_SELECTION);
84 emit createBackup(_objectId, "Select triangles", UPDATE_SELECTION);
85 emit scriptInfo( "detectTriangleAspect(" + QString::number(_objectId) + ", " + QString::number(_aspect) + ")" );
86 }
87 emit log(
88 "Selected " + QString::number(count) + " triangles on object " + QString::number(_objectId)
89 + " with aspect ratio greater than " + QString::number(_aspect) + ".");
90 } else {
91 emit log("Cannot detect skinny triangles on non-trimesh " + QString::number(_objectId) + ".");
92 }
93 }
94
95 //-----------------------------------------------------------------------------
96
97 void
98 MeshRepairPlugin::flipOrientation(int _objectId) {
99
100 // get the target mesh
101 TriMesh* triMesh = 0;
102 PolyMesh* polyMesh = 0;
103
104 PluginFunctions::getMesh(_objectId,triMesh);
105 PluginFunctions::getMesh(_objectId,polyMesh);
106
107 if (triMesh)
108 flipOrientation(*triMesh);
109 else if (polyMesh)
110 flipOrientation(*polyMesh);
111 else
112 emit log( LOGERR,tr("Unsupported Object Type for normal flipping!") );
113
114
115 emit updatedObject(_objectId, UPDATE_ALL);
116 emit createBackup( _objectId, "Flipped Normals", UPDATE_ALL);
117 emit scriptInfo( "flipOrientation(" + QString::number(_objectId) + ")" );
118 }
119
120
121 //-----------------------------------------------------------------------------
LOGERR
Definition: LoggingInterface.hh:96
UPDATE_ALL
const UpdateType UPDATE_ALL(UpdateTypeSet(1))
Identifier for all updates.
OpenMesh::PolyMeshT::Point
Kernel::Point Point
Coordinate type.
Definition: PolyMeshT.hh:112
OpenMesh::TriMesh_ArrayKernelT
Definition: PolyMesh_ArrayKernelT.hh:73
UPDATE_SELECTION
const UpdateType UPDATE_SELECTION(UpdateTypeSet(1)<< 4)
Selection updated.
OpenMesh::PolyMesh_ArrayKernelT
Definition: PolyMesh_ArrayKernelT.hh:94
ACG::Geometry::aspectRatio
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
MeshSelectionT.hh
Functions for selection on a mesh.
MeshRepairPlugin::flipOrientation
void flipOrientation(int _objectId)
Flips the normals of all selected faces by changing the vertex order.
Definition: FaceFunctions.cc:98
PluginFunctions::getMesh
bool getMesh(int _identifier, PolyMesh *&_mesh)
Get the Poly Mesh which has the given identifier.
Definition: PluginFunctionsPolyMesh.cc:101
MeshRepairPlugin::detectTriangleAspect
void detectTriangleAspect(int _objectId, float _aspect)
Detect triangles with aspect ratio greater than _aspect and select them.
Definition: FaceFunctions.cc:52