to_cork_mesh.cpp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2015 Alec Jacobson <alecjacobson@gmail.com>
  4. //
  5. // This Source Code Form is subject to the terms of the Mozilla Public License
  6. // v. 2.0. If a copy of the MPL was not distributed with this file, You can
  7. // obtain one at http://mozilla.org/MPL/2.0/.
  8. #ifndef IGL_NO_CORK
  9. #include "to_cork_mesh.h"
  10. template <
  11. typename DerivedV,
  12. typename DerivedF>
  13. IGL_INLINE void igl::boolean::to_cork_mesh(
  14. const Eigen::PlainObjectBase<DerivedV > & V,
  15. const Eigen::PlainObjectBase<DerivedF > & F,
  16. CorkTriMesh & mesh)
  17. {
  18. using namespace std;
  19. assert((F.cols() == 0 || F.cols() == 3) && "Facets should be triangles.");
  20. assert((V.cols() == 0 || V.cols() == 3) && "Vertices should be in 3D.");
  21. mesh.n_triangles = F.rows();
  22. mesh.n_vertices = V.rows();
  23. mesh.vertices = new double[mesh.n_vertices*3];
  24. mesh.triangles = new uint[mesh.n_triangles*3];
  25. for(size_t v = 0;v<mesh.n_vertices;v++)
  26. {
  27. for(size_t c = 0;c<3;c++)
  28. {
  29. mesh.vertices[v*3+c] = V(v,c);
  30. }
  31. }
  32. for(size_t f = 0;f<mesh.n_triangles;f++)
  33. {
  34. for(size_t c = 0;c<3;c++)
  35. {
  36. mesh.triangles[f*3+c] = F(f,c);
  37. }
  38. }
  39. }
  40. #ifdef IGL_STATIC_LIBRARY
  41. // Explicit template specialization
  42. template void igl::boolean::to_cork_mesh<Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1> >(Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, CorkTriMesh&);
  43. template void igl::boolean::to_cork_mesh<Eigen::Matrix<double, -1, 3, 0, -1, 3>, Eigen::Matrix<int, -1, 3, 0, -1, 3> >(Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 3, 0, -1, 3> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 3, 0, -1, 3> > const&, CorkTriMesh&);
  44. #endif
  45. #endif