internal String DumpUsingTagSequenceNotation(String objectName, String remarkString, string appendString, String sequenceAppendString) { String dump = ""; for (int index = 0; index < Count; index++) { ValidAttribute validAttribute = this[index] as ValidAttribute; if (validAttribute.VR != VR.SQ) { dump += objectName + appendString + "(\"" + validAttribute.TagSequence.ToString() + "\", VR." + validAttribute.VR.ToString(); // Show all the values. Values values = validAttribute.Values; if (values.Count > 0) { dump += ", " + values.ToString(); } dump += ")"; // If a name exists, add this as a comment. if (validAttribute.Name.Length > 0) { dump += " " + remarkString + " " + validAttribute.Name; // No need to have a remark string for this line anymore. remarkString = ""; } //if (validAttribute.VR == VR.UN) //{ // dump+= " " + remarkString + " (value not displayed, consists of " + validAttribute.Values.ByteArrayImplementation.Length.ToString() + " bytes)"; //} dump += "\r\n"; } else { dump += objectName + appendString + "(\"" + validAttribute.TagSequence.ToString() + "\", VR." + validAttribute.VR.ToString() + ")"; // If a name exists, add this as a comment. if (validAttribute.Name.Length > 0) { dump += " " + remarkString + " " + validAttribute.Name; } dump += "\r\n"; for (int itemIndex = 1; itemIndex <= validAttribute.ItemCount; itemIndex++) { SequenceItem item = validAttribute.GetItem(itemIndex); dump += objectName + sequenceAppendString + "(\"" + validAttribute.TagSequence.ToString() + "\", new SequenceItem)\r\n"; dump += item.DumpUsingTagSequenceNotation(objectName, remarkString, appendString, sequenceAppendString); } } } return(dump); }
/// <summary> /// Get a SequenceItem by specifying a tagSequence /// <paramref name="tagSequence">tagSequence</paramref>. /// </summary> /// <param name="tagSequence"> /// The (tag)Sequence of which you want a SequenceItem. /// </param> /// <param name="oneBasedIndex"> /// Specify which SequenceItem is requested. (1 for the first SequenceItem in the sequence) /// </param> /// <example> /// <b>VB .NET</b> /// <code> /// 'Get a SequenceItem by specifying a tagSequence /// /// 'DataSet is inherited from AttributeSet /// Dim myDataSet As DvtkHighLevelInterface.Dicom.Other.DataSet /// /// myDataSet.Read("c:\Somefile.dcm") /// /// 'Get the first Sequence item from the specified Sequence /// Dim mySequenceItem As DvtkHighLevelInterface.Dicom.Other.SequenceItem /// /// If myDataSet.Exists("0x00080096") Then /// If myDataSet.GetitemCount("0x00080096") > 0 Then /// mySequenceItem = myDataSet.Getitem("0x00080096", 1) /// End If /// End If /// </code> /// </example> /// <returns> /// A Values Object containing a list of all values the attribute contains. /// </returns> /// <exception cref="HliException"> /// Tag sequence supplied invalid for this operation. /// </exception> ///<remarks> /// If the attribute requested by the tagSequence is non existent or invalid an empty SequenceItem will be returned. ///</remarks> public SequenceItem Getitem(String tagSequence, int oneBasedIndex) { // // Sanity checks. // if (tagSequence == null) { throw new ArgumentNullException("tagSequence"); } TagSequence internalTagSequence = new TagSequence(tagSequence); if (!internalTagSequence.IsValid) { throw new ArgumentException("Tag sequence is not valid", "tagSequence"); } if (!internalTagSequence.IsSingleAttributeMatching) { throw new ArgumentException("Tag sequence must specify a single attribute", "tagSequence"); } if (oneBasedIndex == 0) { throw new ArgumentException("Index is one based", "oneBasedIndex"); } // // Perform the actual operation. // SequenceItem sequenceItem = null; ValidAttribute validAttribute = this[internalTagSequence] as ValidAttribute; if (validAttribute == null) { sequenceItem = new SequenceItem(); Thread.WriteWarningCurrentThread("Trying to get a sequence item for an invalid attribute with tag sequence " + tagSequence + ". Returning an empty sequence item."); } else { sequenceItem = validAttribute.GetItem(oneBasedIndex); } return(sequenceItem); }
/// <summary> /// Randomizes all attributes contained in this instance. /// </summary> /// <remarks> /// Randomization is performed by replacing each <paramref name="stringToReplace"/> in the values of the attributes contained /// with a random digit between 0 and 9. /// </remarks> /// <param name="stringToReplace">The String to replace (may not be empty).</param> /// <param name="random">A Random instance.</param> public void Randomize(String stringToReplace, Random random) { // // Sanity checks. // if (stringToReplace == null) { throw new ArgumentNullException("stringToReplace"); } else { if (stringToReplace.Length == 0) { throw new ArgumentException("String may not be empty", "stringToReplace"); } } if (random == null) { throw new ArgumentNullException("random"); } // // Perform the randomization. // for (int index = 0; index < Count; index++) { ValidAttribute validAttribute = this[index] as ValidAttribute; if (validAttribute.VR == VR.SQ) { for (int itemIndex = 1; itemIndex <= validAttribute.ItemCount; itemIndex++) { validAttribute.GetItem(itemIndex).Randomize(stringToReplace, random); } } else { validAttribute.Values.Randomize(stringToReplace, random); } } }