Esempio n. 1
0
        private void _btnLoadAnnotations_Click(object sender, EventArgs e)
        {
            using (OpenFileDialog openFileDialog = new OpenFileDialog())
            {
                openFileDialog.Filter = "Annotations File (.xml)|*.xml";

                if (openFileDialog.ShowDialog(this) == DialogResult.OK)
                {
                    AnnContainer tmpContainer = null;
                    try
                    {
                        AnnCodecs codecs = new AnnCodecs();
                        tmpContainer = codecs.Load(openFileDialog.FileName, 1);
                        AnnContainer activeContainer = _automation.Container;
                        if (activeContainer != null)
                        {
                            activeContainer.Children.Clear();
                            if (tmpContainer != null)
                            {
                                foreach (AnnObject annObject in tmpContainer.Children)
                                {
                                    activeContainer.Children.Add(annObject);
                                }
                            }
                        }

                        _automation.Invalidate(LeadRectD.Empty);
                    }
                    catch
                    {
                        Messager.ShowError(this, "Invalid Annotation File");
                    }
                }
            }
        }
        public override bool OnPointerUp(AnnContainer sender, AnnPointerEventArgs e)
        {
            bool handled = base.OnPointerUp(sender, e);

            _richTextEditor.ShowRichTextDialog(TargetObject as AnnRichTextObject);
            return(handled);
        }
Esempio n. 3
0
        public override bool OnPointerMove(AnnContainer sender, AnnPointerEventArgs e)
        {
            bool handled = false;

            if (TargetObject != null && HasStarted)
            {
                LeadPointD pt = ClipPoint(e.Location, ClipRectangle);

                if (!LeadPoint.Equals(pt, _end))
                {
                    _end = pt;
                    LeadPointCollection points = TargetObject.Points;

                    if (points.Count > 1)
                    {
                        if (_clickCount % 2 != 0)
                        {
                            points[points.Count - 1] = pt; // end point
                        }
                    }

                    AnnIntersectionPointObject intersectionPointObject = TargetObject as AnnIntersectionPointObject;
                    if (intersectionPointObject != null)
                    {
                        intersectionPointObject.IntersectionInsideContainer = ClipRectangle.ContainsPoint(intersectionPointObject.IntersectionPoint);
                    }

                    Working();
                }

                handled = true;
            }

            return(handled);
        }
Esempio n. 4
0
        private void AdjustFusionImage_Edit(object sender, AnnRectangleObject fusionEditRect)
        {
            int subCellIndex = _cell.ActiveSubCell;
            int index        = _cmbFusedIndex.SelectedIndex;

            MedicalViewerFusion fusion = _cell.SubCells[subCellIndex].Fusion[index];

            AnnContainer _Container = GetContainer(_cell, fusionEditRect);

            fusion.Rotation = (float)fusionEditRect.Angle;

            LeadPointD[] pt = new LeadPointD[1];


            LeadRectD rect = _Container.Mapper.RectFromContainerCoordinates(fusionEditRect.Rect, AnnFixedStateOperations.None);

            Rectangle displayRect = _cell.GetDisplayedImageRectangle();

            rect.Offset(-displayRect.Left, -displayRect.Top);


            pt[0].X = (float)(rect.X + rect.Width / 2);
            pt[0].Y = (float)(rect.Y + rect.Height / 2);

            LeadPointD point = LeadPointD.Create(pt[0].X, pt[0].Y);


            _cell.AutomationContainer.Mapper.Transform.TransformPoints(pt);

            float normalizedXPosition = (float)(((float)point.X - (float)displayRect.Width / 2) / fusion.FusedImage.Width * 100 / _cell.GetScale(subCellIndex));
            float normalizedYPosition = (float)(((float)point.Y - (float)displayRect.Height / 2) / fusion.FusedImage.Height * 100 / _cell.GetScale(subCellIndex));

            float scaleX = (float)((rect.Width / fusion.FusedImage.Width) * 100 / _cell.GetScale(subCellIndex));
            float scaleY = (float)((rect.Height / fusion.FusedImage.Height) * 100 / _cell.GetScale(subCellIndex));

            if (scaleX == 0)
            {
                scaleX = 0.1F;
            }

            if (scaleY == 0)
            {
                scaleY = 0.1F;
            }

            RectangleF rectangle = new RectangleF(normalizedXPosition, normalizedYPosition, Math.Abs(scaleX), Math.Abs(scaleY));

            fusion.DisplayRectangle = rectangle;

            UpdateFusionUI(index);

            CellData cellData = (CellData)_cell.Tag;

            if (cellData.SyncCellFusion)
            {
                UpdateCellFusions(fusion, subCellIndex, index);
            }

            _cell.Invalidate();
        }
