Пример #1
0
        private void button2_Click(object sender, EventArgs e)
        {
            if (scanRunning == 0)
            {
                scanRunning = 1;

                button2.Text = "Abort scan";
                button2.BackColor = Color.Red;
                button2.ForeColor = Color.White;
                button2.Click -= this.button2_Click;
                button2.Click += new System.EventHandler(this.abortScan);

                // MethodInvoker calculationDelegate = new MethodInvoker(Calculate);
                // IAsyncResult tag = calculationDelegate.BeginInvoke(sender, e, null, null);

                //int allOk = 1;
                // Proceed with the scan only if there is an image (sample) loaded
                if (imageLoaded)
                {
                    // Measure execution time
                    watch = new System.Diagnostics.Stopwatch();
                    watch.Reset();
                    watch.Start();

                    // If dimensions are different from the original image and "just files" is not checked, resize the
                    //try
                    //{
                    if ((int)numericUpDown5.Value * (int)numericUpDown6.Value > 25000000)
                    {
                        if (MessageBox.Show("You are risking an out of memory exception! \n\n By clicking OK you will accept the risk and the model will run with the current parameters. \n\n By clicking Cancel the width and height paramerers will be set to 5000 by 5000 micrometers.", "Risk of running out of memory", MessageBoxButtons.OKCancel) == DialogResult.Cancel)
                        {
                            numericUpDown5.Value = 5000;
                            numericUpDown6.Value = 5000;
                        }
                    }
                    if (!radioButton2.Checked && (((int)numericUpDown5.Value != sampleImage.Width) || ((int)numericUpDown6.Value != sampleImage.Height)))
                    {
                        try
                        {
                            resizedSampleImage = Utilities.ResizeBitmap(sampleImage, (int)numericUpDown5.Value, (int)numericUpDown6.Value);
                            pictureBox1.Image = resizedSampleImage;

                            // Convert to 2D array
                            matrix1 = Utilities.imageTo2DArray(ref resizedSampleImage);
                        }
                        catch (OutOfMemoryException ex)
                        {
                            MessageBox.Show(this, "Out of memory exception has occured during resizing of the image. \n 1. Try using smaller theoretical sample dimensions, \n 2. Try using faster scanning speeds, \n 3. Try using bigger beam diameters, \n 4. Try using lower frequencies \n 5. Try using bigger acquisition times. \n \n If nothing above works, set the settings to their default values.", "Out of Memory tips.");
                            scanRunning = 0;
                            button2.Text = "Run";
                            button2.BackColor = Color.Transparent;
                            button2.ForeColor = Color.Black;
                            button2.Click -= this.abortScan;
                            button2.Click += new System.EventHandler(this.button2_Click);
                            pictureBox1.Image = sampleImage;
                            pictureBox1.Show();
                        }

                    }
                    else
                    {
                        try
                        {
                            matrix1 = Utilities.imageTo2DArray(ref sampleImage);
                        }
                        catch (OutOfMemoryException ex)
                        {
                            MessageBox.Show(this, "Out of memory exception has occured during conversion of image to array. \n 1. Try using smaller theoretical sample dimensions, \n 2. Try using faster scanning speeds, \n 3. Try using bigger beam diameters, \n 4. Try using lower frequencies \n 5. Try using bigger acquisition times. \n \n If nothing above works, set the settings to their default values.", "Out of Memory tips.");
                            scanRunning = 0;
                            button2.Text = "Run";
                            button2.BackColor = Color.Transparent;
                            button2.ForeColor = Color.Black;
                            button2.Click -= this.abortScan;
                            button2.Click += new System.EventHandler(this.button2_Click);
                            pictureBox1.Image = sampleImage;
                            pictureBox1.Show();
                        }
                    }
                    if (scanRunning == 1)
                    {
                        if (radioButton10.Checked) // Convert to optical density
                        {
                            for (int i = 0; i < matrix1.GetLength(0); i++)
                            {
                                for (int j = 0; j < matrix1.GetLength(1); j++)
                                {
                                    if (matrix1[i, j] == 0) { matrix1[i, j] = 1; }
                                    matrix1[i, j] = (int)Math.Round(255.0 * (Math.Log10(255.0 / (double)matrix1[i, j]) / Math.Log10(255.0 / 1.0)));
                                }
                            }
                        }
                        else
                        {
                            for (int i = 0; i < matrix1.GetLength(0); i++)
                            {
                                for (int j = 0; j < matrix1.GetLength(1); j++)
                                {
                                    matrix1[i, j] = 255 - matrix1[i, j];
                                }
                            }
                        }

                        //}
                        //catch (OutOfMemoryException ex)
                        //{
                        //MessageBox.Show(this, "Out of memory exception has occured. Try using smaller theoretical sample dimensions.", "Out of memory");
                        //    allOk = 0;
                        //}
                        // If everything is ok and no exception has occured, then continue with the simulation
                        // Prepare the form for display of progress bar
                        pictureBox1.Hide();
                        Refresh();
                        label12.Visible = true;
                        progressBar1.Visible = true;
                        label13.Visible = true;

                        // Laser laser1 = new Laser(scanSpeed, laserBeamSize, laserFrequency, laserPower, chamberVolume, gasFlow, sampleMatrix);
                        int laserBeamSize = (int)numericUpDown1.Value;

                        // Validate laserBeamSize for round beam == must be divisible by 2.
                        if (radioButton6.Checked && (laserBeamSize % 2 != 0))
                        {
                            laserBeamSize = laserBeamSize + 1;
                        }

                        int lineSpacing = (int)numericUpDown2.Value;
                        int laserFrequency = (int)numericUpDown3.Value;
                        int scanSpeed = (int)numericUpDown4.Value;
                        int chamberVolume = (int)numericUpDown7.Value;
                        int gasFlow = (int)numericUpDown8.Value;
                        double ablationNoise = (double)numericUpDown10.Value;
                        double transferNoise = (double)numericUpDown12.Value;
                        double detectorNoise = (double)numericUpDown13.Value;

                        double acqTime = (double)numericUpDown9.Value;
                        bool beamShape = false;
                        if (radioButton6.Checked) beamShape = true;
                        bool thinSample = false;
                        bool thickSample = false;
                        if (radioButton11.Checked) { thinSample = true; thickSample = false; }
                        int numberOfShots = (int)numericUpDown11.Value;

                        if (radioButton7.Checked) { thickSample = true; thinSample = false; }

                        laicpms1 = new LAICPMS(scanSpeed, laserBeamSize, laserFrequency, lineSpacing, chamberVolume, gasFlow, matrix1, acqTime, ablationNoise, beamShape, thinSample, numberOfShots, thickSample, transferNoise, detectorNoise);
                        laicpms1.RunWorkerCompleted += new RunWorkerCompletedEventHandler(laicpms1_RunWorkerCompleted);
                        laicpms1.ProgressChanged += new ProgressChangedEventHandler(laicpms1_ProgressChanged);

                        //laicpms1.ProgressChanged += laicpms1_ProgressChanged;
                        //laicpms1.RunWorkerCompleted += laicpms1_RunWorkerCompleted;

                        laicpms1.RunWorkerAsync("Hello!");
                    }
                }
                else {
                    MessageBox.Show("Sample image is not loaded.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    scanRunning = 0;
                    button2.Text = "Run";
                    button2.BackColor = Color.Transparent;
                    button2.ForeColor = Color.Black;
                    button2.Click -= this.abortScan;
                    button2.Click += new System.EventHandler(this.button2_Click);
                }
            }
        }
Пример #2
0
        private void button2_Click(object sender, EventArgs e)
        {
            if (scanRunning == 0)
            {
                scanRunning = 1;

                button2.Text      = "Abort scan";
                button2.BackColor = Color.Red;
                button2.ForeColor = Color.White;
                button2.Click    -= this.button2_Click;
                button2.Click    += new System.EventHandler(this.abortScan);

                // MethodInvoker calculationDelegate = new MethodInvoker(Calculate);
                // IAsyncResult tag = calculationDelegate.BeginInvoke(sender, e, null, null);

                //int allOk = 1;
                // Proceed with the scan only if there is an image (sample) loaded
                if (imageLoaded)
                {
                    // Measure execution time
                    watch = new System.Diagnostics.Stopwatch();
                    watch.Reset();
                    watch.Start();

                    // If dimensions are different from the original image and "just files" is not checked, resize the
                    //try
                    //{
                    if ((int)numericUpDown5.Value * (int)numericUpDown6.Value > 25000000)
                    {
                        if (MessageBox.Show("You are risking an out of memory exception! \n\n By clicking OK you will accept the risk and the model will run with the current parameters. \n\n By clicking Cancel the width and height paramerers will be set to 5000 by 5000 micrometers.", "Risk of running out of memory", MessageBoxButtons.OKCancel) == DialogResult.Cancel)
                        {
                            numericUpDown5.Value = 5000;
                            numericUpDown6.Value = 5000;
                        }
                    }
                    if (!radioButton2.Checked && (((int)numericUpDown5.Value != sampleImage.Width) || ((int)numericUpDown6.Value != sampleImage.Height)))
                    {
                        try
                        {
                            resizedSampleImage = Utilities.ResizeBitmap(sampleImage, (int)numericUpDown5.Value, (int)numericUpDown6.Value);
                            pictureBox1.Image  = resizedSampleImage;

                            // Convert to 2D array
                            matrix1 = Utilities.imageTo2DArray(ref resizedSampleImage);
                        }
                        catch (OutOfMemoryException ex)
                        {
                            MessageBox.Show(this, "Out of memory exception has occured during resizing of the image. \n 1. Try using smaller theoretical sample dimensions, \n 2. Try using faster scanning speeds, \n 3. Try using bigger beam diameters, \n 4. Try using lower frequencies \n 5. Try using bigger acquisition times. \n \n If nothing above works, set the settings to their default values.", "Out of Memory tips.");
                            scanRunning       = 0;
                            button2.Text      = "Run";
                            button2.BackColor = Color.Transparent;
                            button2.ForeColor = Color.Black;
                            button2.Click    -= this.abortScan;
                            button2.Click    += new System.EventHandler(this.button2_Click);
                            pictureBox1.Image = sampleImage;
                            pictureBox1.Show();
                        }
                    }
                    else
                    {
                        try
                        {
                            matrix1 = Utilities.imageTo2DArray(ref sampleImage);
                        }
                        catch (OutOfMemoryException ex)
                        {
                            MessageBox.Show(this, "Out of memory exception has occured during conversion of image to array. \n 1. Try using smaller theoretical sample dimensions, \n 2. Try using faster scanning speeds, \n 3. Try using bigger beam diameters, \n 4. Try using lower frequencies \n 5. Try using bigger acquisition times. \n \n If nothing above works, set the settings to their default values.", "Out of Memory tips.");
                            scanRunning       = 0;
                            button2.Text      = "Run";
                            button2.BackColor = Color.Transparent;
                            button2.ForeColor = Color.Black;
                            button2.Click    -= this.abortScan;
                            button2.Click    += new System.EventHandler(this.button2_Click);
                            pictureBox1.Image = sampleImage;
                            pictureBox1.Show();
                        }
                    }
                    if (scanRunning == 1)
                    {
                        if (radioButton10.Checked) // Convert to optical density
                        {
                            for (int i = 0; i < matrix1.GetLength(0); i++)
                            {
                                for (int j = 0; j < matrix1.GetLength(1); j++)
                                {
                                    if (matrix1[i, j] == 0)
                                    {
                                        matrix1[i, j] = 1;
                                    }
                                    matrix1[i, j] = (int)Math.Round(255.0 * (Math.Log10(255.0 / (double)matrix1[i, j]) / Math.Log10(255.0 / 1.0)));
                                }
                            }
                        }
                        else
                        {
                            for (int i = 0; i < matrix1.GetLength(0); i++)
                            {
                                for (int j = 0; j < matrix1.GetLength(1); j++)
                                {
                                    matrix1[i, j] = 255 - matrix1[i, j];
                                }
                            }
                        }

                        //}
                        //catch (OutOfMemoryException ex)
                        //{
                        //MessageBox.Show(this, "Out of memory exception has occured. Try using smaller theoretical sample dimensions.", "Out of memory");
                        //    allOk = 0;
                        //}
                        // If everything is ok and no exception has occured, then continue with the simulation
                        // Prepare the form for display of progress bar
                        pictureBox1.Hide();
                        Refresh();
                        label12.Visible      = true;
                        progressBar1.Visible = true;
                        label13.Visible      = true;

                        // Laser laser1 = new Laser(scanSpeed, laserBeamSize, laserFrequency, laserPower, chamberVolume, gasFlow, sampleMatrix);
                        int laserBeamSize = (int)numericUpDown1.Value;

                        // Validate laserBeamSize for round beam == must be divisible by 2.
                        if (radioButton6.Checked && (laserBeamSize % 2 != 0))
                        {
                            laserBeamSize = laserBeamSize + 1;
                        }

                        int    lineSpacing    = (int)numericUpDown2.Value;
                        int    laserFrequency = (int)numericUpDown3.Value;
                        int    scanSpeed      = (int)numericUpDown4.Value;
                        int    chamberVolume  = (int)numericUpDown7.Value;
                        int    gasFlow        = (int)numericUpDown8.Value;
                        double ablationNoise  = (double)numericUpDown10.Value;
                        double transferNoise  = (double)numericUpDown12.Value;
                        double detectorNoise  = (double)numericUpDown13.Value;

                        double acqTime   = (double)numericUpDown9.Value;
                        bool   beamShape = false;
                        if (radioButton6.Checked)
                        {
                            beamShape = true;
                        }
                        bool thinSample  = false;
                        bool thickSample = false;
                        if (radioButton11.Checked)
                        {
                            thinSample = true; thickSample = false;
                        }
                        int numberOfShots = (int)numericUpDown11.Value;

                        if (radioButton7.Checked)
                        {
                            thickSample = true; thinSample = false;
                        }

                        laicpms1 = new LAICPMS(scanSpeed, laserBeamSize, laserFrequency, lineSpacing, chamberVolume, gasFlow, matrix1, acqTime, ablationNoise, beamShape, thinSample, numberOfShots, thickSample, transferNoise, detectorNoise);
                        laicpms1.RunWorkerCompleted += new RunWorkerCompletedEventHandler(laicpms1_RunWorkerCompleted);
                        laicpms1.ProgressChanged    += new ProgressChangedEventHandler(laicpms1_ProgressChanged);

                        //laicpms1.ProgressChanged += laicpms1_ProgressChanged;
                        //laicpms1.RunWorkerCompleted += laicpms1_RunWorkerCompleted;

                        laicpms1.RunWorkerAsync("Hello!");
                    }
                }
                else
                {
                    MessageBox.Show("Sample image is not loaded.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    scanRunning       = 0;
                    button2.Text      = "Run";
                    button2.BackColor = Color.Transparent;
                    button2.ForeColor = Color.Black;
                    button2.Click    -= this.abortScan;
                    button2.Click    += new System.EventHandler(this.button2_Click);
                }
            }
        }