// // - Properties - // // // - Methods - // /// <summary> /// Do a static compare for the attribute sets supplied. /// /// Note that the parameters attributeSets, attributeSetDescriptions and compareFlagsForAttributeSets /// must have the same size and must be at least size 2. /// </summary> /// <param name="tableDescription">Description of the table.</param> /// <param name="attributeCollections">The attribute sets to compare with each other.</param> /// <param name="attributeCollectionDescriptions">The descriptions of the attribute sets.</param> /// <param name="flags"> /// The compare flags that may be supplied. The following combination of flags may be supplied (using bitwise Or): /// - CompareFlags.None: when only supplying this flag, the attributes are only displayed and no compare is performed. /// - CompareFlags.Compare_present: a check is performed if all attributes with the same tag are present. /// - CompareFlags.Compare_values: a check is performed if all attributes with the same tag have the same values. /// - CompareFlags.Compare_VR: a check is performed if all attributes with the same tag have the same VR. /// </param> /// <returns>The results of the static compare presented as a table (that may be converted to HTML).</returns> public CompareResults CompareAttributeSets(String tableDescription, AttributeCollections attributeCollections, StringCollection attributeCollectionDescriptions, FlagsDicomAttribute flags) { CompareResults compareResults = null; for (int index = 0; index < attributeCollections.Count; index++) { (attributeCollections[index] as DicomAttributeCollection).Flags |= FlagsConvertor.ConvertToFlagsBase(flags); } compareResults = CompareAttributeSets(tableDescription, attributeCollections, attributeCollectionDescriptions); return(compareResults); }
/// <summary> /// Compare the DICOM files in the two directories based on there being corresponding /// files in each directory with the same attribute value for the matching Tag. /// </summary> /// <param name="directory1">Full directory name of first directory.</param> /// <param name="directory2">Full directory name of second directory.</param> /// <param name="matchingTag">DICOM Tag value to match in a file in each directory.</param> /// <returns>Total number of differences between compared files.</returns> public int Compare(String directory1, String directory2, DvtkData.Dimse.Tag matchingTag) { int totalDifferences = 0; StreamWriter htmlOutput = null; try { // create the output file writer if necessary if (_htmlOutputFilename != String.Empty) { htmlOutput = new StreamWriter(_htmlOutputFilename); } // compare all files in directory 1 with corresponding files in directory 2 // - the files compared is based on them having the same attribute value for the // Tag given. DirectoryInfo directoryInfo = new DirectoryInfo(directory1); FileInfo[] fileInfo = directoryInfo.GetFiles(); for (int i = 0; i < fileInfo.Length; i++) { DataSet dataset1 = new DataSet(); String filename1 = fileInfo[i].FullName; dataset1.DvtkDataDataSet = Dvtk.DvtkDataHelper.ReadDataSetFromFile(filename1); // get the attribute value for the matching tag from this dataset String valueToMatch = GetAttributeValueFromDataset(dataset1, matchingTag); if (valueToMatch != String.Empty) { // try to find a dataset (file) containing the same value in directory 2 String filename2 = String.Empty; DataSet dataset2 = GetMatchingDatasetFromStoreDataDirectory(directory2, matchingTag, valueToMatch, out filename2); // if a dataset is returned that contains the matching attribute value go on to compare all the attributes // in both datasets with eachother if (dataset2 != null) { // get a new compare instance and set the comparison flags StaticDicomCompare staticDicomCompare = new StaticDicomCompare(); FlagsDicomAttribute flags = FlagsDicomAttribute.Compare_values | FlagsDicomAttribute.Compare_present | FlagsDicomAttribute.Include_sequence_items; if (_compareVr == false) { staticDicomCompare.DisplayAttributeVR = false; } else { flags |= FlagsDicomAttribute.Compare_VR; } staticDicomCompare.DisplayGroupLength = _displayGroupLength; dataset1.UnVrDefinitionLookUpWhenReading = _unVrDefinitionLookUpWhenReading; dataset2.UnVrDefinitionLookUpWhenReading = _unVrDefinitionLookUpWhenReading; AttributeCollections datasets = new AttributeCollections(); datasets.Add(dataset1); datasets.Add(dataset2); StringCollection datasetDescriptions = new StringCollection(); datasetDescriptions.Add(filename1); datasetDescriptions.Add(filename2); String title = String.Format("Comparison Results with matching using Tag with {0}", matchingTag.ToString()); DvtkHighLevelInterface.Common.Compare.CompareResults datasetCompareResults = staticDicomCompare.CompareAttributeSets(title, datasets, datasetDescriptions, flags); if (htmlOutput != null) { if (_includeDetailedResults == true) { htmlOutput.WriteLine(datasetCompareResults.Table.ConvertToHtml()); } else { htmlOutput.WriteLine("<br />"); String message = String.Format("Compared {0} with {1} - number of differences: {2}", filename1, filename2, datasetCompareResults.DifferencesCount); htmlOutput.WriteLine(message); htmlOutput.WriteLine("<br />"); } } // update the total differences counter totalDifferences += datasetCompareResults.DifferencesCount; } } } } catch (System.Exception) { } if (htmlOutput != null) { htmlOutput.Flush(); htmlOutput.Close(); } return(totalDifferences); }
internal CompareResults CreateCompareResults(int numberOfColumns, AttributeCollections attributeCollections, String tableDescription, StringCollection attributeSetDescriptions) { CompareResults compareResults = new CompareResults(numberOfColumns); compareResults.Table.CellItemSeperator = "<br>"; compareResults.Table.EmptyCellPrefix = BACKGROUND_GREY; int index = 0; String[] header1 = new String[numberOfColumns]; String[] header2 = new String[numberOfColumns]; String[] header3 = new String[numberOfColumns]; int[] columnWidths = new int[numberOfColumns]; if (this.displayCommonTag) { header1[index] = tableDescription; header2[index] = "Common info"; header3[index] = TAG_STRING; columnWidths[index] = PIXEL_WIDTH_TAG; index++; } if (this.displayCommonName) { header1[index] = tableDescription; header2[index] = "Common info"; header3[index] = NAME_STRING; columnWidths[index] = PIXEL_WIDTH_NAME; index++; } for (int attributeSetsIndex = 0; attributeSetsIndex < attributeCollections.Count; attributeSetsIndex++) { if (this.displayAttributeTag) { header1[index] = tableDescription; header2[index] = attributeSetDescriptions[attributeSetsIndex]; header3[index] = TAG_STRING; columnWidths[index] = PIXEL_WIDTH_TAG; index++; } if (this.displayAttributeName && (attributeCollections[attributeSetsIndex] is DicomAttributeCollection)) { header1[index] = tableDescription; header2[index] = attributeSetDescriptions[attributeSetsIndex]; header3[index] = NAME_STRING; columnWidths[index] = PIXEL_WIDTH_NAME; index++; } if (this.displayAttributePresent) { header1[index] = tableDescription; header2[index] = attributeSetDescriptions[attributeSetsIndex]; header3[index] = PRESENT_STRING; columnWidths[index] = PIXEL_WIDTH_PRESENT; index++; } if (this.displayAttributeVR && (attributeCollections[attributeSetsIndex] is DicomAttributeCollection)) { header1[index] = tableDescription; header2[index] = attributeSetDescriptions[attributeSetsIndex]; header3[index] = VR_STRING; columnWidths[index] = PIXEL_WIDTH_VR; index++; } if (this.displayAttributeValues) { header1[index] = tableDescription; header2[index] = attributeSetDescriptions[attributeSetsIndex]; header3[index] = VALUES_STRING; columnWidths[index] = PIXEL_WIDTH_VALUES; index++; } } if (this.displayComments) { header1[index] = tableDescription; header2[index] = "-"; header3[index] = "Comments"; columnWidths[index] = PIXEL_WIDTH_COMMENTS; index++; } compareResults.Table.AddHeader(header1); compareResults.Table.AddHeader(header2); compareResults.Table.AddHeader(header3); compareResults.Table.SetColumnPixelWidths(columnWidths); return(compareResults); }
internal CompareResults CreateCompareResults(int numberOfColumns, AttributeCollections attributeCollections, String tableDescription, StringCollection attributeSetDescriptions) { CompareResults compareResults = new CompareResults(numberOfColumns); compareResults.Table.CellItemSeperator = "<br>"; compareResults.Table.EmptyCellPrefix = BACKGROUND_GREY; int index = 0; String[] header1 = new String[numberOfColumns]; String[] header2 = new String[numberOfColumns]; String[] header3 = new String[numberOfColumns]; int[] columnWidths = new int[numberOfColumns]; if (this.displayCommonTag) { header1[index] = tableDescription; header2[index] = "Common info"; header3[index] = TAG_STRING; columnWidths[index] = PIXEL_WIDTH_TAG; index++; } if (this.displayCommonName) { header1[index] = tableDescription; header2[index] = "Common info"; header3[index] = NAME_STRING; columnWidths[index] = PIXEL_WIDTH_NAME; index++; } for (int attributeSetsIndex = 0; attributeSetsIndex < attributeCollections.Count; attributeSetsIndex++) { if (this.displayAttributeTag) { header1[index] = tableDescription; header2[index] = attributeSetDescriptions[attributeSetsIndex]; header3[index] = TAG_STRING; columnWidths[index] = PIXEL_WIDTH_TAG; index++; } if (this.displayAttributeName && (attributeCollections[attributeSetsIndex] is DicomAttributeCollection)) { header1[index] = tableDescription; header2[index] = attributeSetDescriptions[attributeSetsIndex]; header3[index] = NAME_STRING; columnWidths[index] = PIXEL_WIDTH_NAME; index++; } if (this.displayAttributePresent) { header1[index] = tableDescription; header2[index] = attributeSetDescriptions[attributeSetsIndex]; header3[index] = PRESENT_STRING; columnWidths[index] = PIXEL_WIDTH_PRESENT; index++; } if (this.displayAttributeVR && (attributeCollections[attributeSetsIndex] is DicomAttributeCollection)) { header1[index] = tableDescription; header2[index] = attributeSetDescriptions[attributeSetsIndex]; header3[index] = VR_STRING; columnWidths[index] = PIXEL_WIDTH_VR; index++; } if (this.displayAttributeValues) { header1[index] = tableDescription; header2[index] = attributeSetDescriptions[attributeSetsIndex]; header3[index] = VALUES_STRING; columnWidths[index] = PIXEL_WIDTH_VALUES; index++; } } if (this.displayComments) { header1[index] = tableDescription; header2[index] = "-"; header3[index] = "Comments"; columnWidths[index] = PIXEL_WIDTH_COMMENTS; index++; } compareResults.Table.AddHeader(header1); compareResults.Table.AddHeader(header2); compareResults.Table.AddHeader(header3); compareResults.Table.SetColumnPixelWidths(columnWidths); return(compareResults); }