Esempio n. 5
0
        void _rasterImageList_PostRender(object sender, Leadtools.Controls.ImageViewerRenderEventArgs e)
        {
            for (int i = 0; i < _rasterImageList.Items.Count; i++)
            {
                ImageViewerItem item = _rasterImageList.Items[i];

                LeadRectD itemLeadRect  = _rasterImageList.GetItemBounds(item, ImageViewerItemPart.Item);
                Rectangle itemRect      = new Rectangle((int)itemLeadRect.X, (int)itemLeadRect.Y, (int)itemLeadRect.Width, (int)itemLeadRect.Height);
                LeadSize  itemImageSize = _rasterImageList.GetItemImageSize(item, false);

                LeadRect imageRect = new LeadRect(
                    itemRect.Left + (itemRect.Width - itemImageSize.Width) / 2,
                    itemRect.Top + (itemRect.Height - itemImageSize.Height) / 2,
                    itemImageSize.Width,
                    itemImageSize.Height);

                itemLeadRect = ImageViewer.GetDestinationRectangle(item.Image.ImageWidth, item.Image.ImageHeight, imageRect, ControlSizeMode.None, ControlAlignment.Near, ControlAlignment.Near).ToLeadRectD();

                var destRect = LeadRectD.Create(itemLeadRect.X, itemLeadRect.Y, itemLeadRect.Width * 720.0 / 96.0, itemLeadRect.Height * 720.0 / 96.0);

                destRect.X = 0.0;
                destRect.Y = 0.0;

                //Get the graphic object from the item's image to draw (burn) annotations on it.
                Leadtools.Drawing.RasterImageGdiPlusGraphicsContainer GdiPlusGraphicsContainer = new RasterImageGdiPlusGraphicsContainer(item.Image);
                Graphics g = GdiPlusGraphicsContainer.Graphics;

                // Use anti-aliasing
                g.SmoothingMode = SmoothingMode.AntiAlias;

                // Now draw the annotation s on this rectangle
                if (_automationManager != null && _automation.Containers.Count > 0 && _automation.Containers.Count > i)
                {
                    AnnContainer container = _automation.Containers[i];

                    //Clear the old painting
                    g.Clear(Color.White);

                    //Burn the current annotations to the image list item
                    if (container != null)
                    {
                        AnnWinFormsRenderingEngine engine = new AnnWinFormsRenderingEngine();
                        engine.Resources = _automationManager.Resources;

                        // Save its visible state and set it to true (it is false if viewer is in single mode)
                        bool containerIsVisible = container.IsVisible;
                        container.IsVisible = true;

                        engine.Attach(container, g);
                        engine.BurnToRectWithDpi(destRect, 96, 96, 96, 96);
                        engine.Detach();

                        if (container.IsVisible != containerIsVisible)
                        {
                            container.IsVisible = containerIsVisible;
                        }
                    }
                }
            }
        }
Esempio n. 6
0
        public override bool OnPointerDoubleClick(AnnContainer sender, AnnPointerEventArgs e)
        {
            AnnRichTextObject obj = TargetObject as AnnRichTextObject;

            _richTextEditor.ShowRichTextDialog(obj);

            return(false);
        }
Esempio n. 7
0
 public virtual void AutomationAttach(AnnContainer container)
 {
     if (container != null)
     {
         _container = container;
         container.Children.CollectionChanged += new EventHandler <AnnNotifyCollectionChangedEventArgs>(CollectionChanged);
         container.Layers.CollectionChanged   += new EventHandler <AnnNotifyCollectionChangedEventArgs>(CollectionChanged);
     }
 }
Esempio n. 8
0
        public void SaveToMemory(int pageNumber)
        {
            AnnContainer container = TifEditor.AnnAutomation.Container;

            if (tagsData != null)
            {
                //      container.UnitConverter.DpiX = TifEditor.Viewer.Image.XResolution;
                //      container.UnitConverter.DpiY = TifEditor.Viewer.Image.YResolution;
                tagsData[pageNumber - 1] = annCodec.SaveToTag(container, AnnCodecsTagFormat.Tiff);
            }
        }
 // This method is called when AnnAutomation is created, attach the container
 public void AutomationAttach(AnnContainer container)
 {
     if (_container != container)
     {
         // Save the container, we need it
         _container = container;
         // Create the rendering engint
         //_engine.AttachContainer(container);
     }
     _isAttached = true;
 }
Esempio n. 10
0
        public override bool OnPointerUp(AnnContainer sender, AnnPointerEventArgs e)
        {
            LeadPointCollection points = TargetObject.Points;

            if (_clickCount > 3)
            {
                points.Add(_end); //we want to add  point at the end to infrom us that drawing finished
                EndWorking();
            }

            return(true);
        }
Esempio n. 11
0
        private void _miLoad_Click(object sender, EventArgs e)
        {
            AnnContainer container = _automation.Container;
            AnnCodecs    codecs    = new AnnCodecs();

            using (OpenFileDialog openFileDialog = new OpenFileDialog())
            {
                openFileDialog.Filter = "Annotations File|*.xml";

                if (openFileDialog.ShowDialog(this) == DialogResult.OK)
                {
                    AnnContainer tmpContainer = null;
                    try
                    {
                        tmpContainer = codecs.Load(openFileDialog.FileName, 1);
                    }
                    catch
                    {
                        Messager.ShowError(this, "Invalid Annotation File");
                    }

                    if (tmpContainer != null)
                    {
                        _automation.SelectLayer(null);
                        container.Children.Clear();
                        container.Layers.Clear();

                        container.SelectionObject.SelectedObjects.Clear();
                        foreach (AnnObject annObject in tmpContainer.Children)
                        {
                            container.Children.Add(annObject);
                        }

                        AnnLayerCollection tmpLayers       = tmpContainer.Layers;
                        AnnLayerCollection containerLayers = _containerNode.Layer.Layers;
                        containerLayers.Clear();
                        foreach (AnnLayer layer in tmpLayers)
                        {
                            container.Layers.Add(layer);
                        }

                        _tvLayers.BeginUpdate();
                        _tvLayers.Nodes.Clear();
                        _containerNode.Nodes.Clear();
                        _tvLayers.Nodes.Add(_containerNode);
                        AddLayersNodes(container.Layers, _containerNode);
                        _tvLayers.EndUpdate();

                        _automation.Invalidate(LeadRectD.Empty);
                    }
                }
            }
        }
