Example #1
0
        public void Read(String fullFileName, params String[] definitionFilesFullName)
        {
            DvtkData.Media.DicomFile dvtkDataDicomFile = null;

            if (!File.Exists(fullFileName))
            {
                throw new HliException("Dicom file or raw file \"" + fullFileName + "\" not found.");
            }

            String tempPath = Path.GetTempPath();

            Dvtk.Sessions.ScriptSession dvtkScriptSession = new Dvtk.Sessions.ScriptSession();

            dvtkScriptSession.StorageMode          = Dvtk.Sessions.StorageMode.AsMedia;
            dvtkScriptSession.DataDirectory        = tempPath;
            dvtkScriptSession.ResultsRootDirectory = tempPath;

            foreach (String definitionFileFullName in definitionFilesFullName)
            {
                dvtkScriptSession.DefinitionManagement.LoadDefinitionFile(definitionFileFullName);
            }

            dvtkDataDicomFile = dvtkScriptSession.ReadFile(fullFileName);

            this.dataSet.DvtkDataDataSet = dvtkDataDicomFile.DataSet;
            this.FileMetaInformation.DvtkDataFileMetaInformation = dvtkDataDicomFile.FileMetaInformation;
            this.dvtkDataFileHead = dvtkDataDicomFile.FileHead;
        }
Example #2
0
        public void Read(String fullFileName, DicomThread dicomThread)
        {
            DvtkData.Media.DicomFile dvtkDataDicomFile = null;

            if (!File.Exists(fullFileName))
            {
                throw new HliException("Dicom file or raw file \"" + fullFileName + "\" not found.");
            }

            dvtkDataDicomFile = dicomThread.DvtkScriptSession.ReadFile(fullFileName);

            this.dataSet.DvtkDataDataSet = dvtkDataDicomFile.DataSet;
            this.fileMetaInformation.DvtkDataFileMetaInformation = dvtkDataDicomFile.FileMetaInformation;
            this.dvtkDataFileHead = dvtkDataDicomFile.FileHead;
        }
