offset_surface.cpp 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #include "offset_surface.h"
  2. #include "marching_cubes.h"
  3. #include "../voxel_grid.h"
  4. #include <cassert>
  5. template <
  6. typename DerivedV,
  7. typename DerivedF,
  8. typename isolevelType,
  9. typename sType,
  10. typename DerivedSV,
  11. typename DerivedSF,
  12. typename DerivedGV,
  13. typename Derivedside,
  14. typename DerivedS>
  15. void igl::copyleft::offset_surface(
  16. const Eigen::MatrixBase<DerivedV> & V,
  17. const Eigen::MatrixBase<DerivedF> & F,
  18. const isolevelType isolevel,
  19. const sType s,
  20. const SignedDistanceType & signed_distance_type,
  21. Eigen::PlainObjectBase<DerivedSV> & SV,
  22. Eigen::PlainObjectBase<DerivedSF> & SF,
  23. Eigen::PlainObjectBase<DerivedGV> & GV,
  24. Eigen::PlainObjectBase<Derivedside> & side,
  25. Eigen::PlainObjectBase<DerivedS> & S)
  26. {
  27. {
  28. typedef typename DerivedV::Scalar Scalar;
  29. Eigen::AlignedBox<Scalar,3> box;
  30. typedef Eigen::Matrix<Scalar,1,3> RowVector3S;
  31. assert(V.cols() == 3 && "V must contain positions in 3D");
  32. RowVector3S min_ext = V.colwise().minCoeff().array() - isolevel;
  33. RowVector3S max_ext = V.colwise().maxCoeff().array() + isolevel;
  34. box.extend(min_ext.transpose());
  35. box.extend(max_ext.transpose());
  36. igl::voxel_grid(box,s,0,GV,side);
  37. }
  38. {
  39. Eigen::VectorXi I;
  40. Eigen::Matrix<typename DerivedV::Scalar,Eigen::Dynamic,3> C,N;
  41. igl::signed_distance(
  42. GV,V,F,igl::SIGNED_DISTANCE_TYPE_PSEUDONORMAL,S,I,C,N);
  43. }
  44. DerivedS SS = S.array()-isolevel;
  45. igl::copyleft::marching_cubes(SS,GV,side(0),side(1),side(2),SV,SF);
  46. }
  47. #ifdef IGL_STATIC_LIBRARY
  48. // Explicit template instantiation
  49. template void igl::copyleft::offset_surface<Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1>, double, int, 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, int, 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> >&);
  50. #endif