1
/****************************************************************************
3
* A versatile mesh processing toolbox o o *
5
* Copyright(C) 2005 \/)\/ *
6
* Visual Computing Lab /\/| *
7
* ISTI - Italian National Research Council | *
9
* All rights reserved. *
10
* This program is free software; you can redistribute it and/or modify *
11
* it under the terms of the GNU General Public License as published by *
12
* the Free Software Foundation; either version 2 of the License, or *
13
* (at your option) any later version. *
15
* This program is distributed in the hope that it will be useful, *
16
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
17
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
18
* GNU General Public License (http://www.gnu.org/licenses/gpl.txt) *
21
****************************************************************************/
22
/****************************************************************************
25
Revision 1.8 2007/03/27 12:20:18 cignoni
26
Revamped logging iterface, changed function names in automatic parameters, better selection handling
28
Revision 1.7 2007/03/20 16:23:10 cignoni
29
Big small change in accessing mesh interface. First step toward layers
31
Revision 1.6 2007/03/03 02:03:51 cignoni
32
Removed bug on simplification of selected faces
34
Revision 1.5 2007/02/25 21:31:49 cignoni
35
new parameters for quadric simplification
37
Revision 1.4 2007/01/19 09:12:39 cignoni
38
Added parameters for quality,selection and boundary preservation
40
Revision 1.3 2006/10/19 07:34:24 cignoni
43
Revision 1.2 2006/10/15 17:08:52 cignoni
44
typenames and qualifiers for gcc compliance
46
Revision 1.1 2006/10/10 21:13:08 cignoni
47
Added remove non manifold and quadric simplification filter.
49
****************************************************************************/
57
#include "meshfilter.h"
58
#include <vcg/complex/trimesh/update/position.h>
59
#include <vcg/complex/trimesh/update/bounding.h>
60
#include <vcg/complex/trimesh/update/selection.h>
61
#include <vcg/complex/local_optimization.h>
62
#include <vcg/complex/local_optimization/tri_edge_collapse_quadric.h>
63
#include <vcg/container/simple_temporary_data.h>
64
#include "quadric_simp.h"
69
void QuadricSimplification(CMeshO &m,int TargetFaceNum, bool Selected, CallBackPos *cb)
71
math::Quadric<double> QZero;
73
tri::QuadricTemp TD(m.vert,QZero);
74
tri::QHelper::TDp()=&TD;
76
// we assume that the caller has already set up the tri::MyTriEdgeCollapse::Params() class
77
tri::TriEdgeCollapseQuadricParameter & pp = tri::MyTriEdgeCollapse::Params();
79
if(Selected) // simplify only inside selected faces
81
// select only the vertices having ALL incident faces selected
82
tri::UpdateSelection<CMeshO>::VertexFromFaceStrict(m);
84
// Mark not writable un-selected vertices
85
CMeshO::VertexIterator vi;
86
for(vi=m.vert.begin();vi!=m.vert.end();++vi) if(!(*vi).IsD())
87
if(!(*vi).IsS()) (*vi).ClearW();
91
if(pp.PreserveBoundary && !Selected)
93
pp.FastPreserveBoundary=true;
94
pp.PreserveBoundary = false;
97
if(pp.NormalCheck) pp.NormalThrRad = M_PI/4.0;
100
vcg::LocalOptimization<CMeshO> DeciSession(m);
101
cb(1,"Initializing simplification");
102
DeciSession.Init<tri::MyTriEdgeCollapse >();
105
TargetFaceNum= m.fn - (m.sfn-TargetFaceNum);
106
DeciSession.SetTargetSimplices(TargetFaceNum);
107
DeciSession.SetTimeBudget(0.1f); // this allow to update the progress bar 10 time for sec...
108
// if(TargetError< numeric_limits<double>::max() ) DeciSession.SetTargetMetric(TargetError);
110
int faceToDel=m.fn-TargetFaceNum;
111
while( DeciSession.DoOptimization() && m.fn>TargetFaceNum )
113
cb(100-100*(m.fn-TargetFaceNum)/(faceToDel), "Simplifying...");
116
DeciSession.Finalize<tri::MyTriEdgeCollapse >();
118
if(Selected) // Clear Writable flags
120
CMeshO::VertexIterator vi;
121
for(vi=m.vert.begin();vi!=m.vert.end();++vi)
122
if(!(*vi).IsD()) (*vi).SetW();