Permalink
Browse files

add DICOM Media reader/writer example project from @hdesouky

  • Loading branch information...
1 parent a8c670c commit 6b117635f0a435cc1d4733cd5369c70e5dd5e11a @rcd committed Jan 29, 2013
@@ -10,4 +10,5 @@ copy README.md Distribute\ /Y
copy ChangeLog.md Distribute\ /Y
copy "Examples\C-Store SCP\bin\Release\Dicom.CStoreSCP.exe" Distribute\ /Y
copy "Examples\DICOM Dump\bin\Release\Dicom.Dump.exe" Distribute\ /Y
+copy "Examples\DICOM Media\bin\Release\Dicom.Media.exe" Distribute\ /Y
copy "packages\NLog.2.0.0.2000\lib\net40\NLog.dll" Distribute\ /Y
View
@@ -47,6 +47,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DICOM Dump", "Examples\DICO
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DICOM [Unit Tests]", "DICOM [Unit Tests]\DICOM [Unit Tests].csproj", "{6D0CE6E2-BC02-4E83-8697-18B47CBEF842}"
EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DICOM Media", "Examples\DICOM Media\DICOM Media.csproj", "{00A56C9C-8237-4CB8-ACC9-437C8D366EFC}"
+EndProject
Global
GlobalSection(TestCaseManagementSettings) = postSolution
CategoryFile = DICOM.vsmdi
@@ -108,6 +110,10 @@ Global
{6D0CE6E2-BC02-4E83-8697-18B47CBEF842}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6D0CE6E2-BC02-4E83-8697-18B47CBEF842}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6D0CE6E2-BC02-4E83-8697-18B47CBEF842}.Release|Any CPU.Build.0 = Release|Any CPU
+ {00A56C9C-8237-4CB8-ACC9-437C8D366EFC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {00A56C9C-8237-4CB8-ACC9-437C8D366EFC}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {00A56C9C-8237-4CB8-ACC9-437C8D366EFC}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {00A56C9C-8237-4CB8-ACC9-437C8D366EFC}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@@ -121,6 +127,7 @@ Global
{8DC28743-3826-453A-B400-B0AE7B2C04E7} = {A1D10E37-DC32-4A8E-ABFF-5E5FB3A9687C}
{D9AF008C-EE25-49B3-96F6-E81B8A59D017} = {96052E4E-90EF-431F-A599-8723506A424B}
{8C433ABF-AFE5-4A76-BEBC-74116EC3460E} = {96052E4E-90EF-431F-A599-8723506A424B}
+ {00A56C9C-8237-4CB8-ACC9-437C8D366EFC} = {96052E4E-90EF-431F-A599-8723506A424B}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
BuildVersion_UseGlobalSettings = True
@@ -0,0 +1,68 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">x86</Platform>
+ <ProductVersion>8.0.30703</ProductVersion>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{00A56C9C-8237-4CB8-ACC9-437C8D366EFC}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <RootNamespace>Dicom.Media</RootNamespace>
+ <AssemblyName>Dicom.Media</AssemblyName>
+ <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
+ <TargetFrameworkProfile>
+ </TargetFrameworkProfile>
+ <FileAlignment>512</FileAlignment>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU'">
+ <DebugSymbols>true</DebugSymbols>
+ <OutputPath>bin\Debug\</OutputPath>
+ <DefineConstants>DEBUG;TRACE</DefineConstants>
+ <DebugType>full</DebugType>
+ <PlatformTarget>AnyCPU</PlatformTarget>
+ <ErrorReport>prompt</ErrorReport>
+ <CodeAnalysisIgnoreBuiltInRuleSets>true</CodeAnalysisIgnoreBuiltInRuleSets>
+ <CodeAnalysisIgnoreBuiltInRules>true</CodeAnalysisIgnoreBuiltInRules>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|AnyCPU'">
+ <OutputPath>bin\Release\</OutputPath>
+ <DefineConstants>TRACE</DefineConstants>
+ <Optimize>true</Optimize>
+ <DebugType>pdbonly</DebugType>
+ <PlatformTarget>AnyCPU</PlatformTarget>
+ <ErrorReport>prompt</ErrorReport>
+ <CodeAnalysisIgnoreBuiltInRuleSets>true</CodeAnalysisIgnoreBuiltInRuleSets>
+ <CodeAnalysisIgnoreBuiltInRules>true</CodeAnalysisIgnoreBuiltInRules>
+ </PropertyGroup>
+ <ItemGroup>
+ <Reference Include="System" />
+ <Reference Include="System.Core" />
+ <Reference Include="System.Xml.Linq" />
+ <Reference Include="System.Data.DataSetExtensions" />
+ <Reference Include="Microsoft.CSharp" />
+ <Reference Include="System.Data" />
+ <Reference Include="System.Xml" />
+ </ItemGroup>
+ <ItemGroup>
+ <Compile Include="Program.cs" />
+ <Compile Include="Properties\AssemblyInfo.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="app.config" />
+ </ItemGroup>
+ <ItemGroup>
+ <ProjectReference Include="..\..\DICOM\DICOM.csproj">
+ <Project>{D6E309B0-4837-459E-8C85-ABC268440D62}</Project>
+ <Name>DICOM</Name>
+ </ProjectReference>
+ </ItemGroup>
+ <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
+ <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
+ Other similar extension points exist, see Microsoft.Common.targets.
+ <Target Name="BeforeBuild">
+ </Target>
+ <Target Name="AfterBuild">
+ </Target>
+ -->
+</Project>
@@ -0,0 +1,78 @@
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Text;
+
+namespace Dicom.Media {
+ class Program {
+ static void Main(string[] args) {
+ try {
+ if (args.Length < 2) {
+ PrintUsage();
+ return;
+ }
+
+ var action = args[0];
+ var path = args[1];
+
+ if (action == "read") {
+ path = Path.Combine(path, "DICOMDIR");
+
+ if (!File.Exists(path)) {
+ Console.WriteLine("DICOMDIR file not found: {0}", path);
+ return;
+ }
+
+ ReadMedia(path);
+ return;
+ }
+
+ WriteMedia(path);
+ } catch (Exception ex) {
+ Console.WriteLine(ex.Message);
+ } finally {
+
+ }
+ }
+
+ private static void WriteMedia(string path) {
+ var dicomDirPath = Path.Combine(path, "DICOMDIR");
+
+ var dirInfo = new DirectoryInfo(path);
+
+ var dicomDir = new DicomDirectory();
+ foreach (var file in dirInfo.GetFiles("*.*", SearchOption.AllDirectories)) {
+ var dicomFile = Dicom.DicomFile.Open(file.FullName);
+
+ dicomDir.AddFile(dicomFile, String.Format(@"000001\{0}", file.Name));
+ }
+
+ dicomDir.Save(dicomDirPath);
+ }
+
+ private static void ReadMedia(string fileName) {
+ var dicomDirectory = DicomDirectory.Open(fileName);
+
+ foreach (var patientRecord in dicomDirectory.RootDirectoryRecordCollection) {
+ Console.WriteLine("Patient: {0} ({1})", patientRecord.Get<string>(DicomTag.PatientName), patientRecord.Get<string>(DicomTag.PatientID));
+
+ foreach (var studyRecord in patientRecord.LowerLevelDirectoryRecordCollection) {
+ Console.WriteLine("\tStudy: {0}", studyRecord.Get<string>(DicomTag.StudyInstanceUID));
+
+ foreach (var seriesRecord in studyRecord.LowerLevelDirectoryRecordCollection) {
+ Console.WriteLine("\t\tSeries: {0}", seriesRecord.Get<string>(DicomTag.SeriesInstanceUID));
+
+ foreach (var imageRecord in seriesRecord.LowerLevelDirectoryRecordCollection) {
+ Console.WriteLine("\t\t\tImage: {0} [{1}]", imageRecord.Get<string>(DicomTag.ReferencedSOPInstanceUIDInFile), imageRecord.Get<string>(Dicom.DicomTag.ReferencedFileID));
+ }
+ }
+ }
+ }
+ }
+
+ private static void PrintUsage() {
+ Console.WriteLine("Usage: Dicom.Media.exe read|write <directory>");
+ }
+ }
+}
@@ -0,0 +1,36 @@
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
+// General Information about an assembly is controlled through the following
+// set of attributes. Change these attribute values to modify the information
+// associated with an assembly.
+[assembly: AssemblyTitle("DICOM Media")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("DICOM Media")]
+[assembly: AssemblyCopyright("Copyright © 2013")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+// Setting ComVisible to false makes the types in this assembly not visible
+// to COM components. If you need to access a type in this assembly from
+// COM, set the ComVisible attribute to true on that type.
+[assembly: ComVisible(false)]
+
+// The following GUID is for the ID of the typelib if this project is exposed to COM
+[assembly: Guid("d1332b8f-5bb1-4159-b789-2cb8c00c6da0")]
+
+// Version information for an assembly consists of the following four values:
+//
+// Major Version
+// Minor Version
+// Build Number
+// Revision
+//
+// You can specify all the values or you can default the Build and Revision Numbers
+// by using the '*' as shown below:
+// [assembly: AssemblyVersion("1.0.*")]
+[assembly: AssemblyVersion("1.0.0.0")]
+[assembly: AssemblyFileVersion("1.0.0.0")]
@@ -0,0 +1,3 @@
+<?xml version="1.0"?>
+<configuration>
+<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup></configuration>

0 comments on commit 6b11763

Please sign in to comment.