示例#1
0
        private void heightmapDemo(object sender, RoutedEventArgs e)
        {
            enable3dOutput();

            var toolDiameter = 5.0;
            var margin       = toolDiameter;
            var radius       = 50.0;

            var mapResolution = 0.2;
            var center        = new Point(margin + radius, margin + radius);
            var modelShape    = new ConeShape(center, radius);

            var mapStart = new Point(0, 0);
            var mapEnd   = new Point(mapStart.X + 2 * margin + 2 * radius, mapStart.Y + 2 * margin + 2 * radius);
            var model    = HeightMap.From(modelShape, mapStart, mapEnd, mapResolution);


            //simulate parallel machining
            var blockHeight   = radius + margin;
            var stock         = HeightMap.Flat(blockHeight, mapStart, mapEnd, mapResolution);
            var machiningStep = 1.0;
            var tool          = new BallnoseEndMill(toolDiameter);

            simulateLinearMachining(stock, tool, model, toolDiameter, machiningStep, true);
            simulateLinearMachining(stock, tool, model, toolDiameter, machiningStep, false);

            output3D(stock);
        }
示例#2
0
        private void simulateLinearMachining(HeightMap stock, BallnoseEndMill tool, HeightMap model, double toolDiameter, double machiningStep, bool useDirX)
        {
            var machiningMargin = toolDiameter;
            var toolX           = -machiningMargin;
            var toolY           = -machiningMargin;
            var mapEnd          = stock.End;
            var mapStepSize     = stock.StepSize;
            var toolConvolution = tool.AsConvolution(mapStepSize);

            var resolutionStep = mapStepSize * 0.999;

            if (useDirX)
            {
                while (toolX < mapEnd.X + machiningMargin)
                {
                    toolY = -machiningMargin;

                    while (toolY < mapEnd.Y + machiningMargin)
                    {
                        var machinedPoint    = new Point(toolX, toolY);
                        var convolutedHeight = model.GetMaxAddConvolution(machinedPoint, toolConvolution);
                        var offset           = convolutedHeight; //(blockHeight - convolutedHeight);

                        if (!double.IsInfinity(offset))
                        {
                            stock.ApplyMinSubConvolution(machinedPoint, offset, toolConvolution);
                        }

                        toolY += resolutionStep;
                    }
                    toolX += machiningStep;
                }
            }
            else
            {
                while (toolY < mapEnd.Y + machiningMargin)
                {
                    toolX = -machiningMargin;

                    while (toolX < mapEnd.X + machiningMargin)
                    {
                        var machinedPoint    = new Point(toolX, toolY);
                        var convolutedHeight = model.GetMaxAddConvolution(machinedPoint, toolConvolution);
                        var offset           = convolutedHeight; //(blockHeight - convolutedHeight);

                        if (!double.IsInfinity(offset))
                        {
                            stock.ApplyMinSubConvolution(machinedPoint, offset, toolConvolution);
                        }

                        toolX += resolutionStep;
                    }
                    toolY += machiningStep;
                }
            }
        }