Developer Documentation
LaplacePlugin.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 "LaplacePlugin.hh"
46 
50 
51 #ifdef USE_OPENMP
52 #endif
53 
54 
55 #define UNIFORM_LAPLACE_NAME "Uniform Laplace Length"
56 #define UNIFORM_LAPLACE_SQUARED_NAME "Uniform Laplace Squared Length"
57 
58 void LaplaceLengthPlugin::pluginsInitialized()
59 {
60  emit addTexture( UNIFORM_LAPLACE_NAME , "laplace_length.png" , 1 );
61  emit setTextureMode(UNIFORM_LAPLACE_NAME,"clamp=true,center=true,repeat=false,clamp_min=-20,clamp_max=20");
62 
63  emit addTexture( UNIFORM_LAPLACE_SQUARED_NAME , "laplace_length.png" , 1 );
64  emit setTextureMode(UNIFORM_LAPLACE_SQUARED_NAME,"clamp=true,center=true,repeat=false,clamp_min=-20,clamp_max=20");
65 }
66 
67 void LaplaceLengthPlugin::slotUpdateTexture( QString _textureName , int _identifier )
68 {
69  if ( (_textureName != UNIFORM_LAPLACE_SQUARED_NAME) && (_textureName != UNIFORM_LAPLACE_NAME ) ) {
70  return;
71  }
72 
73  BaseObjectData* object;
74  if (! PluginFunctions::getObject( _identifier , object ) ) {
75  return;
76  }
77 
78  if ( object->dataType( DATA_TRIANGLE_MESH ) ) {
79  TriMesh* mesh = PluginFunctions::triMesh(object);
80  if ( _textureName == UNIFORM_LAPLACE_NAME ) {
81  computeLaplaceLength(mesh);
82  emit updatedTextures(UNIFORM_LAPLACE_NAME,_identifier);
83  }
84  if ( _textureName == UNIFORM_LAPLACE_SQUARED_NAME ) {
85  computeLaplaceSquaredLength(mesh);
86  emit updatedTextures(UNIFORM_LAPLACE_SQUARED_NAME,_identifier);
87  }
88  }
89 
90  if ( object->dataType( DATA_POLY_MESH ) ) {
91  PolyMesh* mesh = PluginFunctions::polyMesh(object);
92  if ( _textureName == UNIFORM_LAPLACE_NAME ) {
93  computeLaplaceLength(mesh);
94  emit updatedTextures(UNIFORM_LAPLACE_NAME,_identifier);
95  }
96  if ( _textureName == UNIFORM_LAPLACE_SQUARED_NAME ) {
97  computeLaplaceSquaredLength(mesh);
98  emit updatedTextures(UNIFORM_LAPLACE_SQUARED_NAME,_identifier);
99  }
100  }
101 }
102 
103 template< typename MeshT >
104 void LaplaceLengthPlugin::computeLaplaceLength(MeshT* _mesh) {
105  OpenMesh::VPropHandleT< ACG::Vec3d > laplace_vector_property;
106  OpenMesh::VPropHandleT< double > laplace_length_property;
107 
108  if(!_mesh->get_property_handle( laplace_vector_property , "Laplace Vector" ))
109  _mesh->add_property( laplace_vector_property, "Laplace Vector" );
110 
111  if(!_mesh->get_property_handle( laplace_length_property , UNIFORM_LAPLACE_NAME ))
112  _mesh->add_property( laplace_length_property, UNIFORM_LAPLACE_NAME );
113 
114 
115  QTime time;
116  time.start();
117  std::vector< typename MeshT::VertexHandle > handles;
118  handles.reserve(_mesh->n_vertices());
119  for ( typename MeshT::VertexIter v_it = _mesh->vertices_begin() ; v_it != _mesh->vertices_end(); ++v_it)
120  handles.push_back( *v_it );
121 
122  #ifdef USE_OPENMP
123  #pragma omp parallel for
124  #endif
125  for ( int i = 0 ; i < (int)handles.size(); ++i ) {
126  const typename MeshT::VertexHandle handle = handles[i];
127 
128  ACG::Vec3d laplace(0.0,0.0,0.0);
129  for ( typename MeshT::VertexVertexIter vv_it(*_mesh , handle) ; vv_it.is_valid() ; ++vv_it )
130  laplace += _mesh->point(*vv_it) - _mesh->point(handle);
131 
132  laplace = 1.0 /(double)_mesh->valence(handle) * laplace;
133  _mesh->property(laplace_vector_property,handle) = laplace;
134  _mesh->property(laplace_length_property,handle) = laplace.norm();
135  }
136 
137 // #ifdef USE_OPENMP
138 // std::cerr << "Laplace parallel took : " << time.elapsed() << std::endl;
139 // #else
140 // std::cerr << "Laplace sequential took : " << time.elapsed() << std::endl;
141 // #endif
142 
143 }
144 
145 template< typename MeshT >
146 void LaplaceLengthPlugin::computeLaplaceSquaredLength(MeshT* _mesh) {
147  computeLaplaceLength(_mesh);
148 
149  OpenMesh::VPropHandleT< ACG::Vec3d > laplace_property;
150  OpenMesh::VPropHandleT< double > laplace_squared;
151 
152  if(!_mesh->get_property_handle( laplace_property , "Laplace Vector" )) {
153  std::cerr << "LaplaceLengthPlugin : Unable to get Laplace Vector property" << std::endl;
154  return;
155  }
156 
157  if(!_mesh->get_property_handle( laplace_squared , UNIFORM_LAPLACE_SQUARED_NAME ))
158  _mesh->add_property( laplace_squared, UNIFORM_LAPLACE_SQUARED_NAME );
159 
160  QTime time;
161  time.start();
162  std::vector< typename MeshT::VertexHandle > handles;
163  handles.reserve(_mesh->n_vertices());
164  for ( typename MeshT::VertexIter v_it = _mesh->vertices_begin() ; v_it != _mesh->vertices_end(); ++v_it)
165  handles.push_back( *v_it );
166 
167  #ifdef USE_OPENMP
168  #pragma omp parallel for
169  #endif
170  for ( int i = 0 ; i < (int)handles.size(); ++i ) {
171  const typename MeshT::VertexHandle handle = handles[i];
172 
173  ACG::Vec3d laplace(0.0,0.0,0.0);
174  for ( typename MeshT::VertexVertexIter vv_it(*_mesh , handle) ; vv_it.is_valid() ; ++vv_it )
175  laplace += _mesh->property(laplace_property,*vv_it) - _mesh->property(laplace_property,handle);
176  laplace = 1.0 /(double)_mesh->valence(handle) * laplace;
177  _mesh->property(laplace_squared,handle) = laplace.norm();
178  }
179 
180 // #ifdef USE_OPENMP
181 // std::cerr << "Laplace Squared parallel took : " << time.elapsed() << std::endl;
182 // #else
183 // std::cerr << "Laplace Squared sequential took : " << time.elapsed() << std::endl;
184 // #endif
185 }
186 
187 
188 
189 
#define DATA_POLY_MESH
Definition: PolyMesh.hh:59
bool dataType(DataType _type) const
Definition: BaseObject.cc:221
TriMesh * triMesh(BaseObjectData *_object)
Get a triangle mesh from an object.
bool getObject(const int _identifier, BaseObject *&_object)
Get the object which has the given identifier.
PolyMesh * polyMesh(BaseObjectData *_object)
Get a poly mesh from an object.
#define DATA_TRIANGLE_MESH
Definition: TriangleMesh.hh:60