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 * $Revision$ *
45 * $LastChangedBy$ *
46 * $Date$ *
47 * *
48 \*===========================================================================*/
49 
50 
51 #include "MeanCurvature.hh"
52 
56 
57 #include <MeshTools/Curvature.hh>
58 
59 #ifdef USE_OPENMP
60 #endif
61 
62 #if QT_VERSION >= 0x050000
63 #else
64 #include <QtGui>
65 #endif
66 
67 MeanCurvaturePlugin::MeanCurvaturePlugin()
68 {
69 }
70 
71 
72 MeanCurvaturePlugin::~MeanCurvaturePlugin()
73 {
74 }
75 
76 
77 void MeanCurvaturePlugin::pluginsInitialized()
78 {
79  emit addTexture( "Mean Curvature" , "mean_curvature.png" , 1 );
80  emit setTextureMode("Mean Curvature","clamp=true,center=true,repeat=false,clamp_min=-20,clamp_max=20");
81 
82  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\""),
83  QStringList(tr("ObjectId")), QStringList(tr("Id of the mesh")));
84 }
85 
86 void MeanCurvaturePlugin::slotUpdateTexture( QString _textureName , int _identifier )
87 {
88  if ( _textureName != "Mean Curvature") {
89  return;
90  }
91 
92  BaseObjectData* object;
93  if (! PluginFunctions::getObject( _identifier , object ) ) {
94  return;
95  }
96 
97  if ( object->dataType( DATA_TRIANGLE_MESH ) ) {
98  TriMesh* mesh = PluginFunctions::triMesh(object);
100  }
101 
102  if ( object->dataType( DATA_POLY_MESH ) ) {
103  PolyMesh* mesh = PluginFunctions::polyMesh(object);
104  computeMeanCurvature(mesh);
105  }
106 
107  emit updatedTextures("Mean Curvature",_identifier);
108 }
109 
111  BaseObjectData* object;
112  if (! PluginFunctions::getObject( _objectId , object ) ) {
113  return false;
114  }
115 
116  if ( object->dataType( DATA_TRIANGLE_MESH ) ) {
117  TriMesh* mesh = PluginFunctions::triMesh(object);
118  computeMeanCurvature(mesh);
119  return true;
120  }
121 
122  if ( object->dataType( DATA_POLY_MESH ) ) {
123  PolyMesh* mesh = PluginFunctions::polyMesh(object);
124  computeMeanCurvature(mesh);
125  return true;
126  }
127 
128  return false;
129 }
130 
131 template< typename MeshT >
133 
135 
136  if(!_mesh->get_property_handle( mean, "Mean Curvature"))
137  _mesh->add_property( mean, "Mean Curvature" );
138 
139  //QTime time;
140  //time.start();
141  std::vector< typename MeshT::VertexHandle > handles;
142  handles.reserve(_mesh->n_vertices());
143  for ( typename MeshT::VertexIter v_it = _mesh->vertices_begin() ; v_it != _mesh->vertices_end(); ++v_it)
144  handles.push_back( *v_it );
145 
146  #ifdef USE_OPENMP
147  #pragma omp parallel for
148  #endif
149  for ( int i = 0 ; i < (int)handles.size(); ++i ) {
150 
151  const typename MeshT::VertexHandle handle = handles[i];
152  ACG::Vec3d curva(0.0,0.0,0.0);
153  double area = 0.0;
154  curvature::discrete_mean_curv_op<MeshT,ACG::Vec3d,double>(*_mesh,handle,curva,area);
155  double curv = curva.norm();
156 
157  if ( (curva | _mesh->normal(handle)) <0 )
158  curv = -curv;
159 
160  _mesh->property(mean,handle) = curv;
161  }
162 
163 }
164 
165 #if QT_VERSION < 0x050000
166  Q_EXPORT_PLUGIN2( meancurvatureplugin , MeanCurvaturePlugin );
167 #endif
bool getObject(int _identifier, BSplineCurveObject *&_object)
PolyMesh * polyMesh(BaseObjectData *_object)
Get a poly mesh from an object.
bool dataType(DataType _type) const
Definition: BaseObject.cc:232
Functions for calculating curvatures.
bool computeMeanCurvature(int _objectId)
Scripting slot to trigger computation of mean curvature.
#define DATA_POLY_MESH
Definition: PolyMesh.hh:65
#define DATA_TRIANGLE_MESH
Definition: TriangleMesh.hh:66
TriMesh * triMesh(BaseObjectData *_object)
Get a triangle mesh from an object.