Surface.pm 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. package Slic3r::Surface;
  2. use strict;
  3. use warnings;
  4. require Exporter;
  5. our @ISA = qw(Exporter);
  6. our @EXPORT_OK = qw(S_TYPE_TOP S_TYPE_BOTTOM S_TYPE_INTERNAL S_TYPE_INTERNALSOLID S_TYPE_INTERNALBRIDGE);
  7. our %EXPORT_TAGS = (types => \@EXPORT_OK);
  8. use constant S_EXPOLYGON => 0;
  9. use constant S_SURFACE_TYPE => 1;
  10. use constant S_DEPTH_LAYERS => 2;
  11. use constant S_BRIDGE_ANGLE => 3;
  12. use constant S_ADDITIONAL_INNER_PERIMETERS => 4;
  13. use constant S_TYPE_TOP => 0;
  14. use constant S_TYPE_BOTTOM => 1;
  15. use constant S_TYPE_INTERNAL => 2;
  16. use constant S_TYPE_INTERNALSOLID => 3;
  17. use constant S_TYPE_INTERNALBRIDGE => 4;
  18. sub new {
  19. my $class = shift;
  20. my %args = @_;
  21. my $self = [
  22. map delete $args{$_}, qw(expolygon surface_type depth_layers bridge_angle additional_inner_perimeters),
  23. ];
  24. $self->[S_DEPTH_LAYERS] //= 1; #/
  25. bless $self, $class;
  26. $self;
  27. }
  28. sub expolygon { $_[0][S_EXPOLYGON] }
  29. sub surface_type { $_[0][S_SURFACE_TYPE] = $_[1] if defined $_[1]; $_[0][S_SURFACE_TYPE] }
  30. sub depth_layers { $_[0][S_DEPTH_LAYERS] } # this integer represents the thickness of the surface expressed in layers
  31. sub bridge_angle { $_[0][S_BRIDGE_ANGLE] = $_[1] if defined $_[1]; $_[0][S_BRIDGE_ANGLE] }
  32. sub additional_inner_perimeters { $_[0][S_ADDITIONAL_INNER_PERIMETERS] = $_[1] if defined $_[1]; $_[0][S_ADDITIONAL_INNER_PERIMETERS] }
  33. # delegate handles
  34. sub encloses_point { $_[0]->expolygon->encloses_point }
  35. sub lines { $_[0]->expolygon->lines }
  36. sub contour { $_[0]->expolygon->contour }
  37. sub holes { $_[0]->expolygon->holes }
  38. # static method to group surfaces having same surface_type, bridge_angle and depth_layers
  39. sub group {
  40. my $class = shift;
  41. my $params = ref $_[0] eq 'HASH' ? shift(@_) : {};
  42. my (@surfaces) = @_;
  43. my %unique_types = ();
  44. foreach my $surface (@surfaces) {
  45. my $type = ($params->{merge_solid} && $surface->is_solid)
  46. ? 'solid'
  47. : $surface->surface_type;
  48. $type .= "_" . ($surface->bridge_angle // ''); #/
  49. $type .= "_" . $surface->depth_layers;
  50. $unique_types{$type} ||= [];
  51. push @{ $unique_types{$type} }, $surface;
  52. }
  53. return values %unique_types;
  54. }
  55. sub offset {
  56. my $self = shift;
  57. return map {
  58. (ref $self)->new(
  59. expolygon => $_,
  60. map { $_ => $self->$_ } qw(surface_type depth_layers bridge_angle),
  61. )
  62. } $self->expolygon->offset_ex(@_);
  63. }
  64. sub clipper_polygon {
  65. my $self = shift;
  66. return {
  67. outer => $self->contour->p,
  68. holes => [
  69. map $_->p, @{$self->holes}
  70. ],
  71. };
  72. }
  73. sub p {
  74. my $self = shift;
  75. return @{$self->expolygon};
  76. }
  77. sub is_solid {
  78. my $self = shift;
  79. my $type = $self->surface_type;
  80. # S_TYPE_INTERNALBRIDGE is not solid because we can't merge it with other solid types
  81. return $type == S_TYPE_TOP
  82. || $type == S_TYPE_BOTTOM
  83. || $type == S_TYPE_INTERNALSOLID;
  84. }
  85. sub is_internal {
  86. my $self = shift;
  87. my $type = $self->surface_type;
  88. return $type == S_TYPE_INTERNAL
  89. || $type == S_TYPE_INTERNALSOLID
  90. || $type == S_TYPE_INTERNALBRIDGE;
  91. }
  92. sub is_bridge {
  93. my $self = shift;
  94. my $type = $self->surface_type;
  95. return $type == S_TYPE_BOTTOM
  96. || $type == S_TYPE_INTERNALBRIDGE;
  97. }
  98. 1;