コード例 #1
0
        public void WriteDecimalString()
        {
            var ds = new DecimalString();
            ds.DData_ = Enumerable.Range(1, 15000).Select(i => ((double)i) + 0.005).ToList();
            ds.Tag = new Tag("00082130");
            byte[] written;
            var settings = DICOMWriteSettings.Default();

            using (var ms = new MemoryStream())
            {
                using (var dw = new DICOMBinaryWriter(ms))
                {

                    DICOMElementWriter.Write(dw, DICOMWriteSettings.Default(), ds);
                }
                written = ms.ToArray();
            }

            using (var dr = new DICOMBinaryReader(written))
            {
                var read = DICOMElementReader.ReadElementImplicitLittleEndian(dr) as DecimalString;
                CollectionAssert.AreEqual(ds.DData_, read.Data_);
            }


        }
コード例 #2
0
        public BeamLimitingDevicePosition()
        {
            si = new SequenceItem();

            //Add blank RTBeamDeviceType
            CodeString cs = new CodeString();
            cs.Tag.Id = TagHelper.RTBEAM_LIMITING_DEVICE_TYPE;
            si.AddObject(cs);

            //Add blank Leaf Jaw Positions
            DecimalString ds = new DecimalString();
            ds.Tag.Id = TagHelper.LEAF_JAW_POSITIONS;
            si.AddObject(ds);
        }
コード例 #3
0
ファイル: Fixed16_16.cs プロジェクト: bblpny/csharputilities
 public string ToString(string format, IFormatProvider formatProvider)
 {
     if (is_int_fmt(ref format))
     {
         return(Value.ToString(format, formatProvider));
     }
     else if (is_dbl_fmt(ref format))
     {
         return(Double.ToString(format, formatProvider));
     }
     else if (null != formatProvider || (null != (object)format))
     {
         return(Decimal.ToString(format, formatProvider));
     }
     else
     {
         return(DecimalString.ToString(formatProvider));
     }
 }
コード例 #4
0
        private void ajouttag(String nom)
        {
            var dcm = DICOMObject.Read(nom);
            var sel = new DICOMSelector(dcm);

            var refDoseRate = new DecimalString
            {
                Tag  = TagHelper.DoseRateSet,
                Data = 400
            };

            var nbBeams = sel.NumberOfBeams.Data;

            for (int i = 0; i < nbBeams; i++)
            {
                sel.ControlPointSequence_[i].Items[0].Add(refDoseRate);
            }
            Console.WriteLine("- Ajout du tag pour l'AutoBreast");
            dcm.Write(nom);
        }
コード例 #5
0
        public void WriteDecimalString()
        {
            var ds = new DecimalString();

            ds.DData_ = Enumerable.Range(1, 15000).Select(i => ((double)i) + 0.005).ToList();
            ds.Tag    = new Tag("00082130");
            byte[] written;
            var    settings = DICOMIOSettings.Default();

            using (var ms = new MemoryStream())
            {
                using (var dw = new DICOMBinaryWriter(ms))
                {
                    DICOMElementWriter.Write(dw, DICOMIOSettings.Default(), ds);
                }
                written = ms.ToArray();
            }

            using (var dr = new DICOMBinaryReader(written))
            {
                var read = DICOMElementReader.ReadElementImplicitLittleEndian(dr) as DecimalString;
                CollectionAssert.AreEqual(ds.DData_, read.Data_);
            }
        }
