|
|
@@ -1,9 +1,9 @@
|
|
|
// This file is part of libigl, a simple c++ geometry processing library.
|
|
|
-//
|
|
|
+//
|
|
|
// Copyright (C) 2016 Alec Jacobson <[email protected]>
|
|
|
-//
|
|
|
-// 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
|
|
|
+//
|
|
|
+// 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 "voxel_grid.h"
|
|
|
#include "grid.h"
|
|
|
@@ -13,7 +13,7 @@ template <
|
|
|
typename DerivedGV,
|
|
|
typename Derivedside>
|
|
|
IGL_INLINE void igl::voxel_grid(
|
|
|
- const Eigen::AlignedBox<Scalar,3> & box,
|
|
|
+ const Eigen::AlignedBox<Scalar,3> & box,
|
|
|
const int in_s,
|
|
|
const int pad_count,
|
|
|
Eigen::PlainObjectBase<DerivedGV> & GV,
|
|
|
@@ -22,6 +22,7 @@ IGL_INLINE void igl::voxel_grid(
|
|
|
using namespace Eigen;
|
|
|
using namespace std;
|
|
|
typename DerivedGV::Index si = -1;
|
|
|
+ side.resize(1, 3);
|
|
|
box.diagonal().maxCoeff(&si);
|
|
|
//DerivedGV::Index si = 0;
|
|
|
//assert(si>=0);
|
|
|
@@ -45,7 +46,7 @@ IGL_INLINE void igl::voxel_grid(
|
|
|
// A * (1-p/s) - A * p/s = max-min
|
|
|
// A * (1-2p/s) = max-min
|
|
|
// A = (max-min)/(1-2p/s)
|
|
|
- const Array<Scalar,3,1> ps=
|
|
|
+ const Array<Scalar,3,1> ps=
|
|
|
(Scalar)(pad_count)/(side.transpose().template cast<Scalar>().array()-1.);
|
|
|
const Array<Scalar,3,1> A = box.diagonal().array()/(1.0-2.*ps);
|
|
|
//// This would result in an "anamorphic", but perfectly fit grid:
|
|
|
@@ -55,7 +56,7 @@ IGL_INLINE void igl::voxel_grid(
|
|
|
// Instead scale by largest factor and move to match center
|
|
|
typename Array<Scalar,3,1>::Index ai = -1;
|
|
|
Scalar a = A.maxCoeff(&ai);
|
|
|
- const Array<Scalar,1,3> ratio =
|
|
|
+ const Array<Scalar,1,3> ratio =
|
|
|
a*(side.template cast<Scalar>().array()-1.0)/(Scalar)(side(ai)-1.0);
|
|
|
GV.array().rowwise() *= ratio;
|
|
|
const Eigen::Matrix<Scalar,1,3> offset = (box.center().transpose()-GV.colwise().mean()).eval();
|