Subversion Repositories gelsvn

Rev

Rev 448 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 448 Rev 595
Line -... Line 1...
-
 
1
/* ----------------------------------------------------------------------- *
-
 
2
 * This file is part of GEL, http://www.imm.dtu.dk/GEL
-
 
3
 * Copyright (C) the authors and DTU Informatics
-
 
4
 * For license and list of authors, see ../../doc/intro.pdf
-
 
5
 * ----------------------------------------------------------------------- */
-
 
6
 
-
 
7
/**
-
 
8
 * @file mesh_optimization.h
-
 
9
 * @brief Functions for energy minimization based mesh optimization.
-
 
10
 */
-
 
11
 
1
#ifndef __HMESH_MESH_OPTIMIZATION_H
12
#ifndef __HMESH_MESH_OPTIMIZATION_H
2
#define __HMESH_MESH_OPTIMIZATION_H
13
#define __HMESH_MESH_OPTIMIZATION_H
3
 
14
 
4
#include "HMesh/Manifold.h"
15
#include "Manifold.h"
5
 
-
 
-
 
16
#include <CGLA/Vec3d.h>
6
namespace HMesh
17
namespace HMesh
7
{
18
{
8
	/** This class represents the energy of an edge. It is used in optimization 
19
    // forward declarations
-
 
20
    //class Manifold;
-
 
21
    //class HalfEdgeID;
-
 
22
 
9
	schemes where edges are swapped (aka flipped). */
23
    /// This class represents the energy of an edge. It is used in optimization schemes where edges are swapped (aka flipped). */
10
  class EnergyFun
24
    class EnergyFun
11
  {
25
    {
12
  public:
26
    public:
13
    virtual double delta_energy(HMesh::HalfEdgeIter) const = 0;
27
        virtual double delta_energy(const Manifold& m, HalfEdgeID h) const = 0;
14
    virtual double energy(HMesh::HalfEdgeIter) const {return 0;}
28
        virtual double energy(const Manifold& m, HalfEdgeID h) const {return 0;}
15
  };
29
    };
16
 
30
	
17
	/// Optimize in a greedy fashion.
31
	class MinAngleEnergy: public EnergyFun
-
 
32
	{
-
 
33
		double min_angle(const CGLA::Vec3d& v0, const CGLA::Vec3d& v1, const CGLA::Vec3d& v2) const;
-
 
34
		double thresh;
-
 
35
		
-
 
36
	public:
-
 
37
		
-
 
38
		MinAngleEnergy(double _thresh): thresh(_thresh) {}
-
 
39
		
18
  void priority_queue_optimization(HMesh::Manifold& m, const EnergyFun& efun);
40
		double delta_energy(const HMesh::Manifold& m, HMesh::HalfEdgeID h) const;
-
 
41
	};
-
 
42
	
-
 
43
	class DihedralEnergy: public EnergyFun
-
 
44
	{
-
 
45
		const double gamma;
-
 
46
		const bool use_alpha;
-
 
47
		
-
 
48
		double cos_ang(const CGLA::Vec3d& n1, const CGLA::Vec3d& n2) const
-
 
49
		{
-
 
50
			return CGLA::s_max(-1.0, CGLA::s_min(1.0, CGLA::dot(n1, n2)));
-
 
51
		}
-
 
52
		
19
	/// Optimize with simulated annealing. Avoids getting trapped in local minima
53
		double edge_alpha_energy(CGLA::Vec3d v1, CGLA::Vec3d v2, double ca) const
-
 
54
		{
-
 
55
			return pow(CGLA::length(v1-v2)*(acos(ca)), 1.0f/gamma); 
-
 
56
		}
-
 
57
		
-
 
58
		double edge_c_energy(CGLA::Vec3d v1, CGLA::Vec3d v2, double ca) const
-
 
59
		{
-
 
60
			return pow(length(v1-v2)*(1-ca), 1.0f/gamma); 
-
 
61
		}
-
 
62
 
20
  void simulated_annealing_optimization(HMesh::Manifold& m, 
63
		void compute_angles(const HMesh::Manifold & m, HMesh::HalfEdgeID h) const;
-
 
64
		
-
 
65
 
-
 
66
 
-
 
67
		mutable double ab_12;
-
 
68
		mutable double ab_a1;
-
 
69
		mutable double ab_b1;
-
 
70
		mutable double ab_2c;
-
 
71
		mutable double ab_2d;
-
 
72
		
-
 
73
		mutable double aa_12;
-
 
74
		mutable double aa_b1;
-
 
75
		mutable double aa_c1;
-
 
76
		mutable double aa_2a;
21
					const EnergyFun& efun,
77
		mutable double aa_2d;
-
 
78
		
-
 
79
	public:
-
 
80
		
-
 
81
		DihedralEnergy(double _gamma = 4.0, bool _use_alpha=false): 
-
 
82
		gamma(_gamma), use_alpha(_use_alpha) {}
-
 
83
		
-
 
84
		double energy(const HMesh::Manifold& m, HMesh::HalfEdgeID h) const;
-
 
85
		
-
 
86
		double delta_energy(const HMesh::Manifold& m, HMesh::HalfEdgeID h) const;
-
 
87
	
-
 
88
		double min_angle(const HMesh::Manifold& m, HMesh::HalfEdgeID h) const
-
 
89
		{
22
					int max_iter=10000);
90
			compute_angles(m, h);
-
 
91
			return CGLA::s_min(CGLA::s_min(CGLA::s_min(CGLA::s_min(aa_12, aa_b1), aa_c1), aa_2a), aa_2d);
-
 
92
		}		
-
 
93
	};
-
 
94
	
-
 
95
	class CurvatureEnergy: public EnergyFun
-
 
96
	{
-
 
97
		double abs_mean_curv(const CGLA::Vec3d& v, const std::vector<CGLA::Vec3d>& ring) const;
-
 
98
	public:
-
 
99
		double delta_energy(const HMesh::Manifold& m, HMesh::HalfEdgeID h) const;
-
 
100
	};		
23
    
101
    
24
	/** Minimize the angle between adjacent triangles. Almost the same as mean curvature 
102
    class ValencyEnergy: public EnergyFun
-
 
103
	{
25
		minimization */
104
	public:
26
	void minimize_dihedral_angle(HMesh::Manifold& m,
105
		double delta_energy(const Manifold& m, HalfEdgeID h) const;
-
 
106
	};
-
 
107
 
-
 
108
 
27
															 int max_iter=10000,
109
    /// Optimize in a greedy fashion.
28
															 bool anneal=false,
110
    void priority_queue_optimization(Manifold& m, const EnergyFun& efun);
-
 
111
 
29
															 bool alpha=false,
112
    /// Optimize with simulated annealing. Avoids getting trapped in local minima
30
															 double gamma=4.0);
113
    void simulated_annealing_optimization(Manifold& m, const EnergyFun& efun, int max_iter=10000);
31
															 
114
 
32
	/** Minimizes mean curvature. This is really the same as dihedral angle optimization
115
    /// Minimize the angle between adjacent triangles. Almost the same as mean curvature minimization 
-
 
116
    void minimize_dihedral_angle(Manifold& m, int max_iter=10000, bool anneal=false, bool alpha=false, double gamma=4.0);
-
 
117
 
33
		except that we weight by edge length */
118
    /// Minimizes mean curvature. This is really the same as dihedral angle optimization except that we weight by edge length 
34
  void minimize_curvature(HMesh::Manifold& m, bool anneal=false);
119
    void minimize_curvature(Manifold& m, bool anneal=false);
35
  
120
 
36
  /// Minimizes gaussian curvature. Probably less useful than mean curvature.
121
    /// Minimizes gaussian curvature. Probably less useful than mean curvature.
37
  void minimize_gauss_curvature(HMesh::Manifold& m, bool anneal=false);
122
    void minimize_gauss_curvature(Manifold& m, bool anneal=false);
38
  
123
 
39
  /// Maximizes the minimum angle of triangles. Makes the mesh more Delaunay.
124
    /// Maximizes the minimum angle of triangles. Makes the mesh more Delaunay.
40
  void maximize_min_angle(HMesh::Manifold& m, float thresh, bool anneal=false);
125
    void maximize_min_angle(Manifold& m, float thresh, bool anneal=false);
41
  
126
 
42
  /// Tries to achieve valence 6 internally and 4 along edges.
127
    /// Tries to achieve valence 6 internally and 4 along edges.
43
  void optimize_valency(HMesh::Manifold& m, bool anneal=false);
128
    void optimize_valency(Manifold& m, bool anneal=false);
44
  
129
 
45
  /// Make radom flips. Useful for generating synthetic test cases.
130
    /// Make radom flips. Useful for generating synthetic test cases.
46
  void randomize_mesh(HMesh::Manifold& m, int max_iter);
131
    void randomize_mesh(Manifold& m, int max_iter);
47
 
132
 
48
}
133
}
49
 
134
 
50
 
135
 
51
#endif
136
#endif