SurfaceCollection.xsp 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. %module{Slic3r::XS};
  2. %{
  3. #include <xsinit.h>
  4. #include "libslic3r/SurfaceCollection.hpp"
  5. %}
  6. %name{Slic3r::Surface::Collection} class SurfaceCollection {
  7. %name{_new} SurfaceCollection();
  8. ~SurfaceCollection();
  9. void clear()
  10. %code{% THIS->surfaces.clear(); %};
  11. void append(Surface* surface)
  12. %code{% THIS->surfaces.push_back(*surface); %};
  13. int count()
  14. %code{% RETVAL = THIS->surfaces.size(); %};
  15. void simplify(double tolerance);
  16. %{
  17. SV*
  18. SurfaceCollection::arrayref()
  19. CODE:
  20. AV* av = newAV();
  21. av_fill(av, THIS->surfaces.size()-1);
  22. int i = 0;
  23. for (Surfaces::iterator it = THIS->surfaces.begin(); it != THIS->surfaces.end(); ++it) {
  24. av_store(av, i++, perl_to_SV_ref(*it));
  25. }
  26. RETVAL = newRV_noinc((SV*)av);
  27. OUTPUT:
  28. RETVAL
  29. SV*
  30. SurfaceCollection::filter_by_type(surface_type)
  31. SurfaceType surface_type;
  32. CODE:
  33. AV* av = newAV();
  34. for (Surfaces::iterator it = THIS->surfaces.begin(); it != THIS->surfaces.end(); ++it) {
  35. if ((*it).surface_type == surface_type) av_push(av, perl_to_SV_ref(*it));
  36. }
  37. RETVAL = newRV_noinc((SV*)av);
  38. OUTPUT:
  39. RETVAL
  40. void
  41. SurfaceCollection::replace(index, surface)
  42. int index
  43. Surface* surface
  44. CODE:
  45. THIS->surfaces[index] = *surface;
  46. void
  47. SurfaceCollection::set_surface_type(index, surface_type)
  48. int index
  49. SurfaceType surface_type;
  50. CODE:
  51. THIS->surfaces[index].surface_type = surface_type;
  52. SV*
  53. SurfaceCollection::group()
  54. CODE:
  55. // perform grouping
  56. std::vector<SurfacesPtr> groups;
  57. THIS->group(&groups);
  58. // build return arrayref
  59. AV* av = newAV();
  60. av_fill(av, groups.size()-1);
  61. size_t i = 0;
  62. for (std::vector<SurfacesPtr>::iterator it = groups.begin(); it != groups.end(); ++it) {
  63. AV* innerav = newAV();
  64. av_fill(innerav, it->size()-1);
  65. size_t j = 0;
  66. for (SurfacesPtr::iterator it_s = it->begin(); it_s != it->end(); ++it_s) {
  67. av_store(innerav, j++, perl_to_SV_clone_ref(**it_s));
  68. }
  69. av_store(av, i++, newRV_noinc((SV*)innerav));
  70. }
  71. RETVAL = newRV_noinc((SV*)av);
  72. OUTPUT:
  73. RETVAL
  74. %}
  75. };