コード例 #1
0
ファイル: MainWindow.xaml.cs プロジェクト: eviltak/DLAProject
        /// <summary>
        /// Generates a Diffusion Limited Aggregate with properties initialised by
        /// current values of sliders and combo-boxes in the UI. Should be called
        /// in a separate thread.
        /// </summary>
        private void GenerateAggregate()
        {
            hasFinished = false;
            uint particle_slider_val = 0;

            // dispatch the particles_slider value access code to UI thread
            Dispatcher.Invoke(() => {
                particle_slider_val = (uint)particles_slider.Value;
            });
            // start asynchronous task calling AggregateUpdateListener to perform rendering
            Task.Factory.StartNew(() => AggregateUpdateListener(particle_slider_val));
            // generate the DLA using value of particle slider
            switch (lattice_dimension)
            {
            case LatticeDimension._2D:
                dla_2d.Generate(particle_slider_val);
                break;

            case LatticeDimension._3D:
                dla_3d.Generate(particle_slider_val);
                break;
            }
            hasFinished = true;
        }
コード例 #2
0
        /// <summary>
        /// Performs CPU intensive work, computing the build-up of an aggregate of `nparticles`
        /// through calling the DLAClassLibrary c++ code. This method should be called in a
        /// separate worker thread.
        /// </summary>
        /// <param name="nparticles">Number of particles in aggregate to produce.</param>
        private void CallNativeCppAggregateGenerators(uint nparticles)
        {
            Timer    simulation_timer = new Timer(25); // create timer for simulation routine
            DateTime startDT          = DateTime.Now;

            simulation_timer.Elapsed  += (source, e) => OnSimulationTimerUpdateEvent(source, e, startDT);
            simulation_timer.AutoReset = true;
            simulation_timer.Enabled   = true;
            // call native c++ code to generate aggregate data structures
            switch (current_executing_dimension)
            {
            case LatticeDimension._2D:
                dla_2d.Generate(nparticles);
                break;

            case LatticeDimension._3D:
                dla_3d.Generate(nparticles);
                break;
            }
            simulation_timer.Stop();
            hasFinished            = true;
            saveCurrentChartSeries = false;
            Dispatcher.Invoke(() => { compare_button.IsEnabled = true; });
        }