TriangleMesh.xsp 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. %module{Slic3r::XS};
  2. %{
  3. #include <xsinit.h>
  4. #include "libslic3r/TriangleMesh.hpp"
  5. #include "libslic3r/TriangleMeshSlicer.hpp"
  6. %}
  7. %name{Slic3r::TriangleMesh} class TriangleMesh {
  8. TriangleMesh();
  9. ~TriangleMesh();
  10. Clone<TriangleMesh> clone()
  11. %code{% RETVAL = THIS; %};
  12. void write_ascii(char* output_file);
  13. void write_binary(char* output_file);
  14. void scale(float factor);
  15. void scale_xyz(Vec3d* versor)
  16. %code{% THIS->scale(versor->cast<float>()); %};
  17. void translate(float x, float y, float z);
  18. void rotate_x(float angle);
  19. void rotate_y(float angle);
  20. void rotate_z(float angle);
  21. void mirror_x();
  22. void mirror_y();
  23. void mirror_z();
  24. void align_to_origin();
  25. void rotate(double angle, Point* center);
  26. void merge(TriangleMesh* mesh)
  27. %code{% THIS->merge(*mesh); %};
  28. Clone<Polygon> convex_hull();
  29. Clone<Vec3d> center()
  30. %code{% RETVAL = THIS->bounding_box().center(); %};
  31. int facets_count();
  32. %{
  33. void
  34. TriangleMesh::ReadFromPerl(vertices, facets)
  35. SV* vertices
  36. SV* facets
  37. CODE:
  38. std::vector<Slic3r::Vec3f> out_vertices;
  39. {
  40. AV* vertices_av = (AV*)SvRV(vertices);
  41. int number_of_vertices = av_len(vertices_av) + 1;
  42. out_vertices.reserve(number_of_vertices);
  43. for (int i = 0; i < number_of_vertices; ++ i) {
  44. AV* vertex_av = (AV*)SvRV(*av_fetch(vertices_av, i, 0));
  45. out_vertices.push_back(Slic3r::Vec3f(SvNV(*av_fetch(vertex_av, 0, 0)), SvNV(*av_fetch(vertex_av, 1, 0)), SvNV(*av_fetch(vertex_av, 2, 0))));
  46. }
  47. }
  48. std::vector<Slic3r::Vec3i> out_indices;
  49. {
  50. AV* facets_av = (AV*)SvRV(facets);
  51. int number_of_facets = av_len(facets_av) + 1;
  52. out_indices.reserve(number_of_facets);
  53. for (int i = 0; i < number_of_facets; ++ i) {
  54. AV* facet_av = (AV*)SvRV(*av_fetch(facets_av, i, 0));
  55. out_indices.push_back(Slic3r::Vec3i(SvIV(*av_fetch(facet_av, 0, 0)), SvIV(*av_fetch(facet_av, 1, 0)), SvIV(*av_fetch(facet_av, 2, 0))));
  56. }
  57. }
  58. *THIS = TriangleMesh(std::move(out_vertices), std::move(out_indices));
  59. SV*
  60. TriangleMesh::vertices()
  61. CODE:
  62. // vertices
  63. AV* vertices = newAV();
  64. av_extend(vertices, THIS->its.vertices.size());
  65. for (size_t i = 0; i < THIS->its.vertices.size(); i++) {
  66. AV* vertex = newAV();
  67. av_store(vertices, i, newRV_noinc((SV*)vertex));
  68. av_extend(vertex, 2);
  69. av_store(vertex, 0, newSVnv(THIS->its.vertices[i](0)));
  70. av_store(vertex, 1, newSVnv(THIS->its.vertices[i](1)));
  71. av_store(vertex, 2, newSVnv(THIS->its.vertices[i](2)));
  72. }
  73. RETVAL = newRV_noinc((SV*)vertices);
  74. OUTPUT:
  75. RETVAL
  76. SV*
  77. TriangleMesh::facets()
  78. CODE:
  79. // facets
  80. AV* facets = newAV();
  81. av_extend(facets, THIS->facets_count());
  82. for (int i = 0; i < THIS->facets_count(); i++) {
  83. AV* facet = newAV();
  84. av_store(facets, i, newRV_noinc((SV*)facet));
  85. av_extend(facet, 2);
  86. av_store(facet, 0, newSVnv(THIS->its.indices[i][0]));
  87. av_store(facet, 1, newSVnv(THIS->its.indices[i][1]));
  88. av_store(facet, 2, newSVnv(THIS->its.indices[i][2]));
  89. }
  90. RETVAL = newRV_noinc((SV*)facets);
  91. OUTPUT:
  92. RETVAL
  93. SV*
  94. TriangleMesh::size()
  95. CODE:
  96. AV* size = newAV();
  97. av_extend(size, 2);
  98. av_store(size, 0, newSVnv(THIS->stats().size(0)));
  99. av_store(size, 1, newSVnv(THIS->stats().size(1)));
  100. av_store(size, 2, newSVnv(THIS->stats().size(2)));
  101. RETVAL = newRV_noinc((SV*)size);
  102. OUTPUT:
  103. RETVAL
  104. %}
  105. };