Esempio n. 12
0
        public override bool OnPointerUp(AnnContainer sender, AnnPointerEventArgs e)
        {
            AnnMidlineObject    midlineObject = TargetObject as AnnMidlineObject;
            LeadPointCollection points        = midlineObject.Points;

            if (ClickCount > 1)
            {
                EndWorking();
            }

            return(true);
        }
Esempio n. 13
0
        public PageTreeNode(AnnContainer annContainer, AutomationObjectsListControl tree) : base(tree)
        {
            InitializeComponent();

            if (annContainer == null)
            {
                throw new ArgumentNullException("annContainer");
            }
            _annContainer = annContainer;

            Width      = Tree.TreeRootNode.Width;
            IsExpanded = false;
            UpdateTitle();
        }
Esempio n. 14
0
        private LeadRect BoundsFromAnnotations(AnnRectangleObject rectObject, AnnContainer container)
        {
            // Convert a rectangle from annotation object to logical coordinates (top-left)
            LeadRectD temp = container.Mapper.RectFromContainerCoordinates(rectObject.Rect, AnnFixedStateOperations.None);

            if (temp.IsEmpty)
            {
                return(LeadRect.Empty);
            }

            temp = _rasterImageViewer.ConvertRect(null, ImageViewerCoordinateType.Control, ImageViewerCoordinateType.Image, temp);
            LeadRect rect = temp.ToLeadRect();

            return(rect);
        }
Esempio n. 15
0
        /// <summary>
        /// Called by the main form to add a new page to the document
        /// </summary>
        public void AddPage(RasterImage page, int width, int height)
        {
            _rasterImageViewer.Image.AddPage(page);

            ResetViewerTransforms();

            AnnContainer container = new AnnContainer();

            container.Mapper = _annAutomation.Container.Mapper.Clone();
            container.Size   = container.Mapper.SizeToContainerCoordinates(LeadSizeD.Create(width, height));

            SetViewerTransforms();

            _annAutomation.Containers.Add(container);
        }
        public AutomationSimpleObjectsListItem(AnnContainer annContainer, AnnObject annObject)
        {
            if (annContainer == null)
            {
                throw new ArgumentNullException("annContainer");
            }
            if (annObject == null)
            {
                throw new ArgumentNullException("annObject");
            }
            if (annObject.Id == AnnObject.SelectObjectId || annObject.Id == AnnObject.None)
            {
                throw new ArgumentException("Cannot create this item with a selection or none annotation object", "annObject");
            }

            _annContainer = annContainer;
            _annObject    = annObject;
        }
        public override void Fill(AnnContainer container, LeadRectD bounds, string color)
        {
            if (_image == null)
            {
                return;
            }

            try
            {
                var fill = new FillCommand(RasterColor.Black);
                _image.AddRectangleToRegion(null, bounds.ToLeadRect(), RasterRegionCombineMode.Set);
                fill.Run(_image);
            }
            finally
            {
                _image.MakeRegionEmpty();
            }
        }
Esempio n. 18
0
        private void UpdateFusionEditRectangle(int index)
        {
            int subCellIndex = _cell.ActiveSubCell;

            MedicalViewerSubCell subCell        = _cell.SubCells[subCellIndex];
            MedicalViewerFusion  fusion         = _cell.SubCells[subCellIndex].Fusion[index];
            AnnRectangleObject   fusionEditRect = ((AnnRectangleObject)subCell.AnnotationContainer.Children[index]);
            double scaleRatio = _cell.GetScale(subCellIndex) / 100;

            Point location = _cell.GetDisplayedImageRectangle().Location;

            AnnContainer container = subCell.AnnotationContainer;
            double       scale     = _cell.GetScale(subCellIndex);

            LeadSizeD fusionEditRectSize = new LeadSizeD();

            fusionEditRectSize.Width  = fusion.FusedImage.Width * fusion.DisplayRectangle.Width * scale / 100;
            fusionEditRectSize.Height = fusion.FusedImage.Height * fusion.DisplayRectangle.Height * scale / 100;

            fusionEditRectSize = container.Mapper.SizeToContainerCoordinates(fusionEditRectSize);

            LeadPointD fusionEditRectPos = new LeadPointD();

            fusionEditRectPos.X = (subCell.AnnotationContainer.Size.Width - fusionEditRectSize.Width) / 2;
            fusionEditRectPos.Y = (subCell.AnnotationContainer.Size.Height - fusionEditRectSize.Height) / 2;

            //container.Bounds
            fusionEditRect.Rect = new LeadRectD(fusionEditRectPos, fusionEditRectSize);

            AnnContainer _Container = GetContainer(_cell, fusionEditRect);

            fusionEditRect.Rotate(fusion.Rotation, new LeadPointD(_Container.Size.Width / 2, _Container.Size.Height / 2));
            LeadPointD point = LeadPointD.Create(fusion.DisplayRectangle.X * fusion.FusedImage.Width * scaleRatio + location.X, fusion.DisplayRectangle.Y * fusion.FusedImage.Height * scaleRatio + location.Y);

            point = _Container.Mapper.PointToContainerCoordinates(point);
            fusionEditRect.Translate(point.X, point.Y);

            fusionEditRect.RotateCenter = new LeadPointD(fusionEditRect.Rect.Left + (fusionEditRect.Rect.Width / 2), fusionEditRect.Rect.Top + (fusionEditRect.Rect.Height / 2));

            _cell.RefreshAnnotation();
            _cell.Automation.Invalidate(LeadRectD.Empty);
            _cell.Invalidate();
        }
        public override byte[] GetImageData(AnnContainer container, LeadRectD bounds)
        {
            if (_image == null)
            {
                return(null);
            }

            using (var image = _image.Clone(bounds.ToLeadRect()))
            {
                using (var codecs = new RasterCodecs())
                {
                    using (var ms = new MemoryStream())
                    {
                        codecs.Save(image, ms, RasterImageFormat.Png, Image.BitsPerPixel);

                        return(ms.ToArray());
                    }
                }
            }
        }