Example #3
0
        /// <summary>
        /// Store the DICOM file into a DICOM Media File in the current Information Model directory.
        /// The file contents might be later used for retrieval.The transfer syntax is also passed so that the TS specified
        /// in the dcm file is used while moving the file to a Storage SCP
        /// </summary>
        /// <param name="dicomFile">The DICOM file to store</param>
        protected void StoreDicomFile(DvtkData.Media.DicomFile dicomFile)
        {
            System.String iom = System.String.Empty;
            if (Name.Equals("PatientRootInformationModel"))
            {
                iom = "PR";
            }
            else if (Name.Equals("StudyRootInformationModel"))
            {
                iom = "SR";
            }
            else if (Name.Equals("PatientStudyOnlyInformationModel"))
            {
                iom = "PS";
            }

            // generate a filename
            System.String filename;
            filename = System.String.Format("{0}\\DVTK_IOM_TMP_{1}_{2:00000000}.DCM", DataDirectory, iom, _fileIndex++);
            DvtkData.Media.DicomFile dicomMediaFile = new DvtkData.Media.DicomFile();

            // set up the file head
            DvtkData.Media.FileHead FileHead = new DvtkData.Media.FileHead();

            // add the Transfer Syntax UID
            //DvtkData.Dul.TransferSyntax transferSyntax = new DvtkData.Dul.TransferSyntax(DvtkData.Dul.TransferSyntax.Explicit_VR_Little_Endian.UID);
            FileHead.TransferSyntax = dicomFile.FileHead.TransferSyntax;

            // set up the file meta information
            DvtkData.Media.FileMetaInformation fileMetaInformation = new DvtkData.Media.FileMetaInformation();

            // add the FMI version
            fileMetaInformation.AddAttribute(Tag.FILE_META_INFORMATION_VERSION.GroupNumber,
                                             Tag.FILE_META_INFORMATION_VERSION.ElementNumber, VR.OB, 1, 2);

            // add the SOP Class UID
            System.String sopClassUid = "";

            DvtkData.Dimse.Attribute attribute = dicomFile.DataSet.GetAttribute(DvtkData.Dimse.Tag.SOP_CLASS_UID);
            if (attribute != null)
            {
                UniqueIdentifier uniqueIdentifier = (UniqueIdentifier)attribute.DicomValue;
                if (uniqueIdentifier.Values.Count > 0)
                {
                    sopClassUid = uniqueIdentifier.Values[0];
                }
            }
            fileMetaInformation.AddAttribute(Tag.MEDIA_STORAGE_SOP_CLASS_UID.GroupNumber,
                                             Tag.MEDIA_STORAGE_SOP_CLASS_UID.ElementNumber, VR.UI, sopClassUid);

            // add the SOP Instance UID
            System.String sopInstanceUid = "";
            attribute = dicomFile.DataSet.GetAttribute(DvtkData.Dimse.Tag.SOP_INSTANCE_UID);
            if (attribute != null)
            {
                UniqueIdentifier uniqueIdentifier = (UniqueIdentifier)attribute.DicomValue;
                if (uniqueIdentifier.Values.Count > 0)
                {
                    sopInstanceUid = uniqueIdentifier.Values[0];
                }
            }
            fileMetaInformation.AddAttribute(Tag.MEDIA_STORAGE_SOP_INSTANCE_UID.GroupNumber,
                                             Tag.MEDIA_STORAGE_SOP_INSTANCE_UID.ElementNumber, VR.UI, sopInstanceUid);

            // add the Transfer Syntax UID
            fileMetaInformation.AddAttribute(Tag.TRANSFER_SYNTAX_UID.GroupNumber,
                                             Tag.TRANSFER_SYNTAX_UID.ElementNumber, VR.UI, dicomFile.FileHead.TransferSyntax);

            // add the Implemenation Class UID
            DvtkData.Dimse.Attribute implentationUID = dicomFile.FileMetaInformation.GetAttribute(0x00020012);
            fileMetaInformation.AddAttribute(Tag.IMPLEMENTATION_CLASS_UID.GroupNumber,
                                             Tag.IMPLEMENTATION_CLASS_UID.ElementNumber, VR.UI, implentationUID);

            // add the Implementation Version Name
            DvtkData.Dimse.Attribute implementationVersion = dicomFile.FileMetaInformation.GetAttribute(0x00020013);
            fileMetaInformation.AddAttribute(Tag.IMPLEMENTATION_VERSION_NAME.GroupNumber,
                                             Tag.IMPLEMENTATION_VERSION_NAME.ElementNumber, VR.SH, implementationVersion);

            // set up the dicomMediaFile contents
            dicomMediaFile.FileHead            = FileHead;
            dicomMediaFile.FileMetaInformation = fileMetaInformation;
            dicomMediaFile.DataSet             = dicomFile.DataSet;

            // write the dicomMediaFile to file
            Dvtk.DvtkDataHelper.WriteDataSetToFile(dicomMediaFile, filename);

            // save the filename in the dataset
            dicomFile.DataSet.Filename = filename;
        }
Example #4
0
 /// <summary>
 /// Constructor. Encapsulated existing DvtkData FileMetaInformation instance and DvtkData FileHead instance.
 /// </summary>
 /// <param name="dvtkDataFileMetaInformation">The encapsulated DvtkData FileMetaInformation instance.</param>
 /// <param name="dvtkDataFileHead">The encapsulated FileHead instance.</param>
 internal FileMetaInformation(DvtkData.Media.FileMetaInformation dvtkDataFileMetaInformation, DvtkData.Media.FileHead dvtkDataFileHead) : base(dvtkDataFileMetaInformation)
 {
     this.dvtkDataFileHead = dvtkDataFileHead;
 }
