Esempio n. 1
0
            public void TestConstructors()
            {
                try
                {
                    DicomAttributeUI attrib = new DicomAttributeUI(DicomTagDictionary.GetDicomTag(DicomTags.AccessionNumber));
                    Assert.Fail("Above statement should throw exception");
                }
                catch (DicomException)
                {

                }

                CreateAttribute();
            }
Esempio n. 2
0
        /// <summary>
        /// Method for dumping the contents of the attribute to a string.
        /// </summary>
        /// <param name="sb">The StringBuilder to write the attribute to.</param>
        /// <param name="prefix">A prefix to place before the value.</param>
        /// <param name="options">The <see cref="DicomDumpOptions"/> to use for the output string.</param>
        public virtual void Dump(StringBuilder sb, string prefix, DicomDumpOptions options)
        {
            int ValueWidth = 40 - prefix.Length;
            int SbLength   = sb.Length;

            sb.Append(prefix);
            sb.AppendFormat("({0:x4},{1:x4}) {2} ", Tag.Group, Tag.Element, Tag.VR.Name);
            if (Count == 0)
            {
                String value = "(no value available)";
                sb.Append(value.PadRight(ValueWidth, ' '));
            }
            else
            {
                if (Tag.VR.IsTextVR)
                {
                    String value;
                    if (Tag.VR == DicomVr.UIvr)
                    {
                        DicomAttributeUI ui = this as DicomAttributeUI;

                        DicomUid uid;
                        bool     ok = ui.TryGetUid(0, out uid);

                        if (ok && uid.Type != UidType.Unknown)
                        {
                            value = "=" + uid.Description;
                            if (Flags.IsSet(options, DicomDumpOptions.ShortenLongValues))
                            {
                                if (value.Length > ValueWidth)
                                {
                                    value = value.Substring(0, ValueWidth - 3);
                                }
                            }
                        }
                        else
                        {
                            value = "[" + ToString() + "]";
                            if (Flags.IsSet(options, DicomDumpOptions.ShortenLongValues))
                            {
                                if (value.Length > ValueWidth)
                                {
                                    value = value.Substring(0, ValueWidth - 4) + "...]";
                                }
                            }
                        }
                    }
                    else
                    {
                        value = "[" + ToString() + "]";
                        if (Flags.IsSet(options, DicomDumpOptions.ShortenLongValues))
                        {
                            if (value.Length > ValueWidth)
                            {
                                value = value.Substring(0, ValueWidth - 4) + "...]";
                            }
                        }
                    }
                    sb.Append(value.PadRight(ValueWidth, ' '));
                }
                else
                {
                    String value = ToString();
                    if (Flags.IsSet(options, DicomDumpOptions.ShortenLongValues))
                    {
                        if (value.Length > ValueWidth)
                        {
                            value = value.Substring(0, ValueWidth - 3) + "...";
                        }
                    }
                    sb.Append(value.PadRight(ValueWidth, ' '));
                }
            }
            sb.AppendFormat(" # {0,4} {2} {1}", StreamLength, Tag.VM, Tag.Name.Replace("&apos;", "'"));

            if (Flags.IsSet(options, DicomDumpOptions.Restrict80CharactersPerLine))
            {
                if (sb.Length > (SbLength + 79))
                {
                    sb.Length = SbLength + 79;
                    //sb.Append(">");
                }
            }
        }
Esempio n. 3
0
 public DicomAttributeUI CreateAttribute()
 {
     DicomAttributeUI attrib = new DicomAttributeUI(DicomTagDictionary.GetDicomTag(DicomTags.StudyInstanceUid));
     Assert.AreEqual(0, attrib.Count);
     Assert.AreEqual(0, attrib.StreamLength);
     return attrib;
 }