Esempio n. 20
0
        void cell_AnnotationCreated(object sender, MedicalViewerAnnotationCreatedEventArgs e)
        {
            AnnRectangleObject rectangle = e.Object as AnnRectangleObject;

            rectangle.RotateGripper = new LeadLengthD();


            _Container = GetContainer((MedicalViewerMultiCell)sender, rectangle);


            for (int i = 0; i < Cell.SubCells.Count; i++)
            {
                AnnContainer container = Cell.SubCells[i].AnnotationContainer;

                if (container != null && container != _Container)
                {
                    container.Children.Add(rectangle);
                }
            }
        }
Esempio n. 21
0
        private void ViewDatasetDialog_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (loaderThread != null)
            {
                loaderThread.Abort();
            }

            if (DialogResult == DialogResult.OK)
            {
                AnnContainer container = Cell.GetAnnotationContainer();

                foreach (AnnRectangleObject rectangle in container.Children)
                {
                    //AnnTransformer transform = new AnnTransformer(container.UnitConverter, rectangle.Transform);
                    //AnnRectangleObject imageRectangle = transform.RectangleToPhysical(rectangle.BoundingRectangle);

                    AnnRectangleObject imageRectangle = new AnnRectangleObject(container.Mapper.RectFromContainerCoordinates(rectangle.Bounds, AnnFixedStateOperations.None));

                    _BlackoutRects.Add(new LeadRect((int)imageRectangle.Bounds.Left, (int)imageRectangle.Bounds.Top, (int)imageRectangle.Bounds.Width, (int)imageRectangle.Bounds.Height));
                }
            }
        }
        public override void SetImageData(AnnContainer container, LeadRectD bounds, byte[] data)
        {
            if (_image == null)
            {
                return;
            }

            using (var ms = new MemoryStream(data))
            {
                using (var codecs = new RasterCodecs())
                {
                    using (var image = codecs.Load(ms))
                    {
                        if (image.ViewPerspective != _image.ViewPerspective)
                        {
                            image.ChangeViewPerspective(_image.ViewPerspective);
                        }

                        if (image.BitsPerPixel != _image.BitsPerPixel || image.Order != _image.Order)
                        {
                            var palette      = _image.GetPalette();
                            var paletteFlags = palette != null ? ColorResolutionCommandPaletteFlags.UsePalette : ColorResolutionCommandPaletteFlags.Optimized;

                            var colorResCommand = new ColorResolutionCommand(
                                ColorResolutionCommandMode.InPlace,
                                _image.BitsPerPixel,
                                _image.Order,
                                RasterDitheringMethod.None,
                                paletteFlags,
                                palette);
                            colorResCommand.Run(image);
                        }

                        var combine = new CombineFastCommand(_image, bounds.ToLeadRect(), LeadPoint.Create(0, 0), CombineFastCommandFlags.SourceCopy);
                        combine.Run(image);
                    }
                }
            }
        }
Esempio n. 23
0
        public override byte[] GetImageData(AnnContainer container, LeadRectD bounds)
        {
            if (_image == null)
            {
                return(null);
            }

            LeadRect rect = bounds.ToLeadRect();

            rect = _image.RectangleToImage(RasterViewPerspective.TopLeft, rect);

            using (var image = _image.Clone(rect))
            {
                using (var codecs = new RasterCodecs())
                {
                    using (var ms = new MemoryStream())
                    {
                        codecs.Save(image, ms, RasterImageFormat.Png, Image.BitsPerPixel);

                        return(ms.ToArray());
                    }
                }
            }
        }
Esempio n. 24
0
        public void LoadFromMemory(int pageNumber)
        {
            AnnContainer container = TifEditor.AnnAutomation.Container;

            container.Objects.Clear();
            try
            {
                TifEditor.AnnAutomation.SelectNone();
            }
            catch (Exception e)
            {
            }
            if (tagsData != null)
            {
                RasterTagMetadata tag = tagsData[pageNumber - 1];
                if (tag != null)
                {
                    //      container.UnitConverter.DpiX = TifEditor.Viewer.Image.XResolution;
                    //      container.UnitConverter.DpiY = TifEditor.Viewer.Image.YResolution;
                    // tag.
                    annCodec.LoadFromTag(tag, container);
                }
            }
        }
Esempio n. 25
0
        public override bool OnPointerDown(AnnContainer sender, AnnPointerEventArgs e)
        {
            bool handled = base.OnPointerDown(sender, e);

            if (e.Button != AnnMouseButton.Left)
            {
                return(handled);
            }

            _clickCount++;

            if (e.Button == AnnMouseButton.Left)
            {
                LeadPointD _begin = ClipPoint(e.Location, ClipRectangle);
                _end = _begin;

                LeadPointCollection points = TargetObject.Points;

                if (_clickCount == 1)
                {
                    points.Add(_begin);
                    points.Add(_end);
                }

                else if (_clickCount % 2 != 0)
                {
                    points.Add(_begin);
                    points.Add(_end);
                }

                StartWorking();
                handled = true;
            }

            return(handled);
        }
