public static bool Run(bool print = false) { var poly = new Polygon(); // Generate the input geometry. poly.Add(Generate.Rectangle(0.0, 0.0, 1.0, 1.0)); // Set user test function. var quality = new QualityOptions() { UserTest = MaxEdgeLength }; // Generate mesh using the polygons Triangulate extension method. var mesh = (Mesh)poly.Triangulate(quality); // Validate. foreach (var e in EdgeIterator.EnumerateEdges(mesh)) { double length = Math.Sqrt(DistSqr(e.GetVertex(0), e.GetVertex(1))); if (length > MAX_EDGE_LENGTH) { return(false); } } if (print) { SvgImage.Save(mesh, "example-8.svg", 500); } return(true); }
public static void Run() { Console.WriteLine("Running example DrawRasterImageOnSVG"); // The path to the documents directory. string dataDir = RunExamples.GetDataDir_DrawingAndFormattingImages(); // Load the image to be drawn using (RasterImage imageToDraw = (RasterImage)Image.Load(dataDir + "asposenet_220_src01.png")) { // Load the image for drawing on it (drawing surface) using (SvgImage canvasImage = (SvgImage)Image.Load(dataDir + "asposenet_220_src02.svg")) { // Drawing on an existing Svg image. Aspose.Imaging.FileFormats.Svg.Graphics.SvgGraphics2D graphics = new Aspose.Imaging.FileFormats.Svg.Graphics.SvgGraphics2D(canvasImage); // Draw a rectagular part of the raster image within the specified bounds of the vector image (drawing surface). // Note that because the source size is equal to the destination one, the drawn image is not stretched. graphics.DrawImage( new Rectangle(0, 0, imageToDraw.Width, imageToDraw.Height), new Rectangle(67, 67, imageToDraw.Width, imageToDraw.Height), imageToDraw); // Save the result image using (SvgImage resultImage = graphics.EndRecording()) { resultImage.Save(dataDir + "asposenet_220_src02.DrawImage.svg"); } } } Console.WriteLine("Finished example DrawRasterImageOnSVG"); }
public static bool Run(bool print = false) { const int N = 50; // Generate point set. var points = Generate.RandomPoints(N, new Rectangle(0, 0, 100, 100)); // We use a polygon as input to enable segment insertion on the convex hull. var poly = new Polygon(N); poly.Points.AddRange(points); // Set the 'convex' option to enclose the convex hull with segments. var options = new ConstraintOptions() { Convex = true }; // Generate mesh. var mesh = poly.Triangulate(options); if (print) { SvgImage.Save(mesh, "example-2.svg", 500); } return(CheckConvexHull(mesh.Segments)); }
public static bool Run(bool print = false) { // The input domain. var r = new Rectangle(0d, 0d, 10d, 10d); var mesh = GetScatteredDataMesh(r); //var mesh = GetStructuredDataMesh(r); // Generate function values for mesh points. double[] data = GetFunctionValues(mesh.Vertices); if (print) { SvgImage.Save(mesh, "example-11.svg", 500); } // The points to interpolate. var xy = Generate.RandomPoints(50, r); var xyData = InterpolateData((Mesh)mesh, data, xy); double error = xy.Max(p => Math.Abs(xyData[p.ID] - F(p))); // L2 error //double error = Math.Sqrt(xy.Sum(p => Math.Pow(xyData[p.ID] - F(p), 2))); // Define tolerance dependent on mesh dimensions and size. double tolerance = 0.5 * Math.Max(r.Width, r.Height) / SIZE; return(error < tolerance); }
public static void Run() { // ExStart:ApplyingMotionWienerFilter // The path to the documents directory. string dataDir = RunExamples.GetDataDir_ModifyingAndConvertingImages(); // Load the image using (SvgImage image = (SvgImage)Image.Load(dataDir + "aspose_logo.Svg")) { // Create an instance of PNG options and Save the results to disk PngOptions pngOptions = new PngOptions(); image.Save(dataDir + "ConvertingSVGToRasterImages_out.png", pngOptions); } // ExEnd:ApplyingMotionWienerFilter }
public static void Run() { Console.WriteLine("Running example ConvertingSVGToRasterImages"); // The path to the documents directory. string dataDir = RunExamples.GetDataDir_ModifyingAndConvertingImages(); // Load the image using (SvgImage image = (SvgImage)Image.Load(dataDir + "aspose_logo.Svg")) { // Create an instance of PNG options and Save the results to disk PngOptions pngOptions = new PngOptions(); image.Save(dataDir + "ConvertingSVGToRasterImages_out.png", pngOptions); } Console.WriteLine("Finished example ConvertingSVGToRasterImages"); }
public static void Run() { Console.WriteLine("Running example DrawVectorImageToRasterImage"); // The path to the documents directory. string dataDir = RunExamples.GetDataDir_DrawingAndFormattingImages(); using (MemoryStream drawnImageStream = new MemoryStream()) { // First, rasterize Svg to Png and write the result to a stream. using (SvgImage svgImage = (SvgImage)Image.Load(dataDir + "asposenet_220_src02.svg")) { SvgRasterizationOptions rasterizationOptions = new SvgRasterizationOptions(); rasterizationOptions.PageSize = svgImage.Size; PngOptions saveOptions = new PngOptions(); saveOptions.VectorRasterizationOptions = rasterizationOptions; svgImage.Save(drawnImageStream, saveOptions); // Now load a Png image from stream for further drawing. drawnImageStream.Seek(0, System.IO.SeekOrigin.Begin); using (RasterImage imageToDraw = (RasterImage)Image.Load(drawnImageStream)) { // Drawing on the existing Svg image. Aspose.Imaging.FileFormats.Svg.Graphics.SvgGraphics2D graphics = new Aspose.Imaging.FileFormats.Svg.Graphics.SvgGraphics2D(svgImage); // Scale down the entire drawn image by 2 times and draw it to the center of the drawing surface. int width = imageToDraw.Width / 2; int height = imageToDraw.Height / 2; Point origin = new Point((svgImage.Width - width) / 2, (svgImage.Height - height) / 2); Size size = new Size(width, height); graphics.DrawImage(imageToDraw, origin, size); // Save the result image using (SvgImage resultImage = graphics.EndRecording()) { resultImage.Save(dataDir + "asposenet_220_src02.DrawVectorImage.svg"); } } } } Console.WriteLine("Finished example DrawVectorImageToRasterImage"); }
public static void Run() { // To get proper output please apply a valid Aspose.Imaging License. You can purchase full license or get 30 day temporary license from http:// Www.aspose.com/purchase/default.aspx."); // ExStart:ApplyingMotionWienerFilter // The path to the documents directory. string dataDir = RunExamples.GetDataDir_ModifyingAndConvertingImages(); // Load the image using (SvgImage image = (SvgImage)Image.Load(dataDir + "aspose_logo.Svg")) { // create an instance of PNG options PngOptions pngOptions = new PngOptions(); //Save the results to disk image.Save(dataDir + "ConvertingSVGToRasterImages_out.png", pngOptions); } // ExEnd:ApplyingMotionWienerFilter }
public static bool Run(bool print = false) { // Generate points. var points = Generate.RandomPoints(50, new Rectangle(0, 0, 100, 100)); // Choose triangulator: Incremental, SweepLine or Dwyer. var triangulator = new Dwyer(); // Generate mesh. var mesh = triangulator.Triangulate(points, new Configuration()); if (print) { SvgImage.Save(mesh, "example-1.svg", 500); } return(mesh.Triangles.Count > 0); }
public static void Run() { Console.WriteLine("Running example SvgNativeResize"); // The path to the documents directory. string dataDir = RunExamples.GetDataDir_ModifyingAndConvertingImages(); // Load the image using (SvgImage image = (SvgImage)Image.Load(dataDir + "aspose_logo.Svg")) { image.Resize(image.Width * 10, image.Height * 15); image.Save(dataDir + "Logotype_10_15_out.png", new PngOptions() { VectorRasterizationOptions = new SvgRasterizationOptions() }); } Console.WriteLine("Finished example SvgNativeResize"); }
public static bool Run(bool print = false) { // Generate the input geometry. var polygon = new Polygon(8, true); // Two intersecting rectangles. var A = Generate.Rectangle(0d, 0d, 4d, 4d, label: 1); var B = Generate.Rectangle(1d, 1d, 4d, 4d, label: 2); polygon.Add(A); polygon.Add(B); // Generate mesh. var mesh = (Mesh)polygon.Triangulate(); if (print) { SvgImage.Save(mesh, "example-7.svg", 500); } // Find a seeding triangle (in this case, the point (2, 2) lies in // both rectangles). var seed = (new TriangleQuadTree(mesh)).Query(2.0, 2.0) as Triangle; var iterator = new RegionIterator(mesh); iterator.Process(seed, t => t.Label ^= 1, 1); iterator.Process(seed, t => t.Label ^= 2, 2); // At this point, all triangles will have label 1, 2 or 3 (= 1 xor 2). // The intersection of A and B. var intersection = mesh.Triangles.Where(t => t.Label == 3); // The difference A \ B. var difference = mesh.Triangles.Where(t => t.Label == 1); // The xor of A and B. var xor = mesh.Triangles.Where(t => t.Label == 1 || t.Label == 2); return(intersection.Any() && difference.Any() && xor.Any()); }
public static bool Run(bool print = false) { var mesh = Example4.CreateMesh(); FindBoundary1(mesh); if (print) { SvgImage.Save(mesh, "example-6-1.svg", 500, true, false); } FindBoundary2(mesh); if (print) { SvgImage.Save(mesh, "example-6-2.svg", 500, true, false); } return(mesh.Triangles.Count > 0); }
public static bool Run(bool print = false) { // Generate the input geometry. var poly = CreatePolygon(); // Set minimum angle quality option. var quality = new QualityOptions() { MinimumAngle = 30.0 }; // Generate mesh using the polygons Triangulate extension method. var mesh = poly.Triangulate(quality); if (print) { SvgImage.Save(mesh, "example-3.svg", 500); } return(mesh.Triangles.Count > 0); }
public static bool Run(bool print = false) { // Generate mesh. var mesh = CreateMesh(); // The ideal area if triangles were equilateral. var area = Math.Sqrt(3) / 4 * h * h; var quality = new QualityMeasure(mesh); if (print) { Console.WriteLine($" Ideal area: {area}"); Console.WriteLine($" Min. area: {quality.AreaMinimum}"); Console.WriteLine($" Max. area: {quality.AreaMaximum}"); Console.WriteLine($" Avg. area: {quality.AreaTotal / mesh.Triangles.Count}"); SvgImage.Save(mesh, "example-4.svg", 500); } return(quality.AreaMinimum < area && quality.AreaMaximum > area); }
public static bool Run(bool print = false) { // Generate the input geometry. var poly = CreatePolygon(); // Define regions (first one defines the area constraint). poly.Regions.Add(new RegionPointer(1.5, 0.0, 1, 0.01)); poly.Regions.Add(new RegionPointer(2.5, 0.0, 2)); // Set quality and constraint options. var options = new ConstraintOptions() { ConformingDelaunay = true }; var quality = new QualityOptions() { MinimumAngle = 25.0, VariableArea = true }; //quality.UserTest = (t, area) => t.Label == 1 && area > 0.01; var mesh = poly.Triangulate(options, quality); var smoother = new SimpleSmoother(); smoother.Smooth(mesh, 5); if (print) { SvgImage.Save(mesh, "example-5.svg", 500); } return(mesh.Triangles.Count > 0); }