Exemple #1
0
 private void Binning_8x8_Checked(object sender, RoutedEventArgs e)
 {
     if (VM == null)
     {
         return;
     }
     VM.HorzBinning = 8;
     VM.VertBinning = 8;
     ImageDisplayControl.SetImageSize(GlobalVars.PixelWidth / VM.HorzBinning,
                                      GlobalVars.PixelHeight / VM.VertBinning,
                                      GlobalVars.MaxPixelValue);
 }
Exemple #2
0
        public async void StartVideo(int numberOfImagesToTake)
        {
            if (m_imager == null)
            {
                return;
            }

            VM.StatusString = "Imaging";

            if (numberOfImagesToTake == 1)
            {
                SnapShotPB.Content = "Cancel";
                VideoPB.IsEnabled  = false;
            }
            else
            {
                SnapShotPB.IsEnabled = false;
                VideoPB.Content      = "Cancel";
            }


            GainSpin.IsEnabled     = false;
            ExposureSpin.IsEnabled = false;
            Optimize1PB.IsEnabled  = false;

            //ExcitationFilterCombo.IsEnabled = false;
            //EmissionFilterCombo.IsEnabled = false;


            m_uiTask = TaskScheduler.FromCurrentSynchronizationContext();

            m_iParams = new ImagingParameters();
            m_iParams.NumIndicators               = 1;
            m_iParams.NumImages                   = numberOfImagesToTake;
            m_iParams.Exposure[0]                 = ((float)VM.Exposure) / 1000;
            m_iParams.CycleTime[0]                = VM.Exposure + 250;
            m_iParams.ExcitationFilter[0]         = (byte)VM.ExFilter.PositionNumber;
            m_iParams.EmissionFilter[0]           = (byte)VM.EmFilter.PositionNumber;
            m_iParams.ExcitationFilterChangeSpeed = 5;
            m_iParams.EmissionFilterChangeSpeed   = 5;
            m_iParams.Gain[0]                         = VM.Gain;
            m_iParams.HorzBinning                     = VM.HorzBinning;
            m_iParams.VertBinning                     = VM.VertBinning;
            m_iParams.LampShutterIsOpen[0]            = true;
            m_iParams.LightIntensity                  = 100;
            m_iParams.SyncExcitationFilterWithImaging = true;

            m_iParams.Image_StartCol = VM.RoiX;
            m_iParams.Image_EndCol   = VM.RoiX + VM.RoiW - 1;
            m_iParams.Image_StartRow = VM.RoiY;
            m_iParams.Image_EndRow   = VM.RoiY + VM.RoiH - 1;

            m_iParams.imageWidth    = VM.RoiW;
            m_iParams.imageHeight   = VM.RoiH;
            m_iParams.maxPixelValue = (2 ^ m_imager.m_camera.BitDepth) - 1;

            m_iParams.ExperimentIndicatorID[0] = 0;  // 0 here indicates that images will not be saved
            m_iParams.IndicatorName[0]         = VM.IndicatorName;

            m_tokenSource = new CancellationTokenSource();
            m_cancelToken = m_tokenSource.Token;

            Progress <int> progress = new Progress <int>();

            progress.ProgressChanged += (sender1, num) =>
            {
                VM.StatusString = "Completed " + num.ToString() + " images";
            };


            ImageDisplayControl.SetImageSize(m_iParams.imageWidth, m_iParams.imageHeight, m_iParams.maxPixelValue);


            m_bitmap = ImageDisplayControl.m_imageBitmap;


            Task ImagingTask = Task.Factory.StartNew(() => m_imager.StartImaging(m_iParams,
                                                                                 null, // no analysis parameters needed here
                                                                                 m_cancelToken, m_uiTask, progress,
                                                                                 ImageDisplayControl, m_colorModel.m_colorMap,
                                                                                 m_histogram), m_cancelToken);


            try
            {
                await ImagingTask;
            }
            catch (AggregateException aggEx)
            {
                StringBuilder sb = new StringBuilder();
                sb.Append("Exception(s) occurred: ");
                foreach (Exception ex in aggEx.InnerExceptions)
                {
                    sb.Append(ex.Message);
                    sb.Append(", ");
                }
                MessageBoxResult result = MessageBox.Show(sb.ToString(), "Exception(s) Occurred", MessageBoxButton.OK, MessageBoxImage.Error);
            }
            catch (OperationCanceledException)
            {
                VM.StatusString = "Canceled";
            }
            catch (Exception ex)
            {
                MessageBoxResult result = MessageBox.Show(ex.Message, "Unknown Exception Occurred", MessageBoxButton.OK, MessageBoxImage.Error);
            }
            finally
            {
                ImagingTask.Dispose();
                OnImagingStopped(EventArgs.Empty);

                VideoPB.Content        = "Video";
                SnapShotPB.Content     = "Snap Shot";
                VideoPB.IsEnabled      = true;
                SnapShotPB.IsEnabled   = true;
                GainSpin.IsEnabled     = true;
                ExposureSpin.IsEnabled = true;
                Optimize1PB.IsEnabled  = true;

                //ExcitationFilterCombo.IsEnabled = true;
                //EmissionFilterCombo.IsEnabled = true;

                VM.IsImaging    = false;
                VM.StatusString = "Ready";
            }
        }