Esempio n. 26
0
        /// <summary>
        /// Xử lý sự kiện Mouseup để vẽ đối tượng cắt ảnh
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void cell_MouseUp(object sender, MouseEventArgs e)
        {
            try
            {
                if (!blnhasJustCreated) return;
                Rectangle Rec = _CurrCell.GetDisplayedImageRectangle();
                X2 = e.X - Rec.X;
                Y2 = e.Y - Rec.Y;
                ImgRec = Rec;
                Leadtools.Annotations.AnnContainer _AnnContainer;
                lastRecObj = null;
                bool bHasRecObj = false;
                if (_DicomMedicalViewer._IsCropping)
                {
                    _AnnContainer = _CurrCell.GetAnnotationContainer();
                    _CurrCell.SetAnnotationContainer(new AnnContainer());
                    AnnContainer _newAnn = new AnnContainer();
                    foreach (AnnObject AnnObj in _AnnContainer.Objects)
                        if (AnnObj.GetType().Equals(new AnnRectangleObject().GetType()) || (AnnObj.GetType().Equals(new AnnTextObject().GetType()) && ((AnnTextObject)AnnObj).Text != null && (((AnnTextObject)AnnObj).Text.ToString() == "L" || ((AnnTextObject)AnnObj).Text.ToString() == "R")))
                        {
                            if (AnnObj.GetType().Equals(new AnnRectangleObject().GetType()))
                            {
                                lastRecObj = (AnnRectangleObject)AnnObj;
                            }
                            else
                                _newAnn.Objects.Add(AnnObj);
                        }


                    if (lastRecObj != null)
                    {
                        lastRecObj.Tag = 2100;// MultiLanguage.GetText(globalVariables.DisplayLanguage, "Cắt ảnh", "CROP");
                        lastRecObj.NameFont = new AnnFont("Arial", new AnnLength(50), FontStyle.Bold);
                        lastRecObj.Pen = new AnnPen(Color.Red, new AnnLength(GetWidthOfCrop()));

                        _newAnn.Objects.Add(lastRecObj);


                    }
                    _CurrCell.SetAnnotationContainer(_newAnn);
                    _CurrCell.Invalidate();
                    //SaveAnnotation(CurrCellFileName);
                    //LoadAnnotation(_CurrCell, GetAnnPath(CurrCellFileName), false);


                }
            }
            catch
            {
            }
            finally
            {
                blnhasJustCreated = false;
            }
        }
Esempio n. 27
0
        private static void RenderContainer(ImageViewerRenderEventArgs e, AnnRenderingEngine renderingEngine, AnnContainer container, bool runMode)
        {
            // Attach to the current container and graphics
            var context       = e.PaintEventArgs.Graphics;
            var clipRectangle = e.PaintEventArgs.ClipRectangle;

            // Render the annotations
            renderingEngine.Attach(container, (Graphics)context);

            try
            {
                // Convert the clip rectangle to annotation coordinates
                var annClipRect = LeadRectD.Create(clipRectangle.X, clipRectangle.Y, clipRectangle.Width, clipRectangle.Height);
                annClipRect = container.Mapper.RectToContainerCoordinates(annClipRect);

                renderingEngine.Render(annClipRect, runMode);
            }
            finally
            {
                renderingEngine.Detach();
            }
        }
Esempio n. 28
0
 public virtual void AutomationDetach()
 {
     _container = null;
 }
