Esempio n. 1
0
/*
 *              /// <summary>
 *              /// Get the number of items in a sequence attribute.
 *              /// </summary>
 *              /// <param name="tagSequence"></param>
 *              /// <returns>
 *              /// The number of sequence items.
 *              ///
 *              /// If the attribute does not exist or is not a sequence, 0 is returned.
 *              /// </returns>
 *              public int GetSequenceItemCount(String tagSequence)
 *              {
 *                      int sequenceItemCount = 0;
 *
 *                      Attribute attribute = GetAttribute(tagSequence);
 *
 *                      if (attribute == null)
 *                      {
 *                              // InterfaceLogging.WriteError(this, "Attribute does not exist. Returning 0.", tagSequence);
 *                              sequenceItemCount = 0;
 *                      }
 *                      else
 *                      {
 *                              if (attribute is SequenceAttribute)
 *                              {
 *                                      SequenceAttribute sequenceAttribute = attribute as SequenceAttribute;
 *
 *                                      sequenceItemCount = sequenceAttribute.ItemCount;
 *                              }
 *                              else
 *                              {
 *                                      // InterfaceLogging.WriteError(this, "Attribute is not a sequence", tagSequence);
 *                                      sequenceItemCount = 0;
 *                              }
 *                      }
 *
 *                      return(sequenceItemCount);
 *              }
 */

        /*
         * // First index determines sequence attribute: zero bas, second index determines : one based.
         * public SequenceItem GetSequenceItem(int index1, int index2)
         * {
         *      SequenceItem sequenceItem = null;
         *
         *      Attribute attribute = GetAttribute(index1);
         *
         *      if (attribute == null)
         *      {
         *              // InterfaceLogging.WriteError(this, "Attribute does not exist. Returning 0.", tagSequence);
         *              sequenceItem = null;
         *      }
         *      else
         *      {
         *              if (attribute is SequenceAttribute)
         *              {
         *                      SequenceAttribute sequenceAttribute = attribute as SequenceAttribute;
         *
         *                      sequenceItem =
         *              }
         *              else
         *              {
         *                      // InterfaceLogging.WriteError(this, "Attribute is not a sequence", tagSequence);
         *                      sequenceItem = null;
         *              }
         *      }
         *
         *      return(sequenceItem);
         * }
         */

        public int GetSequenceItemCount(int index)
        {
            int sequenceItemCount = 0;

            Attribute attribute = GetAttribute(index);

            if (attribute == null)
            {
                // InterfaceLogging.WriteError(this, "Attribute does not exist. Returning 0.", tagSequence);
                sequenceItemCount = 0;
            }
            else
            {
                if (attribute is SequenceAttribute)
                {
                    SequenceAttribute sequenceAttribute = attribute as SequenceAttribute;

                    sequenceItemCount = sequenceAttribute.ItemCount;
                }
                else
                {
                    // InterfaceLogging.WriteError(this, "Attribute is not a sequence", tagSequence);
                    sequenceItemCount = 0;
                }
            }

            return(sequenceItemCount);
        }
Esempio n. 2
0
        //
        // - Methods -
        //



        /// <summary>
        /// Get the HLI Attribute, given a DvtkData attribute.
        /// </summary>
        /// <param name="tagSequence">The tag sequence (one or more tags seperated with an '/') of this attribue.</param>
        /// <param name="dvtkDataAttribute">The DvtkData attribute.</param>
        /// <returns>The HLI Attribute.</returns>
        public static Attribute GetAttribute(String tagSequence, DvtkData.Dimse.Attribute dvtkDataAttribute)
        {
            Attribute attribute = null;

            switch (dvtkDataAttribute.ValueRepresentation)
            {
            // These cases handles the "simple" attributes.
            case VR.AE:                     // Application Entity
            case VR.AS:                     // Age String
            case VR.AT:                     // Attribute Tag
            case VR.CS:                     // Code String
            case VR.DA:                     // Date
            case VR.DS:                     // Decimal String
            case VR.DT:                     // Date Time
            case VR.FL:                     // Floating Point Single
            case VR.FD:                     // Floating Point Double
            case VR.IS:                     // Integer String
            case VR.LO:                     // Long String
            case VR.LT:                     // Long Text
            case VR.PN:                     // Person Name
            case VR.SH:                     // Short String
            case VR.SL:                     // Signed Long
            case VR.SS:                     // Signed Short
            case VR.ST:                     // Short Text
            case VR.TM:                     // Time
            case VR.UI:                     // Unique Identifier (UID)
            case VR.UL:                     // Unsigned Long
            case VR.US:                     // Unsigned Short
            case VR.UT:                     // Unlimited Text
                attribute = new SimpleAttribute(tagSequence, dvtkDataAttribute);
                break;

            // These cases handles the pixel data attributes.
            case VR.OB:                     // Other Byte String
            case VR.OF:                     // Other Float String
            case VR.OW:                     // Other Word String
                attribute = new PixelDataAttribute(tagSequence, dvtkDataAttribute);
                break;

            // This case handles the sequence attributes.
            case VR.SQ:                     // Sequence of Items
                attribute = new SequenceAttribute(tagSequence, dvtkDataAttribute);
                break;

            // This case handles the unknown attributes.
            case VR.UN:                     // Unknown
                attribute = new UnknownAttribute(tagSequence, dvtkDataAttribute);
                break;

            default:
                attribute = null;
                break;
            }

            return(attribute);
        }
