Beispiel #1
0
        public void Insert(string filename)
        {
            var file = new DicomFile(filename);
            file.Load();

            Insert(file);
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            DicomFile file = new DicomFile();
            file.DataSet.SpecificCharacterSet = "ISO_IR 100";

            file.DataSet[DicomTags.SpecificCharacterSet].SetStringValue("ISO_IR 100");
            file.DataSet[DicomTags.PatientsBirthName].SetStringValue("中文");
            file.DataSet[DicomTags.PatientsName].SetStringValue("(中文)");

            file.Save("1.dcm");

            DicomFile readFile = new DicomFile("1.dcm");
            readFile.Load();
            Console.WriteLine(readFile.DataSet[DicomTags.PatientsBirthName].GetString(0, string.Empty));
            Console.WriteLine(readFile.DataSet[DicomTags.PatientsName].GetString(0, string.Empty));

            DicomFile file2 = new DicomFile();
            file2.DataSet.SpecificCharacterSet = "GB18030";

            file2.DataSet[DicomTags.SpecificCharacterSet].SetStringValue("GB18030");
            file2.DataSet[DicomTags.PatientsName].SetStringValue("刘瑞飞(liuruifei)");
            file2.Save("2.dcm");

            DicomFile readFile2 = new DicomFile("2.dcm");
            readFile2.Load();
            Console.WriteLine(readFile2.DataSet[DicomTags.PatientsName].GetString(0, string.Empty));

            Console.WriteLine(@"press any key to exit!");
            Console.ReadKey();

        }
Beispiel #3
0
        static void Main(string[] args)
        {
            if (args.Length < 3)
            {
                Console.WriteLine(@"Usage: ImagerSender.exe filename studynumber seriesnumber");
                return;
            }

            var actions = new List<Action>();
            for (int threadNum = 0; threadNum < Settings1.Default.SendThreadNumber; threadNum++)
            {
                actions.Add( () =>
                    {
                        var f = new DicomFile(args[0]);
                        f.Load();

                        for (int i = 0; i < int.Parse(args[1]); i++)
                        {
                            f.DataSet[DicomTags.StudyInstanceUid].SetString(0, DicomUid.GenerateUid().UID);
                            for (int j = 0; j < int.Parse(args[2]); j++)
                            {
                                f.DataSet[DicomTags.SeriesInstanceUid].SetString(0, DicomUid.GenerateUid().UID);
                                
                                for (int k = 0; k < 20; k++)
                                {
                                    var scu = new StorageScu(Settings1.Default.AETitle, Settings1.Default.RemoteAETitle,
                                        Settings1.Default.RemoteHost, Settings1.Default.RemotePort);
                                    f.DataSet[DicomTags.SopInstanceUid].SetString(0, MyDicomGenerater.GenerateUid());
                                    scu.AddStorageInstance(new StorageInstance(f));
                                    scu.Send();
                                }

                            }
                        }
                    } );
            }
            SpawnAndWait(actions);

            Console.WriteLine(@"Press any key to exist...");
            Console.ReadKey();

        }
		/// <summary>
		/// Creates an instance of <see cref="DicomPixelData"/> from specified image path
		/// </summary>
		/// <param name="path"></param>
		/// <returns>
		/// </returns>
		public static DicomPixelData CreateFrom(string path)
		{
			DicomFile file = new DicomFile(path);
			file.Load();
			return CreateFrom(file);
		}
		/// <summary>
		/// Creates an instance of <see cref="DicomPixelData"/> from specified stream
		/// </summary>
		/// <param name="stream"></param>
		/// <returns>
		/// </returns>
		public static DicomPixelData CreateFrom(Stream stream)
		{
			DicomFile file = new DicomFile();
			file.Load(stream);
			return CreateFrom(file);
		}
		/// <summary>
		/// Called to insert a DICOM file into the directory record structure.
		/// </summary>
		/// <param name="dicomFile"></param>
		/// <param name="optionalRelativeRootPath"></param>
		private void InsertFile(DicomFile dicomFile, string optionalRelativeRootPath)
		{
			try
			{
				if (dicomFile.DataSet.Count == 0)
					dicomFile.Load(DicomReadOptions.StorePixelDataReferences | DicomReadOptions.Default);

				DirectoryRecordSequenceItem patientRecord;
				DirectoryRecordSequenceItem studyRecord;
				DirectoryRecordSequenceItem seriesRecord;

				if (_rootRecord == null)
					_rootRecord = patientRecord = CreatePatientItem(dicomFile);
				else
					patientRecord = GetExistingOrCreateNewPatient(_rootRecord, dicomFile);

				if (patientRecord.LowerLevelDirectoryRecord == null)
					patientRecord.LowerLevelDirectoryRecord = studyRecord = CreateStudyItem(dicomFile);
				else
					studyRecord = GetExistingOrCreateNewStudy(patientRecord.LowerLevelDirectoryRecord, dicomFile);

				if (studyRecord.LowerLevelDirectoryRecord == null)
					studyRecord.LowerLevelDirectoryRecord = seriesRecord = CreateSeriesItem(dicomFile);
				else
					seriesRecord = GetExistingOrCreateNewSeries(studyRecord.LowerLevelDirectoryRecord, dicomFile);

				if (seriesRecord.LowerLevelDirectoryRecord == null)
					seriesRecord.LowerLevelDirectoryRecord = CreateImageItem(dicomFile, optionalRelativeRootPath);
				else
					GetExistingOrCreateNewImage(seriesRecord.LowerLevelDirectoryRecord, dicomFile, optionalRelativeRootPath);
			}
			catch (Exception ex)
			{
				Platform.Log(LogLevel.Error, ex, "Error adding image {0} to directory file", dicomFile.Filename);
				throw;
			}
		}
Beispiel #7
0
        static void Main(string[] args)
        {
            if (args.Length < 2)
            {
                Console.WriteLine(@"Usage: FileLoadTest.exe filepath");
                return;
            }

            string path = args[0];
            string multiThread = args[1];

            Stopwatch watch = new Stopwatch();

            if (multiThread == "0")
            {
                watch.Start();
                DirectoryInfo di = new DirectoryInfo(path);
                List<DicomFile> dicoms = new List<DicomFile>();
                Int64 totalSize = 0;
                int count = 0;
                foreach (FileInfo fi in di.EnumerateFiles())
                {
                    FileStream fs = File.OpenRead(fi.FullName);

                    byte[] buffer = new byte[fi.Length];

                    fs.Read(buffer, 0, buffer.Length);
                    MemoryStream ms = new MemoryStream(buffer);

                    DicomFile dicom = new DicomFile();

                    dicom.Load(ms);
// 
//                     DicomFile dicom = new DicomFile(fi.FullName);
//                     dicom.Load(DicomReadOptions.Default);
//                     totalSize += fi.Length;
//                    dicoms.Add(dicom);

//                     FileStream fs = File.OpenRead(fi.FullName);
// 
//                     byte[] buffer = new byte[fi.Length];
//                     fs.Read(buffer, 0, buffer.Length);

                    totalSize += fi.Length;
                    count += 1;
                }
                watch.Stop();
                Console.WriteLine(@"Load Count: {0}, TotalSize: {1} , Easple Times: {2} second",
                    count, totalSize, watch.ElapsedMilliseconds);
                Console.WriteLine(@"Press any key to exit!");
            }
            else
            {
                watch.Start();
                MultiThreadDicomLoad loader = new MultiThreadDicomLoad();
                loader.LoadAllFile(path);
                watch.Stop();

                Console.WriteLine(@"Load Count: {0}, TotalSize: {1} , Easple Times: {2} second",
                loader.DicomFiles.Count, loader.Size, watch.ElapsedMilliseconds);
                Console.WriteLine(@"Press any key to exit!");
            }
            
        }
Beispiel #8
0
        private void ProcessItem(MemoryStream ms)
        {
            DicomFile df = new DicomFile();

            df.Load(ms);

            //DicomFiles.Add(df);
        }