Esempio n. 1
0
        protected override void Execute()
        {
            try
            {
                WriteHtmlInformation("<br />");
                WriteInformation(string.Format("Reading reference media file from {0}",DCMCompareForm.firstDCMFile));
                WriteHtmlInformation("<br />");

                // Read the DCM File
                DicomFile dcmFile = new DicomFile();

                DataSet refDataset = new DataSet();

                if ((DCMCompareForm.firstDCMFile.ToLower().IndexOf("dicomdir")) != -1)
                {
                    // Read the DICOMDIR dataset
                    refDataset.DvtkDataDataSet = Dvtk.DvtkDataHelper.ReadDataSetFromFile(DCMCompareForm.firstDCMFile);
                }
                else
                {
                    dcmFile.Read(DCMCompareForm.firstDCMFile, this);
                    refDataset = dcmFile.DataSet;
                }

                refDataset.UnVrDefinitionLookUpWhenReading = false;

                FileMetaInformation refFMI = dcmFile.FileMetaInformation;

                WriteInformation(string.Format("Reading source media file from {0}",DCMCompareForm.secondDCMFile));
                WriteHtmlInformation("<br />");

                DataSet srcDataset = new DataSet();

                if ((DCMCompareForm.secondDCMFile.ToLower().IndexOf("dicomdir")) != -1)
                {
                    // Read the DICOMDIR dataset
                    srcDataset.DvtkDataDataSet = Dvtk.DvtkDataHelper.ReadDataSetFromFile(DCMCompareForm.secondDCMFile);
                }
                else
                {
                    dcmFile.Read(DCMCompareForm.secondDCMFile, this);
                    srcDataset = dcmFile.DataSet;
                }

                srcDataset.UnVrDefinitionLookUpWhenReading = false;

                FileMetaInformation srcFMI = dcmFile.FileMetaInformation;

                // Now get the list of filtered attribute
                if(DCMCompareForm.attributesTagList.Count != 0)
                {
                    foreach(string filterAttr in DCMCompareForm.attributesTagList)
                    {
                        try
                        {
                            if(srcDataset.Exists(filterAttr))
                            {
                                srcDataset.Delete(filterAttr);
                            }
                            if(refDataset.Exists(filterAttr))
                            {
                                refDataset.Delete(filterAttr);
                            }
                        }
                        catch(Exception exception)
                        {
                            MessageBox.Show(exception.Message, "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        }
                    }
                    DCMCompareForm.attributesTagList.Clear();
                }

                WriteInformation(string.Format("Comparing the Media files - {0} and {1}",DCMCompareForm.firstDCMFile,DCMCompareForm.secondDCMFile));
                WriteHtmlInformation("<br />");

                StaticDicomCompare staticDicomCompare = new StaticDicomCompare();

                //Determine the VR display based on Transfer syntax
                string srcTransferSyntax = "";
                string refTransferSyntax = "";

                if((srcFMI != null) && srcFMI.Exists("0x00020010"))
                {
                    // Get the Transfer syntax
                    DvtkHighLevelInterface.Dicom.Other.Attribute tranferSyntaxAttr = srcFMI["0x00020010"];
                    srcTransferSyntax = tranferSyntaxAttr.Values[0];
                }
                else
                {
                    WriteHtmlInformation(string.Format("Couldn't retrieve the Transfer syntax from DCM File {0}",DCMCompareForm.secondDCMFile));
                    WriteHtmlInformation("<br />");
                }

                if((refFMI != null) && refFMI.Exists("0x00020010"))
                {
                    // Get the Transfer syntax
                    DvtkHighLevelInterface.Dicom.Other.Attribute tranferSyntaxAttr = refFMI["0x00020010"];
                    refTransferSyntax = tranferSyntaxAttr.Values[0];
                }
                else
                {
                    WriteHtmlInformation(string.Format("Couldn't retrieve the Transfer syntax from DCM File {0}",DCMCompareForm.firstDCMFile));
                    WriteHtmlInformation("<br />");
                }

                FlagsDicomAttribute flags = FlagsDicomAttribute.Compare_values | FlagsDicomAttribute.Compare_present | FlagsDicomAttribute.Include_sequence_items;
                if(( srcTransferSyntax == "1.2.840.10008.1.2") ||
                    ( refTransferSyntax == "1.2.840.10008.1.2"))
                {
                    staticDicomCompare.DisplayAttributeVR = false;
                }
                else
                {
                    flags |= FlagsDicomAttribute.Compare_VR;
                }

                //Check for group length attributes option
                if(DCMCompareForm.filterGroupLengthAttributes)
                {
                    /*for( int i=0; i < srcDataset.Count; i++ )
                    {
                        HLI.Attribute attribute   = srcDataset[i];
                        if(attribute.ElementNumber == 0x0000)
                            srcDataset.Delete(DCMCompareForm.TagString(attribute.GroupNumber,attribute.ElementNumber));
                    }

                    for( int i=0; i < refDataset.Count; i++ )
                    {
                        HLI.Attribute attribute   = refDataset[i];
                        if(attribute.ElementNumber == 0x0000)
                            refDataset.Delete(DCMCompareForm.TagString(attribute.GroupNumber,attribute.ElementNumber));
                    }*/
                    staticDicomCompare.DisplayGroupLength = false;
                }

                int differences = 0;

                if((refFMI != null) && (srcFMI != null))
                {
                    AttributeCollections fmis = new AttributeCollections();
                    fmis.Add(refFMI);
                    fmis.Add(srcFMI);

                    StringCollection fmiDescriptions = new StringCollection();
                    fmiDescriptions.Add("Ref FMI");
                    fmiDescriptions.Add("Src FMI");

                    HLIStaticCompare.CompareResults fmiCompareResults = staticDicomCompare.CompareAttributeSets("FMI compare results", fmis, fmiDescriptions, flags);
                    WriteHtmlInformation(fmiCompareResults.Table.ConvertToHtml());

                    differences += fmiCompareResults.DifferencesCount;
                    NrOfValidationErrors+= (uint)fmiCompareResults.DifferencesCount;
                }

                AttributeCollections datasets = new AttributeCollections();
                datasets.Add(refDataset);
                datasets.Add(srcDataset);

                StringCollection dsDescriptions = new StringCollection();
                dsDescriptions.Add("Ref Dataset");
                dsDescriptions.Add("Src Dataset");

                HLIStaticCompare.CompareResults dsCompareResults = staticDicomCompare.CompareAttributeSets("DataSet compare results", datasets, dsDescriptions, flags);

                WriteHtmlInformation(dsCompareResults.Table.ConvertToHtml());

                differences += dsCompareResults.DifferencesCount;

                WriteHtmlInformation("<b>");
                WriteInformation("Differences found: " + differences.ToString());
                WriteHtmlInformation("</b><br />");

                NrOfValidationErrors+= (uint)dsCompareResults.DifferencesCount;
            }
            catch(Exception exception)
            {
                MessageBox.Show(exception.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
        }
Esempio n. 2
0
        void CreateTableWithoutNav()
        {
            StaticDicomCompare compare = new StaticDicomCompare();
            FlagsDicomAttribute flags = FlagsDicomAttribute.Compare_values | FlagsDicomAttribute.Compare_present | FlagsDicomAttribute.Include_sequence_items;
            StringCollection descriptions = new StringCollection();
            descriptions.Add("Src Dataset");
            descriptions.Add("Annonymized Dataset");
            CompareResults compareResults = compare.CompareAttributeSets("DataSet compare results", datasets, descriptions, flags);

            StringBuilder tableString = new StringBuilder();
            tableString.Append("<left><font color='#0000ff' size = '4'>");
            tableString.Append(string.Format("Comparing the DICOM file {0} with anonymized file",resultFileName));
            tableString.Append("</font>");
            tableString.Append("</left>");
            tableString.Append("<br></br>");
            tableString.Append(compareResults.Table.ConvertToHtml());

            StreamWriter writer = new StreamWriter(initialDirectory + "\\" + resultFileName + "_" + counter.ToString() +".html");
            writer.Write(tableString.ToString());
            writer.Close();
        }
Esempio n. 3
0
        /// <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;
        }
Esempio n. 4
0
        private void CreateTable()
        {
            StaticDicomCompare compare = new StaticDicomCompare();
            FlagsDicomAttribute flags = FlagsDicomAttribute.Compare_values | FlagsDicomAttribute.Compare_present | FlagsDicomAttribute.Include_sequence_items;
            StringCollection descriptions = new StringCollection();
            descriptions.Add("Src Dataset");
            descriptions.Add("Annonymized Dataset");
            CompareResults compareResults = compare.CompareAttributeSets("DataSet compare results", datasets, descriptions, flags);
            string tableString = compareResults.Table.ConvertToHtml();
            StreamWriter writer = new StreamWriter(resultFileName);

            if(utility.AnonymizationType)
                writer.Write("<b><font size='3' color='#0000ff'>Anonymized DCM File (Basic)</font></b>");
            else
                writer.Write("<b><font size='3' color='#0000ff'>Anonymized DCM File (Complete)</font></b>");

            writer.Write(tableString);
            writer.Write("<br/>");
            writer.Close();

            dvtkWebBrowser.Navigate(resultFileName);
        }