65 lines
4.4 KiB
C++
65 lines
4.4 KiB
C++
#include "offset_surface.h"
|
|
#include "marching_cubes.h"
|
|
#include "../voxel_grid.h"
|
|
#include "../signed_distance.h"
|
|
#include "../flood_fill.h"
|
|
#include <cassert>
|
|
|
|
template <
|
|
typename DerivedV,
|
|
typename DerivedF,
|
|
typename isolevelType,
|
|
typename DerivedSV,
|
|
typename DerivedSF,
|
|
typename DerivedGV,
|
|
typename Derivedside,
|
|
typename DerivedS>
|
|
void igl::copyleft::offset_surface(
|
|
const Eigen::MatrixBase<DerivedV> & V,
|
|
const Eigen::MatrixBase<DerivedF> & F,
|
|
const isolevelType isolevel,
|
|
const typename Derivedside::Scalar s,
|
|
const SignedDistanceType & signed_distance_type,
|
|
Eigen::PlainObjectBase<DerivedSV> & SV,
|
|
Eigen::PlainObjectBase<DerivedSF> & SF,
|
|
Eigen::PlainObjectBase<DerivedGV> & GV,
|
|
Eigen::PlainObjectBase<Derivedside> & side,
|
|
Eigen::PlainObjectBase<DerivedS> & S)
|
|
{
|
|
typedef typename DerivedV::Scalar Scalar;
|
|
typedef typename DerivedF::Scalar Index;
|
|
{
|
|
Eigen::AlignedBox<Scalar,3> box;
|
|
typedef Eigen::Matrix<Scalar,1,3> RowVector3S;
|
|
assert(V.cols() == 3 && "V must contain positions in 3D");
|
|
RowVector3S min_ext = V.colwise().minCoeff().array() - isolevel;
|
|
RowVector3S max_ext = V.colwise().maxCoeff().array() + isolevel;
|
|
box.extend(min_ext.transpose());
|
|
box.extend(max_ext.transpose());
|
|
igl::voxel_grid(box,s,1,GV,side);
|
|
}
|
|
|
|
const Scalar h =
|
|
(GV.col(0).maxCoeff()-GV.col(0).minCoeff())/((Scalar)(side(0)-1));
|
|
const Scalar lower_bound = isolevel-sqrt(3.0)*h;
|
|
const Scalar upper_bound = isolevel+sqrt(3.0)*h;
|
|
{
|
|
Eigen::Matrix<Index,Eigen::Dynamic,1> I;
|
|
Eigen::Matrix<typename DerivedV::Scalar,Eigen::Dynamic,3> C,N;
|
|
igl::signed_distance(
|
|
GV,V,F,signed_distance_type,lower_bound,upper_bound,S,I,C,N);
|
|
}
|
|
igl::flood_fill(side,S);
|
|
|
|
DerivedS SS = S.array()-isolevel;
|
|
igl::copyleft::marching_cubes(SS,GV,side(0),side(1),side(2),SV,SF);
|
|
}
|
|
|
|
#ifdef IGL_STATIC_LIBRARY
|
|
// Explicit template instantiation
|
|
// generated by autoexplicit.sh
|
|
template void igl::copyleft::offset_surface<Eigen::Matrix<double, -1, 3, 1, -1, 3>, Eigen::Matrix<int, -1, 3, 1, -1, 3>, double, Eigen::Matrix<double, -1, 3, 1, -1, 3>, Eigen::Matrix<int, -1, 3, 1, -1, 3>, Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<int, 1, 3, 1, 1, 3>, Eigen::Matrix<double, -1, 1, 0, -1, 1> >(Eigen::MatrixBase<Eigen::Matrix<double, -1, 3, 1, -1, 3> > const&, Eigen::MatrixBase<Eigen::Matrix<int, -1, 3, 1, -1, 3> > const&, double, Eigen::Matrix<int, 1, 3, 1, 1, 3>::Scalar, igl::SignedDistanceType const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 3, 1, -1, 3> >&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 3, 1, -1, 3> >&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> >&, Eigen::PlainObjectBase<Eigen::Matrix<int, 1, 3, 1, 1, 3> >&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 1, 0, -1, 1> >&);
|
|
template void igl::copyleft::offset_surface<Eigen::Matrix<float, -1, 3, 1, -1, 3>, Eigen::Matrix<int, -1, 3, 1, -1, 3>, float, Eigen::Matrix<float, -1, 3, 1, -1, 3>, Eigen::Matrix<int, -1, 3, 1, -1, 3>, Eigen::Matrix<float, -1, -1, 0, -1, -1>, Eigen::Matrix<int, 1, 3, 1, 1, 3>, Eigen::Matrix<float, -1, 1, 0, -1, 1> >(Eigen::MatrixBase<Eigen::Matrix<float, -1, 3, 1, -1, 3> > const&, Eigen::MatrixBase<Eigen::Matrix<int, -1, 3, 1, -1, 3> > const&, float, Eigen::Matrix<int, 1, 3, 1, 1, 3>::Scalar, igl::SignedDistanceType const&, Eigen::PlainObjectBase<Eigen::Matrix<float, -1, 3, 1, -1, 3> >&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 3, 1, -1, 3> >&, Eigen::PlainObjectBase<Eigen::Matrix<float, -1, -1, 0, -1, -1> >&, Eigen::PlainObjectBase<Eigen::Matrix<int, 1, 3, 1, 1, 3> >&, Eigen::PlainObjectBase<Eigen::Matrix<float, -1, 1, 0, -1, 1> >&);
|
|
template void igl::copyleft::offset_surface<Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1>, double, Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1>, Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<int, 1, 3, 1, 1, 3>, Eigen::Matrix<double, -1, 1, 0, -1, 1> >(Eigen::MatrixBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, Eigen::MatrixBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, double, Eigen::Matrix<int, 1, 3, 1, 1, 3>::Scalar, igl::SignedDistanceType const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> >&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> >&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> >&, Eigen::PlainObjectBase<Eigen::Matrix<int, 1, 3, 1, 1, 3> >&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 1, 0, -1, 1> >&);
|
|
#endif
|