Esempio n. 4
0
        //public void SaveEfilm(string efilmFullPath, ref string efilmOriginalSopInstanceUID)
        //{
        //    efilmOriginalSopInstanceUID = string.Empty;

        //}

        public void SaveEfilm(string efilmFullPath, ref string efilmOriginalSopInstanceUID, ref string efilmOriginalStudyInstanceUid, bool ifSaveEFilm)
        {
            efilmOriginalSopInstanceUID = string.Empty;

            try
            {
                Logger.LogFuncUp();

                if (_dicomDataHeader == null)
                {
                    return;
                }

                var wrtBmp = RenderControlWriteableBitmap();

                if (wrtBmp == null)
                {
                    throw new ApplicationException("ViewerControl Writeable Bitmap Render failed.");
                }



                byte[] data = ProcessImage(wrtBmp);
                Console.WriteLine(Convert.ToString(wrtBmp.PixelWidth) + " ,,,,," + Convert.ToString(wrtBmp.PixelHeight));

                ////MedViewerLayoutCell layoutCell = medViewerControl.LayoutManager.RootCell;
                ////MedViewerControlCell cell = GetControlCell(layoutCell);


                var pixelHeightTag = new DicomAttributeUS(new DicomTag(Pipeline.Dictionary.Tag.Rows));
                pixelHeightTag.SetUInt16(0, Convert.ToUInt16(wrtBmp.PixelHeight));
                _dicomDataHeader.RemoveDicomAttribute(Pipeline.Dictionary.Tag.Rows);
                _dicomDataHeader.AddDicomAttribute(pixelHeightTag);

                var pixelWidthTag = new DicomAttributeUS(new DicomTag(Pipeline.Dictionary.Tag.Columns));
                pixelWidthTag.SetUInt16(0, Convert.ToUInt16(wrtBmp.PixelWidth));
                _dicomDataHeader.RemoveDicomAttribute(Pipeline.Dictionary.Tag.Columns);
                _dicomDataHeader.AddDicomAttribute(pixelWidthTag);

                var bitStoredTag = new DicomAttributeUS(new DicomTag(Pipeline.Dictionary.Tag.BitsStored));
                bitStoredTag.SetUInt16(0, 8);
                _dicomDataHeader.RemoveDicomAttribute(Pipeline.Dictionary.Tag.BitsStored);
                _dicomDataHeader.AddDicomAttribute(bitStoredTag);

                var bitAllocatedTag = new DicomAttributeUS(new DicomTag(Pipeline.Dictionary.Tag.BitsAllocated));
                bitAllocatedTag.SetUInt16(0, 8);
                _dicomDataHeader.RemoveDicomAttribute(Pipeline.Dictionary.Tag.BitsAllocated);
                _dicomDataHeader.AddDicomAttribute(bitAllocatedTag);

                var hightBitTag = new DicomAttributeUS(new DicomTag(Pipeline.Dictionary.Tag.HighBit));
                hightBitTag.SetUInt16(0, 7);
                _dicomDataHeader.RemoveDicomAttribute(Pipeline.Dictionary.Tag.HighBit);
                _dicomDataHeader.AddDicomAttribute(hightBitTag);

                var pixelRepresentationTag = new DicomAttributeUS(new DicomTag(Pipeline.Dictionary.Tag.PixelRepresentation));
                pixelRepresentationTag.SetUInt16(0, 0);
                _dicomDataHeader.RemoveDicomAttribute(Pipeline.Dictionary.Tag.PixelRepresentation);
                _dicomDataHeader.AddDicomAttribute(pixelRepresentationTag);

                var rescaleSlopeTag = new DicomAttributeDS(new DicomTag(Pipeline.Dictionary.Tag.RescaleSlope));
                rescaleSlopeTag.SetString(0, "1");
                _dicomDataHeader.RemoveDicomAttribute(Pipeline.Dictionary.Tag.RescaleSlope);
                _dicomDataHeader.AddDicomAttribute(rescaleSlopeTag);

                var rescaleInterceptTag = new DicomAttributeDS(new DicomTag(Pipeline.Dictionary.Tag.RescaleIntercept));
                rescaleInterceptTag.SetString(0, "0");;
                _dicomDataHeader.RemoveDicomAttribute(Pipeline.Dictionary.Tag.RescaleIntercept);
                _dicomDataHeader.AddDicomAttribute(rescaleInterceptTag);


                ////insert Photometric Interpretation //maybe can fix inverse problem
                //var photometricInterpretationTag = new DicomAttributeUS(new DicomTag(Pipeline.Dictionary.Tag.PhotometricInterpretation));
                //rescaleInterceptTag.SetString(0, "MONOCHROME2");
                ////_dicomDataHeader.RemoveDicomAttribute(Pipeline.Dictionary.Tag.PhotometricInterpretation);
                //_dicomDataHeader.AddDicomAttribute(photometricInterpretationTag);
                //insert Photometric Interpretation
                _dicomDataHeader.RemoveDicomAttribute(Pipeline.Dictionary.Tag.PhotometricInterpretation);
                var photometricInterpretationTag = DicomAttribute.CreateAttribute(Pipeline.Dictionary.Tag.PhotometricInterpretation);
                if (!photometricInterpretationTag.SetString(0, "MONOCHROME2"))
                {
                    throw new Exception("Failed to Insert Columns to Data header");
                }
                _dicomDataHeader.AddDicomAttribute(photometricInterpretationTag);

                _dicomDataHeader.RemoveDicomAttribute(Pipeline.Dictionary.Tag.WindowWidth);
                _dicomDataHeader.RemoveDicomAttribute(Pipeline.Dictionary.Tag.WindowCenter);
                var windowWidthTag = new DicomAttributeDS(new DicomTag(Pipeline.Dictionary.Tag.WindowWidth));
                //var windowWidthTag = DicomAttribute.CreateAttribute(Pipeline.Dictionary.Tag.WindowWidth);
                windowWidthTag.SetString(0, "256");
                _dicomDataHeader.AddDicomAttribute(windowWidthTag);
                var windowCenterTag = new DicomAttributeDS(new DicomTag(Pipeline.Dictionary.Tag.WindowCenter));
                //var windowCenterTag = DicomAttribute.CreateAttribute(Pipeline.Dictionary.Tag.WindowCenter);
                windowCenterTag.SetString(0, "127");
                _dicomDataHeader.AddDicomAttribute(windowCenterTag);

                if (_dicomDataHeader.Contains(Pipeline.Dictionary.Tag.PixelData))
                {
                    _dicomDataHeader[Pipeline.Dictionary.Tag.PixelData].SetBytes(0, data);
                }
                else
                {
                    var pixelTag = new DicomAttributeOW(new DicomTag(Pipeline.Dictionary.Tag.PixelData));
                    pixelTag.SetBytes(0, data);
                    _dicomDataHeader.AddDicomAttribute(pixelTag);
                }
                _dicomDataHeader.RemoveDicomAttribute(Pipeline.Dictionary.Tag.ShutterShape);
                _dicomDataHeader.RemoveDicomAttribute(Pipeline.Dictionary.Tag.ShutterLowerHorizontalEdge);
                _dicomDataHeader.RemoveDicomAttribute(Pipeline.Dictionary.Tag.ShutterRightVerticalEdge);
                _dicomDataHeader.RemoveDicomAttribute(Pipeline.Dictionary.Tag.ShutterLeftVerticalEdge);
                _dicomDataHeader.RemoveDicomAttribute(Pipeline.Dictionary.Tag.ShutterUpperHorizontalEdge);
                _dicomDataHeader.RemoveDicomAttribute(Pipeline.Dictionary.Tag.ImageHorizontalFlip);
                _dicomDataHeader.RemoveDicomAttribute(Pipeline.Dictionary.Tag.ImageRotation);
                _dicomDataHeader.RemoveDicomAttribute(Pipeline.Dictionary.Tag.SeriesNumber);
                //_dicomDataHeader.RemoveDicomAttribute(Pipeline.Dictionary.Tag.);
                //AssembleTag();

                var uidManager        = McsfDatabaseDicomUIDManagerFactory.Instance().CreateUIDManager();
                var seriesInstanceUid = uidManager.CreateSeriesUID("1", "2", ""); //seriesUID; //
                var imageUid          = uidManager.CreateImageUID("");

                //_dicomDataHeader.RemoveDicomAttribute(Pipeline.Dictionary.Tag.SeriesInstanceUid);
                //var seriesInstanceUidTag = new DicomAttributeUI(new DicomTag(Pipeline.Dictionary.Tag.SeriesInstanceUid));
                //seriesInstanceUidTag.SetString(0, seriesInstanceUid);
                //_dicomDataHeader.AddDicomAttribute(seriesInstanceUidTag);

                _dicomDataHeader.RemoveDicomAttribute(Pipeline.Dictionary.Tag.SOPInstanceUID);
                var sopInstanceUidTag = new DicomAttributeUI(new DicomTag(Pipeline.Dictionary.Tag.SOPInstanceUID));
                sopInstanceUidTag.SetString(0, imageUid);
                _dicomDataHeader.AddDicomAttribute(sopInstanceUidTag);

                _dicomDataHeader.RemoveDicomAttribute(Pipeline.Dictionary.Tag.ImageType);
                var imageTypeCollection = ("DERIVED\\SECONDARY\\DISPLAY\\FILMING\\EFILM").Split('\\');
                InsertStringArrayDicomElement(_dicomDataHeader, Pipeline.Dictionary.Tag.ImageType, imageTypeCollection);

                _dicomDataHeader.RemoveDicomAttribute(Pipeline.Dictionary.Tag.ConversionType);
                var cTypeTag = new DicomAttributeCS(new DicomTag(Pipeline.Dictionary.Tag.ConversionType));
                cTypeTag.SetString(0, "WSD");
                _dicomDataHeader.AddDicomAttribute(cTypeTag);

                _dicomDataHeader.RemoveDicomAttribute(Pipeline.Dictionary.Tag.SeriesDescription);
                var seriesDescriptionTag = new DicomAttributeLO(new DicomTag(Pipeline.Dictionary.Tag.SeriesDescription));
                seriesDescriptionTag.SetString(0, "Electronic film_" + DateTime.Now.ToString());
                _dicomDataHeader.AddDicomAttribute(seriesDescriptionTag);

                _dicomConvertorProxy.SaveFile(_dicomDataHeader, efilmFullPath, _proxy);

                var medViewerControlCell = medViewerControl.LayoutManager.ControlCells.FirstOrDefault();
                if (medViewerControlCell != null)
                {
                    var currentPage = medViewerControlCell.Image.CurrentPage;
                    efilmOriginalSopInstanceUID = currentPage.SOPInstanceUID;
                    var dicomHeader = currentPage.ImageHeader.DicomHeader;
                    if (dicomHeader.ContainsKey(ServiceTagName.StudyInstanceUID))
                    {
                        efilmOriginalStudyInstanceUid = dicomHeader[ServiceTagName.StudyInstanceUID];
                    }
                }

                if (!ifSaveEFilm)
                {
                    return;
                }
                CreateSeries(efilmOriginalStudyInstanceUid, seriesInstanceUid);
                SaveEFilmInCommonSave(seriesInstanceUid);

                Logger.LogFuncDown();
            }
            catch (Exception ex)
            {
                Logger.LogFuncException(ex.Message + ex.StackTrace);
            }
            finally
            {
                medViewerControl.RemoveAll();
            }
        }