本文整理汇总了C#中Polygons.Add方法的典型用法代码示例。如果您正苦于以下问题:C# Polygons.Add方法的具体用法?C# Polygons.Add怎么用?C# Polygons.Add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Polygons
的用法示例。
在下文中一共展示了Polygons.Add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GenerateLinePaths
public static void GenerateLinePaths(Polygons polygonToInfill, ref Polygons infillLinesToPrint, int lineSpacing, int infillExtendIntoPerimeter_um, double rotation, long rotationOffset = 0)
{
if (polygonToInfill.Count > 0)
{
Polygons outlines = polygonToInfill.Offset(infillExtendIntoPerimeter_um);
if (outlines.Count > 0)
{
PointMatrix matrix = new PointMatrix(-(rotation + 90)); // we are rotating the part so we rotate by the negative so the lines go the way we expect
outlines.ApplyMatrix(matrix);
Aabb boundary = new Aabb(outlines);
boundary.min.X = ((boundary.min.X / lineSpacing) - 1) * lineSpacing - rotationOffset;
int xLineCount = (int)((boundary.max.X - boundary.min.X + (lineSpacing - 1)) / lineSpacing);
Polygons unclipedPatern = new Polygons();
long firstX = boundary.min.X / lineSpacing * lineSpacing;
for (int lineIndex = 0; lineIndex < xLineCount; lineIndex++)
{
Polygon line = new Polygon();
line.Add(new IntPoint(firstX + lineIndex * lineSpacing, boundary.min.Y));
line.Add(new IntPoint(firstX + lineIndex * lineSpacing, boundary.max.Y));
unclipedPatern.Add(line);
}
PolyTree ret = new PolyTree();
Clipper clipper = new Clipper();
clipper.AddPaths(unclipedPatern, PolyType.ptSubject, false);
clipper.AddPaths(outlines, PolyType.ptClip, true);
clipper.Execute(ClipType.ctIntersection, ret, PolyFillType.pftPositive, PolyFillType.pftEvenOdd);
Polygons newSegments = Clipper.OpenPathsFromPolyTree(ret);
PointMatrix inversematrix = new PointMatrix((rotation + 90));
newSegments.ApplyMatrix(inversematrix);
infillLinesToPrint.AddRange(newSegments);
}
}
}
示例2: GetAreasRecursive
static private void GetAreasRecursive(PolyNode polyTreeForPlate, Polygons discreteAreas)
{
if (!polyTreeForPlate.IsHole)
{
discreteAreas.Add(polyTreeForPlate.Contour);
}
foreach (PolyNode child in polyTreeForPlate.Childs)
{
GetAreasRecursive(child, discreteAreas);
}
}
示例3: ConvertToLines
public static Polygons ConvertToLines(Polygons polygons)
{
Polygons linePolygons = new Polygons();
foreach(Polygon polygon in polygons)
{
if (polygon.Count > 2)
{
for (int vertexIndex = 0; vertexIndex < polygon.Count; vertexIndex++)
{
linePolygons.Add(new Polygon() { polygon[vertexIndex], polygon[(vertexIndex + 1) % polygon.Count] });
}
}
else
{
linePolygons.Add(polygon);
}
}
return linePolygons;
}
示例4: ProcessPolyTreeNodeIntoSeparatIslands
private static void ProcessPolyTreeNodeIntoSeparatIslands(this Polygons polygonsIn, PolyNode node, List<Polygons> ret)
{
for (int n = 0; n < node.ChildCount; n++)
{
PolyNode child = node.Childs[n];
Polygons polygons = new Polygons();
polygons.Add(child.Contour);
for (int i = 0; i < child.ChildCount; i++)
{
polygons.Add(child.Childs[i].Contour);
polygonsIn.ProcessPolyTreeNodeIntoSeparatIslands(child.Childs[i], ret);
}
ret.Add(polygons);
}
}
示例5: DeepCopy
public static Polygons DeepCopy(this Polygons polygons)
{
Polygons deepCopy = new Polygons();
foreach (Polygon poly in polygons)
{
deepCopy.Add(new Polygon(poly));
}
return deepCopy;
}
示例6: CreateFromString
public static Polygons CreateFromString(string polygonsPackedString)
{
Polygons output = new Polygons();
string[] polygons = polygonsPackedString.Split('|');
foreach (string polygonString in polygons)
{
Polygon nextPoly = PolygonHelper.CreateFromString(polygonString);
if (nextPoly.Count > 0)
{
output.Add(nextPoly);
}
}
return output;
}
示例7: AddPolyNodeToPolygons
//------------------------------------------------------------------------------
public static void AddPolyNodeToPolygons(PolyNode polynode, Polygons polygons)
{
if (polynode.Contour.Count > 0)
polygons.Add(polynode.Contour);
foreach (PolyNode pn in polynode.Childs)
AddPolyNodeToPolygons(pn, polygons);
}
示例8: BuildResult
//------------------------------------------------------------------------------
private void BuildResult(Polygons polyg)
{
polyg.Clear();
polyg.Capacity = m_PolyOuts.Count;
for (int i = 0; i < m_PolyOuts.Count; i++)
{
OutRec outRec = m_PolyOuts[i];
if (outRec.pts == null) continue;
OutPt p = outRec.pts;
int cnt = PointCount(p);
if (cnt < 3) continue;
Polygon pg = new Polygon(cnt);
for (int j = 0; j < cnt; j++)
{
pg.Add(p.pt);
p = p.prev;
}
polyg.Add(pg);
}
}
示例9: GenerateConcentricInfill
public static void GenerateConcentricInfill(ConfigSettings config, Polygons partOutline, ref Polygons fillPolygons, long extrusionWidthOverride_um = 0)
{
if (extrusionWidthOverride_um == 0)
{
extrusionWidthOverride_um = config.extrusionWidth_um;
}
Polygons outlineCopy = new Polygons(partOutline);
foreach (Polygon outline in outlineCopy)
{
if (outline.Count > 0)
{
outline.Add(outline[0]);
}
}
int linespacing_um = (int)(extrusionWidthOverride_um / (config.infillPercent / 100));
while (outlineCopy.Count > 0)
{
for (int outlineIndex = 0; outlineIndex < outlineCopy.Count; outlineIndex++)
{
Polygon r = outlineCopy[outlineIndex];
fillPolygons.Add(r);
}
outlineCopy = outlineCopy.Offset(-linespacing_um);
foreach (Polygon outline in outlineCopy)
{
if (outline.Count > 0)
{
outline.Add(outline[0]);
}
}
}
}
示例10: GenerateHexLinePaths
public static void GenerateHexLinePaths(Polygons in_outline, ref Polygons result, int lineSpacing, int infillExtendIntoPerimeter_um, double rotationDegrees, int layerIndex)
{
int extraRotationAngle = 0;
if (in_outline.Count > 0)
{
Polygons outlines = in_outline.Offset(infillExtendIntoPerimeter_um);
if (outlines.Count > 0)
{
int perIncrementOffset = (int)(lineSpacing * Math.Sqrt(3) / 2 + .5);
PointMatrix matrix = new PointMatrix(-(rotationDegrees + extraRotationAngle)); // we are rotating the part so we rotate by the negative so the lines go the way we expect
outlines.ApplyMatrix(matrix);
Aabb boundary = new Aabb(outlines);
boundary.min.X = ((boundary.min.X / lineSpacing) - 1) * lineSpacing;
boundary.min.Y = ((boundary.min.Y / perIncrementOffset) - 2) * perIncrementOffset;
boundary.max.X += lineSpacing;
boundary.max.Y += perIncrementOffset;
Polygons unclipedPatern = new Polygons();
foreach (IntPoint startPoint in StartPositionIterator(boundary, lineSpacing, layerIndex))
{
Polygon attachedLine = new Polygon();
foreach (IntPoint center in IncrementPositionIterator(startPoint, boundary, lineSpacing, layerIndex))
{
// what we are adding are the little plusses that define the points
// | top
// |
// /\ center
// left/ \ right
//
IntPoint left = center + new IntPoint(-lineSpacing / 2, -perIncrementOffset / 3);
IntPoint right = center + new IntPoint(lineSpacing / 2, -perIncrementOffset / 3);
IntPoint top = center + new IntPoint(0, perIncrementOffset * 2 / 3);
switch (layerIndex % 3)
{
case 0: // left to right
attachedLine.Add(left); attachedLine.Add(center);
attachedLine.Add(center); attachedLine.Add(right);
unclipedPatern.Add(new Polygon() { top, center });
break;
case 1: // left to top
attachedLine.Add(left); attachedLine.Add(center);
attachedLine.Add(center); attachedLine.Add(top);
unclipedPatern.Add(new Polygon() { center, right });
break;
case 2: // top to right
attachedLine.Add(top); attachedLine.Add(center);
attachedLine.Add(center); attachedLine.Add(right);
unclipedPatern.Add(new Polygon() { left, center });
break;
}
}
if (attachedLine.Count > 0)
{
unclipedPatern.Add(attachedLine);
}
}
PolyTree ret = new PolyTree();
Clipper clipper = new Clipper();
clipper.AddPaths(unclipedPatern, PolyType.ptSubject, false);
clipper.AddPaths(outlines, PolyType.ptClip, true);
clipper.Execute(ClipType.ctIntersection, ret, PolyFillType.pftPositive, PolyFillType.pftEvenOdd);
Polygons newSegments = Clipper.OpenPathsFromPolyTree(ret);
PointMatrix inversematrix = new PointMatrix((rotationDegrees + extraRotationAngle));
newSegments.ApplyMatrix(inversematrix);
result.AddRange(newSegments);
}
}
}
示例11: GenerateSkirt
public void GenerateSkirt(int distance, int extrusionWidth_um, int numberOfLoops, int minLength, int initialLayerHeight, ConfigSettings config)
{
LayerDataStorage storage = this;
bool externalOnly = (distance > 0);
for (int skirtLoop = 0; skirtLoop < numberOfLoops; skirtLoop++)
{
int offsetDistance = distance + extrusionWidth_um * skirtLoop + extrusionWidth_um / 2;
Polygons skirtPolygons = new Polygons(storage.wipeTower.Offset(offsetDistance));
for (int extrudeIndex = 0; extrudeIndex < storage.Extruders.Count; extrudeIndex++)
{
if (config.continuousSpiralOuterPerimeter && extrudeIndex > 0)
{
continue;
}
if (storage.Extruders[extrudeIndex].Layers.Count < 1)
{
continue;
}
SliceLayer layer = storage.Extruders[extrudeIndex].Layers[0];
for (int partIndex = 0; partIndex < layer.Islands.Count; partIndex++)
{
if (config.continuousSpiralOuterPerimeter && partIndex > 0)
{
continue;
}
if (externalOnly)
{
Polygons p = new Polygons();
p.Add(layer.Islands[partIndex].IslandOutline[0]);
//p.Add(IntPointHelper.CreateConvexHull(layer.parts[partIndex].outline[0]));
skirtPolygons = skirtPolygons.CreateUnion(p.Offset(offsetDistance));
}
else
{
skirtPolygons = skirtPolygons.CreateUnion(layer.Islands[partIndex].IslandOutline.Offset(offsetDistance));
}
}
}
if (storage.support != null)
{
skirtPolygons = skirtPolygons.CreateUnion(storage.support.GetBedOutlines().Offset(offsetDistance));
}
//Remove small inner skirt holes. Holes have a negative area, remove anything smaller then 100x extrusion "area"
for (int n = 0; n < skirtPolygons.Count; n++)
{
double area = skirtPolygons[n].Area();
if (area < 0 && area > -extrusionWidth_um * extrusionWidth_um * 100)
{
skirtPolygons.RemoveAt(n--);
}
}
storage.skirt.AddAll(skirtPolygons);
int lenght = (int)storage.skirt.PolygonLength();
if (skirtLoop + 1 >= numberOfLoops && lenght > 0 && lenght < minLength)
{
// add more loops for as long as we have not extruded enough length
numberOfLoops++;
}
}
}
示例12: LoadFromFile
//---------------------------------------------------------------------
bool LoadFromFile(string filename, Polygons ppg, double scale = 0,
int xOffset = 0, int yOffset = 0)
{
double scaling = Math.Pow(10, scale);
ppg.Clear();
if (!File.Exists(filename)) return false;
StreamReader sr = new StreamReader(filename);
if (sr == null) return false;
string line;
if ((line = sr.ReadLine()) == null) return false;
int polyCnt, vertCnt;
if (!Int32.TryParse(line, out polyCnt) || polyCnt < 0) return false;
ppg.Capacity = polyCnt;
for (int i = 0; i < polyCnt; i++)
{
if ((line = sr.ReadLine()) == null) return false;
if (!Int32.TryParse(line, out vertCnt) || vertCnt < 0) return false;
Polygon pg = new Polygon(vertCnt);
ppg.Add(pg);
for (int j = 0; j < vertCnt; j++)
{
double x, y;
if ((line = sr.ReadLine()) == null) return false;
char[] delimiters = new char[] { ',', ' ' };
string [] vals = line.Split(delimiters);
if (vals.Length < 2) return false;
if (!double.TryParse(vals[0], out x)) return false;
if (!double.TryParse(vals[1], out y))
if (vals.Length < 2 || !double.TryParse(vals[2], out y)) return false;
x = x * scaling + xOffset;
y = y * scaling + yOffset;
pg.Add(new IntPoint((int)Math.Round(x), (int)Math.Round(y)));
}
}
return true;
}
示例13: BridgeAngle
public bool BridgeAngle(Polygons areaAboveToFill, out double bridgeAngle, string debugName = "")
{
SliceLayer layerToRestOn = this;
bridgeAngle = -1;
Aabb boundaryBox = new Aabb(areaAboveToFill);
//To detect if we have a bridge, first calculate the intersection of the current layer with the previous layer.
// This gives us the islands that the layer rests on.
Polygons islandsToRestOn = new Polygons();
foreach (LayerIsland islandToRestOn in layerToRestOn.Islands)
{
if (!boundaryBox.Hit(islandToRestOn.BoundingBox))
{
continue;
}
islandsToRestOn.AddRange(areaAboveToFill.CreateIntersection(islandToRestOn.IslandOutline));
}
if (OUTPUT_DEBUG_DATA)
{
string outlineString = areaAboveToFill.WriteToString();
string islandOutlineString = "";
foreach (LayerIsland prevLayerIsland in layerToRestOn.Islands)
{
foreach (Polygon islandOutline in prevLayerIsland.IslandOutline)
{
islandOutlineString += islandOutline.WriteToString();
}
islandOutlineString += "|";
}
string islandsString = islandsToRestOn.WriteToString();
}
Polygons islandConvexHuls = new Polygons();
foreach(Polygon poly in islandsToRestOn)
{
islandConvexHuls.Add(poly.CreateConvexHull());
}
if (islandsToRestOn.Count > 5 || islandsToRestOn.Count < 1)
{
return false;
}
if (islandsToRestOn.Count == 1)
{
return GetSingleIslandAngle(areaAboveToFill, islandsToRestOn[0], out bridgeAngle, debugName);
}
// Find the 2 largest islands that we rest on.
double biggestArea = 0;
double nextBiggestArea = 0;
int indexOfBiggest = -1;
int indexOfNextBigest = -1;
for (int islandIndex = 0; islandIndex < islandsToRestOn.Count; islandIndex++)
{
//Skip internal holes
if (!islandsToRestOn[islandIndex].Orientation())
{
continue;
}
double area = Math.Abs(islandConvexHuls[islandIndex].Area());
if (area > biggestArea)
{
if (biggestArea > nextBiggestArea)
{
nextBiggestArea = biggestArea;
indexOfNextBigest = indexOfBiggest;
}
biggestArea = area;
indexOfBiggest = islandIndex;
}
else if (area > nextBiggestArea)
{
nextBiggestArea = area;
indexOfNextBigest = islandIndex;
}
}
if (indexOfBiggest < 0 || indexOfNextBigest < 0)
{
return false;
}
Polygons big1 = new Polygons() { islandConvexHuls[indexOfBiggest] };
Polygons big2 = new Polygons() { islandConvexHuls[indexOfNextBigest] };
Polygons intersection = big1.CreateIntersection(big2);
if(intersection.Count > 0)
{
return GetSingleIslandAngle(areaAboveToFill, islandsToRestOn[indexOfBiggest], out bridgeAngle, debugName);
}
IntPoint center1 = islandsToRestOn[indexOfBiggest].CenterOfMass();
IntPoint center2 = islandsToRestOn[indexOfNextBigest].CenterOfMass();
bridgeAngle = Math.Atan2(center2.Y - center1.Y, center2.X - center1.X) / Math.PI * 180;
//.........这里部分代码省略.........
示例14: CreateLineLoops
public Polygons CreateLineLoops(int pixelsToIntPointsScale, int maxLineLoopsToAdd = int.MaxValue)
{
Polygons LineLoops = new Polygons();
bool[] hasBeenAddedList = new bool[LineSegments.Count];
for (int segmentToAddIndex = 0; segmentToAddIndex < LineSegments.Count; segmentToAddIndex++)
{
if (!hasBeenAddedList[segmentToAddIndex])
{
// now find all the connected segments until we get back to this one
Polygon loopToAdd = new Polygon();
// walk the loop
int currentSegmentIndex = segmentToAddIndex;
LineSegment currentSegment = LineSegments[currentSegmentIndex];
Vector2 connectionVertex = currentSegment.end;
loopToAdd.Add(new IntPoint((long)(connectionVertex.x * pixelsToIntPointsScale), (long)(connectionVertex.y * pixelsToIntPointsScale)));
hasBeenAddedList[currentSegmentIndex] = true;
bool addedToLoop = false;
do
{
bool foundNextSegment = false;
addedToLoop = false;
for (int segmentToCheckIndex = 0; segmentToCheckIndex < LineSegments.Count; segmentToCheckIndex++)
{
LineSegment segmentToCheck = LineSegments[segmentToCheckIndex];
if (!hasBeenAddedList[segmentToCheckIndex])
{
if (connectionVertex == segmentToCheck.start)
{
connectionVertex = segmentToCheck.end;
foundNextSegment = true;
}
else if (connectionVertex == segmentToCheck.end)
{
connectionVertex = segmentToCheck.start;
foundNextSegment = true;
}
else
{
int i = 0;
}
if (foundNextSegment)
{
hasBeenAddedList[segmentToCheckIndex] = true;
currentSegmentIndex = segmentToCheckIndex;
currentSegment = segmentToCheck;
loopToAdd.Add(new IntPoint((long)(connectionVertex.x * pixelsToIntPointsScale), (long)(connectionVertex.y * pixelsToIntPointsScale)));
addedToLoop = true;
break;
}
}
}
} while (addedToLoop);
LineLoops.Add(loopToAdd);
if (LineLoops.Count > maxLineLoopsToAdd)
{
break;
}
}
}
return LineLoops;
}
示例15: GetPathsWithOverlapsRemoved
public Polygons GetPathsWithOverlapsRemoved(Polygon perimeter, int overlapMergeAmount_um)
{
// make a copy that has every point duplicatiod (so that we have them as segments).
Polygon polySegments = new Polygon(perimeter.Count * 2);
for (int i = 0; i < perimeter.Count - 1; i++)
{
IntPoint point = perimeter[i];
IntPoint nextPoint = perimeter[i + 1];
polySegments.Add(point);
polySegments.Add(nextPoint);
}
Altered[] markedAltered = new Altered[polySegments.Count/2];
int segmentCount = polySegments.Count / 2;
// now walk every segment and check if there is another segment that is similar enough to merge them together
for (int firstSegmentIndex = 0; firstSegmentIndex < segmentCount; firstSegmentIndex++)
{
int firstPointIndex = firstSegmentIndex * 2;
for (int checkSegmentIndex = firstSegmentIndex + 1; checkSegmentIndex < segmentCount; checkSegmentIndex++)
{
int checkPointIndex = checkSegmentIndex * 2;
// The first point of start and the last point of check (the path will be coming back on itself).
long startDelta = (polySegments[firstPointIndex] - polySegments[checkPointIndex + 1]).Length();
// if the segmets are similar enough
if (startDelta < overlapMergeAmount_um)
{
// The last point of start and the first point of check (the path will be coming back on itself).
long endDelta = (polySegments[firstPointIndex + 1] - polySegments[checkPointIndex]).Length();
if (endDelta < overlapMergeAmount_um)
{
// move the first segments points to the average of the merge positions
polySegments[firstPointIndex] = (polySegments[firstPointIndex] + polySegments[checkPointIndex + 1]) / 2; // the start
polySegments[firstPointIndex + 1] = (polySegments[firstPointIndex + 1] + polySegments[checkPointIndex]) / 2; // the end
markedAltered[firstSegmentIndex] = Altered.merged;
// mark this segment for removal
markedAltered[checkSegmentIndex] = Altered.remove;
// We only expect to find one match for each segment, so move on to the next segment
break;
}
}
}
}
// Check for perimeter edeges that need to be removed that are the u turns of sectons that go back on themselves.
// __________
// |__________| -> |--------| the 2 vertical sections should be removed
for (int segmentIndex = 0; segmentIndex < segmentCount; segmentIndex++)
{
int prevSegmentIndex = (int)((uint)(segmentIndex - 1) % (uint)segmentCount);
int nextSegmentIndex = (segmentIndex + 1) % segmentCount;
if ((markedAltered[nextSegmentIndex] == Altered.merged && markedAltered[prevSegmentIndex] == Altered.remove)
|| (markedAltered[nextSegmentIndex] == Altered.remove && markedAltered[prevSegmentIndex] == Altered.merged))
{
markedAltered[segmentIndex] = Altered.remove;
}
}
// remove the marked segments
for (int segmentIndex = segmentCount - 1; segmentIndex >= 0; segmentIndex--)
{
int pointIndex = segmentIndex * 2;
if (markedAltered[segmentIndex] == Altered.remove)
{
polySegments.RemoveRange(pointIndex, 2);
}
}
// go through the polySegmets and create a new polygon for every connected set of segmets
Polygons separatedPolygons = new Polygons();
Polygon currentPolygon = new Polygon();
separatedPolygons.Add(currentPolygon);
// put in the first point
for (int segmentIndex = 0; segmentIndex < polySegments.Count; segmentIndex += 2)
{
// add the start point
currentPolygon.Add(polySegments[segmentIndex]);
// if the next segment is not connected to this one
if (segmentIndex < polySegments.Count - 2
&& polySegments[segmentIndex + 1] != polySegments[segmentIndex + 2])
{
// add the end point
currentPolygon.Add(polySegments[segmentIndex + 1]);
// create a new polygon
currentPolygon = new Polygon();
separatedPolygons.Add(currentPolygon);
}
}
// add the end point
currentPolygon.Add(polySegments[polySegments.Count - 1]);
return separatedPolygons;
}