Esempio n. 29
0
        /// <summary>
        /// Load Annotation của một ảnh để hiển thị cho người dùng xem
        /// </summary>
        /// <param name="cell"></param>
        /// <param name="fileName"></param>
        /// <param name="AutoIgnoreCropObject"></param>
        private void LoadAnnotation(MedicalViewerMultiCell cell, string fileName, bool AutoIgnoreCropObject)
        {
            return;
            int count = 1;
            #region 17.5
            //try
            //{
            //    if (fileName != null)
            //    {
            //        AnnCodecs _annCodecs = new AnnCodecs();
            //        _annCodecs.Load(fileName, cell.GetAnnotationContainer(0), 1);

            //        if (AutoIgnoreCropObject)
            //        {
            //            Leadtools.Annotations.AnnContainer _AnnContainer;
            //            lastRecObj = null;
            //            bool bHasRecObj = false;
            //            _AnnContainer = ((MedicalViewerMultiCell)_DicomMedicalViewer._medicalViewer.Cells[_DicomMedicalViewer._medicalViewerCellIndex]).GetAnnotationContainer(0);
            //            ((MedicalViewerMultiCell)_DicomMedicalViewer._medicalViewer.Cells[_DicomMedicalViewer._medicalViewerCellIndex]).SetAnnotationContainer(new AnnContainer());
            //            AnnContainer _newAnn = new AnnContainer();
            //            foreach (AnnObject AnnObj in _AnnContainer.Objects)
            //                if (AnnObj.GetType().Equals(new AnnRectangleObject().GetType()) || (AnnObj.GetType().Equals(new AnnTextObject().GetType()) && ((AnnTextObject)AnnObj).Text != null && (((AnnTextObject)AnnObj).Text.ToString() == "L" || ((AnnTextObject)AnnObj).Text.ToString() == "R")))
            //                {
            //                    if (AnnObj.GetType().Equals(new AnnRectangleObject().GetType()) && ((AnnRectangleObject)AnnObj).Name.ToUpper() == "CẮT ẢNH")
            //                    {
            //                        lastRecObj = (AnnRectangleObject)AnnObj;
            //                    }
            //                    else
            //                        _newAnn.Objects.Add(AnnObj);
            //                }



            //            ((MedicalViewerMultiCell)_DicomMedicalViewer._medicalViewer.Cells[_DicomMedicalViewer._medicalViewerCellIndex]).SetAnnotationContainer(_newAnn);
            //            ((MedicalViewerMultiCell)_DicomMedicalViewer._medicalViewer.Cells[_DicomMedicalViewer._medicalViewerCellIndex]).Invalidate();
            //        }

            //        //count += cell.Image.PageCount;
            //    }
            //}
            //catch (Exception ex)
            //{
            //}
            #endregion
            #region 17.0

            try
            {
                if (fileName != null)
                {
                    FileStream f = new FileStream(fileName, FileMode.OpenOrCreate);
                   
                    cell.LoadAnnotations(f);
                    f.Flush();
                    f.Close();
                    return;
                    if (AutoIgnoreCropObject)
                    {
                        Leadtools.Annotations.AnnContainer _AnnContainer;
                        lastRecObj = null;
                        bool bHasRecObj = false;
                        _AnnContainer = ((MedicalViewerMultiCell)_DicomMedicalViewer._medicalViewer.Cells[_DicomMedicalViewer._medicalViewerCellIndex]).GetAnnotationContainer(0);
                        ((MedicalViewerMultiCell)_DicomMedicalViewer._medicalViewer.Cells[_DicomMedicalViewer._medicalViewerCellIndex]).SetAnnotationContainer(new AnnContainer());
                        AnnContainer _newAnn = new AnnContainer();
                        foreach (AnnObject AnnObj in _AnnContainer.Objects)
                            if (AnnObj.GetType().Equals(new AnnRectangleObject().GetType()) || (AnnObj.GetType().Equals(new AnnTextObject().GetType()) && ((AnnTextObject)AnnObj).Text != null && (((AnnTextObject)AnnObj).Text.ToString() == "L" || ((AnnTextObject)AnnObj).Text.ToString() == "R")))
                            {
                                if (AnnObj.GetType().Equals(new AnnRectangleObject().GetType()) && ((AnnRectangleObject)AnnObj).Tag != null && ((AnnRectangleObject)AnnObj).Tag.ToString().ToUpper() == "2100")
                                {
                                    lastRecObj = (AnnRectangleObject)AnnObj;
                                }
                                else
                                    _newAnn.Objects.Add(AnnObj);
                            }
                        ((MedicalViewerMultiCell)_DicomMedicalViewer._medicalViewer.Cells[_DicomMedicalViewer._medicalViewerCellIndex]).SetAnnotationContainer(_newAnn);
                        ((MedicalViewerMultiCell)_DicomMedicalViewer._medicalViewer.Cells[_DicomMedicalViewer._medicalViewerCellIndex]).Invalidate();
                    }

                    //count += cell.Image.PageCount;
                }
            }
            catch (Exception ex)
            {
            }
            #endregion
        }
