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