示例#1
0
 public virtual void Process(PrintLayerData layerData, ToolpathSet layerPaths)
 {
     foreach (var post in Posts)
     {
         post.Process(layerData, layerPaths);
     }
 }
示例#2
0
 public LayersDetector(ToolpathSet paths, double knownLayerHeight = 0)
 {
     Paths = paths;
     Compute();
     if (knownLayerHeight > 0)
     {
         EstimatedLayerHeight = knownLayerHeight;
     }
 }
示例#3
0
 public virtual bool Generate()
 {
     try {
         generate_result();
         Result = extract_result();
     } catch (Exception e) {
         ErrorF(e.Message, e.StackTrace);
         return(false);
     }
     return(true);
 }
        public CalculateExtrusion(ToolpathSet paths, SingleMaterialFFFSettings settings)
        {
            Paths    = paths;
            Settings = settings;

            EnableRetraction       = settings.EnableRetraction;
            FilamentDiam           = settings.Machine.FilamentDiamMM;
            NozzleDiam             = settings.Machine.NozzleDiamMM;
            LayerHeight            = settings.LayerHeightMM;
            FixedRetractDistance   = settings.RetractDistanceMM;
            MinRetractTravelLength = settings.MinRetractTravelLength;
            SupportExtrudeScale    = settings.SupportVolumeScale;
        }
示例#5
0
        public virtual void Process(PrintLayerData layerData, ToolpathSet layerPaths)
        {
            if (layerData.PreviousLayer == null)
            {
                return;
            }
            if (layerData.PreviousLayer.SupportAreas == null || layerData.PreviousLayer.SupportAreas.Count == 0)
            {
                return;
            }

            LayerCache cache = build_cache(layerData.PreviousLayer);

            Func <Vector3d, Vector3d> ZOffsetF = (v) =>
            {
                return(new Vector3d(v.x, v.y, v.z + ZOffsetMM));
            };

            foreach (var toolpath in layerPaths)
            {
                LinearToolpath tp = toolpath as LinearToolpath;
                if (tp == null)
                {
                    continue;
                }
                if (!tp.FillType.IsPart())
                {
                    continue;
                }

                int N = tp.VertexCount;
                //for ( int i = 0; i < N; ++i ) {
                for (int i = 1; i < N - 1; ++i)
                {       // start and end cannot be modified!
                    PrintVertex v = tp[i];
                    if (is_over_support(v.Position.xy, ref cache))
                    {
                        v.Position = ZOffsetF(v.Position);
                        tp.UpdateVertex(i, v);
                    }
                }
            }
        }
示例#6
0
 public ToolpathSetBuilder(ToolpathSet paths = null)
 {
     Paths = (paths == null) ? new ToolpathSet() : paths;
 }
示例#7
0
        /// <summary>
        /// This is the main driver of the slicing process
        /// </summary>
        protected virtual void generate_result()
        {
            // should be parameterizable? this is 45 degrees...  (is it? 45 if nozzlediam == layerheight...)
            //double fOverhangAllowance = 0.5 * settings.NozzleDiamMM;
            OverhangAllowanceMM = Settings.LayerHeightMM / Math.Tan(45 * MathUtil.Deg2Rad);


            // initialize compiler and get start nozzle position
            Compiler.Begin();

            // We need N above/below shell paths to do roof/floors, and *all* shells to do support.
            // Also we can compute shells in parallel. So we just precompute them all here.
            precompute_shells();
            int nLayers = Slices.Count;

            // Now generate paths for each layer.
            // This could be parallelized to some extent, but we have to pass per-layer paths
            // to Scheduler in layer-order. Probably better to parallelize within-layer computes.
            for (int layer_i = 0; layer_i < nLayers; ++layer_i)
            {
                BeginLayerF(layer_i);

                // make path-accumulator for this layer
                ToolpathSetBuilder paths = new ToolpathSetBuilder();

                // TODO FIX
                //paths.Initialize(Compiler.NozzlePosition);
                paths.Initialize((double)(layer_i) * Settings.LayerHeightMM * Vector3d.AxisZ);

                // layer-up (ie z-change)
                paths.AppendZChange(Settings.LayerHeightMM, Settings.ZTravelSpeed);

                // rest of code does not directly access path builder, instead if
                // sends paths to scheduler.
                SequentialScheduler2d scheduler = new SequentialScheduler2d(paths, Settings);

                // a layer can contain multiple disjoint regions. Process each separately.
                List <ShellsFillPolygon> layer_shells = LayerShells[layer_i];
                for (int si = 0; si < layer_shells.Count; si++)
                {
                    // schedule shell paths that we pre-computed
                    ShellsFillPolygon shells_gen = layer_shells[si];
                    scheduler.AppendCurveSets(shells_gen.Shells);

                    // all client to do configuration (eg change settings for example)
                    BeginShellF(shells_gen, ShellTags.Get(shells_gen));

                    // solid fill areas are inner polygons of shell fills
                    List <GeneralPolygon2d> solid_fill_regions = shells_gen.InnerPolygons;

                    // fill solid regions
                    foreach (GeneralPolygon2d solid_poly in solid_fill_regions)
                    {
                        fill_solid_region(layer_i, solid_poly, scheduler, false);
                    }
                }

                // resulting paths for this layer (Currently we are just discarding this after compiling)
                ToolpathSet layerPaths = paths.Paths;

                // compile this layer
                Compiler.AppendPaths(layerPaths);
            }

            Compiler.End();
        }