Example #5
0
        void SaveFileAsDefinedTS(string transferSyntax)
        {
            if (DCMFile == "")
            {
                richTextBoxLog.AppendText("There is no Media file to save, please select Media file.\n");
                return;
            }

            try
            {
                SaveFileDialog saveAsDlg = new SaveFileDialog();
                saveAsDlg.Filter = "DCM files (*.dcm) |*.dcm | All files (*.*)|*.*";
                FileInfo dcmFileInfo = new FileInfo(DCMFile);
                saveAsDlg.InitialDirectory = dcmFileInfo.DirectoryName;
                saveAsDlg.FileName = dcmFileInfo.Name;
                saveAsDlg.Title = "Save DICOM file...";
                if (saveAsDlg.ShowDialog() == DialogResult.OK)
                {
                    richTextBoxLog.AppendText("Saving the modified Media file.\n");

                    _NewDCMFileName = saveAsDlg.FileName.Trim();

                    if (DCMFile != _NewDCMFileName)
                        _IsSavedInNewDCMFile = true;

                    DvtkData.Media.DicomFile dicomMediaFile = new DvtkData.Media.DicomFile();

                    // set up the file head
                    DvtkData.Media.FileHead fileHead = new DvtkData.Media.FileHead();

                    // add the Transfer Syntax UID
                    DvtkData.Dul.TransferSyntax tSyntax = new DvtkData.Dul.TransferSyntax(transferSyntax);
                    fileHead.TransferSyntax = tSyntax;

                    // set up the file meta information
                    DvtkData.Media.FileMetaInformation fileMetaInformation = new DvtkData.Media.FileMetaInformation();

                    // add the FMI version
                    fileMetaInformation.AddAttribute(DvtkData.Dimse.Tag.FILE_META_INFORMATION_VERSION.GroupNumber,
                        DvtkData.Dimse.Tag.FILE_META_INFORMATION_VERSION.ElementNumber, VR.OB, 1, 2);

                    // add the SOP Class UID
                    fileMetaInformation.AddAttribute(DvtkData.Dimse.Tag.MEDIA_STORAGE_SOP_CLASS_UID.GroupNumber,
                        DvtkData.Dimse.Tag.MEDIA_STORAGE_SOP_CLASS_UID.ElementNumber, VR.UI, _FileMetaInfo.MediaStorageSOPClassUID);

                    // add the SOP Instance UID
                    fileMetaInformation.AddAttribute(DvtkData.Dimse.Tag.MEDIA_STORAGE_SOP_INSTANCE_UID.GroupNumber,
                        DvtkData.Dimse.Tag.MEDIA_STORAGE_SOP_INSTANCE_UID.ElementNumber, VR.UI, _FileMetaInfo.MediaStorageSOPInstanceUID);

                    // add the Transfer Syntax UID
                    fileMetaInformation.AddAttribute(DvtkData.Dimse.Tag.TRANSFER_SYNTAX_UID.GroupNumber,
                        DvtkData.Dimse.Tag.TRANSFER_SYNTAX_UID.ElementNumber, VR.UI, transferSyntax);

                    // add the Implemenation Class UID
                    string implClassUID = "";
				    if(_FileMetaInfo.Exists("0x00020012"))
				    {
					    // Get the Transfer syntax
					    HLI.Attribute implClassUIDAttr = _FileMetaInfo["0x00020012"];
					    implClassUID = implClassUIDAttr.Values[0];
				    }

                    fileMetaInformation.AddAttribute(DvtkData.Dimse.Tag.IMPLEMENTATION_CLASS_UID.GroupNumber,
                        DvtkData.Dimse.Tag.IMPLEMENTATION_CLASS_UID.ElementNumber, VR.UI, implClassUID);

                    // add the Implementation Version Name
                    string implClassVersion = "";
				    if(_FileMetaInfo.Exists("0x00020013"))
				    {
					    // Get the Transfer syntax
					    HLI.Attribute implClassVersionAttr = _FileMetaInfo["0x00020013"];
					    implClassVersion = implClassVersionAttr.Values[0];
				    }

                    fileMetaInformation.AddAttribute(DvtkData.Dimse.Tag.IMPLEMENTATION_VERSION_NAME.GroupNumber,
                        DvtkData.Dimse.Tag.IMPLEMENTATION_VERSION_NAME.ElementNumber, VR.SH, implClassVersion);

                    // set up the dicomMediaFile contents
                    dicomMediaFile.FileHead = fileHead;
                    dicomMediaFile.FileMetaInformation = fileMetaInformation;
                    dicomMediaFile.DataSet = _DCMdataset.DvtkDataDataSet;

                    // write the dicomMediaFile to file
                    Dvtk.DvtkDataHelper.WriteDataSetToFile(dicomMediaFile, _NewDCMFileName);

                    string theLogText = string.Format("Dataset {0} saved successfully with transfer syntax: {1}.\n\n", _NewDCMFileName, transferSyntax);

                    richTextBoxLog.AppendText(theLogText);
                    richTextBoxLog.ScrollToCaret();
                    richTextBoxLog.Focus();

                    //Cleanup the FMI & Dataset
                    IsDCMFileModified = false;
                    _IsAttributeGroupLengthDefined = false;
                    _DCMdataset = null;
                    _FileMetaInfo = null;

                    if (_IsSavedInNewDCMFile)
                    {
                        FileInfo newDcmFileInfo = new FileInfo(_NewDCMFileName);

                        _IsNewDCMFileLoaded = true;
                        this.dirListBox.Path = newDcmFileInfo.DirectoryName;
                        this.fileListBox.Path = this.dirListBox.Path;
                        this.fileListBox.SelectedItem = newDcmFileInfo.Name;

                        this.dirListBox.Refresh();
                        this.fileListBox.Refresh();

                        //Load the new Media file
                        LoadDCMFile(_NewDCMFileName);
                    }
                    else
                    {
                        _IsNewDCMFileLoaded = false;
                        this.dirListBox.Path = dcmFileInfo.DirectoryName;
                        this.fileListBox.Path = this.dirListBox.Path;
                        this.fileListBox.SelectedItem = dcmFileInfo.Name;

                        //Load the new Media file
                        LoadDCMFile(DCMFile);
                    }

                    UpdateTitleBarText();
                }
            }
            catch (Exception exception)
            {
                string theErrorText;

                theErrorText = string.Format("Media file {0} could not be saved:\n{1}\n\n", _NewDCMFileName, exception.Message);

                richTextBoxLog.AppendText(theErrorText);
                richTextBoxLog.ScrollToCaret();
                richTextBoxLog.Focus();

                IsDCMFileModified = false;
                UpdateTitleBarText();
            }            
        }
