IEnumerator UpdateTerrainCoroutine() { var heights = new float[terrainData.heightmapWidth, terrainData.heightmapHeight]; while (true) { renderArea *= 0.98; var startX = baseX - renderArea / 2.0; var startY = baseY - renderArea / 2.0; var renderAreaPerWidth = renderArea / terrainData.heightmapWidth; var renderAreaPerHeight = renderArea / terrainData.heightmapHeight; for (int x = 0; x < terrainData.heightmapWidth; x++) { for (int y = 0; y < terrainData.heightmapHeight; y++) { heights[x, y] = MandelbrotCalculator.Calculate( startX + x * renderAreaPerWidth, startY + y * renderAreaPerHeight); heights[x, y] = heights[x, y] / 10; } } terrainData.SetHeights(0, 0, heights); yield return(null); } }
private void RenderMandelbrotSet() { using (new WaitCursor()) { if (_currentSelectedViewPort != null) { _viewPortHistory.Push(_currentSelectedViewPort); _currentSelectedViewPort = null; } var size = GetImageSize(); var iterationsToCheck = GetIterations(); CurrentGraph = new Graph( size.Width, size.Height, CurrentViewPort, iterationsToCheck); MandelbrotCalculator.renderSet(iterationsToCheck, CurrentGraph); var imageSource = BitmapToImageSource(CurrentGraph.Bitmap); canvas.CanvasImageSource = imageSource; _dragRectangle.Visibility = Visibility.Hidden; canvas.InvalidateVisual(); } }
public static async Task Main(string[] args) { if (args.Length != 1) { throw new ArgumentException($"Illegal number of arguments. Expected: 1, Got {args.Length}"); } var sizeFactor = uint.Parse(args[0]); var width = 1_980 * sizeFactor; var height = 1_020 * sizeFactor; var api = new NativeOpenClApi(); var factory = new PlatformFactory(api); var platforms = factory.GetPlatforms().ToArray(); var platform = platforms[0]; System.Console.WriteLine($"{platform.Id} - {platform.Vendor}"); var ctx = platform.CreateContext(platform.Devices); ctx.Notification += CtxOnNotification; var device = ctx.Devices.First(); //var image = MandelbrotCalculator.Calculate(ctx, device, width, height); var image = await MandelbrotCalculator.CalculateAsync(ctx, device, width, height); SaveBitmap("mandelbrot", (int)width, (int)height, image.ToArray()); ctx.Dispose(); System.Console.WriteLine("--- Finished ---"); }
static void Main(string[] args) { Console.WriteLine("====== WORKER ======"); var sinkPort = ConfigurationManager.AppSettings.Get("sinkPort") ?? "8088"; var ventilatorPort = ConfigurationManager.AppSettings.Get("ventilatorPort") ?? "400"; using (var receiver = new PullSocket($">tcp://localhost:{sinkPort}")) using (var sender = new PushSocket($">tcp://localhost:{ventilatorPort}")) { while (true) { string workload = receiver.ReceiveFrameString(); // the protocoll is as follows: [0] -> lower, [1] -> upper, [2] -> height string[] workLoadArray = workload.Split(','); var calculator = new MandelbrotCalculator(); var result = calculator.Calculate(Convert.ToInt32(workLoadArray[2]), 400, Convert.ToInt32(workLoadArray[0]), Convert.ToInt32(workLoadArray[1])); byte[] data; BinaryFormatter binaryFormatter = new BinaryFormatter(); using (var memoryStream = new MemoryStream()) { binaryFormatter.Serialize(memoryStream, result); data = memoryStream.ToArray(); } Console.WriteLine("Sending"); sender.SendFrame(data); } } }
public IReadOnlyCollection <byte> Compute() { var api = new NativeOpenClApi(); var factory = new PlatformFactory(api); var platform = factory.GetPlatforms().First(f => f.Devices.Count == 1); var ctx = platform.CreateContext(platform.Devices); var device = ctx.Devices.Single(); //Using synchronous calculation, since the MemoryDiagnoser is only able to fetch memory allocations by one thread var result = MandelbrotCalculator.Calculate(ctx, device, ActualWidth, ActualHeight); ctx.Dispose(); return(result); }
public ActionResult <TripleResult> CalculationRequest([FromBody] CalculationRequest calculationRequest) { var calculator = new MandelbrotCalculator(); var result = calculator.Calculate(calculationRequest.Height, calculationRequest.Width); var resultDto = result.Select(item => new TripleResult() { X = item.Item1, Y = item.Item2, Iteration = item.Item3 }).ToList(); //var resultDto = result.Select(item => new TripleResultNew() //{ // Result = item //}).ToList(); return(Ok(resultDto)); }