示例#8
0
 public virtual void Begin()
 {
     PathSet    = new ToolpathSet();
     ActivePath = new LinearToolpath();
 }
        /// <summary>
        /// Compile this set of toolpaths and pass to assembler.
        /// Settings are optional, pass null to ignore
        /// </summary>
        public virtual void AppendPaths(ToolpathSet paths, SingleMaterialFFFSettings pathSettings)
        {
            Assembler.FlushQueues();

            SingleMaterialFFFSettings useSettings = (pathSettings == null) ? Settings : pathSettings;

            CalculateExtrusion calc = new CalculateExtrusion(paths, useSettings);

            calc.Calculate(Assembler.NozzlePosition, Assembler.ExtruderA, Assembler.InRetract);


            int path_index = 0;

            foreach (var gpath in paths)
            {
                path_index++;

                if (IsCommandToolpath(gpath))
                {
                    ProcessCommandToolpath(gpath);
                    continue;
                }

                LinearToolpath p = gpath as LinearToolpath;

                if (p[0].Position.Distance(Assembler.NozzlePosition) > 0.00001)
                {
                    throw new Exception("SingleMaterialFFFCompiler.AppendPaths: path " + path_index + ": Start of path is not same as end of previous path!");
                }

                int i = 0;
                if ((p.Type == ToolpathTypes.Travel || p.Type == ToolpathTypes.PlaneChange) && Assembler.InTravel == false)
                {
                    //Assembler.DisableFan();

                    // do retract cycle
                    if (p[0].Extrusion.x < Assembler.ExtruderA)
                    {
                        if (Assembler.InRetract)
                        {
                            throw new Exception("SingleMaterialFFFCompiler.AppendPaths: path " + path_index + ": already in retract!");
                        }
                        Assembler.BeginRetract(p[0].Position, useSettings.RetractSpeed, p[0].Extrusion.x);
                    }
                    Assembler.BeginTravel();
                }
                else if (p.Type == ToolpathTypes.Deposition)
                {
                    // end travel / retract if we are in that state
                    if (Assembler.InTravel)
                    {
                        if (Assembler.InRetract)
                        {
                            Assembler.EndRetract(p[0].Position, useSettings.RetractSpeed, p[0].Extrusion.x);
                        }
                        Assembler.EndTravel();
                        //Assembler.EnableFan();
                    }
                }

                i = 1;                      // do not need to emit code for first point of path,
                // we are already at this pos

                for (; i < p.VertexCount; ++i)
                {
                    if (p.Type == ToolpathTypes.Travel)
                    {
                        Assembler.AppendMoveTo(p[i].Position, p[i].FeedRate, "Travel");
                    }
                    else if (p.Type == ToolpathTypes.PlaneChange)
                    {
                        Assembler.AppendMoveTo(p[i].Position, p[i].FeedRate, "Plane Change");
                    }
                    else
                    {
                        Assembler.AppendExtrudeTo(p[i].Position, p[i].FeedRate, p[i].Extrusion.x);
                    }
                }
            }


            Assembler.FlushQueues();
        }
        /// <summary>
        /// Compile this set of toolpaths and pass to assembler.
        /// Settings are optional, pass null to ignore
        /// </summary>
        public virtual void AppendPaths(ToolpathSet toolpathSet, IPrintProfileFFF profile)
        {
            Assembler.FlushQueues();

            IPrintProfileFFF useSettings = (profile == null) ? Settings : profile;

            var paths = toolpathSet.GetPaths <PrintVertex>();
            var calc  = new CalculateExtrusion <PrintVertex>(paths, useSettings);

            calc.Calculate(Assembler.NozzlePosition, Assembler.ExtruderA, Assembler.InRetract);

            int path_index = 0;

            foreach (var gpath in toolpathSet)
            {
                path_index++;

                if (IsCommandToolpath(gpath))
                {
                    ProcessCommandToolpath(gpath);
                    continue;
                }

                LinearToolpath p = gpath as LinearToolpath;

                if (p[0].Position.Distance(Assembler.NozzlePosition) > 0.00001)
                {
                    throw new Exception("SingleMaterialFFFCompiler.AppendPaths: path " + path_index + ": Start of path is not same as end of previous path!");
                }

                int i = 0;
                if (p.Type == ToolpathTypes.Travel || p.Type == ToolpathTypes.PlaneChange)
                {
                    HandleTravelAndPlaneChangePath(p, path_index, useSettings);
                }
                else if (p.Type == ToolpathTypes.Deposition)
                {
                    HandleDepositionPath(p, useSettings);
                }

                i = 1;      // do not need to emit code for first point of path,
                            // we are already at this pos

                var currentDimensions = p[1].Dimensions;

                for (; i < p.VertexCount; ++i)
                {
                    if (p.Type == ToolpathTypes.Travel)
                    {
                        Assembler.AppendMoveTo(p[i].Position, p[i].FeedRate, "Travel");
                    }
                    else if (p.Type == ToolpathTypes.PlaneChange)
                    {
                        Assembler.AppendMoveTo(p[i].Position, p[i].FeedRate, "Plane Change");
                    }
                    else
                    {
                        if (p.Type == ToolpathTypes.Deposition && !p[i].Dimensions.EpsilonEqual(currentDimensions, 1e-6))
                        {
                            currentDimensions = p[i].Dimensions;
                            AppendDimensions(p[i].Dimensions);
                        }
                        Assembler.AppendExtrudeTo(p[i].Position, p[i].FeedRate, p[i].Extrusion.x, null);
                    }
                }
            }

            /*
             * TODO: Should there be an EndTravel() call here?
             */
            HandleDepositionEnd();
            Assembler.FlushQueues();
        }
