static SKPath MakePath <T>(LinearToolpath3 <T> path, Func <Vector2d, SKPoint> mapF) where T : IToolpathVertex
        {
            SKPath p = new SKPath();

            p.MoveTo(mapF(path[0].Position.xy));
            for (int i = 1; i < path.VertexCount; i++)
            {
                p.LineTo(mapF(path[i].Position.xy));
            }
            return(p);
        }
        protected virtual void RaiseLineGenerated(LinearToolpath3 <TPrintVertex> toolpath)
        {
            var points = new List <Vector3d>(toolpath.VertexCount);

            foreach (var vertex in toolpath)
            {
                points.Add(vertex.Position);
            }

            RaiseLineGenerated(points, layerIndex);
        }
Beispiel #3
0
 private ToolpathTypes SetTypeFromVertexExtrusions(LinearToolpath3 <PrintVertex> toolpath)
 {
     for (int i = 1; i < toolpath.VertexCount; i++)
     {
         if (!VertexHasNegativeOrZeroExtrusion(toolpath[i - 1], toolpath[i]))
         {
             return(ToolpathTypes.Deposition);
         }
     }
     return(ToolpathTypes.Travel);
 }
Beispiel #4
0
        public void SharpAngleRight()
        {
            var mesher   = new TubeMesher <PrintVertex>();
            var toolpath = new LinearToolpath3 <PrintVertex>(ToolpathTypes.Deposition);

            toolpath.AppendVertex(new PrintVertex(new Vector3d(0, 0, 0), 1000, new Vector2d(0.4, 0.2)), TPVertexFlags.None);
            toolpath.AppendVertex(new PrintVertex(new Vector3d(10, 0, 0), 1000, new Vector2d(0.4, 0.2)), TPVertexFlags.None);
            toolpath.AppendVertex(new PrintVertex(new Vector3d(0, -1, 0), 1000, new Vector2d(0.4, 0.2)), TPVertexFlags.None);

            var mesh = mesher.Generate(toolpath, VertexF);

            ExportMesh(mesh, "SharpAngleRight.stl");
        }
        protected virtual void EmitMesh(LinearToolpath3 <TPrintVertex> toolpath)
        {
            if (toolpath.VertexCount < 2)
            {
                return;
            }

            var mesh = mesher.Generate(toolpath, VertexFactory);

            pointCount += toolpath.VertexCount;

            EndEmit(Tuple.Create(mesh.Vertices.ToArray(), mesh.Triangles.ToArray()), layerIndex);
        }
        private ToolpathPreviewVertex[] CreatePoints(LinearToolpath3 <PrintVertex> toolpath)
        {
            var previewVertices = new ToolpathPreviewVertex[toolpath.VertexCount];

            int i             = 0;
            int fillTypeIndex = fillTypeMapper.GetIntegerFromLabel(toolpath.FillType.GetLabel());

            foreach (var printVertex in toolpath)
            {
                previewVertices[i++] = new ToolpathPreviewVertex(
                    printVertex.Position, fillTypeIndex, layerIndex,
                    color, 1, new CustomColorData(1, 1, 1));
            }
            return(previewVertices);
        }
        public ToolpathPreviewMesh Generate(LinearToolpath3 <TPrintVertex> toolpath, Func <TPrintVertex, Vector3d, float, ToolpathPreviewVertex> vertexFactory)
        {
            this.vertexFactory = vertexFactory;

            var mesh = new ToolpathPreviewMesh();

            var joints = new ToolpathPreviewJoint[toolpath.VertexCount];

            Segment3d?segmentBeforeJoint = null;

            for (int i = 0; i < toolpath.VertexCount; i++)
            {
                Segment3d?segmentAfterJoint = null;

                if (i < toolpath.VertexCount - 1)
                {
                    segmentAfterJoint = new Segment3d(toolpath[i].Position, toolpath[i + 1].Position);
                }

                if (segmentBeforeJoint == null || segmentAfterJoint == null)
                {
                    joints[i] = GenerateButtJoint(segmentBeforeJoint, segmentAfterJoint, toolpath[i], mesh);
                }
                else
                {
                    var angleRad = SignedAngleRad(segmentBeforeJoint.Value.Direction.xy, segmentAfterJoint.Value.Direction.xy);

                    if (Math.Abs(angleRad) > miterThreshold)
                    {
                        joints[i] = GenerateBevelJoint(segmentBeforeJoint.Value, segmentAfterJoint.Value, toolpath[i], mesh);
                    }
                    else
                    {
                        joints[i] = GenerateMiterJoint(segmentBeforeJoint.Value, segmentAfterJoint.Value, toolpath[i], mesh);
                    }
                }

                segmentBeforeJoint = segmentAfterJoint;
            }

            AddEdges(joints, mesh);

            return(mesh);
        }
        protected override LinearToolpath3 <PrintVertex> FinishToolpath()
        {
            if (toolpath == null)
            {
                return(new LinearToolpath3 <PrintVertex>());
            }

            toolpath.Type = SetTypeFromVertexExtrusions(toolpath);
            EmitToolpath(toolpath);

            // TODO: Simplify with "CopyProperties" method on LinearToolpath3
            var newToolpath = new LinearToolpath3 <PrintVertex>(toolpath.Type);

            newToolpath.IsHole   = toolpath.IsHole;
            newToolpath.FillType = toolpath.FillType;
            newToolpath.AppendVertex(toolpath.VertexCount > 0 ? toolpath.End : currentVertex, TPVertexFlags.IsPathStart);

            return(newToolpath);
        }
        static List <SKPath> MakePathSegments <T>(LinearToolpath3 <T> path, Func <Vector2d, SKPoint> mapF, double angleThreshD) where T : IToolpathVertex
        {
            List <SKPath> result = new List <SKPath>();

            Vector2d prevprev = path[0].Position.xy;

            SKPath p = new SKPath();

            result.Add(p);
            p.MoveTo(mapF(prevprev));
            if (path.VertexCount == 1)
            {
                p.LineTo(mapF(prevprev));
                return(result);
            }

            Vector2d prev = path[1].Position.xy;
            int      i    = 2;

            p.LineTo(mapF(prev));

            while (i < path.VertexCount)
            {
                Vector2d next      = path[i++].Position.xy;
                double   turnAngle = Vector2d.AngleD((prevprev - prev).Normalized, (next - prev).Normalized);
                if (turnAngle < angleThreshD)
                {
                    p = new SKPath();
                    result.Add(p);
                    p.MoveTo(mapF(prev));
                    p.LineTo(mapF(next));
                }
                else
                {
                    p.LineTo(mapF(next));
                }
                prevprev = prev;
                prev     = next;
            }
            return(result);
        }
Beispiel #10
0
 protected void EmitToolpath(LinearToolpath3 <TPrintVertex> travel)
 {
     OnToolpathComplete?.Invoke(travel);
 }
 protected virtual void EmitPoints(LinearToolpath3 <PrintVertex> linearToolpath)
 {
     RaisePointsGenerated(CreatePoints(linearToolpath), layerIndex);
 }