Skip to content

Commit

Permalink
Uniform laplacian smoothing and tangential version
Browse files Browse the repository at this point in the history
  • Loading branch information
xionluhnis committed Aug 19, 2014
1 parent 5a73575 commit 29f218d
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 1 deletion.
18 changes: 17 additions & 1 deletion example-visualize/src/ofApp.cpp
Expand Up @@ -59,12 +59,16 @@ void ofApp::update(){
Surface_mesh::Face_property<float> fdata;
switch(prop){
case OGP_UNIFORM_MEAN_CURVATURE:
ofxOpenGP::voronoi_area(mesh);
vdata = ofxOpenGP::uniform_mean_curvature(mesh);
break;
case OGP_MEAN_CURVATURE:
ofxOpenGP::voronoi_area(mesh);
ofxOpenGP::cot_pair(mesh);
vdata = ofxOpenGP::mean_curvature(mesh);
break;
case OGP_GAUSS_CURVATURE:
ofxOpenGP::voronoi_area(mesh);
vdata = ofxOpenGP::gauss_curvature(mesh);
break;
case OGP_VORONOI_AREA:
Expand Down Expand Up @@ -172,13 +176,25 @@ void ofApp::keyPressed(int key){
}
}
break;
case 's':
std::cout << "Smoothing of mesh.\n";
ofxOpenGP::laplace_uniform_smooth(mesh);
mesh.update_vertex_normals();
propChanged = true;
break;
case 't':
std::cout << "Tangential smoothing of mesh.\n";
ofxOpenGP::laplace_uniform_smooth(mesh, true);
mesh.update_vertex_normals();
propChanged = true;
break;
case 'h':
help = !help;
break;
case ' ':
{
ofFile file(ofToDataPath(path));
ofFileDialogResult res = ofSystemLoadDialog("Chose mesh file (.obj, .off, .ply)", false, file.getEnclosingDirectory());
ofFileDialogResult res = ofSystemLoadDialog("Choose mesh file (.obj, .off, .ply)", false, file.getEnclosingDirectory());
if(!res.bSuccess) return;
if(!ofFile(res.getPath()).canRead()) return;
path = res.getPath();
Expand Down
42 changes: 42 additions & 0 deletions src/ofxOpenGP.h
Expand Up @@ -583,4 +583,46 @@ class ofxOpenGP {
return col;
}

///////////////////////////////////////////////////////////////////////////
///// Mesh operations /////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
static void laplace_uniform_smooth(Surface_mesh &mesh, bool tangential = false, unsigned int rounds = 5, float eta = 0.5){
Surface_mesh::Vertex_property<Vec3> laplace = mesh.vertex_property<Vec3>("v:tmp:vec3f");
Surface_mesh::Vertex_property<Normal> normals = mesh.vertex_property<Normal>("v:normal");
if(tangential){
mesh.update_vertex_normals();
}
for(unsigned int r = 0; r < rounds; ++r){
Surface_mesh::Vertex_iterator v_it, v_end = mesh.vertices_end();
for(v_it = mesh.vertices_begin(); v_it != v_end; ++v_it){
Vec3 barycenter(0, 0, 0);
int val = 0;
Surface_mesh::Vertex_around_vertex_circulator vv_it, vv_end;
vv_it = vv_end = mesh.vertices(*v_it);
do {
barycenter += mesh.position(*vv_it);
++val;
} while (++vv_it != vv_end);
barycenter *= 1.0f / val;
Vec3 u = barycenter - mesh.position(*v_it);
if(tangential){
Normal n = normals[*v_it];
float n_norm = n.norm();
if(n_norm == 0 || n_norm != n_norm){
u = Normal(0, 0, 0);
} else {
// tangential component of u
u = u - n * u.dot(n) / n_norm;
}
}
laplace[*v_it] = u;
}
// apply shift
for(v_it = mesh.vertices_begin(); v_it != v_end; ++v_it){
if(mesh.is_boundary(*v_it)) continue;
mesh.position(*v_it) += laplace[*v_it] * eta;
}
}
}

};

0 comments on commit 29f218d

Please sign in to comment.