コード例 #1
0
 private void SetLayerPointsAsProcessed(Layer layer, Cube cube, GCodeConfiguration config)
 {
     for (int i = 0; i < cube.Width - 2 * config.AdditionalPointsToOverflowCubesByWidth; i++)
     {
         for (int j = 0; j < cube.Length - 2 * config.AdditionalPointsToOverflowCubesByLength; j++)
         {
             var xIndex = cube.X + i + config.AdditionalPointsToOverflowCubesByWidth;
             var yIndex = cube.Y + j + config.AdditionalPointsToOverflowCubesByLength;
             layer.Points[xIndex, yIndex].ProcessedStatus = ProcessedStatus.ProcessedWithBoldFreeze;
         }
     }
 }
コード例 #2
0
        public List <IGCodeMove> ProcessClean(GCodeMountain mountain, GCodeConfiguration configuration)
        {
            var spin = new SpinOptions {
                SpinSize = configuration.CleanSpinSizeMM
            };
            var moves = Process(
                mountain,
                configuration,
                0,
                configuration.XIncrementClean,
                configuration.YIncrementClean,
                spin);

            return(moves);
        }
コード例 #3
0
        public GCodeData GetMountainGCode(MountainData mountainData, GCodeConfiguration configuration)
        {
            var gCodeData = new GCodeData();

            // TODO: convert mountainData to mountain
            var mountain = new GCodeMountain(mountainData, configuration);

            var preparationProcessor = new PreparationProcessor();

            gCodeData.PreparationMoves = preparationProcessor.Process(mountain, configuration);

            var mainGCodeProcessor = new MainGCodeProcessor();

            gCodeData.DirtyMoves = mainGCodeProcessor.ProcessDirty(mountain, configuration);
            gCodeData.CleanMoves = mainGCodeProcessor.ProcessClean(mountain, configuration);

            return(gCodeData);
        }
コード例 #4
0
        public List <IGCodeMove> ProcessDirty(GCodeMountain mountain, GCodeConfiguration configuration)
        {
            var moves = new List <IGCodeMove>();

            var spin = new SpinOptions {
                SpinSize = configuration.DirtySpinSizeMM
            };

            var r1Moves = Process(mountain, configuration, configuration.DirtyR1OffsetHeightMM, configuration.XIncrementDirty, configuration.YIncrementDirty, spin);
            var r2Moves = Process(mountain, configuration, configuration.DirtyR2OffsetHeightMM, configuration.XIncrementDirty, configuration.YIncrementDirty, spin);
            var r3Moves = Process(mountain, configuration, configuration.DirtyR3OffsetHeightMM, configuration.XIncrementDirty, configuration.YIncrementDirty, spin);

            moves.AddRange(r1Moves);
            moves.AddRange(r2Moves);
            moves.AddRange(r3Moves);

            return(moves);
        }
コード例 #5
0
        public GCodeMountain(MountainData mountainData, GCodeConfiguration config)
        {
            MountainWidthInGCode  = config.FormSizeMMWidth;
            MountainLengthInGCode = config.FormSizeMMLength;
            MountainHeightInGCode = config.FormSizeMMHeight;

            var minorLength = mountainData.Points.Count;
            var majorLength = mountainData.Points[0].Count;

            Heights = new decimal[minorLength, majorLength];
            for (int i = 0; i < minorLength; i++)
            {
                for (int j = 0; j < majorLength; j++)
                {
                    Heights[i, j] = mountainData.Points[i][j].height;
                }
            }
        }
コード例 #6
0
        public List <IGCodeMove> Process(GCodeMountain mountain, GCodeConfiguration configuration)
        {
            var mountainSplitter = new MountainSplitter();


            var mountainSplitOptions = new MountainSplitOptions {
                HeightPerLayerInGCode = configuration.PreparationHeightMMPerLayer
            };
            var roughSplittedMountain = mountainSplitter.SplitMountainOnLevels(mountain, mountainSplitOptions);

            var moves          = new List <IGCodeMove>();
            var layerProcessor = new CubeLayerProcessor();
            var targetZ        = 0.0m;

            foreach (var layer in roughSplittedMountain.Layers)
            {
                targetZ += roughSplittedMountain.MountainSplitOptions.HeightPerLayerInGCode;
                moves.AddRange(layerProcessor.ProcessLayer(layer, configuration, targetZ));
            }
            return(moves);
        }