Example #6
0
 public DicomFile()
 {
     this.dataSet             = new DataSet();
     this.fileMetaInformation = new FileMetaInformation();
     this.dvtkDataFileHead    = new DvtkData.Media.FileHead();
 }
Example #7
0
 /// <summary>
 /// Constructor. Encapsulated existing DvtkData FileMetaInformation instance and DvtkData FileHead instance.
 /// </summary>
 /// <param name="dvtkDataFileMetaInformation">The encapsulated DvtkData FileMetaInformation instance.</param>
 /// <param name="dvtkDataFileHead">The encapsulated FileHead instance.</param>
 internal FileMetaInformation(DvtkData.Media.FileMetaInformation dvtkDataFileMetaInformation, DvtkData.Media.FileHead dvtkDataFileHead)
     : base(dvtkDataFileMetaInformation)
 {
     this.dvtkDataFileHead = dvtkDataFileHead;
 }
Example #8
0
        public void Read(String fullFileName, params String[] definitionFilesFullName)
        {
            DvtkData.Media.DicomFile dvtkDataDicomFile = null;

            if (!File.Exists(fullFileName))
            {
                throw new HliException("Dicom file or raw file \"" + fullFileName + "\" not found.");
            }

            String tempPath = Path.GetTempPath();

            Dvtk.Sessions.ScriptSession dvtkScriptSession = new Dvtk.Sessions.ScriptSession();

            dvtkScriptSession.StorageMode = Dvtk.Sessions.StorageMode.AsMedia;
            dvtkScriptSession.DataDirectory = tempPath;
            dvtkScriptSession.ResultsRootDirectory = tempPath;

            foreach(String definitionFileFullName in definitionFilesFullName)
            {
                dvtkScriptSession.DefinitionManagement.LoadDefinitionFile(definitionFileFullName);
            }

            dvtkDataDicomFile = dvtkScriptSession.ReadFile(fullFileName);

            this.dataSet.DvtkDataDataSet = dvtkDataDicomFile.DataSet;
            this.FileMetaInformation.DvtkDataFileMetaInformation = dvtkDataDicomFile.FileMetaInformation;
            this.dvtkDataFileHead = dvtkDataDicomFile.FileHead;
        }
Example #9
0
        public void Read(String fullFileName, DicomThread dicomThread)
        {
            DvtkData.Media.DicomFile dvtkDataDicomFile = null;

            if (!File.Exists(fullFileName))
            {
                throw new HliException("Dicom file or raw file \"" + fullFileName + "\" not found.");
            }

            dvtkDataDicomFile = dicomThread.DvtkScriptSession.ReadFile(fullFileName);

            this.dataSet.DvtkDataDataSet = dvtkDataDicomFile.DataSet;
            this.fileMetaInformation.DvtkDataFileMetaInformation = dvtkDataDicomFile.FileMetaInformation;
            this.dvtkDataFileHead = dvtkDataDicomFile.FileHead;
        }
