Exemplo n.º 1
0
        /// <summary>
        /// Renders the Xray image on the CPU.
        /// </summary>
        /// <param name="bsource"></param>
        /// <param name="sourceObject"></param>
        /// <param name="viewObject"></param>
        /// <param name="xrayImageEffect"></param>
        /// <param name="trimatEffect"></param>
        /// <param name="effects"></param>
        /// <param name="displayWidth"></param>
        /// <param name="displayHeight"></param>
        /// <param name="adornerLayerManager"></param>
        /// <param name="displayAnnotations"></param>
        /// <param name="displayMeasurements"></param>
        /// <returns>The newly rendered bitmap.</returns>
        public static BitmapSource GetRenderedXrayImage(BitmapSource bsource,
                                                        SourceObject sourceObject,
                                                        ViewObject viewObject,
                                                        ShaderEffect xrayOrTrimateImageEffect,
                                                        List<Effect> effects,
                                                        double displayWidth,
                                                        double displayHeight,
                                                        AdornerLayerManager adornerLayerManager,
                                                        bool displayAnnotations,
                                                        bool displayMeasurements)
        {
            if (xrayOrTrimateImageEffect != null && xrayOrTrimateImageEffect.GetType() == typeof(XrayImageEffect))
            {
                RenderXrayImage_XRayImageEffect(ref bsource, (XrayImageEffect)xrayOrTrimateImageEffect, sourceObject);
            }
            //else if (xrayOrTrimateImageEffect.GetType() == typeof(TrimatEffect))
            //{
            //    RenderXrayImage_TrimatEffect(ref bsource, (TrimatEffect)xrayOrTrimateImageEffect, sourceObject, viewObject);
            //}
            foreach (Effect effect in effects)
            {
                ApplyEffectToBitmap(ref bsource, effect);
            }
            if (displayAnnotations)
            {
                RenderAnnotations(ref bsource, displayWidth, displayHeight, adornerLayerManager);
            }
            if (displayMeasurements)
            {
                RenderMeasurements(ref bsource, displayWidth, displayHeight, adornerLayerManager);
            }

            return bsource;
        }
Exemplo n.º 2
0
 public ViewObject(string name, uint index, ViewType viewType, SourceObject highEnergy, SourceObject lowEnergy,
                   uint maxDetectorsPerBoard, uint bitsPerPixel, uint samplingSpeed, float samplingSpace, List <AnnotationInfo> annotations)
 {
     m_Name                 = name;
     m_ImageIndex           = index;
     m_ViewType             = viewType;
     m_HighEnergy           = highEnergy;
     m_LowEnergy            = lowEnergy;
     m_MaxDetectorsPerBoard = maxDetectorsPerBoard;
     m_BitsPerPixel         = bitsPerPixel;
     m_SamplingSpeed        = samplingSpeed;
     m_SamplingSpace        = samplingSpace;
     m_Annotations          = annotations;
     m_TIPMarkings          = null;
 }
Exemplo n.º 3
0
 public ViewObject (string name, uint index, ViewType viewType, SourceObject highEnergy, SourceObject lowEnergy,
      uint maxDetectorsPerBoard, uint bitsPerPixel,  uint samplingSpeed, float samplingSpace, List<AnnotationInfo> annotations)
 {
     m_Name = name;
     m_ImageIndex = index;
     m_ViewType = viewType;
     m_HighEnergy = highEnergy;
     m_LowEnergy = lowEnergy;
     m_MaxDetectorsPerBoard = maxDetectorsPerBoard;
     m_BitsPerPixel = bitsPerPixel;
     m_SamplingSpeed = samplingSpeed;
     m_SamplingSpace = samplingSpace;
     m_Annotations = annotations;
     m_TIPMarkings = null;
 }