コード例 #7
0
        public List <IGCodeMove> ProcessLayer(Layer layer, GCodeConfiguration config, decimal targetZ)
        {
            var freeze = new SpinOptions {
                SpinSize = config.PreparationSpinSizeMM
            };
            var commandList = new List <IGCodeMove>();

            var width  = layer.Points.GetLength(0);
            var length = layer.Points.GetLength(1);

            do
            {
                width  = width / 2;
                length = length / 2;

                var cubes = GetCubesToProcess(layer, width, length, config);
                commandList.AddRange(ProcessCubes(cubes, layer, freeze, targetZ, config));
            }while (width >= config.MinWidth && length >= config.MinLength);

            return(commandList);
        }
コード例 #8
0
        private List <IGCodeMove> Process(GCodeMountain mountain, GCodeConfiguration config, decimal zOffset, int xIncrement, int yIncrement, SpinOptions spin)
        {
            var moves = new List <IGCodeMove>();

            // go to zero point
            var currentZ  = 0.0m;
            var x         = 0;
            var y         = 0;
            var previousZ = 0.0m;

            var fromTopToBottom    = true;
            var numberOfPointsPerX = mountain.Heights.GetLength(0);
            var numberOfPointsPerY = mountain.Heights.GetLength(1);

            moves.Add(new GCodeChangeZ {
                Z = 0
            });

            while (x < numberOfPointsPerX)
            {
                if (WithinRadius(mountain, x, y))
                {
                    previousZ = currentZ;
                    currentZ  = Math.Round(GetCurrentZ(mountain, x, y, spin), 2);
                    currentZ  = currentZ + zOffset;
                    currentZ  = Math.Max(config.ZMin, currentZ);
                    currentZ  = Math.Min(config.ZMax, currentZ);

                    var xGCode = mountain.MountainWidthInGCode * x / numberOfPointsPerX;
                    var yGCode = mountain.MountainLengthInGCode * y / numberOfPointsPerY;

                    if (currentZ > previousZ)
                    {
                        moves.Add(new GCodeLine {
                            X = xGCode, Y = yGCode
                        });
                        moves.Add(new GCodeChangeZ {
                            Z = currentZ
                        });
                    }
                    else
                    {
                        moves.Add(new GCodeChangeZ {
                            Z = currentZ
                        });
                        moves.Add(new GCodeLine {
                            X = xGCode, Y = yGCode
                        });
                    }
                }
                y += fromTopToBottom ? yIncrement : -yIncrement;
                if (y < 0)
                {
                    fromTopToBottom = true;
                    y  = 0;
                    x += xIncrement;
                }
                else if (y >= numberOfPointsPerY)
                {
                    fromTopToBottom = false;
                    y  = numberOfPointsPerY - 1;
                    x += xIncrement;
                }
            }

            return(moves);
        }