Esempio n. 30
0
        public static DicomDataSet GeneratePresentationState(string seriesInstanceUID, string annotationData, string description, DicomDataSet seriesDs, int windowCenter, int windowWidth, out string sopInstanceUID)
        {
            AnnCodecs codec = new AnnCodecs();

            using (MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(annotationData)))
            {
                ms.Position = 0;
                AnnCodecsInfo codecInfo = codec.GetInfo(ms);
                ms.Position = 0;
                JavaScriptSerializer      jsSerialzer = new JavaScriptSerializer();
                DicomAnnotationsUtilities dicomAnnotationsUtilities = new DicomAnnotationsUtilities();
                DicomDataSet ds = new DicomDataSet();


                sopInstanceUID = SeriesGenerator.GenerateDicomUniqueIdentifier();
                //Patient Module C.7.1.1
                ds.InsertElementAndSetValue(DicomTag.PatientName, seriesDs.GetValue <string>(DicomTag.PatientName, string.Empty));

                ds.InsertElementAndSetValue(DicomTag.PatientID, seriesDs.GetValue <string>(DicomTag.PatientID, string.Empty));
                ds.InsertElementAndSetValue(DicomTag.PatientBirthDate, "");
                ds.InsertElementAndSetValue(DicomTag.PatientSex, "");

                //Study Module C.7.2.1
                ds.InsertElementAndSetValue(DicomTag.StudyInstanceUID, seriesDs.GetValue <string>(DicomTag.StudyInstanceUID, string.Empty));
                ds.InsertElementAndSetValue(DicomTag.StudyDate, "");
                ds.InsertElementAndSetValue(DicomTag.StudyTime, "");
                ds.InsertElementAndSetValue(DicomTag.ReferringPhysicianName, "");
                ds.InsertElementAndSetValue(DicomTag.StudyID, seriesDs.GetValue <string>(DicomTag.StudyID, string.Empty));
                ds.InsertElementAndSetValue(DicomTag.AccessionNumber, seriesDs.GetValue <string>(DicomTag.AccessionNumber, string.Empty));

                //Series Module C.7.3.1
                ds.InsertElementAndSetValue(DicomTag.SeriesInstanceUID, SeriesGenerator.GenerateDicomUniqueIdentifier());
                ds.InsertElementAndSetValue(DicomTag.Modality, "PR");
                ds.InsertElementAndSetValue(DicomTag.SeriesNumber, 1);
                ds.InsertElementAndSetValue(DicomTag.SeriesDate, DicomDateValue.Now);
                ds.InsertElementAndSetValue(DicomTag.SeriesTime, DicomTimeValue.Now);
                ds.InsertElementAndSetValue(DicomTag.SeriesDescription, "Study layout presentation state");

                //General Equipment Module C.7.5.1
                ds.InsertElementAndSetValue(DicomTag.Manufacturer, "LEADTOOLS IMAGING");
                ds.InsertElementAndSetValue(DicomTag.InstitutionName, "LEADTOOLS, INC.");
                ds.InsertElementAndSetValue(DicomTag.StationName, "HTML5 Viewer");

                //Presentation State Identification Module C.11.10
                ds.InsertElementAndSetValue(DicomTag.PresentationCreationDate, DicomDateValue.Now);
                ds.InsertElementAndSetValue(DicomTag.PresentationCreationTime, DicomTimeValue.Now);
                //Content Identification Macro Table 10-12
                ds.InsertElementAndSetValue(DicomTag.InstanceNumber, 1);
                ds.InsertElementAndSetValue(DicomTag.ContentLabel, "STUDY LAYOUT PRESENTATION");
                ds.InsertElementAndSetValue(DicomTag.ContentDescription, description);
                //ds.InsertElementAndSetValue(DicomTag.ContentCreatorName, userName);

                //Presentation State RelationShip Module C11.11
                PresentationStateRelationShip referncedSeriesSeq = new PresentationStateRelationShip();
                referncedSeriesSeq.ReferencedSeriesSequence = new List <ReferencedSeries>();
                ReferencedSeries referencedSeries = new ReferencedSeries();
                referencedSeries.SeriesInstanceUID       = seriesInstanceUID;
                referencedSeries.ReferencedImageSequence = new List <SopInstanceReference>();
                referncedSeriesSeq.ReferencedSeriesSequence.Add(referencedSeries);


                Dictionary <LeadSize, List <ImageSopInstanceReference> > displayedAreaInstance = new Dictionary <LeadSize, List <ImageSopInstanceReference> >();
                for (int index = 0; index < codecInfo.Pages.Length; index++)
                {
                    AnnContainer container = codec.Load(ms, codecInfo.Pages[index]);
                    ms.Position = 0;

                    if (null == container.UserData)
                    {
                        continue;
                    }

                    AnnUserData refInstance = (AnnUserData)jsSerialzer.Deserialize <AnnUserData>(container.UserData.ToString());

                    if (null != refInstance && null != refInstance.ReferencedImageSequence)
                    {
                        referncedSeriesSeq.ReferencedSeriesSequence[0].ReferencedImageSequence.Add(refInstance.ReferencedImageSequence);

                        // The Medical Viewer defaults dpi to 150
                        // In this case, there is enough information to compute the dpi, which should be 150

                        //double dpiX = 0;
                        //double dpiY = 0;
                        //container.CalculateDpi(out dpiX, out dpiY);

                        //if (dpiX == 0 || dpiY == 0)
                        //{
                        //   dpiX = 150.0;
                        //   dpiY = 150.0;
                        //}
                        double xDpi = 150;
                        double yDpi = 150;

                        dicomAnnotationsUtilities.ImageDpiX = xDpi;
                        dicomAnnotationsUtilities.ImageDpiY = yDpi;


                        DicomElement graphicSequenceItem = dicomAnnotationsUtilities.FromAnnContainerToDataSet(ds, container);

                        DicomElement layerElement = ds.FindFirstElement(graphicSequenceItem, DicomTag.GraphicLayer, false);

                        if (null == layerElement)
                        {
                            ds.InsertElementAndSetValue(graphicSequenceItem, true, DicomTag.GraphicLayer, "LAYER1");
                        }
                        else
                        {
                            ds.SetStringValue(layerElement, "LAYER1", DicomCharacterSetType.Default);
                        }

                        GraphicAnnotationsModule annModule = new GraphicAnnotationsModule();

                        annModule.ReferencedImageSequence = new List <ImageSopInstanceReference>();
                        annModule.ReferencedImageSequence.Add(refInstance.ReferencedImageSequence);

                        ds.Set(graphicSequenceItem, annModule);
                    }

                    if (!refInstance.ImageSize.IsEmpty)
                    {
                        if (!displayedAreaInstance.ContainsKey(refInstance.ImageSize))
                        {
                            displayedAreaInstance[refInstance.ImageSize] = new List <ImageSopInstanceReference>();
                        }

                        displayedAreaInstance[refInstance.ImageSize].Add(refInstance.ReferencedImageSequence);
                    }
                }

                ds.Set(referncedSeriesSeq);

                //Displayed Area Module
                //
                //
                DisplayedAreaModule displayedAreaModule = new DisplayedAreaModule();


                displayedAreaModule.DisplayedAreaSelection = new List <DisplayedAreaSelection>();

                foreach (KeyValuePair <LeadSize, List <ImageSopInstanceReference> > areaInstance in displayedAreaInstance)
                {
                    DisplayedAreaSelection displayedArea = new DisplayedAreaSelection();
                    displayedAreaModule.DisplayedAreaSelection.Add(displayedArea);
                    displayedArea.DisplayedAreaTopLeftHandCorner     = new List <long>();
                    displayedArea.DisplayedAreaBottomRightHandCorner = new List <long>();
                    displayedArea.DisplayedAreaTopLeftHandCorner.Add(1);
                    displayedArea.DisplayedAreaTopLeftHandCorner.Add(1);
                    displayedArea.DisplayedAreaBottomRightHandCorner.Add(areaInstance.Key.Width);
                    displayedArea.DisplayedAreaBottomRightHandCorner.Add(areaInstance.Key.Height);
                    displayedArea.PresentationSizeMode         = PresentationSizeMode.ScaleToFit;
                    displayedArea.PresentationPixelAspectRatio = new List <int>();
                    displayedArea.PresentationPixelAspectRatio.Add(1);
                    displayedArea.PresentationPixelAspectRatio.Add(1);

                    if (displayedAreaInstance.Count > 1)
                    {
                        displayedArea.ReferencedImageSequence = areaInstance.Value;
                    }
                }

                ds.Set(displayedAreaModule);

                //Graphic Layer Module
                GraphicLayerModule graphicLayerModule = new GraphicLayerModule();
                GraphicLayer       layer = new GraphicLayer();

                graphicLayerModule.GraphicLayerSequence = new List <GraphicLayer>();
                layer.GraphicLayerName  = "LAYER1";
                layer.GraphicLayerOrder = 1;
                graphicLayerModule.GraphicLayerSequence.Add(layer);

                ds.Set(graphicLayerModule);

                //Softcopy Presentation LUT Module
                SoftCopyPresentationLutModule presentationLut = new SoftCopyPresentationLutModule();
                presentationLut.PresentationLutShape = PresentationLutShape.Identity;
                if (windowCenter != -1 || windowWidth != -1)
                {
                    SoftCopyVoiLutModule module = new SoftCopyVoiLutModule();

                    module.WindowCenter = new List <double>();
                    module.WindowCenter.Add(windowCenter);
                    module.WindowWidth = new List <double>();
                    module.WindowWidth.Add(windowWidth);
                    ds.Set(module);
                }

                ds.Set(presentationLut);

                //SOP Common Module
                ds.InsertElementAndSetValue(DicomTag.SOPClassUID, DicomUidType.GrayscaleSoftcopyPresentationStateStorage);
                ds.InsertElementAndSetValue(DicomTag.SOPInstanceUID, sopInstanceUID);
                ds.InsertElementAndSetValue(DicomTag.InstanceCreationDate, DicomDateValue.Now);
                ds.InsertElementAndSetValue(DicomTag.InstanceCreationTime, DicomDateValue.Now);
                ds.InsertElementAndSetValue(DicomTag.InstanceNumber, 1);

                return(ds);
            }
        }
