本文整理汇总了C#中DicomFile.Read方法的典型用法代码示例。如果您正苦于以下问题:C# DicomFile.Read方法的具体用法?C# DicomFile.Read怎么用?C# DicomFile.Read使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DicomFile
的用法示例。
在下文中一共展示了DicomFile.Read方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: LoadDCMFile
void LoadDCMFile(string dicomFile)
{
DCMFile = dicomFile;
string definitionDir = Environment.GetEnvironmentVariable("COMMONPROGRAMFILES") + @"\DVTk\Definition Files\DICOM\";
try
{
// Load the Definition Files
DirectoryInfo theDefDirectoryInfo = new DirectoryInfo(definitionDir);
if(theDefDirectoryInfo.Exists)
{
FileInfo[] theDefFilesInfo = theDefDirectoryInfo.GetFiles();
foreach (FileInfo defFile in theDefFilesInfo)
{
bool ok = _MainThread.Options.LoadDefinitionFile(defFile.FullName);
if(!ok)
{
string theWarningText = string.Format("The Definition file {0} could not be loaded.\n", defFile.FullName);
richTextBoxLog.AppendText(theWarningText);
}
}
}
//Subscribe the Dvtk activity report event handler for getting all activity logging.
_MainThread.Options.DvtkScriptSession.ActivityReportEvent += activityReportEventHandler;
_MainThread.Options.DvtkScriptSession.AddGroupLength = true;
// Set the Results & Data directory
_MainThread.Options.ResultsDirectory = Application.StartupPath + "\\" + "Results";
_MainThread.Options.DataDirectory = Application.StartupPath + "\\" + "Results";
// Read the Media file
DicomFile dcmFile = new DicomFile();
dcmFile.Read(dicomFile, _MainThread);
// dcmFile.Read(dicomFile);
// Get the FMI from the selected Media file
if(_FileMetaInfo == null)
_FileMetaInfo = new FileMetaInformation();
_FileMetaInfo = dcmFile.FileMetaInformation;
string tsStr = "Undefined";
if(_FileMetaInfo.Exists("0x00020010"))
{
// Get the Transfer syntax
HLI.Attribute tranferSyntaxAttr = _FileMetaInfo["0x00020010"];
_TransferSyntax = tranferSyntaxAttr.Values[0];
tsStr = _TransferSyntax;
}
menuItemSaveAsELE.Visible = true;
menuItemSaveAsILE.Visible = true;
menuItemSaveAsEBE.Visible = true;
if (_TransferSyntax == "1.2.840.10008.1.2.1")
menuItemSaveAsELE.Visible = false;
else if (_TransferSyntax == "1.2.840.10008.1.2")
menuItemSaveAsILE.Visible = false;
else if (_TransferSyntax == "1.2.840.10008.1.2.2")
menuItemSaveAsEBE.Visible = false;
else
{
menuItemSaveAsELE.Visible = false;
menuItemSaveAsILE.Visible = false;
menuItemSaveAsEBE.Visible = false;
}
// Get the Data set from the selected DICOM file/DICOMDIR
string sopClassUID = "";
if(_FileMetaInfo.Exists("0x00020002"))
{
// Get the Transfer syntax
HLI.Attribute sopClassUIDAttr = _FileMetaInfo["0x00020002"];
sopClassUID = sopClassUIDAttr.Values[0];
}
if(_DCMdataset == null)
_DCMdataset = new HLI.DataSet();
if(sopClassUID == "1.2.840.10008.1.3.10")
{
// Read the DICOMDIR dataset
_DCMdataset.DvtkDataDataSet = Dvtk.DvtkDataHelper.ReadDataSetFromFile(dicomFile);
_IsDICOMDIR = true;
IsRefFilesReadCompleted = false;
backgroundWorkerEditor.RunWorkerAsync();
string msg = "DICOMDIR read successfully.\n";
richTextBoxLog.AppendText(msg);
}
else
{
// Read the Media file dataset
_DCMdataset = dcmFile.DataSet;
_IsDICOMDIR = false;
}
string theInfoText;
//.........这里部分代码省略.........
示例2: ReadDicomdirRefFiles
private void ReadDicomdirRefFiles(string dicomFile)
{
FileInfo dicomDir = new FileInfo(dicomFile);
_RefFileDatasets.Clear();
_RefFileFMIs.Clear();
_RefFileNames.Clear();
// Read all reference file datasets
HLI.Attribute recordSeqAttr = _DCMdataset["0x00041220"];
int recordCount = recordSeqAttr.ItemCount;
for (int i = 0; i < recordCount; i++)
{
HLI.SequenceItem item = recordSeqAttr.GetItem(i + 1);
// Read all attributes in a item
for (int j = 0; j < item.Count; j++)
{
HLI.Attribute recordTypeAttr = item["0x00041430"];
if ((recordTypeAttr.Values[0] == "IMAGE") ||
(recordTypeAttr.Values[0] == "PRESENTATION"))
{
HLI.Attribute refFileIDAttr = item["0x00041500"];
if (refFileIDAttr != null)
{
string refFileName = dicomDir.DirectoryName + "\\";
if (refFileIDAttr.Values.Count != 0)
{
for (int k = 0; k < refFileIDAttr.Values.Count; k++)
{
refFileName += refFileIDAttr.Values[k];
refFileName += @"\";
}
}
refFileName = refFileName.Remove((refFileName.Length - 1), 1);
FileInfo refFileInfo = new FileInfo(refFileName);
if (refFileInfo.Exists)
{
HLI.DataSet refFileDataset = new HLI.DataSet();
// Read the ref file
DicomFile refFile = new DicomFile();
refFile.Read(refFileName, _MainThread);
//refFileDataset.DvtkDataDataSet = Dvtk.DvtkDataHelper.ReadDataSetFromFile(refFileName);
_RefFileDatasets.Add(refFile.DataSet);
_RefFileFMIs.Add(refFile.FileMetaInformation);
_RefFileNames.Add(refFileName);
}
}
}
}
}
}
示例3: HandleSubOperation
private bool HandleSubOperation(System.String moveDestinationAE, System.String dcmFilename, int subOperationIndex)
{
SCU storageScu = new SCU();
storageScu.Initialize(DicomThread.ThreadManager);
storageScu.Options.DeepCopyFrom(DicomThread.Options);
storageScu.Options.Identifier = "StorageSubOperationAsScu";
////Check for Secure connection
//if (DicomThread.Options.SecureConnection)
//{
// storageScu.Options.SecureConnection = true;
// storageScu.Options.CertificateFilename = DicomThread.Options.CertificateFilename;
// storageScu.Options.CredentialsFilename = DicomThread.Options.CredentialsFilename;
//}
storageScu.Options.ResultsFileNameOnlyWithoutExtension = "StorageSubOperationAsScu" + subOperationIndex.ToString();
storageScu.Options.ResultsDirectory = DicomThread.Options.ResultsDirectory;
storageScu.Options.LocalAeTitle = DicomThread.Options.LocalAeTitle;
storageScu.Options.LocalPort = DicomThread.Options.LocalPort;
if (IsHaveMoveDestinations)
{
storageScu.Options.RemoteAeTitle = moveDestinationAE;
storageScu.Options.RemotePort = MoveDestiantions[MoveAEdetailsIndex].Port;
storageScu.Options.RemoteHostName = MoveDestiantions[MoveAEdetailsIndex].IP;
}
else
{
storageScu.Options.RemoteAeTitle = moveDestinationAE;
storageScu.Options.RemotePort = DicomThread.Options.RemotePort;
storageScu.Options.RemoteHostName = DicomThread.Options.RemoteHostName;
}
storageScu.Options.DataDirectory = DicomThread.Options.DataDirectory;
storageScu.Options.StorageMode = Dvtk.Sessions.StorageMode.AsDataSet;
// Read the DCM File
DicomFile dcmFile = new DicomFile();
dcmFile.Read(dcmFilename, storageScu);
FileMetaInformation fMI = dcmFile.FileMetaInformation;
// Get the transfer syntax and SOP class UID
System.String transferSyntax = "1.2.840.10008.1.2";
if((fMI != null) && fMI.Exists("0x00020010"))
{
// Get the Transfer syntax
DvtkHighLevelInterface.Dicom.Other.Attribute tranferSyntaxAttr = fMI["0x00020010"];
transferSyntax = tranferSyntaxAttr.Values[0];
}
Values values = dcmFile.DataSet["0x00080016"].Values;
System.String sopClassUid = values[0];
PresentationContext presentationContext = new PresentationContext(sopClassUid, // Abstract Syntax Name
transferSyntax); // Transfer Syntax Name(s)
PresentationContext[] presentationContexts = new PresentationContext[1];
presentationContexts[0] = presentationContext;
DicomMessage storageMessage = new DicomMessage(DvtkData.Dimse.DimseCommand.CSTORERQ);
storageMessage.DataSet.CloneFrom(dcmFile.DataSet);
storageScu.Start();
bool sendResult = storageScu.TriggerSendAssociationAndWait(storageMessage, presentationContexts);
if (!sendResult)
{
WriteWarning("Association to move destination for Storage Sub-Operation is rejected.");
}
if (storageScu.HasExceptionOccured)
{
WriteError("Storage Sub-Operation As SCU Failed");
}
storageScu.Stop();
DicomMessageCollection cStoreResponses = storageScu.Messages.DicomMessages.CStoreResponses;
// Obtain the value of the C-STORE RSP.The value of this variable is used to determine the attributes of the C-MOVE RSP.
foreach (DicomMessage cStoreRsp in cStoreResponses)
{
cStoreStatusVal = Int32.Parse(cStoreRsp.CommandSet.GetValues("0x00000900")[0]);
}
// Transform the sub results
Xslt.StyleSheetFullFileName = DicomThread.Options.StyleSheetFullFileName;
System.String htmlResultsFilename = Xslt.Transform(storageScu.Options.ResultsDirectory, storageScu.Options.ResultsFileNameOnly);
// Make link to the sub-operation results file
System.String message = System.String.Format("<a href=\"{0}\">Storage sub-operation {1} to AE Title \"{2}\"</a><br/>",
htmlResultsFilename,
subOperationIndex,
moveDestinationAE);
DicomThread.WriteHtmlInformation(message);
return sendResult;
}
示例4: Execute
protected override void Execute()
{
// Read the Media file
try
{
DicomFile dcmFileObj = new DicomFile();
dcmFileObj.Read(dcmFile, this);
}
catch(Exception)
{
WriteHtmlInformation("<br />");
WriteInformation("Error in reading Media file.");
WriteHtmlInformation("<br />");
}
}
示例5: Execute
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
//.........这里部分代码省略.........
示例6: LoadDCMFile
void LoadDCMFile(string dicomFile)
{
DCMFile = dicomFile;
try
{
// Load the Definition Files
foreach (string defFile in _DefFiles)
{
if(!_MainThread.Options.LoadDefinitionFile(defFile))
{
string theWarningText = string.Format("The Definition file {0} could not be loaded.\n", defFile);
richTextBoxLog.AppendText(theWarningText);
}
}
_DefFiles.Clear();
// Set the Data directory
_MainThread.Options.DataDirectory = _DataDirectory;
// Read the DCM File
DicomFile dcmFile = new DicomFile();
dcmFile.DataSet.UnVrDefinitionLookUpWhenReading = false;
dcmFile.Read(_DCMFileName, _MainThread);
// Get the FMI from the selected DCM file
// Get the FMI from the selected DCM file
if(_FileMetaInfo == null)
_FileMetaInfo = new FileMetaInformation();
_FileMetaInfo = dcmFile.FileMetaInformation;
string tsStr;
if(_FileMetaInfo.Exists("0x00020010"))
{
// Get the Transfer syntax
HLI.Attribute tranferSyntaxAttr = _FileMetaInfo["0x00020010"];
_TransferSyntax = tranferSyntaxAttr.Values[0];
tsStr = _TransferSyntax;
}
else
{
_TransferSyntax = "1.2.840.10008.1.2.1";
tsStr = "Undefined, the default transfer syntax will Explicit VR Little Endian";
_FileMetaInfo.Set("0x00020010",VR.UI,"1.2.840.10008.1.2.1");
}
// Get the Data set from the selected DCM file
if(_DCMdataset == null)
_DCMdataset = new HLI.DataSet();
_DCMdataset = dcmFile.DataSet;
string theInfoText;
if(_DCMdataset != null)
{
UpdateAttributeDataGrid();
UpdateFMIDataGrid();
theInfoText = string.Format("DCM file {0} read successfully with Transfer Syntax {1}.\n\n", _DCMFileName,tsStr);
richTextBoxLog.AppendText(theInfoText);
}
else
{
theInfoText = string.Format("Error in reading DCM file {0}\n\n", _DCMFileName);
richTextBoxLog.AppendText(theInfoText);
}
}
catch(Exception exception)
{
string theErrorText;
theErrorText = string.Format("DCM file {0} could not be read:\n{1}\n\n", _DCMFileName, exception.Message);
richTextBoxLog.AppendText(theErrorText);
_DCMdataset = null;
_FileMetaInfo = null;
//dataGridAttributes.SetDataBinding(null, "");
}
//Reset the variable
_IsNewDCMFileLoaded = false;
}
示例7: SendDICOMDataInSingleAssociation
private void SendDICOMDataInSingleAssociation(string[] mediaFiles)
{
// Set the dicom messages to send
List<DicomFile> dicomMessageCollection = new List<DicomFile>();
PresentationContextCollection pcCollection = new PresentationContextCollection();
StoreScu storageScuThread = new StoreScu();
storageScuThread.Initialize(this.overviewThread);
storageScuThread.Options.CopyFrom(this.storageOptions);
String resultsFileBaseName = "StorageOperation_" + System.DateTime.Now.ToString("yyyyMMddHHmmss", System.Globalization.CultureInfo.InvariantCulture);
storageScuThread.Options.ResultsFileNameOnlyWithoutExtension = resultsFileBaseName;
storageScuThread.Options.Identifier = resultsFileBaseName;
storageScuThread.Options.LogThreadStartingAndStoppingInParent = false;
storageScuThread.Options.LogWaitingForCompletionChildThreads = false;
storageScuThread.Options.AutoValidate = false;
//The Current Directory is being set to the Results Directory because
// when DICOMDIRs(or DICOM Files)Media are exported, the Environment.CurrentDirectory
//is set to the Directory in which the DCM objects are present and the export will fail
// if the DICOMDIR is present on a Physical Media.
Environment.CurrentDirectory = this.storageOptions.ResultsDirectory;
foreach (string dcmFilename in mediaFiles)
{
string msg = string.Format("Reading the DICOM object - {0}", dcmFilename);
storageScuThread.WriteInformation(msg);
try
{
// Read the DCM File
DicomFile dcmFile = new DicomFile();
dcmFile.Read(dcmFilename, storageScuThread);
FileMetaInformation fMI = dcmFile.FileMetaInformation;
// Get the transfer syntax and SOP class UID
System.String transferSyntax = "1.2.840.10008.1.2.1";
System.String sopClassUid = "";
if ((fMI != null))
{
// Get the Transfer syntax
HLI.Attribute tranferSyntaxAttr = fMI["0x00020010"];
transferSyntax = tranferSyntaxAttr.Values[0];
// Get the SOP Class UID
Values values = fMI["0x00020002"].Values;
sopClassUid = values[0];
}
else
{
// Get the SOP Class UID
Values values = dcmFile.DataSet["0x00080016"].Values;
sopClassUid = values[0];
}
//Check for DICOMDIR
if(sopClassUid == "")
{
storageScuThread.WriteError("Can't determine SOP Class UID for DCM file. \nSkipping the DCM File.");
continue;
}
else if (sopClassUid == "1.2.840.10008.1.3.10")
{
HLI.DataSet tempDataSet = new HLI.DataSet();
// Read the DICOMDIR dataset
dcmFile.DataSet.DvtkDataDataSet = Dvtk.DvtkDataHelper.ReadDataSetFromFile(dcmFilename);
Dvtk.Sessions.ScriptSession session = this.storageOptions.DvtkScriptSession;
ArrayList refFiles = ImportRefFilesFromDicomdir(dcmFilename, dcmFile.DataSet);
foreach (string refFilename in refFiles)
{
// Read the Reference File
DicomFile refFile = new DicomFile();
refFile.Read(refFilename, storageScuThread);
FileMetaInformation refFMI = refFile.FileMetaInformation;
// Get the transfer syntax and SOP class UID
System.String refTransferSyntax = "1.2.840.10008.1.2.1";
if ((refFMI != null) && refFMI.Exists("0x00020010"))
{
// Get the Transfer syntax
HLI.Attribute refTranferSyntaxAttr = refFMI["0x00020010"];
refTransferSyntax = refTranferSyntaxAttr.Values[0];
}
Values sopValues = refFile.DataSet["0x00080016"].Values;
System.String refSopClassUid = sopValues[0];
PresentationContext refPresentationContext = new PresentationContext(refSopClassUid, // Abstract Syntax Name
refTransferSyntax); // Transfer Syntax Name(s)
pcCollection.Add(refPresentationContext);
//DicomMessage refStorageMessage = new DicomMessage(DvtkData.Dimse.DimseCommand.CSTORERQ);
//.........这里部分代码省略.........
示例8: convertDicomFiles
private string[] convertDicomFiles(string[] mediaFiles)
{
ArrayList listOfConvertedFiles = new ArrayList(mediaFiles.Length);
string finalPath = System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)[email protected]"\DVTk\Storage SCU Emulator\Temp\";
if(Directory.Exists(finalPath))
{
Directory.Delete(finalPath,true);
}
Directory.CreateDirectory(finalPath);
DicomThread conversionThread = new ConversionThread();
conversionThread.Initialize(this.overviewThread);
conversionThread.Options.CopyFrom(this.storageOptions);
String resultsFileBaseName = "StorageOperation_" + System.DateTime.Now.ToString("yyyyMMddHHmmss", System.Globalization.CultureInfo.InvariantCulture);
conversionThread.Options.ResultsFileNameOnlyWithoutExtension = resultsFileBaseName;
conversionThread.Options.Identifier = resultsFileBaseName;
conversionThread.Options.LogThreadStartingAndStoppingInParent = false;
conversionThread.Options.LogWaitingForCompletionChildThreads = false;
conversionThread.Options.AutoValidate = false;
//string[] listOfConvertedFiles = new string[mediaFiles.Length];
foreach (string dcmFileName in mediaFiles)
{
string argumentString = "";
System.String transferSyntax = "";
System.String sopClassUid = "";
try
{
DicomFile dcmFile = new DicomFile();
dcmFile.Read(dcmFileName, conversionThread);
FileMetaInformation fMI = dcmFile.FileMetaInformation;
if ((fMI != null))
{
// Get the Transfer syntax
HLI.Attribute tranferSyntaxAttr = fMI["0x00020010"];
transferSyntax = tranferSyntaxAttr.Values[0];
// Get the SOP Class UID
Values values = fMI["0x00020002"].Values;
sopClassUid = values[0];
}
if (sopClassUid == "")
{
conversionThread.WriteError("Error while performing conversion.Can't determine SOP Class UID for DCM file. \nSkipping the DCM File.");
continue;
}
//Retrieve the files from the DICOMDIR
else if (sopClassUid == "1.2.840.10008.1.3.10")
{
System.String refTransferSyntax = "";
HLI.DataSet tempDataSet = new HLI.DataSet();
// Read the DICOMDIR dataset
dcmFile.DataSet.DvtkDataDataSet = Dvtk.DvtkDataHelper.ReadDataSetFromFile(dcmFileName);
Dvtk.Sessions.ScriptSession session = this.storageOptions.DvtkScriptSession;
ArrayList refFiles = ImportRefFilesFromDicomdir(dcmFileName, dcmFile.DataSet);
foreach (string refFilename in refFiles)
{
// Read the Reference File
DicomFile refFile = new DicomFile();
refFile.Read(refFilename, conversionThread);
FileMetaInformation refFMI = refFile.FileMetaInformation;
// Get the transfer syntax and SOP class UID
if ((refFMI != null) && refFMI.Exists("0x00020010"))
{
// Get the Transfer syntax
HLI.Attribute refTranferSyntaxAttr = refFMI["0x00020010"];
refTransferSyntax = refTranferSyntaxAttr.Values[0];
}
if (transferSyntax == "1.2.840.10008.1.2" || transferSyntax == "1.2.840.10008.1.2.1" || transferSyntax == "1.2.840.10008.1.2.2")
{
try
{
if (radioButtonILE.Checked)
{
if (refTransferSyntax != "1.2.840.10008.1.2")
{
//Perform conversion
string msg = string.Format("Converting the DICOM object - {0} from Transfer Syntax:{1} to Transfer Syntax:{2}", dcmFileName, transferSyntax, "1.2.840.10008.1.2");
conversionThread.WriteInformation(msg);
string outputFileName = finalPath + refFilename.Substring(refFilename.LastIndexOf(@"\") + 1);
argumentString = "+ti" + " \"" + String.Format("{0}", refFilename) + "\" \"" + String.Format("{0}", outputFileName) + "\"";
convertFile(argumentString);
listOfConvertedFiles.Add(outputFileName);
}
else
{ //If the File is encoded in the same TS as the selected TS, no need to convert.
listOfConvertedFiles.Add(refFilename);
}
}
//.........这里部分代码省略.........
示例9: SendDICOMDataInMultipleAssociation
private void SendDICOMDataInMultipleAssociation(string[] mediaFiles)
{
int index = 0;
// Set the dicom messages to send
DicomMessageCollection dicomMessageCollection = new DicomMessageCollection();
PresentationContextCollection pcCollection = new PresentationContextCollection();
//The Current Directory is being set to the Results Directory because
// when DICOMDIRs(or DICOM Files)Media are exported, the Environment.CurrentDirectory
//is set to the Directory in which the DCM objects are present and the export will fail
// if the DICOMDIR is present on a Physical Media.
Environment.CurrentDirectory = this.storageOptions.ResultsDirectory;
foreach (string dcmFilename in mediaFiles)
{
HliScu storageScuSubThread = new HliScu();
storageScuSubThread.Initialize(this.overviewThread);
storageScuSubThread.Options.CopyFrom(this.storageOptions);
storageScuSubThread.Options.Identifier = string.Format("StorageOperation_{0}",index);
String resultsFileBaseName = string.Format("StorageOperation_{0}_", index) + System.DateTime.Now.ToString("yyyyMMddHHmmss", System.Globalization.CultureInfo.InvariantCulture);
storageScuSubThread.Options.ResultsFileNameOnlyWithoutExtension = resultsFileBaseName;
storageScuSubThread.Options.LogThreadStartingAndStoppingInParent = false;
storageScuSubThread.Options.LogWaitingForCompletionChildThreads = false;
storageScuSubThread.Options.AutoValidate = false;
string msg = string.Format("Reading and exporting the DICOM object - {0}", dcmFilename);
storageScuSubThread.WriteInformation(msg);
try
{
// Read the DCM File
DicomFile dcmFile = new DicomFile();
dcmFile.Read(dcmFilename, storageScuSubThread);
FileMetaInformation fMI = dcmFile.FileMetaInformation;
// Get the transfer syntax and SOP class UID
System.String transferSyntax = "1.2.840.10008.1.2.1";
if ((fMI != null) && fMI.Exists("0x00020010"))
{
// Get the Transfer syntax
HLI.Attribute tranferSyntaxAttr = fMI["0x00020010"];
transferSyntax = tranferSyntaxAttr.Values[0];
}
Values values = fMI["0x00020002"].Values;
System.String sopClassUid = values[0];
//Check for DICOMDIR
if (sopClassUid == "1.2.840.10008.1.3.10")
{
// Read the DICOMDIR dataset
dcmFile.DataSet.DvtkDataDataSet = Dvtk.DvtkDataHelper.ReadDataSetFromFile(dcmFilename);
ArrayList refFiles = ImportRefFilesFromDicomdir(dcmFilename, dcmFile.DataSet);
foreach (string refFilename in refFiles)
{
// Read the Reference File
DicomFile refFile = new DicomFile();
refFile.Read(refFilename, storageScuSubThread);
FileMetaInformation refFMI = refFile.FileMetaInformation;
// Get the transfer syntax and SOP class UID
System.String refTransferSyntax = "1.2.840.10008.1.2.1";
if ((refFMI != null) && refFMI.Exists("0x00020010"))
{
// Get the Transfer syntax
HLI.Attribute refTranferSyntaxAttr = refFMI["0x00020010"];
refTransferSyntax = refTranferSyntaxAttr.Values[0];
}
Values sopValues = refFile.DataSet["0x00080016"].Values;
System.String refSopClassUid = sopValues[0];
PresentationContext refPresentationContext = new PresentationContext(refSopClassUid, // Abstract Syntax Name
refTransferSyntax); // Transfer Syntax Name(s)
pcCollection.Add(refPresentationContext);
DicomMessage refStorageMessage = new DicomMessage(DvtkData.Dimse.DimseCommand.CSTORERQ);
refStorageMessage.DataSet.CloneFrom(refFile.DataSet);
dicomMessageCollection.Add(refStorageMessage);
// set the presentation contexts for the association
PresentationContext[] presentationContexts = SetPresentationContexts(pcCollection);
storageScuSubThread.Start();
storageScuSubThread.TriggerSendAssociationAndWait(dicomMessageCollection, presentationContexts);
}
}
else
{
PresentationContext presentationContext = new PresentationContext(sopClassUid, // Abstract Syntax Name
transferSyntax); // Transfer Syntax Name(s)
PresentationContext[] presentationContexts = new PresentationContext[1];
//.........这里部分代码省略.........
示例10: HandleDoWork
private void HandleDoWork(object sender, DoWorkEventArgs e)
{
// Report Progress
ReportProgress(0, "Start");
ValidatorBackgroundWorkerArgument argument = (ValidatorBackgroundWorkerArgument)e.Argument;
//
// Initialization of the media session and context groups.
//
if (this.mediaSession == null)
{
InitializeMediaSession();
}
if (this.contextGroups == null)
{
InitializeContextGroups();
}
//
// Read DICOM file and check if this is a Structured Report file.
//
// Report Progress
ReportProgress(0, "Reading DICOM file: " + argument.structuredReportPath);
DicomFile dicomFile = new DicomFile();
dicomFile.Read(argument.structuredReportPath);
// Perform sanity check if this is a valid Structured Report.
bool valueTypeRootContentItemCorrect = false;
DvtkHighLevelInterface.Dicom.Other.Attribute valueType = dicomFile.DataSet["0x0040A040"];
if (valueType.Exists)
{
if (valueType.Values[0].Trim() == "CONTAINER")
{
valueTypeRootContentItemCorrect = true;
}
}
//
// Validate against the loaded Context Groups and loaded definition files.
//
if (valueTypeRootContentItemCorrect)
{
// Report Progress.
ReportProgress(40, "Parsing DICOM Structured Report: " + argument.structuredReportPath);
// Parse the DICOM Structured Report.
StructuredReport structuredReport = new StructuredReport(dicomFile.DataSet);
// Report Progress.
ReportProgress(60, "Validating content item values...");
// Validate Content Items Value.
ContentItemValueValidationRule contentItemValueValidationRule = new ContentItemValueValidationRule(contextGroups);
structuredReport.RootContentItem.Accept(contentItemValueValidationRule);
// Report Progress.
ReportProgress(85, "Saving results: " + e.Argument.ToString());
// Export structured report results to Xml file.
String xmlFullFileName = Path.Combine(argument.xmlPath, "Output.xml");
structuredReport.ToXml(xmlFullFileName);
// Perform part 3 validation.
this.mediaSession.ResultsRootDirectory = argument.xmlPath;
this.mediaSession.StartResultsGathering("Part 3 validation.xml");
//this.mediaSession.Validate(dicomFile.DvtkDataDicomFile, Dvtk.Sessions.ValidationControlFlags.None);
this.mediaSession.ValidateMediaFiles(new string[] { argument.structuredReportPath });
this.mediaSession.EndResultsGathering();
// Report Progress.
ReportProgress(100, "");
}
else
{
// Report Progress.
ReportProgress(100, "");
throw new Exception("Aborting validation because DICOM file does not contain Attribute Value Type (0040,A040) with value \"CONTAINER\" for root Content Item.");
}
}
示例11: RetrievingFilesFromDirectory
private void RetrievingFilesFromDirectory()
{
try
{
String indexFileName = initialDirectory + @"/index1.htm";
StringBuilder indexContent = new StringBuilder();
indexContent.Append("<center><font size='5' color='#0000ff'>");
if(utility.AnonymizationType)
{
indexContent.Append("Anonymized DCM files (Basic)</font></center>");
}
else
{
indexContent.Append("Anonymized DCM files (Complete)</font></center>");
}
indexContent.Append("<left><font color='black' size = '4'><br></br> Input Directory: " + inputDirectory);
indexContent.Append("</font>");
indexContent.Append("</left>");
indexContent.Append("<br></br>");
indexContent.Append("<font size='3'>");
HLI.DataSet srcDataset = null;
DicomFile dcmFile = null;
allDCMFilesTemp = new ArrayList();
FileInfo mediaInputFileInfo = null;
string mediaFileDir = inputDirectory;
DirectoryInfo theDirectoryInfo = new DirectoryInfo(mediaFileDir);
allDCMFilesTemp = utility.GetFilesRecursively(theDirectoryInfo);
foreach ( string fileName in allDCMFilesTemp)
{
mediaInputFileInfo = new FileInfo(fileName);
counter++;
dcmFile = new DicomFile();
dcmFile.Read(fileName, mainThread);
// Get the Data set from the selected DCM file
srcDataset = dcmFile.DataSet;
indexContent.Append("<li><a href='" + mediaInputFileInfo.Name + "_" + counter.ToString() +".html'>" + fileName.Substring(inputDirectory.Length) + "</a></li>");
HLI.DataSet annonymizedDataset = srcDataset.Clone();
utility.PatientAttributes(annonymizedDataset);
for ( int number = 0; number < annonymizedDataset.Count; number++)
{
HLI.Attribute attribute = annonymizedDataset[number];
if (attribute.VR == VR.SQ)
{
utility.SequenceAttribute_recursive(attribute);
}
else
{
utility.CacheAndRepairIdentifyingAttribute(attribute);
utility.UpdateAnonymizedAttributes(attribute);
}
}
//Save annonymized data to selected directory
string savedFileName = "";
if(mediaInputFileInfo.Extension != "")
{
string srcFileNameWithoutExtn = mediaInputFileInfo.Name.Substring(0,(mediaInputFileInfo.Name.Length-4));
savedFileName = outputDirectory + "\\" + srcFileNameWithoutExtn + "_an";
}
else
savedFileName = outputDirectory + "\\" + mediaInputFileInfo.Name + "_an";
dcmFile.DataSet = annonymizedDataset;
dcmFile.Write(savedFileName);
datasets = new AttributeCollections();
datasets.Add(srcDataset);
datasets.Add(annonymizedDataset);
//Cleanup temp file
utility.cleanup();
resultFileName = mediaInputFileInfo.Name;
CreateTableWithoutNav();
}
StreamWriter writer = new StreamWriter(indexFileName);
indexContent.Append("</font>");
indexContent.Append("<left><font color='black' size = '4'><br></br> Output Directory: " + outputDirectory);
indexContent.Append("</font>");
indexContent.Append("</left>");
writer.Write(indexContent.ToString());
writer.Close();
dvtkWebBrowser.Navigate(indexFileName);
}
catch ( Exception e)
{
MessageBox.Show(e.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
//.........这里部分代码省略.........
示例12: AnonymizeDCMFile
private void AnonymizeDCMFile()
{
try
{
utility.AnonymizationType = anonymizationMode;
CreateDICOMDIR.Enabled = true;
OpenFileDialog fileDialog = new OpenFileDialog();
fileDialog.Multiselect = false;
fileDialog.ReadOnlyChecked = true;
fileDialog.Title = "Select DCM File";
fileDialog.Filter = "DCM files (*.dcm) |*.dcm|All files (*.*)|*.*";
// Show the file dialog.
// If the user pressed the OK button...
if (fileDialog.ShowDialog() == DialogResult.OK)
{
DicomFile dcmFile = new DicomFile();
dcmFile.Read(fileDialog.FileName, mainThread);
// Get the Data set from the selected DCM file
HLI.DataSet srcDataset = dcmFile.DataSet;
SaveFileDialog saveDialog = new SaveFileDialog();
FileInfo saveFileInfo = null;
saveDialog.Filter = "DCM files (*.dcm) |*.dcm|All files (*.*)|*.*";
if (saveDialog.ShowDialog() == DialogResult.OK)
{
HLI.DataSet annonymizedDataset = srcDataset.Clone();
utility.PatientAttributes(annonymizedDataset);
for ( int number = 0; number < annonymizedDataset.Count; number++)
{
HLI.Attribute attribute = annonymizedDataset[number];
if (attribute.VR == VR.SQ)
{
utility.SequenceAttribute_recursive(attribute);
}
else
{
utility.CacheAndRepairIdentifyingAttribute(attribute);
utility.UpdateAnonymizedAttributes(attribute);
}
}
datasets = new AttributeCollections();
datasets.Add(srcDataset);
datasets.Add(annonymizedDataset);
//Save annonymized data to selected file
saveFileInfo = new FileInfo(saveDialog.FileName);
dcmFile.DataSet = annonymizedDataset;
dcmFile.Write(saveFileInfo.FullName);
//Cleanup temp file
utility.cleanup();
}
else
{
return;
}
string htmlFileName = initialDirectory + "\\" + saveFileInfo.Name + ".html";
XmlTextWriter writer = new XmlTextWriter(htmlFileName, System.Text.Encoding.UTF8);
writer.WriteStartElement("b");
writer.WriteRaw(@"<b><font size='3' color='#ff0000'>DCM File Anonymization Started...</font></b>");
writer.WriteEndElement();
writer.Close();
resultFileName = htmlFileName;
System.Threading.Thread t = new System.Threading.Thread(new ThreadStart(CreateTable));
dvtkWebBrowser.Navigate(htmlFileName);
t.Start();
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
示例13: RandomizeDatasets
private void RandomizeDatasets()
{
// Read the DCM File
DicomFile dcmFile = new DicomFile();
dcmFile.Read(selectedDCMFile, this);
// Randomize the dataset
Random random = new Random((int)System.DateTime.Now.Ticks);
WriteInformation("Sending randomized responses:\r\n");
for (int i=0; i<nrOfRandomRsps; i++)
{
DataSet randomDataset = null;
randomDataset = dcmFile.DataSet.Clone();
randomDataset.Randomize("@",random);
Attribute patNameAttr = randomDataset["0x00100010"];
string patName = patNameAttr.Values[0];
Attribute patIDAttr = randomDataset["0x00100020"];
string patID = patIDAttr.Values[0];
WriteInformation(string.Format("Response:{0}\r\nPatient Name: {1}, Patient ID: {2}\r\n", i+1,patName,patID));
randomizedDatasets.Add(randomDataset);
}
}