예제 #1
0
 internal FileMetaInformation(DvtkData.Dimse.AttributeSet dvtkDataAttributeSet) : base(dvtkDataAttributeSet)
 {
     if (dvtkDataAttributeSet == null)
     {
         DvtkHighLevelInterfaceException.Throw("Parameter may not be null/Nothing.");
     }
 }
예제 #2
0
파일: CommandSet.cs 프로젝트: top501/DVTK-1
 internal CommandSet(DvtkData.Dimse.CommandSet dvtkDataCommandSet) : base(dvtkDataCommandSet)
 {
     if (dvtkDataCommandSet == null)
     {
         DvtkHighLevelInterfaceException.Throw("Parameter may not be null/Nothing.");
     }
 }
예제 #3
0
        /// <summary>
        /// Get the Value Multiplicity of an Attribute.
        /// </summary>
        /// <param name="tagSequence">The tag sequence (one or more tags seperated with an '/').</param>
        /// <returns>The Value Multiplicity.</returns>
        public int GetAttributeVm(String tagSequence)
        {
            // Start Interface logging.
            // InterfaceLogging.Start(this, tagSequence);

            int vm = 0;

            Attribute attribute = GetAttribute(tagSequence);

            // If attribute does not exist...
            if (attribute == null)
            {
                // InterfaceLogging.WriteError("Attribute does not exist.\r\nReturning 0 as VM.");

                vm = 0;
            }
            // If attribute exists...
            else
            {
                if (attribute is SimpleAttribute)
                {
                    SimpleAttribute simpleAttribute = attribute as SimpleAttribute;

                    vm = simpleAttribute.GetValues().Count;
                }
                else if (attribute is PixelDataAttribute)
                {
                    // InterfaceLogging.WriteWarning("Determining of VM not implemented for pixel data attributes in the High Level Interface./r/nReturning 1");
                    vm = 1;
                }
                else if (attribute is SequenceAttribute)
                {
                    // InterfaceLogging.WriteWarning("Determining of VM not implemented for sequence attributes with VR in the High Level Interface./r/nReturning 1");
                    vm = 1;
                }
                else if (attribute is UnknownAttribute)
                {
                    // InterfaceLogging.WriteWarning("Determining of VM not implemented for attributes with VR Unknown in the High Level Interface./r/nReturning 1");
                    vm = 1;
                }
                else
                {
                    DvtkHighLevelInterfaceException.Throw("Not expecting this type of attribute in the code");
                }
            }

            // End Interface logging.
            // InterfaceLogging.End(vm);

            return(vm);
        }
예제 #4
0
파일: Attribute.cs 프로젝트: top501/DVTK-1
        //
        // - Constructors -
        //

        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="tagSequence">The tag sequence (one or more tags seperated with an '/') of this attribue.</param>
        /// <param name="attribute">
        /// The encapsulated Attribute from the DvtkData librbary.
        /// May not be null.
        /// </param>
        public Attribute(String tagSequence, DvtkData.Dimse.Attribute dvtkDataAttribute)
        {
            this.tagSequence = tagSequence;

            if (dvtkDataAttribute == null)
            {
                // Sanity check.
                DvtkHighLevelInterfaceException.Throw("Parameter may not be null.");
            }
            else
            {
                this.dvtkDataAttribute = dvtkDataAttribute;
            }
        }
