Skip to content

Commit

Permalink
added energy typo to arap
Browse files Browse the repository at this point in the history
  • Loading branch information
teseoch committed Aug 10, 2020
1 parent bfe4ded commit d209694
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
10 changes: 8 additions & 2 deletions classes/classes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace py = pybind11;
PYBIND11_MODULE(pyigl_classes, m)
{
py::class_<igl::ARAPData>(m, "ARAP")
.def(py::init([](Eigen::MatrixXd &v, Eigen::MatrixXi &f, int dim, Eigen::MatrixXi &b) {
.def(py::init([](Eigen::MatrixXd &v, Eigen::MatrixXi &f, int dim, Eigen::MatrixXi &b, const int energy_type) {
if (dim == 3)
{
assert_valid_tet_or_tri_mesh(v, f);
Expand All @@ -25,8 +25,14 @@ PYBIND11_MODULE(pyigl_classes, m)
{
throw pybind11::value_error("Invalid dimension must be 2 or 3 but got " + std::to_string(dim));
}
if (energy_type >= igl::NUM_ARAP_ENERGY_TYPES)
{
throw pybind11::value_error("Invalid Energy Type. Must be one of igl.ARAP_ENERGY_TYPE_*");
}

std::unique_ptr<igl::ARAPData> adata = std::make_unique<igl::ARAPData>();
adata->energy = static_cast<igl::ARAPEnergyType>(energy_type);

if (b.cols() == 1)
igl::arap_precomputation(v, f, dim, b, *adata);
else if (b.rows() == 1)
Expand All @@ -35,7 +41,7 @@ PYBIND11_MODULE(pyigl_classes, m)
throw pybind11::value_error("Invalid dimension for b, must be a vector, got " + std::to_string(b.rows()) + "x" + std::to_string(b.cols()));
return adata;
}),
py::arg("v"), py::arg("f"), py::arg("dim"), py::arg("b"))
py::arg("v"), py::arg("f"), py::arg("dim"), py::arg("b"), py::arg("energy_type") = 3)
.def(
"solve", [](igl::ARAPData &self, Eigen::MatrixXd &bc, Eigen::MatrixXd &initial_guess) {
if (bc.size() > 0)
Expand Down
7 changes: 6 additions & 1 deletion igl/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,16 @@
SLIM_ENERGY_TYPE_EXP_CONFORMAL = 4
SLIM_ENERGY_TYPE_EXP_SYMMETRIC_DIRICHLET = 5

SIGNED_DISTANCE_TYPE_PSEUDONORMAL = 0,
SIGNED_DISTANCE_TYPE_PSEUDONORMAL = 0
SIGNED_DISTANCE_TYPE_WINDING_NUMBER = 1
SIGNED_DISTANCE_TYPE_DEFAULT = 2
SIGNED_DISTANCE_TYPE_UNSIGNED = 3

ARAP_ENERGY_TYPE_SPOKES = 0
ARAP_ENERGY_TYPE_SPOKES_AND_RIMS = 1
ARAP_ENERGY_TYPE_ELEMENTS = 2
ARAP_ENERGY_TYPE_DEFAULT = 3


def check_dependencies(deps):
import sys
Expand Down
10 changes: 10 additions & 0 deletions tests/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -914,6 +914,16 @@ def test_arap3(self):
arap = igl.ARAP(v, f, 2, np.zeros((0)))
uva = arap.solve(np.zeros((0, 0)), uv)

def test_arap4(self):
v, f = igl.read_triangle_mesh(os.path.join(self.test_path, "camelhead.off"))
b = igl.boundary_loop(f)
thetas = np.linspace(0, 2 * np.pi, len(b))[:, np.newaxis]
bc = np.concatenate([np.cos(thetas), np.sin(thetas), np.zeros_like(thetas)], axis=1)
uv_initial_guess = igl.harmonic_weights(v, f, b, bc, 1)

arap = igl.ARAP(v, f, 3, b, igl.ARAP_ENERGY_TYPE_SPOKES)
uva = arap.solve(bc, uv_initial_guess)

def test_slim(self):
v, f, _ = igl.read_off(os.path.join(self.test_path, "camelhead.off"))
b = igl.boundary_loop(f)
Expand Down

0 comments on commit d209694

Please sign in to comment.