Esempio n. 1
0
        private void backgroundWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {   // This event is necessary because int he doword event, many things cannot be done, such as button enabling
            // because they must be performed by a different thread.

            if (e.Error != null)
            {
                MessageBox.Show(e.Error.Message);
            }
            else if (e.Cancelled)
            {
                // Next, handle the case where the user canceled
                // the operation.
                // Note that due to a race condition in
                // the DoWork event handler, the Cancelled
                // flag may not have been set, even though
                // CancelAsync was called.
                measurementProgressBar.Value = 0;

                MeasurementResults.SetAllCancelled();
                DataGridMeasurementResult.ItemsSource = null;
                DataGridMeasurementResult.ItemsSource = MeasurementResults.Result;

                DetectionResults.SetAllNotDetected();
                DataGridDetectionResult.ItemsSource = null;
                DataGridDetectionResult.ItemsSource = DetectionResults.Result;

                string log = "*******************************\r\n";
                log += ImageInfo.measurementTime;
                log += "\r\nMeasurement Cancelled.";
                string path = AppDomain.CurrentDomain.BaseDirectory + "\\QCLog.koning";
                using (StreamWriter sw = File.AppendText(path))
                {
                    sw.WriteLine(log);
                    sw.WriteLine("\n");
                }
            }
            else
            {
                string log = "*******************************\r\n";
                log += ImageInfo.measurementTime;
                log += "\r\nImage Directory: \r\n" + ImageInfo.inputPath + "\r\n";

                // output results
                if (ImageInfo.phFlag)
                {
                    log += ("Phantom detected, starting on " + Path.GetFileName(ImageInfo.fileNames[ImageInfo.phStart]) + "\r\n");
                    DetectionResults.SetDetected("Phantom");
                }
                else
                {
                    log += "Phantom not detected\r\n";
                    DetectionResults.SetNotDetected("Phantom");
                }
                if (ImageInfo.hcFlag)
                {
                    log += ("Contrast structures detected, starting on " + Path.GetFileName(ImageInfo.fileNames[ImageInfo.hcStart]) + "\r\n");
                    DetectionResults.SetDetected("Tumor");
                }
                else
                {
                    log += "Contrast structures not detected\r\n";
                    DetectionResults.SetNotDetected("Tumor");
                }
                if (ImageInfo.wtFlag)
                {
                    log += ("Water detected\r\n");
                    DetectionResults.SetDetected("Water");
                }
                else
                {
                    log += "Phantom not detected\r\n";
                    DetectionResults.SetNotDetected("Water");
                }
                if (ImageInfo.clFlag)
                {
                    log += ("Calcifications detected, on " + Path.GetFileName(ImageInfo.fileNames[ImageInfo.clIndex]) + "\r\n");
                    DetectionResults.SetDetected("Calcification");
                }
                else
                {
                    log += "Calcifications not detected";
                    DetectionResults.SetNotDetected("Calcification");
                }


                DataGridDetectionResult.ItemsSource = null;
                DataGridDetectionResult.ItemsSource = DetectionResults.Result;

                // only show measurements if high contrast is detected
                if (ImageInfo.hcFlag)
                {
                    string measurementResult = "";
                    measurementResult += string.Format("\r\nCT Number Accuracy:\r\n     Tumor: {0:F2}\r\n     Water: {1:F2}\r\nField Uniformity: {2:F2}", ImageInfo.hcCTValue, ImageInfo.wtCTValue, ImageInfo.imgUniformity);
                    measurementResult += string.Format("\r\nNoise: {0:F2}\r\nContrast-to-Noise Ratio: {1:F2}", ImageInfo.imgNoise, ImageInfo.lcContrast / ImageInfo.imgNoise);
                    log += measurementResult;

                    MeasurementResults.SetValue("Image Noise:", string.Format("{0:F2}", ImageInfo.imgNoise));
                    MeasurementResults.SetValue("Tumor CT Number:", string.Format("{0:F2}", ImageInfo.hcCTValue));
                    MeasurementResults.SetValue("Water CT Number:", string.Format("{0:F2}", ImageInfo.wtCTValue));
                    MeasurementResults.SetValue("Field Uniformity:", string.Format("{0:F2}", ImageInfo.imgUniformity));
                    MeasurementResults.SetValue("Contrast to Noise Ratio:", string.Format("{0:F2}", ImageInfo.lcContrast / ImageInfo.imgNoise));

                    //// Display the contrastlabel image upon measurement finishing
                    short[] img = new short[ImageInfo.Height * ImageInfo.Width];
                    if (ImgEvaluation.readShortData(ImageInfo.outputPath + "\\ContrastLabel_" + ImageInfo.Width + "x" + ImageInfo.Height + ".img", img, 0, ImageInfo.Height * ImageInfo.Width))
                    {
                        DisplayShortImage(img, ImageInfo.Height, ImageInfo.Width);
                    }
                    img = null;

                    DisplayImage();
                }
                else
                {
                    log += "\r\nMeasurements not performed as high contrast structure not detected.";
                    MeasurementResults.SetAllFailed();
                }

                DataGridMeasurementResult.ItemsSource = null;
                DataGridMeasurementResult.ItemsSource = MeasurementResults.Result;

                string path = AppDomain.CurrentDomain.BaseDirectory + "\\QCLog.koning";

                using (StreamWriter sw = File.AppendText(path))
                {
                    sw.WriteLine(log);
                    sw.WriteLine("\n");
                }
            }
            measurementProgressBar.Value = 0;
        }