12#ifndef EASY3D_ALGO_SURFACE_MESH_SIMPLIFICATION_H
13#define EASY3D_ALGO_SURFACE_MESH_SIMPLIFICATION_H
15#include <easy3d/core/surface_mesh.h>
16#include <easy3d/core/heap.h>
28 Quadric(
double a,
double b,
double c,
double d,
29 double e,
double f,
double g,
32 : a_(a), b_(b), c_(c), d_(d),
38 explicit Quadric(
double a = 0.0,
double b = 0.0,
double c = 0.0,
double d = 0.0)
39 : a_(a * a), b_(a * b), c_(a * c), d_(a * d),
40 e_(b * b), f_(b * c), g_(b * d),
50 void clear() { a_ = b_ = c_ = d_ = e_ = f_ = g_ = h_ = i_ = j_ = 0.0; }
84 const double x(p[0]), y(p[1]), z(p[2]);
85 return a_ * x * x + 2.0 * b_ * x * y + 2.0 * c_ * x * z + 2.0 * d_ * x
86 + e_ * y * y + 2.0 * f_ * y * z + 2.0 * g_ * y
87 + h_ * z * z + 2.0 * i_ * z
93 double a_, b_, c_, d_,
109 : center_normal_(normal), angle_(
angle) {
116 float angle()
const {
return angle_; }
123 const float dp =
dot(center_normal_, nc.center_normal_);
127 angle_ = std::max(angle_, nc.angle_);
131 else if (dp < -0.99999) {
132 angle_ =
static_cast<float>(2 * M_PI);
135 float center_angle = std::acos(dp);
136 float min_angle = std::min(-angle_, center_angle - nc.angle_);
137 float max_angle = std::max(angle_, center_angle + nc.angle_);
138 angle_ = 0.5f * (max_angle - min_angle);
141 float axis_angle = 0.5f * (min_angle + max_angle);
142 center_normal_ = ((center_normal_ * std::sin(center_angle - axis_angle) +
143 nc.center_normal_ * std::sin(axis_angle)) /
144 std::sin(center_angle));
175 void initialize(
float aspect_ratio = 0.0,
float edge_length = 0.0,
176 unsigned int max_valence = 0,
float normal_deviation = 0.0,
177 float hausdorff_error = 0.0);
180 void simplify(
unsigned int n_vertices);
197 struct CollapseData {
214 class HeapInterface {
217 : prio_(prio), pos_(pos) {
235 typedef std::vector<vec3> Points;
242 bool is_collapse_legal(
const CollapseData &cd);
245 float priority(
const CollapseData &cd);
248 void postprocess_collapse(
const CollapseData &cd);
278 float normal_deviation_;
279 float hausdorff_error_;
282 unsigned int max_valence_;
A class implementing a heap.
Definition: heap.h:59
A class implementing a normal cone.
Definition: surface_mesh_simplification.h:102
NormalCone & merge(const NormalCone &nc)
merge *this with nc. *this will then enclose both cones.
Definition: surface_mesh_simplification.h:122
NormalCone & merge(const vec3 &n)
merge *this with n.
Definition: surface_mesh_simplification.h:119
NormalCone()=default
default constructor (not initialized)
NormalCone(const vec3 &normal, float angle=0.0)
Initialize cone with center (unit vector) and angle (radius in radians)
Definition: surface_mesh_simplification.h:108
float angle() const
returns size of cone (radius in radians)
Definition: surface_mesh_simplification.h:116
const vec3 & center_normal() const
returns center normal
Definition: surface_mesh_simplification.h:113
A quadric as a symmetric 4x4 matrix. Used by the error quadric mesh decimation algorithms.
Definition: surface_mesh_simplification.h:25
Quadric & operator*=(double s)
multiply quadric by a scalar
Definition: surface_mesh_simplification.h:68
double operator()(const vec3 &p) const
evaluate quadric Q at position p by computing (p^T * Q * p)
Definition: surface_mesh_simplification.h:83
Quadric & operator+=(const Quadric &q)
add given quadric to this quadric
Definition: surface_mesh_simplification.h:53
Quadric(double a=0.0, double b=0.0, double c=0.0, double d=0.0)
constructor quadric from given plane equation: ax+by+cz+d=0
Definition: surface_mesh_simplification.h:38
Quadric(double a, double b, double c, double d, double e, double f, double g, double h, double i, double j)
construct quadric from upper triangle of symmetric 4x4 matrix
Definition: surface_mesh_simplification.h:28
void clear()
set all matrix entries to zero
Definition: surface_mesh_simplification.h:50
Quadric(const vec3 &n, const vec3 &p)
construct from point and normal specifying a plane
Definition: surface_mesh_simplification.h:45
Definition: surface_mesh.h:233
Definition: surface_mesh.h:257
A halfedge data structure for polygonal meshes of 2-manifold.
Definition: surface_mesh.h:52
Surface mesh simplification based on approximation error and fairness criteria.
Definition: surface_mesh_simplification.h:166
SurfaceMeshSimplification(SurfaceMesh *mesh)
Construct with mesh to be simplified.
Definition: surface_mesh_simplification.cpp:20
void simplify(unsigned int n_vertices)
Simplify mesh to n vertices.
Definition: surface_mesh_simplification.cpp:124
void initialize(float aspect_ratio=0.0, float edge_length=0.0, unsigned int max_valence=0, float normal_deviation=0.0, float hausdorff_error=0.0)
Initialize with given parameters.
Definition: surface_mesh_simplification.cpp:42
Definition: collider.cpp:182
FT dot(const std::vector< FT > &, const std::vector< FT > &)
Inner product for vectors.
Definition: matrix.h:1803
Definition: surface_mesh.h:134
Definition: surface_mesh.h:114
Definition: surface_mesh.h:104