コード例 #9
0
        private List <IGCodeMove> GetCommandsForCube(Cube cube, Layer layer, SpinOptions freeze, decimal targetZ, GCodeConfiguration config)
        {
            var commands = new List <IGCodeMove>();

            var mmBetweenPointsForX = config.FormSizeMMWidth / layer.Points.GetLength(0);
            var mmBetweenPointsForY = config.FormSizeMMLength / layer.Points.GetLength(1);

            var minX = cube.X * mmBetweenPointsForX + freeze.SpinSize / 2;
            var minY = cube.Y * mmBetweenPointsForY + freeze.SpinSize / 2;
            var maxX = (cube.X + cube.Width) * mmBetweenPointsForX - freeze.SpinSize / 2;
            var maxY = (cube.Y + cube.Length) * mmBetweenPointsForY - freeze.SpinSize / 2;

            var currentX = minX;
            var currentY = minY;
            var currentZ = targetZ - layer.SplittedMountain.MountainSplitOptions.HeightPerLayerInGCode;

            var xDirection      = 1;
            var fromTopToBottom = true;

            var stepZ = config.PreparationHeightMMPerLayer;

            commands.Add(new GCodeChangeZ {
                Z = 0
            });
            commands.Add(new GCodeMove {
                X = minX, Y = minY
            });

            do
            {
                currentZ = Math.Min(currentZ + stepZ, targetZ);
                commands.Add(new GCodeChangeZ {
                    Z = currentZ
                });

                while (true)
                {
                    currentY = fromTopToBottom ? maxY : minY;
                    commands.Add(new GCodeLine {
                        X = currentX, Y = currentY
                    });
                    fromTopToBottom = !fromTopToBottom;

                    if ((currentX == maxX && xDirection > 0) ||
                        (currentX == minX && xDirection < 0))
                    {
                        break;
                    }

                    currentX += xDirection * freeze.SpinSize / 2;
                    if (currentX > maxX)
                    {
                        currentX = maxX;
                    }
                    if (currentX < minX)
                    {
                        currentX = minX;
                    }

                    commands.Add(new GCodeLine {
                        X = currentX, Y = currentY
                    });
                }

                xDirection *= -1;
            }while (currentZ != targetZ);
            return(commands);
        }
コード例 #10
0
        private List <IGCodeMove> ProcessCubes(List <Cube> cubes, Layer layer, SpinOptions freeze, decimal targetZ, GCodeConfiguration config)
        {
            var commands = new List <IGCodeMove>();

            foreach (var cube in cubes)
            {
                commands.AddRange(GetCommandsForCube(cube, layer, freeze, targetZ, config));
                SetLayerPointsAsProcessed(layer, cube, config);
            }
            return(commands);
        }
コード例 #11
0
        private bool NeedToProcessCube(Layer layer, Cube cube, int totalWidth, int totalLength, GCodeConfiguration config)
        {
            for (int i = 0; i < cube.Width; i++)
            {
                for (int j = 0; j < cube.Length; j++)
                {
                    var xIndex = cube.X + i;
                    var yIndex = cube.Y + j;
                    if (xIndex < 0 || yIndex < 0 || xIndex >= totalWidth || yIndex >= totalLength)
                    {
                        continue;
                    }

                    var pointOfInterest = layer.Points[xIndex, yIndex];
                    if (!pointOfInterest.ShouldBeProcessed)
                    {
                        return(false);
                    }
                    if (i >= config.AdditionalPointsToOverflowCubesByWidth &&
                        j >= config.AdditionalPointsToOverflowCubesByLength &&
                        i < cube.Width - 2 * config.AdditionalPointsToOverflowCubesByWidth &&
                        j < cube.Length - 2 * config.AdditionalPointsToOverflowCubesByLength && pointOfInterest.ProcessedStatus != ProcessedStatus.NotProcessed)
                    {
                        return(false);
                    }
                }
            }
            return(true);
        }
コード例 #12
0
        private List <Cube> GetCubesToProcess(Layer layer, int cubeWidth, int cubeLength, GCodeConfiguration config)
        {
            var cubes       = new List <Cube>();
            var totalWidth  = layer.Points.GetLength(0);
            var totalLength = layer.Points.GetLength(1);

            for (int i = 0; i < totalWidth / cubeWidth; i++)
            {
                for (int j = 0; j < totalLength / cubeLength; j++)
                {
                    var cube = new Cube
                    {
                        X      = i * cubeWidth - config.AdditionalPointsToOverflowCubesByWidth,
                        Y      = j * cubeLength - config.AdditionalPointsToOverflowCubesByLength,
                        Width  = cubeWidth + 2 * config.AdditionalPointsToOverflowCubesByWidth,
                        Length = cubeLength + 2 * config.AdditionalPointsToOverflowCubesByLength
                    };

                    if (NeedToProcessCube(layer, cube, totalWidth, totalLength, config))
                    {
                        cubes.Add(cube);
                    }
                }
            }
            return(cubes);
        }