OpenABF 2.1.0
Loading...
Searching...
No Matches
AlternativeSolvers.cpp

Alternative solvers demo

Demonstrates flattening using a conjugate gradient solver instead of SparseLU.

#include <iostream>
#include <Eigen/IterativeLinearSolvers>
#include "OpenABF/OpenABF.hpp"
auto main() -> int
{
// Define the matrix, mesh, and vec classes
using Mtx = Eigen::SparseMatrix<float>;
using Vec3f = OpenABF::Vec3f;
// Define the solvers and methods
using ABFSolver = Eigen::ConjugateGradient<Mtx, Eigen::Lower | Eigen::Upper>;
using LSCMSolver = Eigen::LeastSquaresConjugateGradient<Mtx>;
// Pre-define vertices list
const std::vector vertices = {Vec3f{0.f, 0.f, 0.f}, Vec3f{2.f, 0.f, 0.f},
Vec3f{1.f, std::sqrt(3.f), 0.f},
Vec3f{1.f, std::sqrt(3.f) / 3.f, std::sqrt(6.f) * 2.f / 3.f}};
// Create the 4 pyramid vertices
auto mesh = ABF::Mesh::New();
mesh->insert_vertices(vertices);
// Create the 3 pyramid triangles (the 4th is open)
mesh->insert_faces({{1, 3, 0}, {3, 2, 0}, {3, 1, 2}});
// Run ABF++
std::size_t iters{0};
float grad{OpenABF::INF<float>};
ABF::Compute(mesh, iters, grad);
std::cout << "ABF++ Final gradient: " << grad << std::endl;
std::cout << "ABF++ Iterations: " << iters << std::endl;
// Run LSCM
// Print flattened positions
for (const auto& v : mesh->vertices()) {
std::cout << v->idx << ": " << vertices[v->idx] << " -> " << v->pos << std::endl;
}
// Write the flattened mesh
WriteMesh("openabf_example_alternative_solvers.obj", mesh);
}
Compute parameterized interior angles using ABF++.
Definition OpenABF.hpp:2640
static void Compute(typename Mesh::Pointer &mesh, std::size_t &iters, T &gradient, const std::size_t maxIters=10, T gradThreshold=T(0.001))
Compute parameterized interior angles.
Definition OpenABF.hpp:2678
MeshType Mesh
Mesh type alias.
Definition OpenABF.hpp:2643
Compute parameterized mesh using Angle-based LSCM.
Definition OpenABF.hpp:2987
static void Compute(typename Mesh::Pointer &mesh)
Compute the parameterized mesh using automatic pin selection.
Definition OpenABF.hpp:3018
Vec< float, 3 > Vec3f
3D, 32-bit float vector
Definition OpenABF.hpp:419
constexpr T INF
Inf, templated for floating-point type.
Definition OpenABF.hpp:69