static void Main(string[] args) { Console.WriteLine("----------------------------------"); Console.WriteLine("JPG Outline to STL Conversion Tool"); Console.WriteLine("----------------------------------\n"); Program program = new Program(); Console.WriteLine("Enter a path to a '.jpg' file:"); string userFile = Console.ReadLine(); Console.WriteLine("Enter a destination path for the '.stl' file:"); string destFile = Console.ReadLine(); Console.WriteLine(); //Get image from filepath program.img = new Bitmap(userFile); program.pixelArray = new char[program.img.Height, program.img.Width]; program.outlinePoints = new ArrayList(); //Read in all pixels from image, store in array program.readInPixels(); Point startCoords = program.searchForStart(); if (startCoords == null) { Console.Write("No graphic found"); Console.ReadKey(); System.Environment.Exit(1); } Point endCoords = new Point(startCoords.getX(), startCoords.getY()); program.createOutline(startCoords, endCoords); //program.debugDraw(); program.createSTL(destFile); Console.Write("File Creation Complete"); Console.ReadKey(); }
//Mark outline points of shape private void createOutline(Point startCoords, Point endCoords) { Console.WriteLine("Processing..."); do { //Define surrounding 8 pixels char[] kernel = new char[8]; kernel[0] = pixelArray[(int)startCoords.getX() - 1, (int)startCoords.getY() - 1]; kernel[1] = pixelArray[(int)startCoords.getX() - 1, (int)startCoords.getY() + 0]; kernel[2] = pixelArray[(int)startCoords.getX() - 1, (int)startCoords.getY() + 1]; kernel[3] = pixelArray[(int)startCoords.getX() + 0, (int)startCoords.getY() + 1]; kernel[4] = pixelArray[(int)startCoords.getX() + 1, (int)startCoords.getY() + 1]; kernel[5] = pixelArray[(int)startCoords.getX() + 1, (int)startCoords.getY() + 0]; kernel[6] = pixelArray[(int)startCoords.getX() + 1, (int)startCoords.getY() - 1]; kernel[7] = pixelArray[(int)startCoords.getX() + 0, (int)startCoords.getY() - 1]; //Define locations of surrounding 8 pixels Point[] kernelLocations = new Point[8]; kernelLocations[0] = new Point(startCoords.getX() - 1, startCoords.getY() - 1); kernelLocations[1] = new Point(startCoords.getX() - 1, startCoords.getY() + 0); kernelLocations[2] = new Point(startCoords.getX() - 1, startCoords.getY() + 1); kernelLocations[3] = new Point(startCoords.getX() + 0, startCoords.getY() + 1); kernelLocations[4] = new Point(startCoords.getX() + 1, startCoords.getY() + 1); kernelLocations[5] = new Point(startCoords.getX() + 1, startCoords.getY() + 0); kernelLocations[6] = new Point(startCoords.getX() + 1, startCoords.getY() - 1); kernelLocations[7] = new Point(startCoords.getX() + 0, startCoords.getY() - 1); //Search for barrier int i = 0; while (kernel[i] != '0') { i++; if (i == 8) { i = 0; } } //Search for clockwise exit edge of barrier while (kernel[i] != ' ') { i++; if (i == 8) { i = 0; } } //Search for clockwise entrance edge of barrier while (kernel[i] != '0') { i++; if (i == 8) { i = 0; } } i--; if (i == -1) { i = 7; } //Mark location for debugging pixelArray[(int)kernelLocations[i].getX(), (int)kernelLocations[i].getY()] = '*'; //Set new start coordinates to found location startCoords = kernelLocations[i]; outlinePoints.Add(new Point(startCoords.getX(), startCoords.getY())); } while (!(startCoords.getX() == endCoords.getX() && startCoords.getY() == endCoords.getY())); //if (startCoords.getX() == endCoords.getX() && startCoords.getY() == endCoords.getY()) //{ // return; //} return; //createOutline(startCoords, endCoords); }