GEL  2
GEL is a library for Geometry and Linear Algebra
/Users/jab/Documents/Teaching/02585/GEL2_and_demos/GEL/src/HMesh/mesh_optimization.h
00001 /* ----------------------------------------------------------------------- *
00002  * This file is part of GEL, www.imm.dtu.dk/GEL
00003  * Copyright (C) the authors (see AUTHORS.txt) and DTU Informatics
00004  *
00005  * Principal authors:
00006  *  Christian Thode Larsen (thode2d@gmail.com)
00007  *  J. Andreas Baerentzen (jab@imm.dtu.dk)
00008  *
00009  * See LICENSE.txt for licensing information
00010  * ----------------------------------------------------------------------- */
00011 
00012 #ifndef __HMESH_MESH_OPTIMIZATION_H
00013 #define __HMESH_MESH_OPTIMIZATION_H
00014 
00015 #include "Manifold.h"
00016 #include <CGLA/Vec3d.h>
00017 namespace HMesh
00018 {
00019     // forward declarations
00020     //class Manifold;
00021     //class HalfEdgeID;
00022 
00024     class EnergyFun
00025     {
00026     public:
00027         virtual double delta_energy(const Manifold& m, HalfEdgeID h) const = 0;
00028         virtual double energy(const Manifold& m, HalfEdgeID h) const {return 0;}
00029     };
00030         
00031         class MinAngleEnergy: public EnergyFun
00032         {
00033                 double min_angle(const CGLA::Vec3d& v0, const CGLA::Vec3d& v1, const CGLA::Vec3d& v2) const;
00034                 double thresh;
00035                 
00036         public:
00037                 
00038                 MinAngleEnergy(double _thresh): thresh(_thresh) {}
00039                 
00040                 double delta_energy(const HMesh::Manifold& m, HMesh::HalfEdgeID h) const;
00041         };
00042         
00043         class DihedralEnergy: public EnergyFun
00044         {
00045                 const double gamma;
00046                 const bool use_alpha;
00047                 
00048                 double cos_ang(const CGLA::Vec3d& n1, const CGLA::Vec3d& n2) const
00049                 {
00050                         return CGLA::s_max(-1.0, CGLA::s_min(1.0, CGLA::dot(n1, n2)));
00051                 }
00052                 
00053                 double edge_alpha_energy(CGLA::Vec3d v1, CGLA::Vec3d v2, double ca) const
00054                 {
00055                         return pow(CGLA::length(v1-v2)*(acos(ca)), 1.0f/gamma); 
00056                 }
00057                 
00058                 double edge_c_energy(CGLA::Vec3d v1, CGLA::Vec3d v2, double ca) const
00059                 {
00060                         return pow(length(v1-v2)*(1-ca), 1.0f/gamma); 
00061                 }
00062 
00063                 void compute_angles(const HMesh::Manifold & m, HMesh::HalfEdgeID h) const;
00064                 
00065 
00066 
00067                 mutable double ab_12;
00068                 mutable double ab_a1;
00069                 mutable double ab_b1;
00070                 mutable double ab_2c;
00071                 mutable double ab_2d;
00072                 
00073                 mutable double aa_12;
00074                 mutable double aa_b1;
00075                 mutable double aa_c1;
00076                 mutable double aa_2a;
00077                 mutable double aa_2d;
00078                 
00079         public:
00080                 
00081                 DihedralEnergy(double _gamma = 4.0, bool _use_alpha=false): 
00082                 gamma(_gamma), use_alpha(_use_alpha) {}
00083                 
00084                 double energy(const HMesh::Manifold& m, HMesh::HalfEdgeID h) const;
00085                 
00086                 double delta_energy(const HMesh::Manifold& m, HMesh::HalfEdgeID h) const;
00087         
00088                 double min_angle(const HMesh::Manifold& m, HMesh::HalfEdgeID h) const
00089                 {
00090                         compute_angles(m, h);
00091                         return CGLA::s_min(CGLA::s_min(CGLA::s_min(CGLA::s_min(aa_12, aa_b1), aa_c1), aa_2a), aa_2d);
00092                 }               
00093         };
00094         
00095         class CurvatureEnergy: public EnergyFun
00096         {
00097                 double abs_mean_curv(const CGLA::Vec3d& v, const std::vector<CGLA::Vec3d>& ring) const;
00098         public:
00099                 double delta_energy(const HMesh::Manifold& m, HMesh::HalfEdgeID h) const;
00100         };              
00101 
00103     void priority_queue_optimization(Manifold& m, const EnergyFun& efun);
00104 
00106     void simulated_annealing_optimization(Manifold& m, const EnergyFun& efun, int max_iter=10000);
00107 
00109     void minimize_dihedral_angle(Manifold& m, int max_iter=10000, bool anneal=false, bool alpha=false, double gamma=4.0);
00110 
00112     void minimize_curvature(Manifold& m, bool anneal=false);
00113 
00115     void minimize_gauss_curvature(Manifold& m, bool anneal=false);
00116 
00118     void maximize_min_angle(Manifold& m, float thresh, bool anneal=false);
00119 
00121     void optimize_valency(Manifold& m, bool anneal=false);
00122 
00124     void randomize_mesh(Manifold& m, int max_iter);
00125 
00126 }
00127 
00128 
00129 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations