Example #1
0
        /// <summary>
        /// Write a dicom file object to a (persistent) Media Storage file.
        /// </summary>
        /// <param name="file">dicom file object to write</param>
        /// <param name="mediaFileName">file name to write to</param>
        /// <returns></returns>
        public static bool WriteDataSetToFile(
			DicomFile file,
			string mediaFileName)
        {
            if (file == null) throw new System.ArgumentNullException("file");
            if (mediaFileName == null) throw new System.ArgumentNullException("mediaFileName");

            return MDataSet.WriteFile(file, mediaFileName);
        }
Example #2
0
        /// <summary>
        /// Write a dicom file object to a (persistent) Media Storage file.
        /// </summary>
        /// <param name="file">dicom file object to write</param>
        /// <param name="mediaFileName">file name to write to</param>
        /// <returns></returns>
        public static bool WriteDataSetToFile(
			DicomFile file,
			string mediaFileName)
        {
            if (file == null) throw new System.ArgumentNullException("file");
            if (mediaFileName == null) throw new System.ArgumentNullException("mediaFileName");

            FileMetaInformation fmi = file.FileMetaInformation;
            if (fmi == null)
            {
                fmi = new FileMetaInformation();

                //Set the default transfer syntax(ELE) attribute in FMI
                fmi.AddAttribute("0x00020010",VR.UI,"1.2.840.10008.1.2.1");

                file.FileMetaInformation = fmi;
            }

            return MDataSet.WriteFile(file, mediaFileName);
        }
Example #3
0
        /// <summary>
        /// <see cref="IMediaValidation.Validate"/>
        /// </summary>
        public bool Validate(DicomFile file, ValidationControlFlags validationControlFlags)
        {
            if (file == null) throw new System.ArgumentNullException("file");
            if ((validationControlFlags & ValidationControlFlags.UseReferences) != 0)
                throw new System.ArgumentException();
            //
            // Convert flags
            //
            Wrappers.ValidationControlFlags
                wrappersValidationControlFlags = Wrappers.ValidationControlFlags.None;
            if ((validationControlFlags & ValidationControlFlags.UseDefinitions) != 0)
                wrappersValidationControlFlags |= Wrappers.ValidationControlFlags.UseDefinitions;
            if ((validationControlFlags & ValidationControlFlags.UseReferences) != 0)
                wrappersValidationControlFlags |= Wrappers.ValidationControlFlags.UseReferences;
            if ((validationControlFlags & ValidationControlFlags.UseValueRepresentations) != 0)
                wrappersValidationControlFlags |= Wrappers.ValidationControlFlags.UseValueRepresentations;

            return this.m_adaptee.Validate(file, wrappersValidationControlFlags);
        }
Example #4
0
        /// <summary>
        /// <see cref="IDicomFile.WriteFile"/>
        /// </summary>
        public bool WriteFile(
			DicomFile file,
			string mediaFileName)
        {
            if (file == null) throw new System.ArgumentNullException("file");
            if (mediaFileName == null) throw new System.ArgumentNullException("mediaFileName");
            return this.m_MBaseSession.WriteMedia(file, mediaFileName);
        }
Example #5
0
        /// <summary>
        /// Save selected dataset as DCM FIle
        /// </summary>
        /// <param name="data"></param>
        /// <param name="filename"></param>
        public bool DumpAsDCMFile(byte[] data, string tranferSyntax, string filename)
        {
            bool ok = false;

            //Set Dataset
            string tempFile = Application.StartupPath + @"\Dcm\temp.dcm";
            using(FileStream f=new FileStream(tempFile,FileMode.Create))
            {
                f.Write(data,0,data.Length);
                f.Close();
            }

            //Read Dataset from the file
            DataSet dataset = Dvtk.DvtkDataHelper.ReadDataSetFromFile(tempFile,true);

            //Delete the temp file
            FileInfo tempfile = new FileInfo(tempFile);
            tempfile.Delete();

            if(dataset == null)
            {
                return false;
            }

            DicomFile dicomMediaFile = new DicomFile();

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

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

            // set up the file meta information
            FileMetaInformation fileMetaInformation = new 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 = dataset.GetAttribute(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 = dataset.GetAttribute(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, tranferSyntax);

            // add the Implemenation Class UID
            fileMetaInformation.AddAttribute(Tag.IMPLEMENTATION_CLASS_UID.GroupNumber,
                Tag.IMPLEMENTATION_CLASS_UID.ElementNumber, VR.UI, "1.2.826.0.1.3680043.2.1545.1");

            // add the Implementation Version Name
            fileMetaInformation.AddAttribute(Tag.IMPLEMENTATION_VERSION_NAME.GroupNumber,
                Tag.IMPLEMENTATION_VERSION_NAME.ElementNumber, VR.SH, "DNA");

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

            // write the dicomMediaFile to file
            if(Dvtk.DvtkDataHelper.WriteDataSetToFile(dicomMediaFile, filename))
            {
                string message = string.Format("DataSet logged to file {0} at {1}\r\n",filename,System.DateTime.Now);
                Out(message,true);
                ok = true;
            }

            //Clear all temporary pix files
            FileInfo file = new FileInfo(filename);
            ArrayList theFilesToRemove = new ArrayList();
            DirectoryInfo theDirectoryInfo = new DirectoryInfo(file.DirectoryName);
            FileInfo[] thePixFilesInfo;

            if (theDirectoryInfo.Exists)
            {
                thePixFilesInfo = theDirectoryInfo.GetFiles("*.pix");

                foreach (FileInfo theFileInfo in thePixFilesInfo)
                {
                    string thePixFileName = theFileInfo.Name;

                    theFilesToRemove.Add(thePixFileName);
                }
            }

            //Delete all pix files
            foreach(string theFileName in theFilesToRemove)
            {
                string theFullFileName = System.IO.Path.Combine(theDirectoryInfo.FullName, theFileName);

                if (File.Exists(theFullFileName))
                {
                    try
                    {
                        File.Delete(theFullFileName);
                    }
                    catch(Exception exception)
                    {
                        string theWarningText = string.Format("Could not be delete the {0} temporary file.\n due to exception: {1}\n\n", theFullFileName, exception.Message);

                        Out(theWarningText,true);
                    }
                }
            }

            return ok;
        }