offset_surface.cpp 3.2 KB

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