예제 #5
0
        public Values GetAttributeValues(int index)
        {
            Values theValues = null;

            Attribute attribute = GetAttribute(index);

            if (attribute == null)
            {
                // InterfaceLogging.WriteError("Attribute does not exist.");
                // Temporary.
                theValues = new InvalidValues("0x00000000");
            }
            else
            {
                if (attribute is SimpleAttribute)
                {
                    SimpleAttribute simpleAttribute = attribute as SimpleAttribute;

                    theValues = simpleAttribute.GetValues();
                }
                else if (attribute is PixelDataAttribute)
                {
                    // InterfaceLogging.WriteWarning("Getting values not implemented for pixel data attributes in the High Level Interface./r/nReturning single empty string");
                    // Temporary.
                    theValues = new ValidValues("0x00000000", "");
                }
                else if (attribute is SequenceAttribute)
                {
                    // InterfaceLogging.WriteError("Attribute with tag sequence " + tagSequence + " is a sequence attribute.");
                    // Temporary.
                    theValues = new InvalidValues("0x00000000");
                }
                else if (attribute is UnknownAttribute)
                {
                    // InterfaceLogging.WriteWarning("Getting values not implemented for attributes with VR Unknown in the High Level Interface./r/nReturning single empty string");
                    // Temporary.
                    theValues = new ValidValues("0x00000000", "");
                }
                else
                {
                    DvtkHighLevelInterfaceException.Throw("Not expecting this type of attribute in the code");
                }
            }

            // End Interface logging.
            // InterfaceLogging.End(theValues);

            return(theValues);
        }
예제 #6
0
파일: SetMethod.cs 프로젝트: top501/DVTK-1
        private static void SetSequenceAttribute(AttributeSet attributeSet, SetParameterGroup setParameterGroup)
        {
            foreach (Object parameter in setParameterGroup.values)
            {
                // Check if all parameters are of type sequence item.
                if (!(parameter is SequenceItem))
                {
                    DvtkHighLevelInterfaceException.Throw("Error while setting the Sequence attribute with tag " + setParameterGroup.tagAsString + ". Only sequence items are allowed as parameters.");
                }
            }

            ValidAttribute sequenceAttribute = new ValidAttribute(setParameterGroup.tagAsUInt32, VR.SQ);

            foreach (SequenceItem sequenceItem in setParameterGroup.values)
            {
                sequenceAttribute.AddItem(sequenceItem);
            }

            attributeSet.Set(sequenceAttribute);
        }
예제 #7
0
        /// <summary>
        /// Check if the supplied values are equal to the content of this object.
        /// </summary>
        /// <param name="parameters">
        /// Single values to compare with.
        /// Supplying multiple objects of type Values is not allowed.
        /// </param>
        /// <returns>Boolean indicating if the Values are equal.</returns>
        public override bool EqualTo(params Object[] parameters)
        {
            // Start Interface logging.
            // InterfaceLogging.Start(this, parameters);

            bool equalTo = true;

            // Check for correctness parameters.
            foreach (Object parameter in parameters)
            {
                if (parameter is Values)
                {
                    DvtkHighLevelInterfaceException.Throw("Not allowed to supply multiple objects of type Values.");
                }
            }

            if (Count == parameters.Length)
            {
                // Note: the Get method of this object is 1-bases and the []operator of parameters is 0-based.
                for (int index = 1; index <= Count; index++)
                {
                    if (GetString(index) != parameters[index - 1].ToString())
                    {
                        equalTo = false;
                        break;
                    }
                }
            }
            else
            {
                equalTo = false;
            }

            // End Interface logging.
            // InterfaceLogging.End(equalTo);

            return(equalTo);
        }
