Developer Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
GeneralMeshFixing.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: 15713 $ *
46  * $LastChangedBy: moebius $ *
47  * $Date: 2012-10-25 12:58:58 +0200 (Do, 25 Okt 2012) $ *
48  * *
49 \*===========================================================================*/
50 
51 
52 
53 
54 #include "MeshRepairPlugin.hh"
55 #include "MeshFixingT.hh"
56 #include "NonManifoldVertexFixingT.hh"
57 #include "BoundarySnappingT.hh"
58 
59 //-----------------------------------------------------------------------------
60 
61 void MeshRepairPlugin::snapBoundary(int _objectId, double _eps)
62 {
63  TriMesh* triMesh = 0;
64  PolyMesh* polyMesh = 0;
65 
66  PluginFunctions::getMesh(_objectId, triMesh);
67  PluginFunctions::getMesh(_objectId, polyMesh);
68  if (triMesh) {
69  BoundarySnappingT<TriMesh> snapper(*triMesh);
70  snapper.snap(_eps);
71  }
72  else if (polyMesh) {
73  BoundarySnappingT<PolyMesh> snapper(*polyMesh);
74  snapper.snap(_eps);
75  } else
76  {
77  emit log(LOGERR, tr("Unsupported Object Type."));
78  return;
79  }
80 
81  emit updatedObject(_objectId, UPDATE_ALL);
82  emit createBackup(_objectId, "snapBoundary", UPDATE_ALL);
83  emit scriptInfo("snapBoundary(" + QString::number(_objectId) + ", " + QString::number(_eps) +")");
84 }
85 
86 //-----------------------------------------------------------------------------
87 
89 {
90  TriMesh* triMesh = 0;
91  PolyMesh* polyMesh = 0;
92 
93  PluginFunctions::getMesh(_objectId, triMesh);
94  PluginFunctions::getMesh(_objectId, polyMesh);
95  if (triMesh) {
96  NonManifoldVertexFixingT<TriMesh> fixer(*triMesh);
97  fixer.fix();
98  }
99  else if (polyMesh) {
100  NonManifoldVertexFixingT<PolyMesh> fixer(*polyMesh);
101  fixer.fix();
102  } else
103  {
104  emit log(LOGERR, tr("Unsupported Object Type."));
105  return;
106  }
107 
108  emit updatedObject(_objectId, UPDATE_ALL);
109  emit createBackup(_objectId, "fixNonManifoldVertices", UPDATE_ALL);
110  emit scriptInfo("fixNonManifoldVertices(" + QString::number(_objectId) + ")");
111 }
112 
113 //-----------------------------------------------------------------------------
114 
115 void
116 MeshRepairPlugin::fixMesh(int _objectId, double _epsilon) {
117  // get the target mesh
118  TriMesh* triMesh = 0;
119 
120  PluginFunctions::getMesh(_objectId,triMesh);
121 
122  if (triMesh) {
123  MeshFixing<TriMesh> fixer(*triMesh,_epsilon);
124 
125  if ( !fixer.fix() )
126  emit log(LOGERR, "Fixmesh encountered Problems! Object: " + QString::number(_objectId) + ".");
127 
128  // Recompute normals
129  triMesh->update_normals();
130 
131  emit updatedObject(_objectId, UPDATE_ALL);
132  emit createBackup(_objectId, "Fixed mesh", UPDATE_ALL);
133 
134  emit scriptInfo( "fixMesh(" + QString::number(_objectId) + ", " + QString::number(_epsilon) + ")" );
135 
136  } else
137  emit log( LOGERR,tr("Unsupported Object Type for mesh fixing!") );
138 
139 }
140 
141 //-----------------------------------------------------------------------------
Fix a mesh.
Definition: MeshFixingT.hh:89
bool getMesh(int _identifier, PolyMesh *&_mesh)
Get the Poly Mesh which has the given identifier.
void snap(double _epsilon)
snaps boundary vertices
void snapBoundary(int _objectId, double _eps)
Snaps selected vertices at boundaries.
const UpdateType UPDATE_ALL(UpdateTypeSet(1))
Identifier for all updates.
void fixMesh(int _objectId, double _epsilon)
Fix a mesh.
Removed non-manifold vertices from a mesh by duplicating them.
Snaps selected vertices at boundaries.
void fixNonManifoldVertices(int _objectId)
remove non-manifold vertices by duplicating them