public void CsPotrace_Export2GCode_Export2GCode_0010() { using var bmp = PotraceTraceTests.getSquare(); var trace = new Potrace().PotraceTrace(bmp); // Image size is only used for DEBUG (static variable hardocded to FALSE) var gcodeLines = Potrace.Export2GCode(trace, 0, 0, 10, "ON", "OFF", bmp.Size); Assert.Equal(11, gcodeLines.Count); Assert.Equal("G0 X0.2 Y0.5", gcodeLines[0]); Assert.Equal("ON", gcodeLines[1]); Assert.Equal("G1 X0.288 Y0.712", gcodeLines[2]); Assert.Equal("G2 X0.5 Y0.8 I0.212 J-0.212", gcodeLines[3]); Assert.Equal("G2 X0.712 Y0.712 I0 J-0.3", gcodeLines[4]); Assert.Equal("G1 X0.8 Y0.5", gcodeLines[5]); Assert.Equal("G1 X0.712 Y0.288", gcodeLines[6]); Assert.Equal("G2 X0.5 Y0.2 I-0.212 J0.212", gcodeLines[7]); Assert.Equal("G2 X0.288 Y0.288 I0 J0.3", gcodeLines[8]); Assert.Equal("G1 X0.2 Y0.5", gcodeLines[9]); Assert.Equal("OFF", gcodeLines[10]); }
public void CsPotrace_Export2GCode_Export2GCode_N5520() { using var bmp = PotraceTraceTests.getSquare(); var trace = new Potrace().PotraceTrace(bmp); // Image size is only used for DEBUG (static variable hardocded to FALSE) var gcodeLines = Potrace.Export2GCode(trace, -5, -5, 20, "ON", "OFF", bmp.Size); Assert.Equal(11, gcodeLines.Count); Assert.Equal("G0 X-4.9 Y-4.75", gcodeLines[0]); Assert.Equal("ON", gcodeLines[1]); Assert.Equal("G1 X-4.856 Y-4.644", gcodeLines[2]); Assert.Equal("G2 X-4.75 Y-4.6 I0.106 J-0.106", gcodeLines[3]); Assert.Equal("G2 X-4.644 Y-4.644 I0 J-0.15", gcodeLines[4]); Assert.Equal("G1 X-4.6 Y-4.75", gcodeLines[5]); Assert.Equal("G1 X-4.644 Y-4.856", gcodeLines[6]); Assert.Equal("G2 X-4.75 Y-4.9 I-0.106 J0.106", gcodeLines[7]); Assert.Equal("G2 X-4.856 Y-4.856 I0 J0.15", gcodeLines[8]); Assert.Equal("G1 X-4.9 Y-4.75", gcodeLines[9]); Assert.Equal("OFF", gcodeLines[10]); }
public void LoadImagePotrace(Bitmap bmp, string filename, bool UseSpotRemoval, int SpotRemoval, bool UseSmoothing, decimal Smoothing, bool UseOptimize, decimal Optimize, L2LConf c) { bmp.RotateFlip(RotateFlipType.RotateNoneFlipY); long start = Tools.HiResTimer.TotalMilliseconds; mTotalTravelOff = 0; mTotalTravelOn = 0; mEstimatedTimeOff = TimeSpan.Zero; mEstimatedTimeOn = TimeSpan.Zero; list.Clear(); mRange.ResetRange(); Potrace.turdsize = (int)(UseSpotRemoval ? SpotRemoval : 2); Potrace.alphamax = UseSmoothing ? (double)Smoothing : 0.0; Potrace.opttolerance = UseOptimize ? (double)Optimize : 0.2; Potrace.curveoptimizing = UseOptimize; //optimize the path p, replacing sequences of Bezier segments by a single segment when possible. List <List <CsPotrace.Curve> > plist = Potrace.PotraceTrace(bmp); if (c.dir != RasterConverter.ImageProcessor.Direction.None) { using (Bitmap ptb = new Bitmap(bmp.Width, bmp.Height)) { using (Graphics g = Graphics.FromImage(ptb)) { //Potrace.Export2GDIPlus(plist, g, Brushes.Black, null, (Math.Max(c.res/c.fres, 1) + 1) / 2.0f); Potrace.Export2GDIPlus(plist, g, Brushes.Black, null, Math.Max(1, c.res / c.fres)); using (Bitmap resampled = RasterConverter.ImageTransform.ResizeImage(ptb, new Size((int)(bmp.Width * c.fres / c.res), (int)(bmp.Height * c.fres / c.res)), true, InterpolationMode.HighQualityBicubic)) { //absolute list.Add(new GrblCommand("G90")); //use travel speed list.Add(new GrblCommand(String.Format("F{0}", c.travelSpeed))); //move fast to offset list.Add(new GrblCommand(String.Format("G0 X{0} Y{1}", formatnumber(c.oX), formatnumber(c.oY)))); if (c.pwm) { list.Add(new GrblCommand(String.Format("{0} S0", c.lOn))); //laser on and power to zero } else { list.Add(new GrblCommand(String.Format("{0} S255", c.lOff))); //laser off and power to max power } //set speed to markspeed list.Add(new GrblCommand(String.Format("G1 F{0}", c.markSpeed))); //relative list.Add(new GrblCommand("G91")); c.vectorfilling = true; ImageLine2Line(resampled, c); //laser off list.Add(new GrblCommand(c.lOff)); } } } } //absolute list.Add(new GrblCommand("G90")); //use travel speed list.Add(new GrblCommand(String.Format("F{0}", c.travelSpeed))); //move fast to offset list.Add(new GrblCommand(String.Format("G0 X{0} Y{1}", formatnumber(c.oX), formatnumber(c.oY)))); //laser off and power to maxPower list.Add(new GrblCommand(String.Format("{0} S{1}", c.lOff, c.maxPower))); //set speed to borderspeed list.Add(new GrblCommand(String.Format("G1 F{0}", c.borderSpeed))); //trace borders List <string> gc = Potrace.Export2GCode(plist, c.oX, c.oY, c.res, c.lOn, c.lOff, bmp.Size); foreach (string code in gc) { list.Add(new GrblCommand(code)); } //laser off list.Add(new GrblCommand(String.Format("{0}", c.lOff))); //move fast to origin list.Add(new GrblCommand("G0 X0 Y0")); Analyze(); long elapsed = Tools.HiResTimer.TotalMilliseconds - start; if (OnFileLoaded != null) { OnFileLoaded(elapsed, filename); } }
public void LoadImagePotrace(Bitmap bmp, string filename, bool UseSpotRemoval, int SpotRemoval, bool UseSmoothing, decimal Smoothing, bool UseOptimize, decimal Optimize, bool useOptimizeFast, L2LConf c, bool append) { RiseOnFileLoading(filename); bmp.RotateFlip(RotateFlipType.RotateNoneFlipY); DateTime start = DateTime.Now; if (!append) { list.Clear(); } Potrace potrace = new Potrace(); //list.Add(new GrblCommand("G90")); //absolute (Moved to custom Header) mRange.ResetRange(); potrace.turdsize = (int)(UseSpotRemoval ? SpotRemoval : 2); potrace.alphamax = UseSmoothing ? (double)Smoothing : 0.0; potrace.opttolerance = UseOptimize ? (double)Optimize : 0.2; potrace.curveoptimizing = UseOptimize; //optimize the path p, replacing sequences of Bezier segments by a single segment when possible. List <List <Curve> > plist = potrace.PotraceTrace(bmp); if (c.dir != RasterConverter.Direction.None) { using (Bitmap ptb = new Bitmap(bmp.Width, bmp.Height)) { using (Graphics g = Graphics.FromImage(ptb)) { //Potrace.Export2GDIPlus(plist, g, Brushes.Black, null, (Math.Max(c.res/c.fres, 1) + 1) / 2.0f); Potrace.Export2GDIPlus(plist, g, Brushes.Black, null, Math.Max(1, c.res / c.fres)); using (Bitmap resampled = RasterConverter.ImageTransform.ResizeImage(ptb, new Size((int)(bmp.Width * c.fres / c.res), (int)(bmp.Height * c.fres / c.res)), true, InterpolationMode.HighQualityBicubic)) { if (c.pwm) { list.Add(new GrblCommand(String.Format("{0} S0", c.lOn))); //laser on and power to zero } else { list.Add(new GrblCommand(String.Format("{0} S255", c.lOff))); //laser off and power to max power } //set speed to markspeed // For marlin, need to specify G1 each time : // list.Add(new GrblCommand(String.Format("G1 F{0}", c.markSpeed))); list.Add(new GrblCommand(String.Format("F{0}", c.markSpeed))); c.vectorfilling = true; ImageLine2Line(resampled, c); //laser off list.Add(new GrblCommand(c.lOff)); } } } } //Optimize fast movement if (useOptimizeFast) { plist = OptimizePaths(plist); } //laser off and power to maxPower list.Add(new GrblCommand(String.Format("{0} S{1}", c.lOff, c.maxPower))); //set speed to borderspeed // For marlin, need to specify G1 each time : //list.Add(new GrblCommand(String.Format("G1 F{0}", c.borderSpeed))); list.Add(new GrblCommand(String.Format("F{0}", c.borderSpeed))); //trace borders List <string> gc = Potrace.Export2GCode(plist, c.oX, c.oY, c.res, c.lOn, c.lOff, bmp.Size); foreach (string code in gc) { list.Add(new GrblCommand(code)); } //laser off (superflua??) //list.Add(new GrblCommand(String.Format("{0}", c.lOff))); Analyze(); long elapsed = (long)(DateTime.Now - start).TotalMilliseconds; RiseOnFileLoaded(filename, elapsed); }