Exemple #3
0
        public async void TakeSnapShot()
        {
            if (m_imager == null)
            {
                return;
            }

            if (m_displayPipeline == null)
            {
                BuildPipelines();
            }


            SnapShotPB.Content     = "Cancel";
            VideoPB.IsEnabled      = false;
            GainSpin.IsEnabled     = false;
            ExposureSpin.IsEnabled = false;
            Optimize1PB.IsEnabled  = false;

            m_tokenSource = new CancellationTokenSource();
            m_cancelToken = m_tokenSource.Token;

            VM.StatusString = "Imaging";

            ImageDisplayControl.SetImageSize(VM.RoiW / VM.HorzBinning, VM.RoiH / VM.VertBinning, GlobalVars.MaxPixelValue);


            m_grayImage = null;


            //Task ImagingTask = Task.Factory.StartNew(() => m_imager.AcquireImage(VM.Exposure, VM.Gain, VM.HorzBinning, VM.VertBinning, out grayImage)
            //                                                                     , m_cancelToken);



            Task ImagingTask = Task.Factory.StartNew(() => m_imager.TakeSnapShot(out m_grayImage, VM.Exposure, VM.Gain, VM.HorzBinning, VM.VertBinning,
                                                                                 VM.ExFilter.PositionNumber, VM.EmFilter.PositionNumber)
                                                     , m_cancelToken);

            try
            {
                await ImagingTask;

                // display image
                if (m_grayImage != null)
                {
                    m_imageWidth  = VM.RoiW / VM.HorzBinning;
                    m_imageHeight = VM.RoiH / VM.VertBinning;

                    m_displayPipeline.Post(Tuple.Create(m_grayImage, 0, m_imageWidth, m_imageHeight,
                                                        m_colorModel.m_colorMap));
                    m_histogramPipeline.Post(m_grayImage);
                }
            }
            catch (AggregateException aggEx)
            {
                StringBuilder sb = new StringBuilder();
                sb.Append("Exception(s) occurred: ");
                foreach (Exception ex in aggEx.InnerExceptions)
                {
                    sb.Append(ex.Message);
                    sb.Append(", ");
                }
                MessageBoxResult result = MessageBox.Show(sb.ToString(), "Exception(s) Occurred", MessageBoxButton.OK, MessageBoxImage.Error);
            }
            catch (OperationCanceledException)
            {
                VM.StatusString = "Canceled";
            }
            catch (Exception ex)
            {
                MessageBoxResult result = MessageBox.Show(ex.Message, "Unknown Exception Occurred", MessageBoxButton.OK, MessageBoxImage.Error);
            }
            finally
            {
                ImagingTask.Dispose();
                OnImagingStopped(EventArgs.Empty);

                VideoPB.Content        = "Video";
                SnapShotPB.Content     = "Snap Shot";
                VideoPB.IsEnabled      = true;
                SnapShotPB.IsEnabled   = true;
                GainSpin.IsEnabled     = true;
                ExposureSpin.IsEnabled = true;
                Optimize1PB.IsEnabled  = true;

                //ExcitationFilterCombo.IsEnabled = true;
                //EmissionFilterCombo.IsEnabled = true;

                VM.IsImaging    = false;
                VM.StatusString = "Ready";
            }
        }