public void startRendering(Scene scene, Display display)
        {
            scene.prepareForRender();

            m_imageSampler.setScene(scene);

            m_imageSampler.startTracing(display);
        }
        public BucketWorker(Rectangle imgPlaneRect, Rectangle bucketRect, Display display, IPixelSampler pixelSampler, Scene scene, ManualResetEvent doneEvent)
        {
            _doneEvent = doneEvent;

            m_pixelSampler = pixelSampler;
            m_scene = scene;
            m_imgPlaneRect = imgPlaneRect;
            m_bucketRect = bucketRect;
            m_bucketRect.Intersect(imgPlaneRect);
            m_display = display;
        }
        void RenderButtonClick(object sender, EventArgs e)
        {
            OpenFileDialog openDialog = new OpenFileDialog();
            openDialog.DefaultExt = "scene";
            openDialog.Filter = "Scene files (*.scene)|*.scene|" + "All files|*.*";

            if (openDialog.ShowDialog() == DialogResult.OK)
            {
                m_display = new Display();
                m_display.onImageUpdate += onImageUpdateHandler;

                SmartThreadPool smartThreadPool = new SmartThreadPool();

                RaytracerMainThread renderThread = new RaytracerMainThread(openDialog.FileName, m_display);
                smartThreadPool.QueueWorkItem(new WorkItemCallback(renderThread.ThreadPoolCallback));
            }
        }
        public void startRaytracing( Display display )
        {
            scene.setBackgroundColor(new Color3(0.6, 0.6, 0.6));

            try
            {
                IntegratorMain integrator = new IntegratorMain();
                PixelSamplerOne pixelSampler = new PixelSamplerOne(integrator);
                ImageSamplerBuckets imageSampler = new ImageSamplerBuckets(pixelSampler);
                RendrerBase renderer = new RendrerBase(imageSampler);

                renderer.startRendering( scene, display);
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine(e.Message);
            }
        }
        private void startRaytracingThreading(Display display)
        {
            Rectangle imgPlaneRect = new Rectangle(0, 0, m_scene.globalSettings.imageWidth, m_scene.globalSettings.imageHeight);

            int cellWidth = m_scene.globalSettings.bucketWidth;
            int cellHeight = m_scene.globalSettings.bucketHeight;

            List<Rectangle> bucketsRect = new List<Rectangle>();
            List<Bitmap> bucketsBmp = new List<Bitmap>();

            int maxRows = (int)System.Math.Ceiling((float)imgPlaneRect.Height / (float)cellHeight);
            int maxCol = (int)System.Math.Ceiling((float)imgPlaneRect.Width / (float)cellWidth);

            if ((maxRows % 2) > 0)
                maxRows++;

            if ((maxCol % 2) > 0)
                maxCol++;

            ManualResetEvent[] doneEvents = new ManualResetEvent[maxRows*maxCol];
            int bucketID = 0;

            // Create an instance of the Smart Thread Pool
            SmartThreadPool smartThreadPool = new SmartThreadPool();
            smartThreadPool.MaxThreads = m_scene.globalSettings.maxTreadsCount;

            Rectangle[] buckets;
            IBucketOrder bucketOrderer = new RowBucketOrder();
            bucketOrderer.getBucketSequence(cellWidth, cellHeight, maxCol, maxRows, out buckets);

            foreach (var bucketRect in buckets) {
                doneEvents[bucketID] = new ManualResetEvent(false);
                BucketWorker f = new BucketWorker(imgPlaneRect, bucketRect, display, m_pixelSampler, m_scene, doneEvents[bucketID]);
                smartThreadPool.QueueWorkItem(new WorkItemCallback(f.ThreadPoolCallback), bucketID);
                bucketID++;
            }

            smartThreadPool.WaitForIdle();
        }
 public void startTracing(Display display)
 {
     display.imageBegin(m_scene.globalSettings.imageWidth, m_scene.globalSettings.imageHeight);
     this.startRaytracingThreading( display );
 }
 public RaytracerMainThread(string sceneFileName, Display display)
 {
     m_sceneFileName = sceneFileName;
     m_display = display;
 }