~ubuntu-branches/ubuntu/lucid/meshlab/lucid

« back to all changes in this revision

Viewing changes to meshlab/src/meshlabplugins/filter_meshing/quadric_simp.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Teemu Ikonen
  • Date: 2009-10-08 16:40:41 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20091008164041-0c2ealqv8b8uc20c
Tags: 1.2.2-1
* New upstream version
* Do not build filter_isoparametrization because liblevmar dependency
  is not (yet) in Debian
* Fix compilation with gcc-4.4, thanks to Jonathan Liu for the patch
  (closes: #539544)
* rules: Add compiler variables to the qmake call (for testing with new
  GCC versions)
* io_3ds.pro: Make LIBS and INCLUDEPATH point to Debian version of lib3ds
* io_epoch.pro: Make LIBS point to Debian version of libbz2
* control:
  - Move Homepage URL to the source package section
  - Update to standards-version 3.8.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/****************************************************************************
 
2
 * MeshLab                                                           o o     *
 
3
 * A versatile mesh processing toolbox                             o     o   *
 
4
 *                                                                _   O  _   *
 
5
 * Copyright(C) 2005                                                \/)\/    *
 
6
 * Visual Computing Lab                                            /\/|      *
 
7
 * ISTI - Italian National Research Council                           |      *
 
8
 *                                                                    \      *
 
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.                                       *
 
14
 *                                                                           *
 
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)          *
 
19
 * for more details.                                                         *
 
20
 *                                                                           *
 
21
 ****************************************************************************/
 
22
/****************************************************************************
 
23
  History
 
24
$Log$
 
25
Revision 1.8  2007/03/27 12:20:18  cignoni
 
26
Revamped logging iterface, changed function names in automatic parameters, better selection handling
 
27
 
 
28
Revision 1.7  2007/03/20 16:23:10  cignoni
 
29
Big small change in accessing mesh interface. First step toward layers
 
30
 
 
31
Revision 1.6  2007/03/03 02:03:51  cignoni
 
32
Removed bug on simplification of selected faces
 
33
 
 
34
Revision 1.5  2007/02/25 21:31:49  cignoni
 
35
new parameters for quadric simplification
 
36
 
 
37
Revision 1.4  2007/01/19 09:12:39  cignoni
 
38
Added parameters for quality,selection and boundary preservation
 
39
 
 
40
Revision 1.3  2006/10/19 07:34:24  cignoni
 
41
added callback
 
42
 
 
43
Revision 1.2  2006/10/15 17:08:52  cignoni
 
44
typenames and qualifiers for gcc compliance
 
45
 
 
46
Revision 1.1  2006/10/10 21:13:08  cignoni
 
47
Added remove non manifold and quadric simplification filter.
 
48
 
 
49
****************************************************************************/
 
50
#include <QtGui>
 
51
 
 
52
#include <math.h>
 
53
#include <stdlib.h>
 
54
 
 
55
#include <limits>
 
56
 
 
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"
 
65
 
 
66
using namespace vcg;
 
67
using namespace std;
 
68
 
 
69
void QuadricSimplification(CMeshO &m,int  TargetFaceNum, bool Selected, CallBackPos *cb)
 
70
{
 
71
  math::Quadric<double> QZero;
 
72
  QZero.SetZero();
 
73
  tri::QuadricTemp TD(m.vert,QZero);
 
74
  tri::QHelper::TDp()=&TD;
 
75
 
 
76
        // we assume that the caller has already set up the tri::MyTriEdgeCollapse::Params() class
 
77
        tri::TriEdgeCollapseQuadricParameter & pp = tri::MyTriEdgeCollapse::Params();
 
78
  
 
79
  if(Selected) // simplify only inside selected faces
 
80
  {
 
81
    // select only the vertices having ALL incident faces selected
 
82
    tri::UpdateSelection<CMeshO>::VertexFromFaceStrict(m);
 
83
 
 
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();
 
88
                      else (*vi).SetW();
 
89
  }
 
90
 
 
91
  if(pp.PreserveBoundary && !Selected) 
 
92
        {
 
93
    pp.FastPreserveBoundary=true;
 
94
                pp.PreserveBoundary = false;
 
95
        }
 
96
                
 
97
  if(pp.NormalCheck) pp.NormalThrRad = M_PI/4.0;
 
98
        
 
99
        
 
100
  vcg::LocalOptimization<CMeshO> DeciSession(m);
 
101
        cb(1,"Initializing simplification");
 
102
        DeciSession.Init<tri::MyTriEdgeCollapse >();
 
103
 
 
104
        if(Selected)
 
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);
 
109
  int startFn=m.fn;
 
110
  int faceToDel=m.fn-TargetFaceNum;
 
111
 while( DeciSession.DoOptimization() && m.fn>TargetFaceNum )
 
112
 {
 
113
   cb(100-100*(m.fn-TargetFaceNum)/(faceToDel), "Simplifying...");
 
114
 };
 
115
 
 
116
        DeciSession.Finalize<tri::MyTriEdgeCollapse >();
 
117
  
 
118
  if(Selected) // Clear Writable flags 
 
119
  {
 
120
    CMeshO::VertexIterator  vi;
 
121
    for(vi=m.vert.begin();vi!=m.vert.end();++vi) 
 
122
      if(!(*vi).IsD()) (*vi).SetW();
 
123
  }
 
124
}