예제 #8
0
        static public Tag[] InterpretTagSequence(String tagSequence)
        {
            bool      interpreted  = true;
            ArrayList tagArrayList = new ArrayList();

            String[] tagsAsString = tagSequence.Split('/');

            foreach (String tagAsString in tagsAsString)
            {
                Tag tag = new Tag();
                tag.tagAsString = tagAsString;

                // Check if the tag starts with "0x".
                if (!tagAsString.StartsWith("0x"))
                {
                    // InterfaceLogging.WriteError("Invalid syntax: " + tagAsString + " does not start with \"0x\".");
                    interpreted = false;
                    break;
                }

                // If this tag contains an index, determine it.
                int indexOfBracket = tagAsString.IndexOf("[");

                if (indexOfBracket != -1)
                {
                    try
                    {
                        tag.tagWithoutIndex = tagAsString.Substring(0, indexOfBracket);

                        String indexAsString = tagAsString.Substring(indexOfBracket + 1);

                        indexAsString = indexAsString.Substring(0, indexAsString.Length - 1);

                        // indexAsString should now contain the actual index number.

                        tag.Index = Convert.ToInt32(indexAsString);

                        if (tag.Index < 1)
                        {
                            // InterfaceLogging.WriteError("Invalid syntax: index of " + tagAsString + " must be greater than 0.");
                            interpreted = false;
                            break;
                        }
                    }
                    catch
                    {
                        // InterfaceLogging.WriteError("Invalid syntax for tag " + tagAsString + ".");
                        interpreted = false;
                        break;
                    }
                }
                else
                {
                    tag.tagWithoutIndex = tagAsString;
                }

                try
                {
                    tag.tagAsUInt32 = Convert.ToUInt32(tag.tagWithoutIndex, 16);
                }
                catch
                {
                    // InterfaceLogging.WriteError("Invalid syntax for tag " + tagAsString + ".");
                    interpreted = false;
                    break;
                }


                tagArrayList.Add(tag);
            }

            if (interpreted)
            {
                // Final checks:
                // - At leats one tag must be present.
                // - Last tag may not contain an index and.
                // - All tags besides the last one must contain an index.
                if (tagArrayList.Count == 0)
                {
                    // InterfaceLogging.WriteError("Tag sequence must contain at least one tag.");
                    interpreted = false;
                }
                else
                {
                    if (((tagArrayList[tagArrayList.Count - 1]) as Tag).ContainsIndex)
                    {
                        // InterfaceLogging.WriteError("Last tag of tag sequence may not contain an index.");
                        interpreted = false;
                    }

                    for (int tagIndex = 0; tagIndex < tagArrayList.Count - 1; tagIndex++)
                    {
                        if (!((tagArrayList[tagIndex]) as Tag).ContainsIndex)
                        {
                            // InterfaceLogging.WriteError("All tags besides the last one in tag sequence must contain an index.");
                            interpreted = false;
                            break;
                        }
                    }
                }
            }

            if (!interpreted)
            {
                DvtkHighLevelInterfaceException.Throw("Invalid Syntax for tag sequence.");
            }

            return(tagArrayList.ToArray(typeof(Tag)) as Tag[]);
        }
예제 #9
0
파일: SetMethod.cs 프로젝트: top501/DVTK-1
        public static ArrayList GetParameterGroups(params Object[] parameters)
        {
            int  parameterIndex = 0;
            bool interpreted    = true;

            ArrayList setParameterGroups = new ArrayList();

            // Loop through all parameters of this method.
            while (parameterIndex < parameters.Length)
            {
                SetParameterGroup setParameterGroup = new SetParameterGroup();
                Object            parameter         = null;

                // Determine the tag of the attribute.

                parameter = parameters[parameterIndex];
                if (parameter is String)
                {
                    setParameterGroup.tagAsString = parameter as String;

                    // Check the syntax of the first tag and determine the UInt32 representation.
                    if (!setParameterGroup.tagAsString.StartsWith("0x"))
                    {
                        // InterfaceLogging.WriteError("Invalid tag sequence(missing \"0x\" in a tag).");
                        interpreted = false;
                        break;
                    }

                    try
                    {
                        setParameterGroup.tagAsUInt32 = Convert.ToUInt32(setParameterGroup.tagAsString, 16);
                    }
                    catch
                    {
                        // InterfaceLogging.WriteError("Invalid tag sequence.");
                        interpreted = false;
                        break;
                    }
                }
                else
                {
                    // InterfaceLogging.WriteError("Tag is not supplied as a String");
                    interpreted = false;
                    break;
                }

                parameterIndex++;
                parameter = parameters[parameterIndex];

                // Determine the VR of the attribute.

                if (parameter is DvtkData.Dimse.VR)
                {
                    setParameterGroup.vR = (DvtkData.Dimse.VR)parameter;
                }
                else
                {
                    // InterfaceLogging.WriteError("Expecting DvtkData.Dimse.VR");
                    interpreted = false;
                    break;
                }

                parameterIndex++;

                // Determine the attribute values (zero or more).

                bool continueWithAttributeValues = true;

                while (continueWithAttributeValues)
                {
                    // If no more parameters are present to process...
                    if (parameterIndex >= parameters.Length)
                    {
                        continueWithAttributeValues = false;
                    }
                    // If the index is not pointing to the last parameter...
                    else if ((parameterIndex + 1) < parameters.Length)
                    {
                        // If the index is pointing to the next attribute...
                        if (parameters[parameterIndex + 1] is DvtkData.Dimse.VR)
                        {
                            continueWithAttributeValues = false;
                        }
                    }

                    if (continueWithAttributeValues)
                    {
                        setParameterGroup.values.Add(parameters[parameterIndex]);
                        parameterIndex++;
                    }
                }

                setParameterGroups.Add(setParameterGroup);
            }

            if (!interpreted)
            {
                DvtkHighLevelInterfaceException.Throw("Error while interpreting parameters of Set method.");
            }

            return(setParameterGroups);
        }
