33 const Eigen::MatrixXd &d,
35 std::function<
double(Eigen::MatrixXd &)> energy,
36 double cur_energy = -1)
40 old_energy = cur_energy;
43 old_energy = energy(
x);
45 double new_energy = old_energy;
47 int MAX_STEP_SIZE_ITER = 12;
49 while (new_energy >= old_energy && cur_iter < MAX_STEP_SIZE_ITER) {
50 Eigen::MatrixXd new_x =
x + step_size * d;
52 double cur_e = energy(new_x);
53 if (cur_e >= old_energy) {
70 double delta_in =
pow(
b, 2) - 4 * a * c;
74 double delta =
sqrt(delta_in);
75 t1 = (-
b + delta) / (2 * a);
76 t2 = (-
b - delta) / (2 * a);
82 if (!std::isfinite(t1) || !std::isfinite(t2)) {
86 double tmp_n =
min(t1, t2);
103 const Eigen::MatrixXi &
F,
113 const double &U11 = uv(v1, 0);
114 const double &U12 = uv(v1, 1);
115 const double &U21 = uv(
v2, 0);
116 const double &U22 = uv(
v2, 1);
117 const double &U31 = uv(v3, 0);
118 const double &U32 = uv(v3, 1);
120 const double &V11 = d(v1, 0);
121 const double &V12 = d(v1, 1);
122 const double &V21 = d(
v2, 0);
123 const double &V22 = d(
v2, 1);
124 const double &V31 = d(v3, 0);
125 const double &V32 = d(v3, 1);
127 double a = V11 * V22 - V12 * V21 - V11 * V32 + V12 * V31 + V21 * V32 - V22 * V31;
128 double b = U11 * V22 - U12 * V21 - U21 * V12 + U22 * V11 - U11 * V32 + U12 * V31 + U31 * V12 -
129 U32 * V11 + U21 * V32 - U22 * V31 - U31 * V22 + U32 * V21;
130 double c = U11 * U22 - U12 * U21 - U11 * U32 + U12 * U31 + U21 * U32 - U22 * U31;
136 const Eigen::MatrixXi &
F,
140 double max_step = INFINITY;
143 for (
int f = 0; f <
F.rows(); f++) {
145 max_step =
min(max_step, min_positive_root);
151 Eigen::MatrixXd &cur_v,
152 Eigen::MatrixXd &dst_v,
153 std::function<
double(Eigen::MatrixXd &)> energy,
158 Eigen::MatrixXd d = dst_v - cur_v;
160 double max_step_size =
min(1., min_step_to_singularity * 0.8);
161 return line_search(cur_v, d, max_step_size, energy, cur_energy);
ATTR_WARN_UNUSED_RESULT const BMVert * v2
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)