Exemplo n.º 4
0
        private List<ViewObject> GetImageData()
        {
            List<ViewObject> ret = new List<ViewObject>();

            MemoryStream tipMS = null;

            bool injectTIP = false;

            TIPStatus tipStatus;

            if (m_CaseObj.caseType == CaseType.FTICase)
            {
                DataAttachment ftiAttachment = null;
                foreach (DataAttachment attachment in m_CaseObj.attachments.GetFTIImageAttachments())
                {
                    tipMS = attachment.attachmentData;
                    injectTIP = true;
                    ftiAttachment = attachment;
                    break;
                }

                m_CaseObj.attachments.Remove(ftiAttachment);
            }

            foreach (DataAttachment attachment in m_CaseObj.attachments.GetXrayImageAttachments())
            {
                MemoryStream ms = attachment.attachmentData;

                System.Windows.Rect view0Rect = new System.Windows.Rect();
                System.Windows.Rect view1Rect = new System.Windows.Rect();

                if (injectTIP)
                {
                    tipStatus = new TIPStatus();

                    _PxeAccess.OpenPXEImageFromMemoryWithTIP(ms, tipMS, ref tipStatus);

                    if (tipStatus.injectionsucess == 0)
                    {
                        m_CaseObj.IsCaseEditable = false;
                        m_SysConfig.SelectedArchiveDuringAutoSelect = true;
                        m_DisplayFTIError = true;
                    }
                    else
                    {
                        view0Rect = new System.Windows.Rect(new Point((double)tipStatus.injectLocation_view0.left,
                                                       (double)tipStatus.injectLocation_view0.top),
                                             new Point((double)tipStatus.injectLocation_view0.right,
                                                       (double)tipStatus.injectLocation_view0.bottom));

                        view1Rect = new System.Windows.Rect(new Point((double)tipStatus.injectLocation_view1.left,
                                                       (double)tipStatus.injectLocation_view1.top),
                                             new Point((double)tipStatus.injectLocation_view1.right,
                                                       (double)tipStatus.injectLocation_view1.bottom));
                    }
                }
                else
                {
                    _PxeAccess.OpenPXEImageFromMemory(ms);
                }

                if (_PxeAccess.GetPxeHeader().sequenceNum != null)
                {
                    if (m_CaseObj.scanInfo == null)
                    {
                        m_CaseObj.scanInfo = new ScanInfo();
                    }

                    if (m_CaseObj.scanInfo.container == null)
                    {
                        m_CaseObj.scanInfo.container = new Container();
                    }

                    m_CaseObj.scanInfo.container.SequenceNum = _PxeAccess.GetPxeHeader().sequenceNum.ToString();
                }

                if (_PxeAccess.GetPxeHeader().batchNumber != null)
                {
                    if (m_CaseObj.scanInfo == null)
                    {
                        m_CaseObj.scanInfo = new ScanInfo();
                    }

                    if (m_CaseObj.scanInfo.conveyance == null)
                    {
                        m_CaseObj.scanInfo.conveyance = new Conveyance();
                    }

                    m_CaseObj.scanInfo.conveyance.BatchNum = _PxeAccess.GetPxeHeader().batchNumber.ToString();
                }

                if (_PxeAccess.GetPxeHeader().viewBuffer_0.isValidView != 0)
                {
                    SourceObject highEnergy = null;
                    SourceObject lowEnergy = null;
                    ViewType viewType = ViewType.Unknown;

                    int width = (int)_PxeAccess.GetPxeHeader().viewBuffer_0.width;
                    int height = (int)_PxeAccess.GetPxeHeader().viewBuffer_0.height;

                    if (_PxeAccess.GetPxeHeader().viewBuffer_0.isDualEnergy != 0)
                    {
                        highEnergy = new SourceObject(_PxeAccess.GetImageBuffer("RawH"), width, height, m_SysConfig.FlipView1XAxis, m_SysConfig.FlipView1YAxis);
                        lowEnergy = new SourceObject(_PxeAccess.GetImageBuffer("RawL"), width, height, m_SysConfig.FlipView1XAxis, m_SysConfig.FlipView1YAxis);
                        viewType = ViewType.DualEnergy;
                    }
                    else if (width > 0 && height > 0 && _PxeAccess.GetPxeHeader().viewBuffer_0.isHighEnergy != 0)
                    {
                        highEnergy = new SourceObject(_PxeAccess.GetImageBuffer("RawH"), width, height, m_SysConfig.FlipView1XAxis, m_SysConfig.FlipView1YAxis);
                        viewType = ViewType.HighEnergy;
                    }
                    else if (width > 0 && height > 0 && _PxeAccess.GetPxeHeader().viewBuffer_0.isHighEnergy == 0)
                    {
                        lowEnergy = new SourceObject(_PxeAccess.GetImageBuffer("RawL"), width, height, m_SysConfig.FlipView1XAxis, m_SysConfig.FlipView1YAxis);
                        viewType = ViewType.LowEnergy;
                    }

                    ViewObject viewObj = new ViewObject("View0",
                                                        _PxeAccess.GetPxeHeader().pxeIndex,
                                                        viewType,
                                                        highEnergy,
                                                        lowEnergy,
                                                        _PxeAccess.GetPxeHeader().detectorsPerBoard,
                                                        _PxeAccess.GetPxeHeader().bitsPerPixel,
                                                        _PxeAccess.GetPxeHeader().samplingSpeed,
                                                        _PxeAccess.GetPxeHeader().samplingSpace,
                                                        GetAnnotationsForView("View0"));

                    if (injectTIP)
                    {
                        viewObj.TIPMarkings = new List<System.Windows.Rect>();
                        viewObj.TIPMarkings.Add(view0Rect);
                    }

                    ret.Add(viewObj);
                }

                if (_PxeAccess.GetPxeHeader().viewBuffer_1.isValidView != 0)
                {
                    SourceObject highEnergy = null;
                    SourceObject lowEnergy = null;
                    ViewType viewType = ViewType.Unknown;

                    int width = (int)_PxeAccess.GetPxeHeader().viewBuffer_1.width;
                    int height = (int)_PxeAccess.GetPxeHeader().viewBuffer_1.height;

                    if (_PxeAccess.GetPxeHeader().viewBuffer_0.isDualEnergy != 0)
                    {
                        highEnergy = new SourceObject(_PxeAccess.GetImageBuffer("RawH1"), width, height, m_SysConfig.FlipView2XAxis, m_SysConfig.FlipView2YAxis);
                        lowEnergy = new SourceObject(_PxeAccess.GetImageBuffer("RawL1"), width, height, m_SysConfig.FlipView2XAxis, m_SysConfig.FlipView2YAxis);
                        viewType = ViewType.DualEnergy;
                    }
                    else if (width > 0 && height > 0 && _PxeAccess.GetPxeHeader().viewBuffer_0.isHighEnergy != 0)
                    {
                        highEnergy = new SourceObject(_PxeAccess.GetImageBuffer("RawH1"), width, height, m_SysConfig.FlipView2XAxis, m_SysConfig.FlipView2YAxis);
                        viewType = ViewType.HighEnergy;
                    }
                    else if (width > 0 && height > 0 && _PxeAccess.GetPxeHeader().viewBuffer_0.isHighEnergy == 0)
                    {
                        lowEnergy = new SourceObject(_PxeAccess.GetImageBuffer("RawL1"), width, height, m_SysConfig.FlipView2XAxis, m_SysConfig.FlipView2YAxis);
                        viewType = ViewType.LowEnergy;
                    }

                    ViewObject viewObj = new ViewObject("View1",
                                                        _PxeAccess.GetPxeHeader().pxeIndex,
                                                        viewType,
                                                        highEnergy,
                                                        lowEnergy,
                                                        _PxeAccess.GetPxeHeader().detectorsPerBoard,
                                                        _PxeAccess.GetPxeHeader().bitsPerPixel,
                                                        _PxeAccess.GetPxeHeader().samplingSpeed,
                                                        _PxeAccess.GetPxeHeader().samplingSpace,
                                                        GetAnnotationsForView("View1"));

                    if (injectTIP)
                    {
                        viewObj.TIPMarkings = new List<System.Windows.Rect>();
                        viewObj.TIPMarkings.Add(view1Rect);
                    }

                    ret.Add(viewObj);
                }
            }

            return ret;
        }