Esempio n. 31
0
        void RealizeAnnotationV2()
        {
            try
            {
                // Create and set up the container
                AnnContainer container = new AnnContainer();
                IntPtr hdc = RasterImagePainter.CreateLeadDC(_CurrCell.Image);
                container.Bounds = new AnnRectangle(0, 0, _CurrCell.Image.ImageWidth, _CurrCell.Image.ImageHeight);
                container.UnitConverter = new AnnUnitConverter(_CurrCell.Image.XResolution, _CurrCell.Image.YResolution);
                container.Draw(_CurrCell.Image);
                using (RasterCodecs _codecs = new RasterCodecs())
                {
                    _codecs.Save(_CurrCell.Image, _CurrCell.Image.Tags.ToString(), RasterImageFormat.DicomGray, _CurrCell.Image.BitsPerPixel);
                }
               


            }
            catch
            {
            }
        }
Esempio n. 32
0
 public virtual void AutomationAttach(AnnContainer container)
 {
     _container = container;
 }
Esempio n. 33
0
 private AnnRectangle GetObjectRealBoundingRectangle(AnnObject obj,AnnContainer container)
 {
     return _DicomMedicalViewer.GetObjectRealBoundingRectangle(obj, container);
 }
 public AnnFourParallelLinesDrawer(IAnnAutomationControl automationControl, AnnContainer container, AnnParallelLinesObject annParallelLinesObject)
     : base(automationControl, container, annParallelLinesObject)
 {
 }
Esempio n. 35
0
        public void RotateImageAndAnnotations(int angle, AnnContainer container)
        {
            
            // round the angle
            angle %= 360;

            if (angle == 0)
                return;  // nothing to do

            // when we rotate an image, this is what happens:
            //  1. the image is rotated around its center (width/2, height/2)
            //  2. the image is translated so that its top,left position is at 0,0

            // to calculate this translation, we:
            //  1. find the 4 end points of the container
            //  2. rotate these points
            //  3. find the minimum/maximum "out of range" point
            //  4. calculate the translation (amount to bring this "out of range" point back into view)
            PointF[] pts =
         {
            new PointF(0, 0),
            new PointF(viewer.Image.ImageWidth, 0),
            new PointF(viewer.Image.ImageWidth, viewer.Image.ImageHeight),
            new PointF(0, viewer.Image.ImageHeight)
         };

            PointF origin = new PointF(viewer.Image.ImageWidth / 2, viewer.Image.ImageHeight / 2);

            using (Matrix m = new Matrix())
            {
                m.RotateAt(angle, origin);
                m.TransformPoints(pts);
            }

            float xMin = pts[0].X;
            float yMin = pts[0].Y;

            for (int i = 1; i < pts.Length; i++)
            {
                if (pts[i].X < xMin)
                    xMin = pts[i].X;

                if (pts[i].Y < yMin)
                    yMin = pts[i].Y;
            }

            float xTranslate = -xMin;
            float yTranslate = -yMin;

            // now, rotate the image
            // Note, in this demo we will rotate only the view perspective, but you can use the RotateCommand to rotate
            // the annotations and the image around angle angle
            viewer.Image.RotateViewPerspective(angle);

            AnnPoint annOrigin = new AnnPoint(origin, AnnUnit.Pixel);

            // rotate and translate the annotations
            foreach (AnnObject obj in container.Objects)
            {
                obj.Rotate(angle, annOrigin);

                if (xTranslate != 0 || yTranslate != 0)
                    obj.Translate(xTranslate, yTranslate);
            }

            // re-set the container bounds
            container.Bounds = new AnnRectangle(0, 0, viewer.Image.ImageWidth, viewer.Image.ImageHeight);
        }