Developer Documentation

MeanCurvature.cc
1 /*===========================================================================*\
2 * *
3 * OpenFlipper *
4 * Copyright (c) 2001-2015, RWTH-Aachen University *
5 * Department of Computer Graphics and Multimedia *
6 * All rights reserved. *
7 * www.openflipper.org *
8 * *
9 *---------------------------------------------------------------------------*
10 * This file is part of OpenFlipper. *
11 *---------------------------------------------------------------------------*
12 * *
13 * Redistribution and use in source and binary forms, with or without *
14 * modification, are permitted provided that the following conditions *
15 * are met: *
16 * *
17 * 1. Redistributions of source code must retain the above copyright notice, *
18 * this list of conditions and the following disclaimer. *
19 * *
20 * 2. Redistributions in binary form must reproduce the above copyright *
21 * notice, this list of conditions and the following disclaimer in the *
22 * documentation and/or other materials provided with the distribution. *
23 * *
24 * 3. Neither the name of the copyright holder nor the names of its *
25 * contributors may be used to endorse or promote products derived from *
26 * this software without specific prior written permission. *
27 * *
28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
29 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
30 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
31 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
32 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
33 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
34 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
35 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
36 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
37 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
38 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
39 * *
40 \*===========================================================================*/
41
42
43
44
45 #include "MeanCurvature.hh"
46
47 #include <OpenFlipper/BasePlugin/PluginFunctions.hh>
48 #include <ObjectTypes/PolyMesh/PolyMesh.hh>
49 #include <ObjectTypes/TriangleMesh/TriangleMesh.hh>
50
51 #include <MeshTools/Curvature.hh>
52
53 #ifdef USE_OPENMP
54 #endif
55
56
57 MeanCurvaturePlugin::MeanCurvaturePlugin()
58 {
59 }
60
61
62 MeanCurvaturePlugin::~MeanCurvaturePlugin()
63 {
64 }
65
66
67 void MeanCurvaturePlugin::pluginsInitialized()
68 {
69 emit addTexture( "Mean Curvature" , "mean_curvature.png" , 1 );
70 emit setTextureMode("Mean Curvature","clamp=true,center=true,repeat=false,clamp_min=-20,clamp_max=20");
71
72 emit setSlotDescription(tr("computeMeanCurvature(int)"), tr("Compute the mean curvature on a mesh. The curvature will be stored on the mesh on the vertex property called \"Mean Curvature\""),
73 QStringList(tr("ObjectId")), QStringList(tr("Id of the mesh")));
74 }
75
76 void MeanCurvaturePlugin::slotUpdateTexture( QString _textureName , int _identifier )
77 {
78 if ( _textureName != "Mean Curvature") {
79 return;
80 }
81
82 BaseObjectData* object;
83 if (! PluginFunctions::getObject( _identifier , object ) ) {
84 return;
85 }
86
87 if ( object->dataType( DATA_TRIANGLE_MESH ) ) {
88 TriMesh* mesh = PluginFunctions::triMesh(object);
89 computeMeanCurvature(mesh);
90 }
91
92 if ( object->dataType( DATA_POLY_MESH ) ) {
93 PolyMesh* mesh = PluginFunctions::polyMesh(object);
94 computeMeanCurvature(mesh);
95 }
96
97 emit updatedTextures("Mean Curvature",_identifier);
98 }
99
100 bool MeanCurvaturePlugin::computeMeanCurvature(int _objectId) {
101 BaseObjectData* object;
102 if (! PluginFunctions::getObject( _objectId , object ) ) {
103 return false;
104 }
105
106 if ( object->dataType( DATA_TRIANGLE_MESH ) ) {
107 TriMesh* mesh = PluginFunctions::triMesh(object);
108 computeMeanCurvature(mesh);
109 return true;
110 }
111
112 if ( object->dataType( DATA_POLY_MESH ) ) {
113 PolyMesh* mesh = PluginFunctions::polyMesh(object);
114 computeMeanCurvature(mesh);
115 return true;
116 }
117
118 return false;
119 }
120
121 template< typename MeshT >
122 void MeanCurvaturePlugin::computeMeanCurvature(MeshT* _mesh) {
123
124 OpenMesh::VPropHandleT< double > mean;
125
126 if(!_mesh->get_property_handle( mean, "Mean Curvature"))
127 _mesh->add_property( mean, "Mean Curvature" );
128
129 //QTime time;
130 //time.start();
131 std::vector< typename MeshT::VertexHandle > handles;
132 handles.reserve(_mesh->n_vertices());
133 for ( typename MeshT::VertexIter v_it = _mesh->vertices_begin() ; v_it != _mesh->vertices_end(); ++v_it)
134 handles.push_back( *v_it );
135
136 #ifdef USE_OPENMP
137 #pragma omp parallel for
138 #endif
139 for ( int i = 0 ; i < (int)handles.size(); ++i ) {
140
141 const typename MeshT::VertexHandle handle = handles[i];
142 ACG::Vec3d curva(0.0,0.0,0.0);
143 double area = 0.0;
144 curvature::discrete_mean_curv_op<MeshT,ACG::Vec3d,double>(*_mesh,handle,curva,area);
145 double curv = curva.norm();
146
147 if ( (curva | _mesh->normal(handle)) <0 )
148 curv = -curv;
149
150 _mesh->property(mean,handle) = curv;
151 }
152
153 }
154
OpenMesh::VPropHandleT
Definition: Property.hh:484
DATA_TRIANGLE_MESH
#define DATA_TRIANGLE_MESH
Definition: TriangleMesh.hh:60
DATA_POLY_MESH
#define DATA_POLY_MESH
Definition: PolyMesh.hh:59
PluginFunctions::polyMesh
PolyMesh * polyMesh(BaseObjectData *_object)
Get a poly mesh from an object.
Definition: PluginFunctionsPolyMesh.cc:128
Curvature.hh
Functions for calculating curvatures.
PluginFunctions::getObject
bool getObject(const int _identifier, BaseObject *&_object)
Get the object which has the given identifier.
Definition: PluginFunctions.cc:296
OpenMesh::TriMesh_ArrayKernelT
Definition: PolyMesh_ArrayKernelT.hh:73
OpenMesh::VectorT
Definition: Vector11T.hh:83
PluginFunctions::triMesh
TriMesh * triMesh(BaseObjectData *_object)
Get a triangle mesh from an object.
Definition: PluginFunctionsTriangleMesh.cc:134
PluginFunctions.hh
OpenMesh::PolyMesh_ArrayKernelT
Definition: PolyMesh_ArrayKernelT.hh:94
BaseObject::dataType
bool dataType(DataType _type) const
Definition: BaseObject.cc:221
MeanCurvaturePlugin::computeMeanCurvature
bool computeMeanCurvature(int _objectId)
Scripting slot to trigger computation of mean curvature.
Definition: MeanCurvature.cc:100
TriangleMesh.hh
BaseObjectData
Definition: BaseObjectData.hh:102
PolyMesh.hh