Exemplo n.º 5
0
        public void Dispose ()
        {
            CultureResources.getDataProvider().DataChanged -= this.CultureResources_DataChanged;
            HistoryList.IsOpen = false;

            PseudoColor_ComboBox.Items.Clear();
            PseudoColor_ComboBox = null;

            m_Filters.Clear();
            m_Filters = null;

            m_FilterManager.Dispose();
            m_FilterManager = null;

            m_SourceObject = null;
            m_History = null;

            PanAndZoomControl.Content = null;
            PanAndZoomControl = null;

            m_ViewObject.Dispose();
            m_ViewObject = null;
        }
Exemplo n.º 6
0
        public void Setup (ViewObject content, History history, SysConfiguration sysConfig)
        {
            if (!IsSetup)
            {
                m_ViewObject = content;

                m_History = history;
                m_History.CurrentHistoryChangedEvent += new CurrentHistoryChanged(ApplyHistory);

                if (m_ViewObject.HighEnergy != null)
                {
                    m_SourceObject = m_ViewObject.HighEnergy;
                    HEImage.Source = new BitmapImage(new Uri(@"/L3.Cargo.Workstation.Plugins.XRayImageBase;component/Resources/Icons/HEOn.png", UriKind.Relative));
                    LEImage.Source = new BitmapImage(new Uri(@"/L3.Cargo.Workstation.Plugins.XRayImageBase;component/Resources/Icons/LEOff.png", UriKind.Relative));
                }
                else if (m_ViewObject.LowEnergy != null)
                {
                    m_SourceObject = m_ViewObject.LowEnergy;
                    HEImage.Source = new BitmapImage(new Uri(@"/L3.Cargo.Workstation.Plugins.XRayImageBase;component/Resources/Icons/HEOff.png", UriKind.Relative));
                    LEImage.Source = new BitmapImage(new Uri(@"/L3.Cargo.Workstation.Plugins.XRayImageBase;component/Resources/Icons/LEOn.png", UriKind.Relative));
                }
                else
                {
                    throw new Exception();
                }

                if (m_ViewObject.LowEnergy == null ||
                    m_ViewObject.HighEnergy == null)
                {
                    XRayDualEnergy_ToolBar.Visibility = Visibility.Collapsed;
                }
                else
                {
                    HistoryDualEnergy dualEnergy = new HistoryDualEnergy();
                    dualEnergy.name = "HighEnergy";
                    m_History.SetFirstStep(dualEnergy);
                }

                if (sysConfig != null)
                {
                    m_sysConfig = sysConfig;
                    CreateUserMacroControls();
                    Macro_Toolbar.Visibility = Visibility.Visible;
                }

                CreateBufferControls();

                CreateFilterControls();

                CreateColorMappingControls();

                MainImage.Source = m_SourceObject.Source;
                MainImage.Height = m_SourceObject.Height;
                MainImage.Width = m_SourceObject.Width;
                
                HistoryBuffer buffer = new HistoryBuffer();
                buffer.name = "Original Gray Scale";

                m_History.SetFirstStep(buffer);

                HistoryList.DataContext = m_History.Step;

                IsApplyHistoryFromSetup = true;

                m_History.ApplyStep();

                IsApplyHistoryFromSetup = false;

                IsSetup = true;
            }
        }