Example #10
0
 public DicomFile()
 {
     this.dataSet = new DataSet();
     this.fileMetaInformation = new FileMetaInformation();
     this.dvtkDataFileHead = new DvtkData.Media.FileHead();
 }
        /// <summary>
        /// Store the DICOM file into a DICOM Media File in the current Information Model directory.
        /// The file contents might be later used for retrieval.The transfer syntax is also passed so that the TS specified
        /// in the dcm file is used while moving the file to a Storage SCP
        /// </summary>
        /// <param name="dicomFile">The DICOM file to store</param>
        protected void StoreDicomFile(DvtkData.Media.DicomFile dicomFile)
        {
            System.String iom = System.String.Empty;
            if (Name.Equals("PatientRootInformationModel"))
            {
                iom = "PR";
            }
            else if (Name.Equals("StudyRootInformationModel"))
            {
                iom = "SR";
            }
            else if (Name.Equals("PatientStudyOnlyInformationModel"))
            {
                iom = "PS";
            }

            // generate a filename
            System.String filename;
            filename = System.String.Format("{0}\\DVTK_IOM_TMP_{1}_{2:00000000}.DCM", DataDirectory, iom, _fileIndex++);
            DvtkData.Media.DicomFile dicomMediaFile = new DvtkData.Media.DicomFile();

            // set up the file head
            DvtkData.Media.FileHead FileHead = new DvtkData.Media.FileHead();

            // add the Transfer Syntax UID
            //DvtkData.Dul.TransferSyntax transferSyntax = new DvtkData.Dul.TransferSyntax(DvtkData.Dul.TransferSyntax.Explicit_VR_Little_Endian.UID);
            FileHead.TransferSyntax = dicomFile.FileHead.TransferSyntax;

            // set up the file meta information
            DvtkData.Media.FileMetaInformation fileMetaInformation = new DvtkData.Media.FileMetaInformation();

            // add the FMI version
            fileMetaInformation.AddAttribute(Tag.FILE_META_INFORMATION_VERSION.GroupNumber,
                Tag.FILE_META_INFORMATION_VERSION.ElementNumber, VR.OB, 1, 2);

            // add the SOP Class UID
            System.String sopClassUid = "";

            DvtkData.Dimse.Attribute attribute = dicomFile.DataSet.GetAttribute(DvtkData.Dimse.Tag.SOP_CLASS_UID);
            if (attribute != null)
            {
                UniqueIdentifier uniqueIdentifier = (UniqueIdentifier)attribute.DicomValue;
                if (uniqueIdentifier.Values.Count > 0)
                {
                    sopClassUid = uniqueIdentifier.Values[0];
                }
            }
            fileMetaInformation.AddAttribute(Tag.MEDIA_STORAGE_SOP_CLASS_UID.GroupNumber,
                Tag.MEDIA_STORAGE_SOP_CLASS_UID.ElementNumber, VR.UI, sopClassUid);

            // add the SOP Instance UID
            System.String sopInstanceUid = "";
            attribute = dicomFile.DataSet.GetAttribute(DvtkData.Dimse.Tag.SOP_INSTANCE_UID);
            if (attribute != null)
            {
                UniqueIdentifier uniqueIdentifier = (UniqueIdentifier)attribute.DicomValue;
                if (uniqueIdentifier.Values.Count > 0)
                {
                    sopInstanceUid = uniqueIdentifier.Values[0];
                }
            }
            fileMetaInformation.AddAttribute(Tag.MEDIA_STORAGE_SOP_INSTANCE_UID.GroupNumber,
                Tag.MEDIA_STORAGE_SOP_INSTANCE_UID.ElementNumber, VR.UI, sopInstanceUid);

            // add the Transfer Syntax UID
            fileMetaInformation.AddAttribute(Tag.TRANSFER_SYNTAX_UID.GroupNumber,
                Tag.TRANSFER_SYNTAX_UID.ElementNumber, VR.UI, dicomFile.FileHead.TransferSyntax);

            // add the Implemenation Class UID
            DvtkData.Dimse.Attribute implentationUID = dicomFile.FileMetaInformation.GetAttribute(0x00020012);
            fileMetaInformation.AddAttribute(Tag.IMPLEMENTATION_CLASS_UID.GroupNumber,
                Tag.IMPLEMENTATION_CLASS_UID.ElementNumber, VR.UI, implentationUID);

            // add the Implementation Version Name
            DvtkData.Dimse.Attribute implementationVersion = dicomFile.FileMetaInformation.GetAttribute(0x00020013);
            fileMetaInformation.AddAttribute(Tag.IMPLEMENTATION_VERSION_NAME.GroupNumber,
                Tag.IMPLEMENTATION_VERSION_NAME.ElementNumber, VR.SH, implementationVersion);

            // set up the dicomMediaFile contents
            dicomMediaFile.FileHead = FileHead;
            dicomMediaFile.FileMetaInformation = fileMetaInformation;
            dicomMediaFile.DataSet = dicomFile.DataSet;

            // write the dicomMediaFile to file
            Dvtk.DvtkDataHelper.WriteDataSetToFile(dicomMediaFile, filename);

            // save the filename in the dataset
            dicomFile.DataSet.Filename = filename;
        }