Esempio n. 3
0
        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.");
                }
            }

            SequenceAttribute sequenceAttribute = new SequenceAttribute(setParameterGroup.tagAsUInt32);

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

            attributeSet.Set(sequenceAttribute);
        }
Esempio n. 4
0
        /// <summary>
        /// Get the attribute set this attribute belongs to.
        /// TODO!!: merge this code with GetAttribute method.
        /// </summary>
        /// <param name="tagSequence"></param>
        /// <returns></returns>
        internal AttributeSet GetAttributeSet(String tagSequence)
        {
            Tag[]     tags;
            Attribute attribute = null;

            tags = Tag.InterpretTagSequence(tagSequence);

            AttributeSet currentAttributeSet = this;
            String       currentTagSequence  = "";
            String       currentTagSequenceLastTagNoIndex = "";

            foreach (Tag tag in tags)
            {
                // Set the currentTagSequence.
                if (currentTagSequence == "")
                {
                    currentTagSequence = tag.TagAsString;
                    currentTagSequenceLastTagNoIndex = tag.TagWithoutIndex;
                }
                else
                {
                    currentTagSequence += "/" + tag.TagAsString;
                    currentTagSequenceLastTagNoIndex = currentTagSequence + "/" + tag.TagWithoutIndex;
                }

                // Create the correct Attribute object.
                DvtkData.Dimse.Attribute dvtkDataAttribute = currentAttributeSet.dvtkDataAttributeSet.GetAttribute(tag.TagAsUInt32);

                if (dvtkDataAttribute == null)
                {
                    attribute = null;
                    break;
                }
                else
                {
                    attribute = Attribute.GetAttribute(tagSequence, dvtkDataAttribute);
                }

                // If this tag contains an index, check that the attribute is a sequence attribute
                // and retrieve the correct attribute set from it.
                if (tag.ContainsIndex)
                {
                    if (attribute is SequenceAttribute)
                    {
                        SequenceAttribute sequenceAttribute = attribute as SequenceAttribute;

                        if (tag.Index > sequenceAttribute.ItemCount)
                        {
                            String errorText = "Sequence attribute with tag sequence " + currentTagSequenceLastTagNoIndex + " contains " + sequenceAttribute.ItemCount.ToString() + " items.";
                            errorText += "\r\nThe script however is expecting it to have an item with index " + tag.Index.ToString() + ".";

                            // InterfaceLogging.WriteError(errorText);
                            attribute = null;
                            break;
                        }
                        else
                        {
                            currentAttributeSet = sequenceAttribute.GetItem(tag.Index);
                        }
                    }
                    else
                    {
                        String errorText = "Attribute with tag sequence " + currentTagSequenceLastTagNoIndex + " is not a sequence attribute.";
                        errorText += "\r\nThe script however is expecting it because the tag sequence " + currentTagSequence + " contains an index.";

                        // InterfaceLogging.WriteError(errorText);
                        attribute = null;
                        break;
                    }
                }
            }

            return(currentAttributeSet);
        }
Esempio n. 5
0
        //
        // - Methods -
        //
        /// <summary>
        /// Get the HLI Attribute, given a DvtkData attribute.
        /// </summary>
        /// <param name="tagSequence">The tag sequence (one or more tags seperated with an '/') of this attribue.</param>
        /// <param name="dvtkDataAttribute">The DvtkData attribute.</param>
        /// <returns>The HLI Attribute.</returns>
        public static Attribute GetAttribute(String tagSequence, DvtkData.Dimse.Attribute dvtkDataAttribute)
        {
            Attribute attribute = null;

            switch(dvtkDataAttribute.ValueRepresentation)
            {
                    // These cases handles the "simple" attributes.
                case VR.AE: // Application Entity
                case VR.AS: // Age String
                case VR.AT: // Attribute Tag
                case VR.CS: // Code String
                case VR.DA: // Date
                case VR.DS: // Decimal String
                case VR.DT: // Date Time
                case VR.FL: // Floating Point Single
                case VR.FD: // Floating Point Double
                case VR.IS: // Integer String
                case VR.LO: // Long String
                case VR.LT: // Long Text
                case VR.PN: // Person Name
                case VR.SH: // Short String
                case VR.SL: // Signed Long
                case VR.SS: // Signed Short
                case VR.ST: // Short Text
                case VR.TM: // Time
                case VR.UI: // Unique Identifier (UID)
                case VR.UL: // Unsigned Long
                case VR.US: // Unsigned Short
                case VR.UT: // Unlimited Text
                    attribute = new SimpleAttribute(tagSequence, dvtkDataAttribute);
                    break;

                    // These cases handles the pixel data attributes.
                case VR.OB: // Other Byte String
                case VR.OF: // Other Float String
                case VR.OW: // Other Word String
                    attribute = new PixelDataAttribute(tagSequence, dvtkDataAttribute);
                    break;

                    // This case handles the sequence attributes.
                case VR.SQ: // Sequence of Items
                    attribute = new SequenceAttribute(tagSequence, dvtkDataAttribute);
                    break;

                    // This case handles the unknown attributes.
                case VR.UN: // Unknown
                    attribute = new UnknownAttribute(tagSequence, dvtkDataAttribute);
                    break;

                default:
                    attribute = null;
                    break;
            }

            return attribute;
        }
Esempio n. 6
0
        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.");
                }
            }

            SequenceAttribute sequenceAttribute = new SequenceAttribute(setParameterGroup.tagAsUInt32);

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

            attributeSet.Set(sequenceAttribute);
        }