Exemplo n.º 7
0
        protected void CreateWindow (Point startPoint, Point endPoint)
        {
            startPoint = FitPointInImage(startPoint);
            endPoint = FitPointInImage(endPoint);
            
            for (int index = m_AOIWindows.Count - 1; index >= 0; index--)
            {
                if (m_AOIWindows[index].IsLoaded == false)
                {
                    m_AOIWindows.RemoveAt(index);
                }
            }

            //TODO: This needs to be configurable
            if (m_AOIWindows.Count >= 3)
            {
                return;
            }


            if (startPoint.X > endPoint.X)
            {
                double temp = endPoint.X;
                endPoint.X = startPoint.X;
                startPoint.X = temp;
            }

            if (startPoint.Y > endPoint.Y)
            {
                double temp = endPoint.Y;
                endPoint.Y = startPoint.Y;
                startPoint.Y = temp;
            }

            SourceObject highEnergy = null;
            SourceObject lowEnergy = null;
            SourceObject trimat = null;
            ViewType viewType = ViewType.Unknown;

            if (m_ViewObject.HighEnergy != null)
            {
                double heightratio = m_ViewObject.HighEnergy.Height / base.ActualHeight;
                double widthratio = m_ViewObject.HighEnergy.Width / base.ActualWidth;

                int StartX = (int)(startPoint.X * widthratio);
                int StartY = (int)(startPoint.Y * heightratio);
                int EndX = (int)(endPoint.X * widthratio);
                int EndY = (int)(endPoint.Y * heightratio);

                int width = EndX - StartX;
                int height = EndY - StartY;

                float[] data = new float[width * height];

                for (int j = StartY, k = 0; j < EndY; j++, k++)
                {
                    for (int i = StartX, l = 0; i < EndX; i++, l++)
                    {
                        data[(k * width) + l] = m_ViewObject.HighEnergy.Data[(j * m_ViewObject.HighEnergy.Width) + i];
                    }
                }

                highEnergy = new SourceObject(data, width, height, false, false);
                viewType = ViewType.HighEnergy;
            }

            if (m_ViewObject.LowEnergy != null)
            {
                double heightratio = m_ViewObject.LowEnergy.Height / base.ActualHeight;
                double widthratio = m_ViewObject.LowEnergy.Width / base.ActualWidth;

                int StartX = (int)(startPoint.X * widthratio);
                int StartY = (int)(startPoint.Y * heightratio);
                int EndX = (int)(endPoint.X * widthratio);
                int EndY = (int)(endPoint.Y * heightratio);

                int width = EndX - StartX;
                int height = EndY - StartY;

                float[] data = new float[width * height];

                for (int j = StartY, k = 0; j < EndY; j++, k++)
                {
                    for (int i = StartX, l = 0; i < EndX; i++, l++)
                    {
                        data[(k * width) + l] = m_ViewObject.LowEnergy.Data[(j * m_ViewObject.LowEnergy.Width) + i];
                    }
                }

                lowEnergy = new SourceObject(data, width, height, false, false);
                viewType = ViewType.LowEnergy;
            }

            ViewObject viewObj = new ViewObject(m_ViewObject.Name, m_ViewObject.ImageIndex, viewType, highEnergy, lowEnergy, m_ViewObject.MaxDetectorsPerBoard, m_ViewObject.BitsPerPixel, m_ViewObject.SamplingSpeed, m_ViewObject.SamplingSpace, new List<AnnotationInfo>());
            try
            {
                AOIWindow window = new AOIWindow();
                window.AlgServerRequestEvent += new AlgServerRequestEventHandler(AOIWindow_AlgServerRequestEvent);
                window.Setup(viewObj);
                window.AOIXRayView.MainImage.Width = (int)(endPoint.X - startPoint.X);
                window.AOIXRayView.MainImage.Height = (int)(endPoint.Y - startPoint.Y);
                window.Show();

                foreach (AOIWindow aoiWindow in m_AOIWindows)
                {
                    if (window.Top == aoiWindow.Top && (window.Left == aoiWindow.Left))
                    {
                        window.Top = aoiWindow.Top + 25;
                        window.Left = aoiWindow.Left + 25;
                    }
                }

                m_AOIWindows.Add(window);
            }
            catch (Exception ex)
            {

            }
        }
