private LineStrip LineStripFromPolygon(Path polygon) { LineStrip line = new LineStrip(); foreach (IntPoint point in polygon) { line.Append(TransformTo3D(point)); } return(line); }
//private float height = .050f; private LineStrip FindLargestLoop(Segment start) { //height += 0.050f; Vector3 normal = new Vector3 (0, 0, 1); Segment next = start; List<Segment> seen = new List<Segment>(); while (!seen.Contains(next)) { //GL.Disable(EnableCap.Lighting); //GL.LineWidth(3); //GL.Begin(PrimitiveType.Lines); //GL.Color3(Color.Blue); //GL.Vertex3(next.a.vector.X, next.a.vector.Y, height); //GL.Color3(Color.LightGreen); //height += .010f; //GL.Vertex3(next.b.vector.X, next.b.vector.Y, height); //GL.End(); //GL.LineWidth(1); //GL.Enable(EnableCap.Lighting); seen.Add(next); Segment best = null; float largestAngle = 0; foreach (Segment s in next.b.used_as_a) { float angle = Angle(-s.Normal, next.Normal, normal); if (angle > largestAngle) { largestAngle = angle; best = s; } } if (best == null) { // No loops return null; } // Destructive: remove references to this element so it's not searched again. // Note: only need to remove forward links (from used_as_a). The links from // used_as_b could be cleared too, but it's not necessary for the algorithm. next.b.used_as_a.Clear(); //next.b.used_as_b.Clear(); next = best; } // Remove all up to the first matched index int index = seen.IndexOf(next); seen.RemoveRange(0, index); LineStrip loop = new LineStrip(); foreach (Segment seg in seen) { loop.Append(seg.a.vector); } return loop; }
private LineStrip LineStripFromPolygon(Path polygon) { LineStrip line = new LineStrip(); foreach (IntPoint point in polygon) { line.Append(TransformTo3D(point)); } return line; }
private void boundaryCheckButton_Click(object sender, EventArgs e) { float xMin = -router.ToolDiameter; float xMax = router.ToolDiameter; float yMin = -router.ToolDiameter; float yMax = router.ToolDiameter; foreach (Object o in drawing3D.GetObjects()) { if (o is TriangleMeshGUI) { var triangles = o as TriangleMeshGUI; xMin = Math.Min(triangles.MinPoint.X - router.ToolDiameter + triangles.Offset.X, xMin); xMax = Math.Max(triangles.MaxPoint.X + router.ToolDiameter + triangles.Offset.X, xMax); yMin = Math.Min(triangles.MinPoint.Y - router.ToolDiameter + triangles.Offset.Y, yMin); yMax = Math.Max(triangles.MaxPoint.Y + router.ToolDiameter + triangles.Offset.Y, yMax); } } LineStrip r = new LineStrip(); r.Append(new Vector3(xMin, yMin, router.MoveHeight)); r.Append(new Vector3(xMax, yMin, router.MoveHeight)); r.Append(new Vector3(xMax, yMax, router.MoveHeight)); r.Append(new Vector3(xMin, yMax, router.MoveHeight)); r.Append(new Vector3(xMin, yMin, router.MoveHeight)); router.RoutPath(r, false, Vector3.Zero); router.Complete(); }
/// <summary> /// Create another line strip which follows the same path, but avoids tab locations. /// NOTE: this currently only works on closed input lines. The algorithm could /// be modified to work correctly with open paths too, but that's not needed yet. /// </summary> /// <param name="input"></param> /// <returns></returns> public LineStrip AvoidTabs(LineStrip input) { LineStrip ret = new LineStrip(); foreach (var segment in input.Segments(LineStrip.Type.Closed)) { if (segment.Length < 0.0001f) { continue; } if (segment.A.Z > tabHeight && segment.B.Z > tabHeight) { ret.Append(segment.B); continue; } List<LineSegment> remainingSegments = new List<LineSegment>(); remainingSegments.Add(segment); foreach (Vector3 tab in this.TabLocations) { var i = new LineSegmentCircleIntersect(segment, tab, tabRadius + toolRadius); if (i.type == LineSegmentCircleIntersect.IntersectType.Segment) { List<LineSegment> temp = new List<LineSegment>(); foreach (var seg in remainingSegments) { temp.AddRange(seg.Subtract(i.IntersectSegment)); } remainingSegments = temp; } } remainingSegments.RemoveAll(s => s.Length < 0.0001f); if (remainingSegments.Count == 0) { // Entire segment is within a tab TestAddPoint(ClearHeight(segment.B, tabHeight), ret.Vertices); } else { // Everything described in "remainingSegments" is outside of the tab, and the spaces // between are on the tab. The path between is known since it's always a straight line. remainingSegments.Sort((s1, s2) => (s1.A - segment.A).Length.CompareTo((s2.A - segment.A).Length)); foreach (var s in remainingSegments) { TestAddPoint(ClearHeight(s.A, tabHeight), ret.Vertices); TestAddPoint(s.A, ret.Vertices); TestAddPoint(s.B, ret.Vertices); TestAddPoint(ClearHeight(s.B, tabHeight), ret.Vertices); } TestAddPoint(ClearHeight(segment.B, tabHeight), ret.Vertices); } } return ret; }
//private float height = .050f; private LineStrip FindLargestLoop(Segment start) { //height += 0.050f; Vector3 normal = new Vector3(0, 0, 1); Segment next = start; List <Segment> seen = new List <Segment>(); while (!seen.Contains(next)) { //GL.Disable(EnableCap.Lighting); //GL.LineWidth(3); //GL.Begin(PrimitiveType.Lines); //GL.Color3(Color.Blue); //GL.Vertex3(next.a.vector.X, next.a.vector.Y, height); //GL.Color3(Color.LightGreen); //height += .010f; //GL.Vertex3(next.b.vector.X, next.b.vector.Y, height); //GL.End(); //GL.LineWidth(1); //GL.Enable(EnableCap.Lighting); seen.Add(next); Segment best = null; float largestAngle = 0; foreach (Segment s in next.b.used_as_a) { float angle = Angle(-s.Normal, next.Normal, normal); if (angle > largestAngle) { largestAngle = angle; best = s; } } if (best == null) { // No loops return(null); } // Destructive: remove references to this element so it's not searched again. // Note: only need to remove forward links (from used_as_a). The links from // used_as_b could be cleared too, but it's not necessary for the algorithm. next.b.used_as_a.Clear(); //next.b.used_as_b.Clear(); next = best; } // Remove all up to the first matched index int index = seen.IndexOf(next); seen.RemoveRange(0, index); LineStrip loop = new LineStrip(); foreach (Segment seg in seen) { loop.Append(seg.a.vector); } return(loop); }