-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmeancurvatureflowfilter.cpp
105 lines (93 loc) · 4.42 KB
/
meancurvatureflowfilter.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/****************************************************************************
* MeshLab o o *
* A versatile mesh processing toolbox o o *
* _ O _ *
* Copyright(C) 2005 \/)\/ *
* Visual Computing Lab /\/| *
* ISTI - Italian National Research Council | *
* \ *
* All rights reserved. *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License (http://www.gnu.org/licenses/gpl.txt) *
* for more details. *
* *
****************************************************************************/
#include "meancurvatureflowfilter.h"
#include <vcg/complex/algorithms/update/curvature_fitting.h>
#include <vcg/complex/algorithms/clean.h>
#include <QtScript>
MeanCurvaureFlowPlugin::MeanCurvaureFlowPlugin()
{
typeList << FP_MOVE_VERTEX;
foreach(FilterIDType tt , types())
actionList << new QAction(filterName(tt), this);
}
QString MeanCurvaureFlowPlugin::filterName(FilterIDType filterId) const
{
switch(filterId) {
case FP_MOVE_VERTEX : return QString("Mean curvature flow");
default : assert(0);
}
return QString();
}
QString MeanCurvaureFlowPlugin::filterInfo(FilterIDType filterId) const
{
switch(filterId) {
case FP_MOVE_VERTEX : return QString("Move the vertices of the mesh along vertex normal according to curvature.\n"
" Warrning: This version works only with closed meshes.");
default : assert(0);
}
return QString("Unknown Filter");
}
MeanCurvaureFlowPlugin::FilterClass MeanCurvaureFlowPlugin::getClass(QAction *a)
{
switch(ID(a))
{
case FP_MOVE_VERTEX : return MeshFilterInterface::Smoothing;
default : assert(0);
}
return MeshFilterInterface::Generic;
}
void MeanCurvaureFlowPlugin::initParameterSet(QAction *action,MeshModel &m, RichParameterSet & parlst)
{
switch(ID(action))
{
case FP_MOVE_VERTEX :
parlst.addParam(new RichFloat("Time",
0.01f,
"Mean curvature factor",
"Value which will be multiplied with curvature."));
break;
default : assert(0);
}
//Enable curvature and adjacency relations needed to compute a curvature.
m.updateDataMask(MeshModel::MM_VERTCURV);
m.updateDataMask(MeshModel::MM_VERTCURVDIR);
m.updateDataMask(MeshModel::MM_VERTFACETOPO);
m.updateDataMask(MeshModel::MM_FACEFACETOPO);
vcg::tri::Clean<CMeshO>::RemoveUnreferencedVertex(m.cm);
vcg::tri::Allocator<CMeshO>::CompactVertexVector(m.cm);
vcg::tri::UpdateCurvatureFitting<CMeshO>::computeCurvature( m.cm );
}
// The Real Core Function doing the actual mesh processing.
bool MeanCurvaureFlowPlugin::applyFilter(QAction */*filter*/, MeshDocument &md, RichParameterSet & par, vcg::CallBackPos *cb)
{
CMeshO &m = md.mm()->cm;
for(unsigned int i = 0; i< m.vert.size(); i++)
{
m.vert[i].P() -= m.vert[i].cN() * (( m.vert[i].K1() + m.vert[i].K2() ) / 2.) * par.getFloat("Time");
}
// Log function dump textual info in the lower part of the MeshLab screen.
Log("Successfully displaced %i vertices",m.vn);
vcg::tri::UpdateBounding<CMeshO>::Box(m);
return true;
}
MESHLAB_PLUGIN_NAME_EXPORTER(MeanCurvaureFlowPlugin)