private void GenerateIsideCache() { int width = (int)Round(polygonBounds.Width() / unitsPerPixel); int height = (int)Round(polygonBounds.Height() / unitsPerPixel); DistanceFromOutside = new ImageBuffer(width + 4, height + 4, 8, new blender_gray(1)); // Set the transform to image space polygonsToImageTransform = Affine.NewIdentity(); // move it to 0, 0 polygonsToImageTransform *= Affine.NewTranslation(-polygonBounds.minX, -polygonBounds.minY); // scale to fit cache polygonsToImageTransform *= Affine.NewScaling(width / (double)polygonBounds.Width(), height / (double)polygonBounds.Height()); // and move it in 2 pixels polygonsToImageTransform *= Affine.NewTranslation(2, 2); // and render the polygon to the image DistanceFromOutside.NewGraphics2D().Render(new VertexSourceApplyTransform(CreatePathStorage(Polygons), polygonsToImageTransform), Color.White); // Now lets create an image that we can use to move points inside the outline // First create an image that is fully set on all color values of the original image DistanceFromOutside.DoThreshold(1); //var image32 = new ImageBuffer(InsetMap.Width, InsetMap.Height); //image32.NewGraphics2D().Render(InsetMap, 0, 0); //ImageTgaIO.Save(image32, "c:\\temp\\before.tga"); CalculateDistance(DistanceFromOutside); //image32.NewGraphics2D().Render(InsetMap, 0, 0); //ImageTgaIO.Save(image32, "c:\\temp\\test.tga"); }
private void GenerateIsideCache() { int width = (int)Round(polygonBounds.Width() / unitsPerPixel); int height = (int)Round(polygonBounds.Height() / unitsPerPixel); InsideCache = new ImageBuffer(width + 4, height + 4, 8, new blender_gray(1)); // Set the transform to image space polygonsToImageTransform = Affine.NewIdentity(); // move it to 0, 0 polygonsToImageTransform *= Affine.NewTranslation(-polygonBounds.minX, -polygonBounds.minY); // scale to fit cache polygonsToImageTransform *= Affine.NewScaling(width / (double)polygonBounds.Width(), height / (double)polygonBounds.Height()); // and move it in 2 pixels polygonsToImageTransform *= Affine.NewTranslation(2, 2); // and render the polygon to the image InsideCache.NewGraphics2D().Render(new VertexSourceApplyTransform(CreatePathStorage(Polygons), polygonsToImageTransform), Color.White); // Now lets create an image that we can use to move points inside the outline // First create an image that is fully set on all color values of the original image InsetMap = new ImageBuffer(InsideCache); InsetMap.DoThreshold(1); // Then erode the image multiple times to get the a map of desired insets int count = 8; int step = 255 / count; ImageBuffer last = InsetMap; for (int i = 0; i < count; i++) { var erode = new ImageBuffer(last); erode.DoErode3x3Binary(255); Paint(InsetMap, erode, (i + 1) * step); last = erode; } }