示例#11
0
        /// <summary>
        /// Compile this set of toolpaths and pass to assembler.
        /// Settings are optional, pass null to ignore
        /// </summary>
        public virtual void AppendPaths(ToolpathSet paths, SingleMaterialFFFSettings pathSettings)
        {
            SingleMaterialFFFSettings useSettings = (pathSettings == null) ? Settings : pathSettings;

            int path_index = 0;

            foreach (var gpath in paths)
            {
                path_index++;

                if (IsCommandToolpath(gpath))
                {
                    ProcessCommandToolpath(gpath);
                    continue;
                }

                LinearToolpath p = gpath as LinearToolpath;

                // [RMS] this doesn't work because we are doing retract inside assembler...
                //if (p[0].Position.Distance(Assembler.ToolPosition) > 0.00001)
                //	throw new Exception("SingleMaterialFFFCompiler.AppendPaths: path "
                //                    + path_index + ": Start of path is not same as end of previous path!");

                int i = 0;
                if (p.Type == ToolpathTypes.Travel || p.Type == ToolpathTypes.PlaneChange)
                {
                    // do retract cycle
                    if (Assembler.InRetract == false)
                    {
                        Assembler.BeginRetract(useSettings.RetractDistanceMM, useSettings.RetractSpeed, "Retract");
                    }
                    if (Assembler.InTravel == false)
                    {
                        Assembler.BeginTravel();
                    }
                }
                else if (p.Type == ToolpathTypes.Cut)
                {
                    if (Assembler.InTravel)
                    {
                        Assembler.EndTravel();
                    }

                    if (Assembler.InRetract)
                    {
                        Assembler.EndRetract(useSettings.RetractSpeed, "End Retract");
                    }
                }

                i = 1;      // do not need to emit code for first point of path,
                            // we are already at this pos
                for (; i < p.VertexCount; ++i)
                {
                    if (p.Type == ToolpathTypes.Travel)
                    {
                        Assembler.AppendMoveTo(p[i].Position, p[i].FeedRate, "Travel");
                    }
                    else if (p.Type == ToolpathTypes.PlaneChange)
                    {
                        Assembler.AppendMoveTo(p[i].Position, p[i].FeedRate, "Plane Change");
                    }
                    else
                    {
                        Assembler.AppendCutTo(p[i].Position, p[i].FeedRate);
                    }
                }
            }
        }
示例#12
0
 public virtual void AppendPaths(ToolpathSet paths)
 {
     Assembler.AppendPaths(paths);
 }
示例#13
0
 public CalculatePrintTime(ToolpathSet paths, SingleMaterialFFFSettings settings)
 {
     Paths    = paths;
     Settings = settings;
 }
示例#14
0
 public CalculatePrintTime(ToolpathSet paths)
 {
     Paths = paths;
 }
示例#15
0
 public GenericPathsAssembler()
 {
     AccumulatedPaths = new ToolpathSet();
 }