mirror of
https://git.mirrors.martin98.com/https://github.com/prusa3d/PrusaSlicer.git
synced 2025-08-17 21:25:59 +08:00

* 1. Remove all global include_directories. * 2. Move 3d party dependencies from src to budled deps if possible. * Unify and enforce one way of including headers: e.g. #include "libslic3r/GCode.hpp" vs #include "GCode.hpp" (always use the "libslic3r/GCode.hpp" option). * Make all dependencies (also header only) a cmake target.
51 lines
1.1 KiB
C++
51 lines
1.1 KiB
C++
// This file is part of libigl, a simple c++ geometry processing library.
|
|
//
|
|
// Copyright (C) 2016 Michael Rabinovich
|
|
//
|
|
// This Source Code Form is subject to the terms of the Mozilla Public License
|
|
// v. 2.0. If a copy of the MPL was not distributed with this file, You can
|
|
// obtain one at http://mozilla.org/MPL/2.0/.
|
|
#include "line_search.h"
|
|
|
|
IGL_INLINE double igl::line_search(
|
|
Eigen::MatrixXd& x,
|
|
const Eigen::MatrixXd& d,
|
|
double step_size,
|
|
std::function<double(Eigen::MatrixXd&)> energy,
|
|
double cur_energy)
|
|
{
|
|
double old_energy;
|
|
if (cur_energy > 0)
|
|
{
|
|
old_energy = cur_energy;
|
|
}
|
|
else
|
|
{
|
|
old_energy = energy(x); // no energy was given -> need to compute the current energy
|
|
}
|
|
double new_energy = old_energy;
|
|
int cur_iter = 0; int MAX_STEP_SIZE_ITER = 12;
|
|
|
|
while (new_energy >= old_energy && cur_iter < MAX_STEP_SIZE_ITER)
|
|
{
|
|
Eigen::MatrixXd new_x = x + step_size * d;
|
|
|
|
double cur_e = energy(new_x);
|
|
if ( cur_e >= old_energy)
|
|
{
|
|
step_size /= 2;
|
|
}
|
|
else
|
|
{
|
|
x = new_x;
|
|
new_energy = cur_e;
|
|
}
|
|
cur_iter++;
|
|
}
|
|
return new_energy;
|
|
}
|
|
|
|
|
|
#ifdef IGL_STATIC_LIBRARY
|
|
#endif
|