Developer Documentation

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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 * $Revision$ *
46 * $LastChangedBy$ *
47 * $Date$ *
48 * *
49 \*===========================================================================*/
50
51
52
53
54 #include "MeshRepairPlugin.hh"
55 #include <MeshTools/MeshSelectionT.hh>
56
57 //-----------------------------------------------------------------------------
58
59 void
60 MeshRepairPlugin::detectTriangleAspect(int _objectId, float _aspect) {
61
62 // get the target mesh
63 TriMesh* mesh = 0;
64
65 PluginFunctions::getMesh(_objectId, mesh);
66
67 if (mesh) {
68
69 unsigned int count(0);
70
71 // Clear current face selection
72 MeshSelection::clearFaceSelection(mesh);
73
74 TriMesh::FaceIter f_it, f_end(mesh->faces_end());
75 TriMesh::FVIter fv_it;
76 TriMesh::FEIter fe_it;
77
78 for (f_it = mesh->faces_begin(); f_it != f_end; ++f_it) {
79 fv_it = mesh->fv_iter(*f_it);
80
81 const TriMesh::Point& p0 = mesh->point(*fv_it);
82 const TriMesh::Point& p1 = mesh->point(*(++fv_it));
83 const TriMesh::Point& p2 = mesh->point(*(++fv_it));
84
85 if (ACG::Geometry::aspectRatio(p0, p1, p2) > _aspect) {
86 mesh->status(*f_it).set_selected(true);
87 ++count;
88 }
89 }
90 if (count > 0) {
91 emit updatedObject(_objectId, UPDATE_SELECTION);
92 emit createBackup(_objectId, "Select triangles", UPDATE_SELECTION);
93 emit scriptInfo( "detectTriangleAspect(" + QString::number(_objectId) + ", " + QString::number(_aspect) + ")" );
94 }
95 emit log(
96 "Selected " + QString::number(count) + " triangles on object " + QString::number(_objectId)
97 + " with aspect ratio greater than " + QString::number(_aspect) + ".");
98 } else {
99 emit log("Cannot detect skinny triangles on non-trimesh " + QString::number(_objectId) + ".");
100 }
101 }
102
103 //-----------------------------------------------------------------------------
104
105 void
106 MeshRepairPlugin::flipOrientation(int _objectId) {
107
108 // get the target mesh
109 TriMesh* triMesh = 0;
110 PolyMesh* polyMesh = 0;
111
112 PluginFunctions::getMesh(_objectId,triMesh);
113 PluginFunctions::getMesh(_objectId,polyMesh);
114
115 if (triMesh)
116 flipOrientation(*triMesh);
117 else if (polyMesh)
118 flipOrientation(*polyMesh);
119 else
120 emit log( LOGERR,tr("Unsupported Object Type for normal flipping!") );
121
122
123 emit updatedObject(_objectId, UPDATE_ALL);
124 emit createBackup( _objectId, "Flipped Normals", UPDATE_ALL);
125 emit scriptInfo( "flipOrientation(" + QString::number(_objectId) + ")" );
126 }
127
128
129 //-----------------------------------------------------------------------------
OpenMesh::PolyMesh_ArrayKernelT
Definition: PolyMesh_ArrayKernelT.hh:98
MeshRepairPlugin::flipOrientation
void flipOrientation(int _objectId)
Flips the normals of all selected faces by changing the vertex order.
Definition: FaceFunctions.cc:106
PluginFunctions::getMesh
bool getMesh(int _identifier, PolyMesh *&_mesh)
Get the Poly Mesh which has the given identifier.
Definition: PluginFunctionsPolyMesh.cc:107
LOGERR
Definition: LoggingInterface.hh:107
UPDATE_ALL
const UpdateType UPDATE_ALL(UpdateTypeSet(1))
Identifier for all updates.
MeshRepairPlugin::detectTriangleAspect
void detectTriangleAspect(int _objectId, float _aspect)
Detect triangles with aspect ratio greater than _aspect and select them.
Definition: FaceFunctions.cc:60
UPDATE_SELECTION
const UpdateType UPDATE_SELECTION(UpdateTypeSet(1)<< 4)
Selection updated.
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:1266
MeshSelectionT.hh
Functions for selection on a mesh.