34 const Eigen::MatrixXd &d,
36 std::function<
double(Eigen::MatrixXd &)> energy,
37 double cur_energy = -1)
41 old_energy = cur_energy;
44 old_energy = energy(x);
46 double new_energy = old_energy;
48 int MAX_STEP_SIZE_ITER = 12;
50 while (new_energy >= old_energy && cur_iter < MAX_STEP_SIZE_ITER) {
51 Eigen::MatrixXd new_x = x + step_size * d;
53 double cur_e = energy(new_x);
54 if (cur_e >= old_energy) {
71 double delta_in =
pow(
b, 2) - 4 * a * c;
75 double delta =
sqrt(delta_in);
76 t1 = (-
b + delta) / (2 * a);
77 t2 = (-
b - delta) / (2 * a);
83 if (!std::isfinite(t1) || !std::isfinite(t2)) {
87 double tmp_n =
min(t1, t2);
108 const Eigen::MatrixXi &F,
118 const double &U11 = uv(v1, 0);
119 const double &U12 = uv(v1, 1);
120 const double &U21 = uv(
v2, 0);
121 const double &U22 = uv(
v2, 1);
122 const double &U31 = uv(v3, 0);
123 const double &U32 = uv(v3, 1);
125 const double &V11 = d(v1, 0);
126 const double &V12 = d(v1, 1);
127 const double &V21 = d(
v2, 0);
128 const double &V22 = d(
v2, 1);
129 const double &V31 = d(v3, 0);
130 const double &V32 = d(v3, 1);
132 double a = V11 * V22 - V12 * V21 - V11 * V32 + V12 * V31 + V21 * V32 - V22 * V31;
133 double b = U11 * V22 - U12 * V21 - U21 * V12 + U22 * V11 - U11 * V32 + U12 * V31 + U31 * V12 -
134 U32 * V11 + U21 * V32 - U22 * V31 - U31 * V22 + U32 * V21;
135 double c = U11 * U22 - U12 * U21 - U11 * U32 + U12 * U31 + U21 * U32 - U22 * U31;
141 const Eigen::MatrixXi &F,
145 double max_step = INFINITY;
148 for (
int f = 0; f < F.rows(); f++) {
150 max_step =
min(max_step, min_positive_root);
156 Eigen::MatrixXd &cur_v,
157 Eigen::MatrixXd &dst_v,
158 std::function<
double(Eigen::MatrixXd &)> energy,
163 Eigen::MatrixXd d = dst_v - cur_v;
165 double max_step_size =
min(1., min_step_to_singularity * 0.8);
166 return line_search(cur_v, d, max_step_size, energy, cur_energy);
ATTR_WARN_UNUSED_RESULT const BMVert * v2
local_group_size(16, 16) .push_constant(Type b
pow(value.r - subtrahend, 2.0)") .do_static_compilation(true)
static double get_min_pos_root_2D(const Eigen::MatrixXd &uv, const Eigen::MatrixXi &F, Eigen::MatrixXd &d, int f)
static double get_smallest_pos_quad_zero(double a, double b, double c)
static double line_search(Eigen::MatrixXd &x, const Eigen::MatrixXd &d, double step_size, std::function< double(Eigen::MatrixXd &)> energy, double cur_energy=-1)
static double compute_max_step_from_singularities(const Eigen::MatrixXd &uv, const Eigen::MatrixXi &F, Eigen::MatrixXd &d)
double flip_avoiding_line_search(const Eigen::MatrixXi F, Eigen::MatrixXd &cur_v, Eigen::MatrixXd &dst_v, std::function< double(Eigen::MatrixXd &)> energy, double cur_energy)