コード例 #6
0
ファイル: DicomComparator.cs プロジェクト: top501/DVTK-1
        private System.String GetAttributeValue(DvtkData.Dimse.Attribute attribute)
        {
            System.String attributeValue = System.String.Empty;
            if ((attribute == null) ||
                (attribute.Length == 0))
            {
                return(attributeValue);
            }

            switch (attribute.ValueRepresentation)
            {
            case VR.AE:
            {
                ApplicationEntity applicationEntity = (ApplicationEntity)attribute.DicomValue;
                attributeValue = applicationEntity.Values[0];
                break;
            }

            case VR.AS:
            {
                AgeString ageString = (AgeString)attribute.DicomValue;
                attributeValue = ageString.Values[0];
                break;
            }

            case VR.CS:
            {
                CodeString codeString = (CodeString)attribute.DicomValue;
                attributeValue = codeString.Values[0];
                break;
            }

            case VR.DA:
            {
                Date date = (Date)attribute.DicomValue;
                attributeValue = date.Values[0];
                break;
            }

            case VR.DS:
            {
                DecimalString decimalString = (DecimalString)attribute.DicomValue;
                attributeValue = decimalString.Values[0];
                break;
            }

            case VR.DT:
            {
                DvtkData.Dimse.DateTime dateTime = (DvtkData.Dimse.DateTime)attribute.DicomValue;
                attributeValue = dateTime.Values[0];
                break;
            }

            case VR.IS:
            {
                IntegerString integerString = (IntegerString)attribute.DicomValue;
                attributeValue = integerString.Values[0];
                break;
            }

            case VR.LO:
            {
                LongString longString = (LongString)attribute.DicomValue;
                attributeValue = longString.Values[0];
                break;
            }

            case VR.LT:
            {
                LongText longText = (LongText)attribute.DicomValue;
                attributeValue = longText.Value;
                break;
            }

            case VR.PN:
            {
                PersonName personName = (PersonName)attribute.DicomValue;
                attributeValue = personName.Values[0];
                break;
            }

            case VR.SH:
            {
                ShortString shortString = (ShortString)attribute.DicomValue;
                attributeValue = shortString.Values[0];
                break;
            }

            case VR.SQ:
            {
                // Special case looking for the SOP Class UID
                SequenceOfItems sequenceOfItems = (SequenceOfItems)attribute.DicomValue;
                if ((sequenceOfItems != null) &&
                    (sequenceOfItems.Sequence.Count == 1))
                {
                    // Special case looking for the SOP Class UID
                    SequenceItem item = sequenceOfItems.Sequence[0];
                    attribute      = item.GetAttribute(new Tag(0x0008, 0x1150));
                    attributeValue = GetAttributeValue(attribute);
                }
                break;
            }

            case VR.ST:
            {
                ShortText shortText = (ShortText)attribute.DicomValue;
                attributeValue = shortText.Value;
                break;
            }

            case VR.TM:
            {
                Time time = (Time)attribute.DicomValue;
                attributeValue = time.Values[0];
                break;
            }

            case VR.UI:
            {
                UniqueIdentifier uniqueIdentifier = (UniqueIdentifier)attribute.DicomValue;
                attributeValue = uniqueIdentifier.Values[0];
                break;
            }

            default:
                break;
            }

            return(attributeValue);
        }
コード例 #7
0
        private IDICOMElement GenerateZeroDecimalString(Tag tag)
        {
            DecimalString ds = new DecimalString(tag, new double[] { 0.0 });

            return(ds);
        }