예제 #10
0
        //
        // - Methods -
        //

        /// <summary>
        /// Get the values from this attribute.
        /// </summary>
        /// <returns>The values.</returns>
        public ValidValues GetValues()
        {
            ValidValues validValues = null;

            switch (dvtkDataAttribute.ValueRepresentation)
            {
            case VR.AE:                     // Application Entity
                DvtkData.Dimse.ApplicationEntity theApplicationEntity = this.dvtkDataAttribute.DicomValue as DvtkData.Dimse.ApplicationEntity;
                validValues = new ValidValues(this.tagSequence, theApplicationEntity.Values);
                break;

            case VR.AS:                     // Age String
                DvtkData.Dimse.AgeString theAgeString = this.dvtkDataAttribute.DicomValue as DvtkData.Dimse.AgeString;
                validValues = new ValidValues(this.tagSequence, theAgeString.Values);
                break;

            case VR.AT:                     // Attribute Tag
                DvtkData.Dimse.AttributeTag theAttributeTag = this.dvtkDataAttribute.DicomValue as DvtkData.Dimse.AttributeTag;
                validValues = new ValidValues(this.tagSequence, theAttributeTag.Values);
                break;

            case VR.CS:                     // Code String
                DvtkData.Dimse.CodeString theCodeString = this.dvtkDataAttribute.DicomValue as DvtkData.Dimse.CodeString;
                validValues = new ValidValues(this.tagSequence, theCodeString.Values);
                break;

            case VR.DA:                     // Date
                DvtkData.Dimse.Date theDate = this.dvtkDataAttribute.DicomValue as DvtkData.Dimse.Date;
                validValues = new ValidValues(this.tagSequence, theDate.Values);
                break;

            case VR.DS:                     // Decimal String
                DvtkData.Dimse.DecimalString theDecimalString = this.dvtkDataAttribute.DicomValue as DvtkData.Dimse.DecimalString;
                validValues = new ValidValues(this.tagSequence, theDecimalString.Values);
                break;

            case VR.DT:                     // Date Time
                DvtkData.Dimse.DateTime theDateTime = this.dvtkDataAttribute.DicomValue as DvtkData.Dimse.DateTime;
                validValues = new ValidValues(this.tagSequence, theDateTime.Values);
                break;

            case VR.FD:                     // Floating Point Double
                DvtkData.Dimse.FloatingPointDouble theFloatingPointDouble = this.dvtkDataAttribute.DicomValue as DvtkData.Dimse.FloatingPointDouble;
                validValues = new ValidValues(this.tagSequence, theFloatingPointDouble.Values);
                break;

            case VR.FL:                     // Floating Point Single
                DvtkData.Dimse.FloatingPointSingle theFloatingPointSingle = this.dvtkDataAttribute.DicomValue as DvtkData.Dimse.FloatingPointSingle;
                validValues = new ValidValues(this.tagSequence, theFloatingPointSingle.Values);
                break;

            case VR.IS:                     // Integer String
                DvtkData.Dimse.IntegerString theIntegerString = this.dvtkDataAttribute.DicomValue as DvtkData.Dimse.IntegerString;
                validValues = new ValidValues(this.tagSequence, theIntegerString.Values);
                break;

            case VR.LO:                     // Long String
                DvtkData.Dimse.LongString theLongString = this.dvtkDataAttribute.DicomValue as DvtkData.Dimse.LongString;
                validValues = new ValidValues(this.tagSequence, theLongString.Values);
                break;

            case VR.LT:                     // Long Text
                DvtkData.Dimse.LongText theLongText = this.dvtkDataAttribute.DicomValue as DvtkData.Dimse.LongText;
                validValues = new ValidValues(this.tagSequence, theLongText.Value);
                break;

            case VR.PN:                     // Person Name
                DvtkData.Dimse.PersonName thePersonName = this.dvtkDataAttribute.DicomValue as DvtkData.Dimse.PersonName;
                validValues = new ValidValues(this.tagSequence, thePersonName.Values);
                break;

            case VR.SH:                     // Short String
                DvtkData.Dimse.ShortString theShortString = this.dvtkDataAttribute.DicomValue as DvtkData.Dimse.ShortString;
                validValues = new ValidValues(this.tagSequence, theShortString.Values);
                break;

            case VR.SL:                     // Signed Long
                DvtkData.Dimse.SignedLong theSignedLong = this.dvtkDataAttribute.DicomValue as DvtkData.Dimse.SignedLong;
                validValues = new ValidValues(this.tagSequence, theSignedLong.Values);
                break;

            case VR.SS:                     // Signed Short
                DvtkData.Dimse.SignedShort theSignedShort = this.dvtkDataAttribute.DicomValue as DvtkData.Dimse.SignedShort;
                validValues = new ValidValues(this.tagSequence, theSignedShort.Values);
                break;

            case VR.ST:                     // Short Text
                DvtkData.Dimse.ShortText theShortText = this.dvtkDataAttribute.DicomValue as DvtkData.Dimse.ShortText;
                validValues = new ValidValues(this.tagSequence, theShortText.Value);
                break;

            case VR.TM:                     // Time
                DvtkData.Dimse.Time theTime = this.dvtkDataAttribute.DicomValue as DvtkData.Dimse.Time;
                validValues = new ValidValues(this.tagSequence, theTime.Values);
                break;

            case VR.UI:                     // Unique Identifier (UID)
                DvtkData.Dimse.UniqueIdentifier theUniqueIdentifier = this.dvtkDataAttribute.DicomValue as DvtkData.Dimse.UniqueIdentifier;
                validValues = new ValidValues(this.tagSequence, theUniqueIdentifier.Values);
                break;

            case VR.UL:                     // Unsigned Long
                DvtkData.Dimse.UnsignedLong theUnsignedLong = this.dvtkDataAttribute.DicomValue as DvtkData.Dimse.UnsignedLong;
                validValues = new ValidValues(this.tagSequence, theUnsignedLong.Values);
                break;

            case VR.US:                     // Unsigned Short
                DvtkData.Dimse.UnsignedShort theUnsignedShort = this.dvtkDataAttribute.DicomValue as DvtkData.Dimse.UnsignedShort;
                validValues = new ValidValues(this.tagSequence, theUnsignedShort.Values);
                break;

            case VR.UT:                     // Unlimited Text
                DvtkData.Dimse.UnlimitedText theUnlimitedText = this.dvtkDataAttribute.DicomValue as DvtkData.Dimse.UnlimitedText;
                validValues = new ValidValues(this.tagSequence, theUnlimitedText.Value);
                break;

            default:
                DvtkHighLevelInterfaceException.Throw("VR " + dvtkDataAttribute.ValueRepresentation.ToString() + " is not handled by class SimpleAttribute.");
                break;
            }

            return(validValues);
        }