Developer Documentation
NormalFixing.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 
47 #include "MeshRepairPlugin.hh"
48 
49 
50 //-----------------------------------------------------------------------------
51 
52 
54  BaseObjectData* object = 0;
55  PluginFunctions::getObject(_objectId,object);
56 
57  if ( object == 0) {
58  emit log(LOGERR,tr("updateFaceNormals: Unable to get object %1. ").arg(_objectId) );
59  return;
60  }
61 
62  if ( object->dataType(DATA_TRIANGLE_MESH) ) {
63  TriMesh* mesh = PluginFunctions::triMesh(object);
64  mesh->update_face_normals();
65  emit updatedObject(_objectId, UPDATE_ALL);
66  emit createBackup( _objectId, "Updated Face Normals", UPDATE_ALL);
67  emit scriptInfo( "updateFaceNormals(" + QString::number(_objectId) + ")" );
68  } else if ( object->dataType(DATA_POLY_MESH) ) {
69  PolyMesh* mesh = PluginFunctions::polyMesh(object);
70  mesh->update_face_normals();
71  emit updatedObject(_objectId, UPDATE_ALL);
72  emit createBackup( _objectId, "Updated Face Normals", UPDATE_ALL);
73  emit scriptInfo( "updateFaceNormals(" + QString::number(_objectId) + ")" );
74  } else
75  emit log(LOGERR,tr("updateFaceNormals: MeshRepair only works on triangle and poly meshes!") );
76 
77 }
78 
79 
80 //-----------------------------------------------------------------------------
81 
83  BaseObjectData* object = 0;
84  PluginFunctions::getObject(_objectId,object);
85 
86  if ( object == 0) {
87  emit log(LOGERR,tr("updateFaceNormals: Unable to get object %1. ").arg(_objectId) );
88  return;
89  }
90 
91  if ( object->dataType(DATA_TRIANGLE_MESH) ) {
92  TriMesh* mesh = PluginFunctions::triMesh(object);
93  mesh->request_halfedge_normals();
95  emit updatedObject(_objectId, UPDATE_ALL);
96  emit createBackup( _objectId, "Updated Face Normals", UPDATE_ALL);
97  emit scriptInfo( "updateFaceNormals(" + QString::number(_objectId) + ")" );
98  } else if ( object->dataType(DATA_POLY_MESH) ) {
99  PolyMesh* mesh = PluginFunctions::polyMesh(object);
100  mesh->request_halfedge_normals();
101  mesh->update_halfedge_normals();
102  emit updatedObject(_objectId, UPDATE_ALL);
103  emit createBackup( _objectId, "Updated Face Normals", UPDATE_ALL);
104  emit scriptInfo( "updateFaceNormals(" + QString::number(_objectId) + ")" );
105  } else
106  emit log(LOGERR,tr("updateFaceNormals: MeshRepair only works on triangle and poly meshes!") );
107 
108 }
109 
110 
111 //-----------------------------------------------------------------------------
112 
113 
115  BaseObjectData* object = 0;
116  PluginFunctions::getObject(_objectId,object);
117 
118  if ( object == 0) {
119  emit log(LOGERR,tr("updateVertexNormals: Unable to get object %1. ").arg(_objectId) );
120  return;
121  }
122 
123  if ( object->dataType(DATA_TRIANGLE_MESH) ) {
124  TriMesh* mesh = PluginFunctions::triMesh(object);
125  mesh->update_vertex_normals();
126  emit updatedObject(_objectId, UPDATE_ALL);
127  emit createBackup( _objectId, "Updated Vertex Normals", UPDATE_ALL);
128  emit scriptInfo( "updateVertexNormals(" + QString::number(_objectId) + ")" );
129  } else if ( object->dataType(DATA_POLY_MESH) ) {
130  PolyMesh* mesh = PluginFunctions::polyMesh(object);
131  mesh->update_vertex_normals();
132  emit updatedObject(_objectId, UPDATE_ALL);
133  emit createBackup( _objectId, "Updated Vertex Normals", UPDATE_ALL);
134  emit scriptInfo( "updateVertexNormals(" + QString::number(_objectId) + ")" );
135  } else
136  emit log(LOGERR,tr("updateVertexNormals: MeshRepair only works on triangle and poly meshes!") );
137 }
138 
139 //-----------------------------------------------------------------------------
140 
141 void MeshRepairPlugin::updateNormals(int _objectId) {
142  BaseObjectData* object = 0;
143  PluginFunctions::getObject(_objectId,object);
144 
145  if ( object == 0) {
146  emit log(LOGERR,tr("updateNormals: Unable to get object %1. ").arg(_objectId) );
147  return;
148  }
149 
150  if ( object->dataType(DATA_TRIANGLE_MESH) ) {
151  TriMesh* mesh = PluginFunctions::triMesh(object);
152  mesh->update_normals();
153  emit scriptInfo( "updateNormals(" + QString::number(_objectId) + ")" );
154  } else if ( object->dataType(DATA_POLY_MESH) ) {
155  PolyMesh* mesh = PluginFunctions::polyMesh(object);
156  mesh->update_normals();
157  emit updatedObject(_objectId, UPDATE_ALL);
158  emit createBackup( _objectId, "Updated All Normals", UPDATE_ALL);
159  emit scriptInfo( "updateNormals(" + QString::number(_objectId) + ")" );
160  } else
161  emit log(LOGERR,tr("updateNormals: MeshRepair only works on triangle and poly meshes!") );
162 }
163 
164 
void updateNormals(int _objectId)
Recomputes the face and vertex normals of an object.
#define DATA_TRIANGLE_MESH
Definition: TriangleMesh.hh:60
#define DATA_POLY_MESH
Definition: PolyMesh.hh:59
const UpdateType UPDATE_ALL(UpdateTypeSet(1))
Identifier for all updates.
PolyMesh * polyMesh(BaseObjectData *_object)
Get a poly mesh from an object.
bool getObject(const int _identifier, BaseObject *&_object)
Get the object which has the given identifier.
TriMesh * triMesh(BaseObjectData *_object)
Get a triangle mesh from an object.
bool dataType(DataType _type) const
Definition: BaseObject.cc:221
void updateVertexNormals(int _objectId)
Recomputes the vertex normals of an object.
void update_vertex_normals()
Update normal vectors for all vertices.
void update_normals()
Compute normals for all primitives.
void update_face_normals()
Update normal vectors for all faces.
void updateHalfedgeNormals(int _objectId)
Recomputes the halfedge normals of an object.
Definition: NormalFixing.cc:82
void update_halfedge_normals(const double _feature_angle=0.8)
Update normal vectors for all halfedges.
void updateFaceNormals(int _objectId)
Recomputes the face normals of an object.
Definition: NormalFixing.cc:53