Developer Documentation
Loading...
Searching...
No Matches
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#include "GaussCurvature.hh"
45
47
48
50
53
54#ifdef USE_OPENMP
55#endif
56
57
58GaussCurvaturePlugin::GaussCurvaturePlugin()
59{
60}
61
62
63GaussCurvaturePlugin::~GaussCurvaturePlugin()
64{
65}
66
67
68
69void GaussCurvaturePlugin::pluginsInitialized()
70{
71 emit addTexture( "Gaussian Curvature" , "gauss_curvature.png" , 1 );
72 emit setTextureMode("Gaussian Curvature","clamp=true,clamp_min=-1,clamp_max=1,center=true");
73
74 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\""),
75 QStringList(tr("ObjectId")), QStringList(tr("Id of the mesh")));
76}
77
78void GaussCurvaturePlugin::slotUpdateTexture(QString _textureName , int _identifier )
79{
80 if ( _textureName != "Gaussian Curvature")
81 return;
82
83 BaseObjectData* object;
84 if (! PluginFunctions::getObject( _identifier , object ) ) {
85 return;
86 }
87
88 if ( object->dataType( DATA_TRIANGLE_MESH ) ) {
89 TriMesh* mesh = PluginFunctions::triMesh(object);
90 computeGaussianCurvature(mesh);
91 }
92
93 if ( object->dataType( DATA_POLY_MESH ) ) {
94 PolyMesh* mesh = PluginFunctions::polyMesh(object);
95 computeGaussianCurvature(mesh);
96 }
97
98 emit updatedTextures("Gaussian Curvature",_identifier);
99}
100
101
103 BaseObjectData* object;
104 if (! PluginFunctions::getObject( _objectId , object ) ) {
105 return false;
106 }
107
108 if ( object->dataType( DATA_TRIANGLE_MESH ) ) {
109 TriMesh* mesh = PluginFunctions::triMesh(object);
110 computeGaussianCurvature(mesh);
111 return true;
112 }
113
114 if ( object->dataType( DATA_POLY_MESH ) ) {
115 PolyMesh* mesh = PluginFunctions::polyMesh(object);
116 computeGaussianCurvature(mesh);
117 return true;
118 }
119
120 return false;
121}
122
123
124template< typename MeshT >
125void GaussCurvaturePlugin::computeGaussianCurvature( MeshT* _mesh) {
127
128 if(!_mesh->get_property_handle( gauss, "Gaussian Curvature"))
129 _mesh->add_property( gauss, "Gaussian Curvature" );
130
131#ifdef USE_OPENMP
132 std::vector< typename MeshT::VertexHandle > handles;
133 handles.reserve(_mesh->n_vertices());
134 for (auto v_it : _mesh->vertices())
135 handles.push_back( v_it );
136
137
138 #pragma omp parallel for
139 for ( int i = 0 ; i < (int)handles.size(); ++i )
140 _mesh->property(gauss,handles[i]) = curvature::gauss_curvature(*_mesh,handles[i]);
141
142#else
143 for (auto v_it : _mesh->vertices())
144 _mesh->property(gauss,v_it) = curvature::gauss_curvature(*_mesh,v_it);
145#endif
146
147}
148
149
Functions for calculating curvatures.
#define DATA_POLY_MESH
Definition PolyMesh.hh:59
#define DATA_TRIANGLE_MESH
bool dataType(DataType _type) const
bool computeGaussCurvature(int _objectId)
Scripting slot to trigger computation of gaussian curvature.
size_t n_vertices() const override
Get number of vertices in mesh.
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.
PolyMesh * polyMesh(BaseObjectData *_object)
Get a poly mesh from an object.