offset_surface.cpp 4.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #include "offset_surface.h"
  2. #include "marching_cubes.h"
  3. #include "../voxel_grid.h"
  4. #include "../signed_distance.h"
  5. #include "../flood_fill.h"
  6. #include <cassert>
  7. template <
  8. typename DerivedV,
  9. typename DerivedF,
  10. typename isolevelType,
  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 typename Derivedside::Scalar 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. typedef typename DerivedV::Scalar Scalar;
  29. typedef typename DerivedF::Scalar Index;
  30. {
  31. Eigen::AlignedBox<Scalar,3> box;
  32. typedef Eigen::Matrix<Scalar,1,3> RowVector3S;
  33. assert(V.cols() == 3 && "V must contain positions in 3D");
  34. RowVector3S min_ext = V.colwise().minCoeff().array() - isolevel;
  35. RowVector3S max_ext = V.colwise().maxCoeff().array() + isolevel;
  36. box.extend(min_ext.transpose());
  37. box.extend(max_ext.transpose());
  38. igl::voxel_grid(box,s,1,GV,side);
  39. }
  40. const Scalar h =
  41. (GV.col(0).maxCoeff()-GV.col(0).minCoeff())/((Scalar)(side(0)-1));
  42. const Scalar lower_bound = isolevel-sqrt(3.0)*h;
  43. const Scalar upper_bound = isolevel+sqrt(3.0)*h;
  44. {
  45. Eigen::Matrix<Index,Eigen::Dynamic,1> I;
  46. Eigen::Matrix<typename DerivedV::Scalar,Eigen::Dynamic,3> C,N;
  47. igl::signed_distance(
  48. GV,V,F,signed_distance_type,lower_bound,upper_bound,S,I,C,N);
  49. }
  50. igl::flood_fill(side,S);
  51. DerivedS SS = S.array()-isolevel;
  52. igl::copyleft::marching_cubes(SS,GV,side(0),side(1),side(2),SV,SF);
  53. }
  54. #ifdef IGL_STATIC_LIBRARY
  55. // Explicit template instantiation
  56. // generated by autoexplicit.sh
  57. 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> >&);
  58. 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> >&);
  59. 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> >&);
  60. #endif