Developer Documentation
GaussCurvature.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 #include "GaussCurvature.hh"
51 
53 
54 #if QT_VERSION >= 0x050000
55 #else
56  #include <QtGui>
57 #endif
58 
59 #include <MeshTools/Curvature.hh>
60 
63 
64 #ifdef USE_OPENMP
65 #endif
66 
67 
68 GaussCurvaturePlugin::GaussCurvaturePlugin()
69 {
70 }
71 
72 
73 GaussCurvaturePlugin::~GaussCurvaturePlugin()
74 {
75 }
76 
77 
78 
79 void GaussCurvaturePlugin::pluginsInitialized()
80 {
81  emit addTexture( "Gaussian Curvature" , "gauss_curvature.png" , 1 );
82  emit setTextureMode("Gaussian Curvature","clamp=true,clamp_min=-1,clamp_max=1,center=true");
83 
84  emit setSlotDescription(tr("computeGaussCurvature(int)"), tr("Compute the gaussian curvature on a mesh. The curvature will be stored on the mesh on the vertex property called \"Gaussian Curvature\""),
85  QStringList(tr("ObjectId")), QStringList(tr("Id of the mesh")));
86 }
87 
88 void GaussCurvaturePlugin::slotUpdateTexture( QString _textureName , int _identifier )
89 {
90  if ( _textureName != "Gaussian Curvature")
91  return;
92 
93  BaseObjectData* object;
94  if (! PluginFunctions::getObject( _identifier , object ) ) {
95  return;
96  }
97 
98  if ( object->dataType( DATA_TRIANGLE_MESH ) ) {
99  TriMesh* mesh = PluginFunctions::triMesh(object);
100  computeGaussianCurvature(mesh);
101  }
102 
103  if ( object->dataType( DATA_POLY_MESH ) ) {
104  PolyMesh* mesh = PluginFunctions::polyMesh(object);
105  computeGaussianCurvature(mesh);
106  }
107 
108  emit updatedTextures("Gaussian Curvature",_identifier);
109 }
110 
111 
113  BaseObjectData* object;
114  if (! PluginFunctions::getObject( _objectId , object ) ) {
115  return false;
116  }
117 
118  if ( object->dataType( DATA_TRIANGLE_MESH ) ) {
119  TriMesh* mesh = PluginFunctions::triMesh(object);
120  computeGaussianCurvature(mesh);
121  return true;
122  }
123 
124  if ( object->dataType( DATA_POLY_MESH ) ) {
125  PolyMesh* mesh = PluginFunctions::polyMesh(object);
126  computeGaussianCurvature(mesh);
127  return true;
128  }
129 
130  return false;
131 }
132 
133 
134 template< typename MeshT >
135 void GaussCurvaturePlugin::computeGaussianCurvature( MeshT* _mesh) {
137 
138  if(!_mesh->get_property_handle( gauss, "Gaussian Curvature"))
139  _mesh->add_property( gauss, "Gaussian Curvature" );
140 
141 #ifdef USE_OPENMP
142  std::vector< typename MeshT::VertexHandle > handles;
143  handles.reserve(_mesh->n_vertices());
144  for ( typename MeshT::VertexIter v_it = _mesh->vertices_begin() ; v_it != _mesh->vertices_end(); ++v_it)
145  handles.push_back( *v_it );
146 
147 
148  #pragma omp parallel for
149  for ( int i = 0 ; i < (int)handles.size(); ++i )
150  _mesh->property(gauss,handles[i]) = curvature::gauss_curvature(*_mesh,handles[i]);
151 
152 #else
153  for ( typename MeshT::VertexIter v_it = _mesh->vertices_begin() ; v_it != _mesh->vertices_end(); ++v_it)
154  _mesh->property(gauss,*v_it) = curvature::gauss_curvature(*_mesh,*v_it);
155 #endif
156 
157 }
158 
159 #if QT_VERSION < 0x050000
160  Q_EXPORT_PLUGIN2( gausscurvatureplugin , GaussCurvaturePlugin );
161 #endif
162 
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 computeGaussCurvature(int _objectId)
Scripting slot to trigger computation of gaussian 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.