forked from MatterHackers/MatterSlice
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLayerIsland.cs
103 lines (87 loc) · 3.21 KB
/
LayerIsland.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/*
This file is part of MatterSlice. A command line utility for
generating 3D printing GCode.
Copyright (C) 2013 David Braam
Copyright (c) 2014, Lars Brubaker
MatterSlice is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
using ClipperLib;
using System;
using System.Collections.Generic;
namespace MatterHackers.MatterSlice
{
using Polygons = List<List<IntPoint>>;
/// <summary>
/// Represents the data for one island.
/// A single island can be more than one polygon as they have both the outline and the hole polygons.
/// </summary>
public class LayerIsland
{
public Aabb BoundingBox = new Aabb();
/// <summary>
/// The outline of the island as defined by the original mesh polygons (not inset at all).
/// </summary>
public Polygons IslandOutline = new Polygons();
public Polygons AvoidCrossingBoundary = new Polygons();
/// <summary>
/// The IslandOutline inset as many times as there are perimeters for the part.
/// </summary>
public List<Polygons> InsetToolPaths = new List<Polygons>();
public Polygons SolidTopToolPaths = new Polygons();
public Polygons SolidBottomToolPaths = new Polygons();
public Polygons SolidInfillToolPaths = new Polygons();
public Polygons InfillToolPaths = new Polygons();
private static readonly double minimumDistanceToCreateNewPosition = 10;
public void GenerateInsets(int extrusionWidth_um, int outerExtrusionWidth_um, int insetCount)
{
LayerIsland part = this;
part.BoundingBox.Calculate(part.IslandOutline);
part.AvoidCrossingBoundary = part.IslandOutline.Offset(-extrusionWidth_um);
if (insetCount == 0)
{
// if we have no insets defined still create one
part.InsetToolPaths.Add(part.IslandOutline);
}
else // generate the insets
{
int currentOffset = 0;
// Inset 0 will use the outerExtrusionWidth_um, everyone else will use extrusionWidth_um
int offsetBy = outerExtrusionWidth_um / 2;
for (int i = 0; i < insetCount; i++)
{
// Increment by half the offset amount
currentOffset += offsetBy;
Polygons currentInset = part.IslandOutline.Offset(-currentOffset);
// make sure our polygon data is reasonable
currentInset = Clipper.CleanPolygons(currentInset, minimumDistanceToCreateNewPosition);
// check that we have actual paths
if (currentInset.Count > 0)
{
part.InsetToolPaths.Add(currentInset);
// Increment by the second half
currentOffset += offsetBy;
}
else
{
// we are done making insets as we have no area left
break;
}
if (i == 0)
{
// Reset offset amount to half the standard extrusion width
offsetBy = extrusionWidth_um / 2;
}
}
}
}
};
}