Exemplo n.º 8
0
        public static void RenderXrayImage_XRayImageEffect(ref BitmapSource bsource, XrayImageEffect xrayImageEffect, SourceObject sourceObject)
        {
            //BitmapSource bsource = XRay_Image.Source as BitmapSource;

            PixelFormat pixelFormat = PixelFormats.Bgr24;

            int pixelOffset = pixelFormat.BitsPerPixel / 8;
            int stride = sourceObject.Width * pixelOffset;

            byte[] newData = new byte[sourceObject.Data.Length * pixelOffset];

            double min = xrayImageEffect.LowerBound;
            double max = xrayImageEffect.UpperBound;

            Color lowerBoundColor = xrayImageEffect.LowerBoundColor;
            Color upperBoundColor = xrayImageEffect.UpperBoundColor;

            bool enableSQRT = xrayImageEffect.EnableSquareroot > 0 ? true : false;
            bool enableSQRE = xrayImageEffect.EnableSquare > 0 ? true : false;

            Parallel.For(0, sourceObject.Data.Length, i =>
            {
                float data = sourceObject.Data[i];
                Color color = new Color();

                if (data < min)
                {
                    color.ScB = (data * lowerBoundColor.ScB);
                    color.ScG = (data * lowerBoundColor.ScG);
                    color.ScR = (data * lowerBoundColor.ScR);
                }
                else if (data > max)
                {
                    if (upperBoundColor == Colors.White)
                    {
                        color.ScB = 1.0F;
                        color.ScG = 1.0F;
                        color.ScR = 1.0F;
                    }
                    else
                    {
                        color.ScB = (data * upperBoundColor.ScB);
                        color.ScG = (data * upperBoundColor.ScG);
                        color.ScR = (data * upperBoundColor.ScR);
                    }
                }
                else if (enableSQRT)
                {
                    double Diff = max - min;
                    color.ScR = color.ScG = color.ScB = (float)(Math.Sqrt(16777216 * ((data - min) / Diff)) / Math.Sqrt(16777216));
                }
                else if (enableSQRE)
                {
                    double Diff = max - min;
                    color.ScR = color.ScG = color.ScB = (float)Math.Pow(((data - min) / Diff), 2);
                }
                else
                {
                    double Diff = max - min;
                    color.ScR = color.ScG = color.ScB = (float)((data - min) / Diff);
                }

                newData[i * pixelOffset + 0] = color.B;
                newData[i * pixelOffset + 1] = color.G;
                newData[i * pixelOffset + 2] = color.R;
            });

            bsource = BitmapSource.Create(sourceObject.Width, sourceObject.Height, 96.0, 96.0, pixelFormat, null, newData, stride);
        }