private void Generate() { try { totalHorzMaps = int.Parse(txHorz.Text); totalVertMaps = int.Parse(txVert.Text); } catch { MessageBox.Show("Invalid value(s) for 'No. Cells'."); return; } if (!initted) { GConnectionDialog gcd = new GConnectionDialog(); if (gcd.ShowDialog() == DialogResult.OK) { // initialise application ga = new GApplication(true); ga.ApplicationName = "Alchemi Fractal Generator - Alchemi sample"; ga.Connection = gcd.Connection; } else { return; } // set dependencies ga.Manifest.Add(new ModuleDependency(typeof(KarlsTools.Complex).Module)); ga.Manifest.Add(new ModuleDependency(typeof(MandelThread).Module)); // subscribe to events ga.ThreadFinish += new GThreadFinish(UpdateBitmap); ga.ApplicationFinish += new GApplicationFinish(AppDone); try { ga.Start(); } catch (Exception e) { MessageBox.Show(e.ToString()); } initted = true; } startTime = DateTime.Now; for (int mapNumX = 0; mapNumX < totalHorzMaps; mapNumX++) { for (int mapNumY = 0; mapNumY < totalVertMaps; mapNumY++) { MandelThread mandel = new MandelThread( mapNumX, mapNumY, width / totalHorzMaps, height / totalVertMaps, xOffset + mapNumX * width / totalHorzMaps, yOffset + mapNumY * height / totalVertMaps, zoom, pbColorOne.BackColor, pbColorTwo.BackColor ); //ga.Threads.Add(mandel); ga.StartThread(mandel); } } pb.Minimum = 0; pb.Value = 0; pb.Maximum = totalHorzMaps * totalVertMaps; }
private void render_Click(object sender, EventArgs e) { stop.Enabled = true; render.Enabled = !stop.Enabled; drawnFirstSegment = false; showSplash(); // model path modelPath = paths[modelCombo.SelectedIndex]; // get width and height from combo box imageWidth = Int32.Parse(widthCombo.SelectedItem.ToString()); imageHeight = Int32.Parse(heightCombo.SelectedItem.ToString()); // get cols and rows from up downs columns = Decimal.ToInt32(columnsUpDown.Value); rows = Decimal.ToInt32(rowsUpDown.Value); segmentWidth = imageWidth / columns; segmentHeight = imageHeight / rows; int x = 0; int y = 0; logger.Debug("WIDTH:" + imageWidth); logger.Debug("HEIGHT:" + imageHeight); logger.Debug("COLUMNS:" + columns); logger.Debug("ROWS:" + rows); logger.Debug("" + modelPath); // reset the display clearImage(); if (!initted) { GConnectionDialog gcd = new GConnectionDialog(); gcd.ShowDialog(); ga = new GApplication(true); ga.ApplicationName = "Alchemi POV-Ray Renderer - Alchemi sample"; ga.Connection = gcd.Connection; ga.ThreadFinish += new GThreadFinish(ga_ThreadFinish); ga.ThreadFailed += new GThreadFailed(ga_ThreadFailed); ga.ApplicationFinish += new GApplicationFinish(ga_ApplicationFinish); ga.Manifest.Add(new ModuleDependency(typeof(RenderThread).Module)); initted = true; } if (ga != null && ga.Running) { ga.Stop(); } pbar.Maximum = columns * rows; pbar.Minimum = 0; pbar.Value = 0; lbProgress.Text = "Starting to render image ... "; for (int col = 0; col < columns; col++) { for (int row = 0; row < rows; row++) { x = col * segmentWidth; y = row * segmentHeight; int startRowPixel = y + 1; int endRowPixel = y + segmentHeight; int startColPixel = x + 1; int endColPixel = x + segmentWidth; RenderThread rth = new RenderThread(modelPath, imageWidth, imageHeight, segmentWidth, segmentHeight, startRowPixel, endRowPixel, startColPixel, endColPixel, ""); rth.BasePath = this.basepath; rth.Col = col + 1; rth.Row = row + 1; ga.Threads.Add(rth); } } try { ga.Start(); } catch (Exception ex) { Console.WriteLine("" + ex.StackTrace); MessageBox.Show("Alchemi Rendering Failed!" + ex.ToString()); } lbProgress.Text = "Rendering image ... "; ShowBusyGif(); }