コード例 #8
0
ファイル: ImageHelper.cs プロジェクト: ragradev/Evil-DICOM
        /// <summary>
        /// This method retrieves the relevant image properties from a DICOM file for rendering
        /// the image
        /// </summary>
        /// <param name="df">the DICOM file to be processed</param>
        /// <returns>the image properties of the image</returns>
        public static ImageProperties PullProperties(DICOMFile df)
        {
            ImageProperties props = new ImageProperties();

            //Get Number of Rows
            try
            {
                UnsignedShort rowsObject = df.ROWS as UnsignedShort;
                props.Rows = rowsObject.Data;
            }
            catch (Exception e)
            {
                Console.WriteLine("Could not find number of rows");
            }

            //Get Number of Columns
            try
            {
                UnsignedShort columnsObject = df.COLUMNS as UnsignedShort;
                props.Columns = columnsObject.Data;
            }
            catch (Exception e)
            {
                Console.WriteLine("Could not find number of columns");
            }

            //Get Bit Depth
            try
            {
                UnsignedShort bitsAllocated = df.BITS_ALLOCATED as UnsignedShort;
                props.BitsAllocated = bitsAllocated.Data;
            }
            catch (Exception e)
            {
                Console.WriteLine("Could not find bits allocated");
            }

            //Get Pixel Height and Width
            try
            {
                DecimalString pixelSpacing = df.PIXEL_SPACING as DecimalString;
                props.PixelHeight = pixelSpacing.Data[0];
                props.PixelWidth = pixelSpacing.Data[1];
            }
            catch (Exception e)
            {
                Console.WriteLine("Could not find pixel spacing");
            }

            //Get SliceThickness
            try
            {
                DecimalString sliceThickness = df.SLICE_THICKNESS as DecimalString;
                props.SliceThickness = sliceThickness.Data[0];
            }
            catch (Exception e)
            {
                Console.WriteLine("Could not find slice thickness");
            }

            //Get Image Number
            try
            {
                IntegerString imageNumber = df.INSTANCE_NUMBER as IntegerString;
                props.ImageNumber = imageNumber.Data[0];
            }
            catch (Exception e)
            {
                Console.WriteLine("Could not find slice thickness");
            }

            //Get Window and Level
            try
            {
                DecimalString window = df.WINDOW_WIDTH as DecimalString;
                DecimalString level = df.WINDOW_CENTER as DecimalString;
                props.WindowAndLevel = new WindowLevel(window.Data[0], level.Data[0]);
            }
            catch (Exception e)
            {
                Console.WriteLine("Could not find window and level");
            }
            //Is This A Dose File
            try
            {
                if (df.DOSE_UNITS.Data != null) { props.IsDose = true; }
                else { props.IsDose = false; }
            }
            catch (Exception e)
            {
                Console.WriteLine("Could not determine if file was a dose file");
            }

            //Read In Scaling Function
            try
            {
                DecimalString slope = props.IsDose ? df.DOSE_GRID_SCALING as DecimalString : df.RESCALE_SLOPE as DecimalString;
                DecimalString intercept = props.IsDose ? null : df.RESCALE_INTERCEPT as DecimalString;
                if (intercept == null) { intercept = new DecimalString(); intercept.Data = new double[] { 0 }; }
                props.Function = new ScalingFunction(slope.Data[0], intercept.Data[0]);
            }
            catch (Exception e)
            {
                Console.WriteLine("Could not find scaling function");
            }

            //Get Samples Per Pixel
            try
            {
                UnsignedShort samples = df.SAMPLES_PER_PIXEL as UnsignedShort;
                props.SamplesPerPixel = samples.Data;
            }
            catch (Exception e)
            {
                Console.WriteLine("Could not find samples per pixel");
            }

            //Get Transfer Syntax
            try
            {
                UniqueIdentifier syntax = df.TRANSFER_SYNTAX_UID as UniqueIdentifier;
                string stringSyntax = syntax.Data;

                switch (stringSyntax)
                {
                    case Constants.EXPLICIT_VR_BIG_ENDIAN: props.TransferSyntax = Constants.TransferSyntax.EXPLICIT_VR_BIG_ENDIAN; break;
                    case Constants.EXPLICIT_VR_LITTLE_ENDIAN: props.TransferSyntax = Constants.TransferSyntax.EXPLICIT_VR_LITTLE_ENDIAN; break;
                    case Constants.IMPLICIT_VR_LITTLE_ENDIAN: props.TransferSyntax = Constants.TransferSyntax.IMPLICIT_VR_LITTLE_ENDIAN; break;
                    case Constants.JPEG_2000: props.TransferSyntax = Constants.TransferSyntax.JPEG_2000; break;
                    case Constants.JPEG_2000_LOSSLESS: props.TransferSyntax = Constants.TransferSyntax.JPEG_2000_LOSSLESS; break;
                    case Constants.JPEG_BASELINE: props.TransferSyntax = Constants.TransferSyntax.JPEG_BASELINE; break;
                    case Constants.JPEG_EXTENDED: props.TransferSyntax = Constants.TransferSyntax.JPEG_EXTENDED; break;
                    case Constants.JPEG_LOSSLESS_14: props.TransferSyntax = Constants.TransferSyntax.JPEG_LOSSLESS_14; break;
                    case Constants.JPEG_LOSSLESS_14_S1: props.TransferSyntax = Constants.TransferSyntax.JPEG_LOSSLESS_14_S1; break;
                    case Constants.JPEG_LOSSLESS_15: props.TransferSyntax = Constants.TransferSyntax.JPEG_LOSSLESS_15; break;
                    case Constants.JPEG_LS_LOSSLESS: props.TransferSyntax = Constants.TransferSyntax.JPEG_LS_LOSSLESS; break;
                    case Constants.JPEG_LS_NEAR_LOSSLESS: props.TransferSyntax = Constants.TransferSyntax.JPEG_LS_NEAR_LOSSLESS; break;
                    case Constants.JPEG_PROGRESSIVE: props.TransferSyntax = Constants.TransferSyntax.JPEG_PROGRESSIVE; break;
                    case Constants.RLE_LOSSLESS: props.TransferSyntax = Constants.TransferSyntax.RLE_LOSSLESS; break;
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Could not find transfer syntax");
            }

            //Get Image Position
            try
            {
                DecimalString imagePosition = df.IMAGE_POSITION as DecimalString;
                props.ImagePosition = new Position(imagePosition.Data[0], imagePosition.Data[1], imagePosition.Data[3]);
            }
            catch (Exception e)
            {
                Console.WriteLine("Could not find image position");
            }

            //Set Number of Frames
            try
            {
                IntegerString numberOfFrames = df.NUMBER_OF_FRAMES as IntegerString;
                props.NumberOfFrames = numberOfFrames.Data[0];
            }
            catch (Exception e) { Console.WriteLine("Could not find number of frames"); }

            //Set Grid Frame Offset Vector
            try
            {
                DecimalString offsetVector = df.GRID_FRAME_OFFSET_VECTOR as DecimalString;
                props.OffsetVector = offsetVector.Data;
            }
            catch (Exception e) { Console.WriteLine("Could not find grid frame offset vector"); }

            return props;
        }
コード例 #9
0
ファイル: DataComposer.cs プロジェクト: andre1102/Evil-DICOM
        public static byte[] GetStringBytes(VR vr, IDICOMElement el)
        {
            string data;

            byte[] unpadded;
            switch (vr)
            {
            case VR.AgeString:
                AgeString age = el as AgeString;
                data     = age.DataContainer.SingleValue;
                unpadded = GetASCIIBytes(data);
                return(DataRestriction.EnforceEvenLength(unpadded, vr));

            case VR.ApplicationEntity:
                ApplicationEntity ae = el as ApplicationEntity;
                unpadded = GetASCIIBytes(ae.DataContainer.SingleValue);
                return(DataRestriction.EnforceEvenLength(unpadded, vr));

            case VR.CodeString:
                CodeString cs = el as CodeString;
                unpadded = GetASCIIBytes(cs.Data);
                return(DataRestriction.EnforceEvenLength(unpadded, vr));

            case VR.Date:
                Date d = el as Date;
                data     = StringDataComposer.ComposeDate(d.DataContainer.SingleValue);
                unpadded = GetASCIIBytes(data);
                return(DataRestriction.EnforceEvenLength(unpadded, vr));

            case VR.DateTime:
                EvilDICOM.Core.Element.DateTime dt = el as EvilDICOM.Core.Element.DateTime;
                data     = StringDataComposer.ComposeDateTime(dt.DataContainer.SingleValue);
                unpadded = GetASCIIBytes(data);
                return(DataRestriction.EnforceEvenLength(unpadded, vr));

            case VR.DecimalString:
                DecimalString ds = el as DecimalString;
                data     = StringDataComposer.ComposeDecimalString(ds.DataContainer.MultipicityValue.ToArray());
                unpadded = GetASCIIBytes(data);
                return(DataRestriction.EnforceEvenLength(unpadded, vr));

            case VR.IntegerString:
                IntegerString iSt = el as IntegerString;
                data     = StringDataComposer.ComposeIntegerString(iSt.DataContainer.MultipicityValue.ToArray());
                unpadded = GetASCIIBytes(data);
                return(DataRestriction.EnforceEvenLength(unpadded, vr));

            case VR.LongString:
                LongString ls = el as LongString;
                unpadded = GetASCIIBytes(ls.Data);
                return(DataRestriction.EnforceEvenLength(unpadded, vr));

            case VR.LongText:
                LongText lt = el as LongText;
                unpadded = GetASCIIBytes(lt.Data);
                return(DataRestriction.EnforceEvenLength(unpadded, vr));

            case VR.PersonName:
                PersonName pn = el as PersonName;
                unpadded = GetASCIIBytes(pn.Data);
                return(DataRestriction.EnforceEvenLength(unpadded, vr));

            case VR.ShortString:
                ShortString ss = el as ShortString;
                unpadded = GetASCIIBytes(ss.Data);
                return(DataRestriction.EnforceEvenLength(unpadded, vr));

            case VR.ShortText:
                ShortText st = el as ShortText;
                unpadded = GetASCIIBytes(st.Data);
                return(DataRestriction.EnforceEvenLength(unpadded, vr));

            case VR.Time:
                Time t = el as Time;
                data     = StringDataComposer.ComposeTime(t.DataContainer.SingleValue);
                unpadded = GetASCIIBytes(data);
                return(DataRestriction.EnforceEvenLength(unpadded, vr));

            case VR.UnlimitedText:
                UnlimitedText ut = el as UnlimitedText;
                unpadded = GetASCIIBytes(ut.Data);
                return(DataRestriction.EnforceEvenLength(unpadded, vr));

            case VR.UniqueIdentifier:
                UniqueIdentifier ui = el as UniqueIdentifier;
                unpadded = GetASCIIBytes(ui.Data);
                return(DataRestriction.EnforceEvenLength(unpadded, vr));

            default: return(null);
            }
        }
コード例 #10
0
 public void Cleanup()
 {
     _decimalString = null;
 }
コード例 #11
0
 public void Init()
 {
     _decimalString = new DecimalString(TagHelper.Beam​Dose​Specification​Point, new[] { 1.0, -3.5, 2.5 });
 }
コード例 #12
0
        /// <summary>
        /// This static function returns the Re-Construted value of the particular Dicom attribute.
        /// </summary>
        /// <param name="attribute">Dicom attribute contains tag vr and value</param>
        /// <returns>Returns the value of the Dicom attribute</returns>
        public static String GetDicomValue(DvtkData.Dimse.Attribute attribute)
        {
            String dumpString = "";

            if (attribute != null && attribute.Length != 0)
            {
                switch (attribute.ValueRepresentation)
                {
                case VR.AE:
                {
                    ApplicationEntity applicationEntity = (ApplicationEntity)attribute.DicomValue;
                    dumpString += String.Format("{0}", GetValues(applicationEntity.Values));
                    break;
                }

                case VR.AS:
                {
                    AgeString ageString = (AgeString)attribute.DicomValue;
                    dumpString += String.Format("{0}", GetValues(ageString.Values));
                    break;
                }

                case VR.AT:
                {
                    AttributeTag attributeTag = (AttributeTag)attribute.DicomValue;
                    Console.WriteLine("{0}", GetValues(attributeTag.Values));
                    break;
                }

                case VR.CS:
                {
                    CodeString codeString = (CodeString)attribute.DicomValue;
                    dumpString += String.Format("{0}", GetValues(codeString.Values));
                    break;
                }

                case VR.DA:
                {
                    Date date = (Date)attribute.DicomValue;
                    dumpString += String.Format("{0}", GetValues(date.Values));
                    break;
                }

                case VR.DS:
                {
                    DecimalString decimalString = (DecimalString)attribute.DicomValue;
                    dumpString += String.Format("{0}", GetValues(decimalString.Values));
                    break;
                }

                case VR.DT:
                {
                    DvtkData.Dimse.DateTime dateTime = (DvtkData.Dimse.DateTime)attribute.DicomValue;
                    dumpString += String.Format("{0}", GetValues(dateTime.Values));
                    break;
                }

                case VR.FD:
                {
                    FloatingPointDouble floatingPointDouble = (FloatingPointDouble)attribute.DicomValue;
                    dumpString += String.Format("{0}", GetValues(floatingPointDouble.Values));
                    break;
                }

                case VR.FL:
                {
                    FloatingPointSingle floatingPointSingle = (FloatingPointSingle)attribute.DicomValue;
                    dumpString += String.Format("{0}", GetValues(floatingPointSingle.Values));
                    break;
                }

                case VR.IS:
                {
                    IntegerString integerString = (IntegerString)attribute.DicomValue;
                    dumpString += String.Format("{0}", GetValues(integerString.Values));
                    break;
                }

                case VR.LO:
                {
                    LongString longString = (LongString)attribute.DicomValue;
                    dumpString += String.Format("{0}", GetValues(longString.Values));
                    break;
                }

                case VR.LT:
                {
                    LongText longText = (LongText)attribute.DicomValue;
                    dumpString += String.Format("{0}", longText.Value);
                    break;
                }

                case VR.OB:
                {
                    OtherByteString otherByteString = (OtherByteString)attribute.DicomValue;
                    dumpString += String.Format("{0}", otherByteString.FileName);
                    break;
                }

                case VR.OF:
                {
                    OtherFloatString otherFloatString = (OtherFloatString)attribute.DicomValue;
                    dumpString += String.Format("{0}", otherFloatString.FileName);
                    break;
                }

                case VR.OW:
                {
                    OtherWordString otherWordString = (OtherWordString)attribute.DicomValue;
                    dumpString += String.Format("{0}", otherWordString.FileName);
                    break;
                }

                case VR.OV:
                {
                    OtherVeryLongString otherVeryLongString = (OtherVeryLongString)attribute.DicomValue;
                    dumpString += String.Format("{0}", otherVeryLongString.FileName);
                    break;
                }

                case VR.PN:
                {
                    PersonName personName = (PersonName)attribute.DicomValue;
                    dumpString += String.Format("{0}", GetValues(personName.Values));
                    break;
                }

                case VR.SH:
                {
                    ShortString shortString = (ShortString)attribute.DicomValue;
                    dumpString += String.Format("{0}", GetValues(shortString.Values));
                    break;
                }

                case VR.SL:
                {
                    SignedLong signedLong = (SignedLong)attribute.DicomValue;
                    dumpString += String.Format("{0}", GetValues(signedLong.Values));
                    break;
                }

                case VR.SQ:
                {
                    //SequenceOfItems sequenceOfItems = (SequenceOfItems)attribute.DicomValue;
                    //int itemNumber = 1;
                    //dumpString += "\r\n";
                    //foreach (SequenceItem item in sequenceOfItems.Sequence)
                    //{
                    //    dumpString += String.Format("> Begin Item: {0}\r\n", itemNumber);
                    //    dumpString += item.Dump(prefix);
                    //    dumpString += prefix + String.Format("> End Item: {0}\r\n", itemNumber++);
                    //}
                    break;
                }

                case VR.SS:
                {
                    SignedShort signedShort = (SignedShort)attribute.DicomValue;
                    dumpString += String.Format("{0}", GetValues(signedShort.Values));
                    break;
                }

                case VR.ST:
                {
                    ShortText shortText = (ShortText)attribute.DicomValue;
                    dumpString += String.Format("{0}", shortText.Value);
                    break;
                }

                case VR.TM:
                {
                    Time time = (Time)attribute.DicomValue;
                    dumpString += String.Format("{0}", GetValues(time.Values));
                    break;
                }

                case VR.UI:
                {
                    UniqueIdentifier uniqueIdentifier = (UniqueIdentifier)attribute.DicomValue;
                    dumpString += String.Format("{0}", GetValues(uniqueIdentifier.Values));
                    break;
                }

                case VR.UL:
                {
                    UnsignedLong unsignedLong = (UnsignedLong)attribute.DicomValue;
                    dumpString += String.Format("{0}", GetValues(unsignedLong.Values));
                    break;
                }

                case VR.UN:
                {
                    break;
                }

                case VR.US:
                {
                    UnsignedShort unsignedShort = (UnsignedShort)attribute.DicomValue;
                    dumpString += String.Format("{0}", GetValues(unsignedShort.Values));
                    break;
                }

                case VR.UT:
                {
                    break;
                }

                case VR.UR:
                {
                    break;
                }

                case VR.UC:
                {
                    break;
                }

                default:
                    dumpString += String.Format("\'  \'");
                    break;
                }
            }
            else
            {
                dumpString += String.Format("\'  \'");
            }


            return(dumpString);
        }
コード例 #13
0
        private object GetParameterValue(
            DataParameterBase dataParameter,
            object value)
        {
            object value2;

            if (value != null)
            {
                if (value == DBNull.Value)
                {
                    value2 = DBNull.Value;
                }
                else
                {
                    switch (dataParameter.DbType)
                    {
                    case DbType.Boolean:
                        var valueStr = (string)value;
                        var ok       = double.TryParse(valueStr, NumberStyles.Any, null, out var valueDbl);
                        value2 = ok ? Convert.ToBoolean(valueDbl) : Convert.ToBoolean(value);
                        break;

                    case DbType.Int16:
                        value2 = Convert.ToInt32(value);
                        break;

                    case DbType.Int32:
                        value2 = Convert.ToInt32(value);
                        break;

                    case DbType.Decimal:
                    case DbType.VarNumeric:
                        valueStr = value.ToString();
                        var decimalString = new DecimalString(value.ToString());

                        if (dataParameter.Precision != 0 && decimalString.Precision > dataParameter.Precision)
                        {
                            throw new Exception("Invalid precision");
                        }
                        else if (dataParameter.Scale != 0 && decimalString.Scale > dataParameter.Scale)
                        {
                            throw new Exception("Invalid scale");
                        }
                        else
                        {
                            IFormatProvider formatProvider = CultureInfo.InvariantCulture;
                            value2 = Convert.ToDecimal(valueStr, formatProvider);
                        }

                        break;

                    case DbType.Double:
                        value2 = Convert.ToDouble(value);
                        break;

                    case DbType.String:
                    case DbType.StringFixedLength:
                    case DbType.AnsiString:
                    case DbType.AnsiStringFixedLength:
                        valueStr = Convert.ToString(value);

                        if (dataParameter.Size > 0 && valueStr.Length > dataParameter.Size)
                        {
                            throw new Exception("Length exceeds size of parameter");
                        }
                        else
                        {
                            value2 = valueStr;
                        }

                        break;

                    case DbType.DateTime:
                        try
                        {
                            value2 = Convert.ToDateTime(value);
                        }
                        catch
                        {
                            var formats = new[]
                            {
                                "yyyyMMdd",
                                "yyyyMMdd HH:mm:ss"
                            };

                            IFormatProvider formatProvider = CultureInfo.InvariantCulture;
                            value2 = DateTime.ParseExact(value.ToString(), formats, formatProvider,
                                                         DateTimeStyles.None);
                        }

                        break;

                    default:
                        value2 = value;
                        break;
                    }
                }
            }
            else
            {
                value2 = null;
            }

            return(value2);
        }
コード例 #14
0
 private IDICOMElement GenerateZeroDecimalString(Tag tag)
 {
     DecimalString ds = new DecimalString(tag, new double[] { 0.0 });
     return ds;
 }
コード例 #15
0
ファイル: DICOMReader.cs プロジェクト: ragradev/Evil-DICOM
        private static DICOMElement CreateVRObject(string vr, Constants.EncodeType encType, byte[] data, Tag t, bool isLittleEndian, bool isIndefinite)
        {
            switch (vr)
            {
                case "CS":
                    CodeString cs = new CodeString();
                    cs.ByteData = data;
                    cs.EncodeType = encType;
                    cs.IsLittleEndian = isLittleEndian;
                    cs.Tag = t;
                    return cs;

                case "SH":
                    ShortString sh = new ShortString();
                    sh.ByteData = data;
                    sh.EncodeType = encType;
                    sh.IsLittleEndian = isLittleEndian;
                    sh.Tag = t;
                    return sh;

                case "LO":
                    LongString lo = new LongString();
                    lo.ByteData = data;
                    lo.EncodeType = encType;
                    lo.IsLittleEndian = isLittleEndian;
                    lo.Tag = t;
                    return lo;

                case "ST":
                    ShortText st = new ShortText();
                    st.ByteData = data;
                    st.EncodeType = encType;
                    st.IsLittleEndian = isLittleEndian;
                    st.Tag = t;
                    return st;

                case "LT":
                    LongText lt = new LongText();
                    lt.ByteData = data;
                    lt.EncodeType = encType;
                    lt.IsLittleEndian = isLittleEndian;
                    lt.Tag = t;
                    return lt;

                case "UT":
                    UnlimitedText ut = new UnlimitedText();
                    ut.ByteData = data;
                    ut.EncodeType = encType;
                    ut.IsLittleEndian = isLittleEndian;
                    ut.Tag = t;
                    return ut;

                case "AE":
                    ApplicationEntity ae = new ApplicationEntity();
                    ae.ByteData = data;
                    ae.EncodeType = encType;
                    ae.IsLittleEndian = isLittleEndian;
                    ae.Tag = t;
                    return ae;

                case "PN":
                    PersonsName pn = new PersonsName();
                    pn.ByteData = data;
                    pn.EncodeType = encType;
                    pn.IsLittleEndian = isLittleEndian;
                    pn.Tag = t;
                    return pn;

                case "UI":
                    UniqueIdentifier ui = new UniqueIdentifier();
                    ui.ByteData = data;
                    ui.EncodeType = encType;
                    ui.IsLittleEndian = isLittleEndian;
                    ui.Tag = t;
                    return ui;

                case "DA":
                    DateVR da = new DateVR();
                    da.ByteData = data;
                    da.EncodeType = encType;
                    da.IsLittleEndian = isLittleEndian;
                    da.Tag = t;
                    return da;

                case "TM":
                    TimeVR tm = new TimeVR();
                    tm.ByteData = data;
                    tm.EncodeType = encType;
                    tm.IsLittleEndian = isLittleEndian;
                    tm.Tag = t;
                    return tm;

                case "DT":
                    DateTimeVR dt = new DateTimeVR();
                    dt.ByteData = data;
                    dt.EncodeType = encType;
                    dt.IsLittleEndian = isLittleEndian;
                    dt.Tag = t;
                    return dt;

                case "AS":
                    AgeString aSt = new AgeString();
                    aSt.ByteData = data;
                    aSt.EncodeType = encType;
                    aSt.IsLittleEndian = isLittleEndian;
                    aSt.Tag = t;
                    return aSt;

                case "IS":
                    IntegerString iSt = new IntegerString();
                    iSt.ByteData = data;
                    iSt.EncodeType = encType;
                    iSt.IsLittleEndian = isLittleEndian;
                    iSt.Tag = t;
                    return iSt;

                case "DS":
                    DecimalString ds = new DecimalString();
                    ds.ByteData = data;
                    ds.EncodeType = encType;
                    ds.IsLittleEndian = isLittleEndian;
                    ds.Tag = t;
                    return ds;

                case "SS":
                    SignedShort ss = new SignedShort();
                    ss.ByteData = data;
                    ss.EncodeType = encType;
                    ss.IsLittleEndian = isLittleEndian;
                    ss.Tag = t;
                    return ss;

                case "US":
                    UnsignedShort us = new UnsignedShort();
                    us.ByteData = data;
                    us.EncodeType = encType;
                    us.IsLittleEndian = isLittleEndian;
                    us.Tag = t;
                    return us;

                case "SL":
                    SignedLong sl = new SignedLong();
                    sl.ByteData = data;
                    sl.EncodeType = encType;
                    sl.IsLittleEndian = isLittleEndian;
                    sl.Tag = t;
                    return sl;

                case "UL":
                    UnsignedLong ul = new UnsignedLong();
                    ul.ByteData = data;
                    ul.EncodeType = encType;
                    ul.IsLittleEndian = isLittleEndian;
                    ul.Tag = t;
                    return ul;

                case "AT":
                    AttributeTag at = new AttributeTag();
                    at.ByteData = data;
                    at.EncodeType = encType;
                    at.IsLittleEndian = isLittleEndian;
                    at.Tag = t;
                    return at;

                case "FL":
                    FloatingPointSingle fl = new FloatingPointSingle();
                    fl.ByteData = data;
                    fl.EncodeType = encType;
                    fl.IsLittleEndian = isLittleEndian;
                    fl.Tag = t;
                    return fl;

                case "FD":
                    FloatingPointDouble fd = new FloatingPointDouble();
                    fd.ByteData = data;
                    fd.EncodeType = encType;
                    fd.IsLittleEndian = isLittleEndian;
                    fd.Tag = t;
                    return fd;

                case "OB":
                    if (t.Id == TagHelper.PIXEL_DATA)
                    {
                        PixelData fd1 = new PixelData(data, encType, isLittleEndian, "OB", isIndefinite);
                        fd1.Format = isIndefinite ? FrameDataFormat.ENCAPSULATED : FrameDataFormat.NATIVE;
                        fd1.EncodeType = encType;
                        fd1.IsLittleEndian = isLittleEndian;
                        fd1.Tag = t;
                        return fd1;
                    }
                    else
                    {
                        OtherByteString ob = new OtherByteString();
                        ob.ByteData = data;
                        ob.EncodeType = encType;
                        ob.IsLittleEndian = isLittleEndian;
                        ob.Tag = t;
                        return ob;
                    }
                case "OW":
                    if (t.Id == TagHelper.PIXEL_DATA)
                    {
                        PixelData fd2 = new PixelData(data, encType, isLittleEndian, "OW", isIndefinite);
                        fd2.Format = isIndefinite ? FrameDataFormat.ENCAPSULATED : FrameDataFormat.NATIVE;
                        fd2.EncodeType = encType;
                        fd2.IsLittleEndian = isLittleEndian;
                        fd2.Tag = t;
                        return fd2;
                    }
                    else
                    {
                        OtherWordString ow = new OtherWordString();
                        ow.ByteData = data;
                        ow.EncodeType = encType;
                        ow.IsLittleEndian = isLittleEndian;
                        ow.Tag = t;
                        return ow;
                    }

                case "OF":
                    OtherFloatString of = new OtherFloatString();
                    of.ByteData = data;
                    of.EncodeType = encType;
                    of.IsLittleEndian = isLittleEndian;
                    of.Tag = t;
                    return of;

                case "SQ":
                    Sequence s = new Sequence();
                    s.ByteData = data;
                    s.EncodeType = encType;
                    s.IsLittleEndian = isLittleEndian;
                    s.Tag = t;
                    s.ReadChildren();
                    return s;

                default:
                    //Case for unknown VR
                    DICOMElement dOb = new DICOMElement();
                    dOb.ByteData = data;
                    dOb.EncodeType = encType;
                    dOb.IsLittleEndian = isLittleEndian;
                    dOb.Tag = t;
                    return dOb;
            }
        }
コード例 #16
0
        protected virtual void UpdateTarget(DICOMSelector verificationSelector, IntegerString channelNumber, IntegerString numberOfControlPoints, DecimalString channelLength, DecimalString channelTotalTime, DecimalString sourceApplicatorLength, DecimalString sourceApplicatorStep, DecimalString finalCumulativeTimeweight, Sequence brachyControlPointSeq, int channelId)
        {
            var channelSeq = verificationSelector.ChannelSequence;

            foreach (var item in channelSeq.Data_)
            {
                var itemSelector = new DICOMSelector(item);
                var cn           = itemSelector.ChannelNumber.Data;
                if (cn != channelId)
                {
                    continue;
                }
                itemSelector.NumberOfControlPoints = numberOfControlPoints;
                //itemSelector.ChannelLength;
                itemSelector.ChannelTotalTime           = channelTotalTime;
                itemSelector.SourceApplicatorLength     = sourceApplicatorLength;
                itemSelector.SourceApplicatorStepSize   = sourceApplicatorStep;
                itemSelector.FinalCumulativeTimeWeight  = finalCumulativeTimeweight;
                itemSelector.BrachyControlPointSequence = brachyControlPointSeq;
            }
        }
コード例 #17
0
 public void Cleanup()
 {
     _decimalString = null;
 }
コード例 #18
0
 public void Init()
 {
     _decimalString = new DecimalString(TagHelper.BEAM_DOSE_SPECIFICATION_POINT, new[] {1.0, -3.5, 2.5});
 }
コード例 #19
0
 public void Init()
 {
     _decimalString = new DecimalString(TagHelper.BEAM_DOSE_SPECIFICATION_POINT, new[] { 1.0, -3.5, 2.5 });
 }