本文整理汇总了C#中StudyXml.SetMemento方法的典型用法代码示例。如果您正苦于以下问题:C# StudyXml.SetMemento方法的具体用法?C# StudyXml.SetMemento怎么用?C# StudyXml.SetMemento使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类StudyXml
的用法示例。
在下文中一共展示了StudyXml.SetMemento方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: LoadInstance
/// <summary>
/// Load the first instance from the first series of the StudyXml file for a study.
/// </summary>
/// <param name="location">The storage location of the study.</param>
/// <returns></returns>
protected static DicomFile LoadInstance(StudyStorageLocation location)
{
string studyXml = Path.Combine(location.GetStudyPath(), location.StudyInstanceUid + ".xml");
if (!File.Exists(studyXml))
{
return null;
}
FileStream stream = FileStreamOpener.OpenForRead(studyXml, FileMode.Open);
var theDoc = new XmlDocument();
StudyXmlIo.Read(theDoc, stream);
stream.Close();
stream.Dispose();
var xml = new StudyXml();
xml.SetMemento(theDoc);
IEnumerator<SeriesXml> seriesEnumerator = xml.GetEnumerator();
if (seriesEnumerator.MoveNext())
{
SeriesXml seriesXml = seriesEnumerator.Current;
IEnumerator<InstanceXml> instanceEnumerator = seriesXml.GetEnumerator();
if (instanceEnumerator.MoveNext())
{
InstanceXml instance = instanceEnumerator.Current;
var file = new DicomFile("file.dcm",new DicomAttributeCollection(), instance.Collection)
{TransferSyntax = instance.TransferSyntax};
return file;
}
}
return null;
}
示例2: TestSopClass
public void TestSopClass()
{
List<DicomFile> images = SetupImages(4);
string seriesUid = images[0].DataSet[DicomTags.SeriesInstanceUid].ToString();
images[0].MediaStorageSopClassUid = SopClass.EnhancedCtImageStorageUid;
images[1].MediaStorageSopClassUid = SopClass.EnhancedMrImageStorageUid;
images[2].MediaStorageSopClassUid = SopClass.EnhancedSrStorageUid;
images[3].MediaStorageSopClassUid = SopClass.EnhancedXaImageStorageUid;
StudyXml xml = new StudyXml();
foreach (DicomFile file in images)
xml.AddFile(file);
XmlDocument doc = xml.GetMemento(new StudyXmlOutputSettings());
Assert.AreEqual(xml[seriesUid][images[0].DataSet[DicomTags.SopInstanceUid]].SopClass.Uid, SopClass.EnhancedCtImageStorageUid);
Assert.AreEqual(xml[seriesUid][images[1].DataSet[DicomTags.SopInstanceUid]].SopClass.Uid, SopClass.EnhancedMrImageStorageUid);
Assert.AreEqual(xml[seriesUid][images[2].DataSet[DicomTags.SopInstanceUid]].SopClass.Uid, SopClass.EnhancedSrStorageUid);
Assert.AreEqual(xml[seriesUid][images[3].DataSet[DicomTags.SopInstanceUid]].SopClass.Uid, SopClass.EnhancedXaImageStorageUid);
xml = new StudyXml();
xml.SetMemento(doc);
Assert.AreEqual(xml[seriesUid][images[0].DataSet[DicomTags.SopInstanceUid]].SopClass.Uid, SopClass.EnhancedCtImageStorageUid);
Assert.AreEqual(xml[seriesUid][images[1].DataSet[DicomTags.SopInstanceUid]].SopClass.Uid, SopClass.EnhancedMrImageStorageUid);
Assert.AreEqual(xml[seriesUid][images[2].DataSet[DicomTags.SopInstanceUid]].SopClass.Uid, SopClass.EnhancedSrStorageUid);
Assert.AreEqual(xml[seriesUid][images[3].DataSet[DicomTags.SopInstanceUid]].SopClass.Uid, SopClass.EnhancedXaImageStorageUid);
}
示例3: OnExecute
/// <summary>
/// Apply the rules.
/// </summary>
/// <remarks>
/// When rules are applied, we are simply adding new <see cref="ServerDatabaseCommand"/> instances
/// for the rules to the currently executing <see cref="ServerCommandProcessor"/>. They will be
/// executed after all other rules have been executed.
/// </remarks>
protected override void OnExecute(CommandProcessor theProcessor)
{
string studyXmlFile = Path.Combine(_directory, String.Format("{0}.xml", _studyInstanceUid));
StudyXml theXml = new StudyXml(_studyInstanceUid);
if (File.Exists(studyXmlFile))
{
using (Stream fileStream = FileStreamOpener.OpenForRead(studyXmlFile, FileMode.Open))
{
var theMemento = new StudyXmlMemento();
StudyXmlIo.Read(theMemento, fileStream);
theXml.SetMemento(theMemento);
fileStream.Close();
}
}
else
{
string errorMsg = String.Format("Unable to load study XML file of restored study: {0}", studyXmlFile);
Platform.Log(LogLevel.Error, errorMsg);
throw new ApplicationException(errorMsg);
}
DicomFile defaultFile = null;
bool rulesExecuted = false;
foreach (SeriesXml seriesXml in theXml)
{
foreach (InstanceXml instanceXml in seriesXml)
{
// Skip non-image objects
if (instanceXml.SopClass.Equals(SopClass.KeyObjectSelectionDocumentStorage)
|| instanceXml.SopClass.Equals(SopClass.GrayscaleSoftcopyPresentationStateStorageSopClass)
|| instanceXml.SopClass.Equals(SopClass.BlendingSoftcopyPresentationStateStorageSopClass)
|| instanceXml.SopClass.Equals(SopClass.ColorSoftcopyPresentationStateStorageSopClass))
{
// Save the first one encountered, just in case the whole study is non-image objects.
if (defaultFile == null)
defaultFile = new DicomFile("test", new DicomAttributeCollection(), instanceXml.Collection);
continue;
}
DicomFile file = new DicomFile("test", new DicomAttributeCollection(), instanceXml.Collection);
_context.Message = file;
_engine.Execute(_context);
rulesExecuted = true;
break;
}
if (rulesExecuted) break;
}
if (!rulesExecuted && defaultFile != null)
{
_context.Message = defaultFile;
_engine.Execute(_context);
}
}
示例4: LoadStudyXml
/// <summary>
/// Load the StudyXml file.
/// </summary>
/// <param name="studyXmlFile"></param>
public void LoadStudyXml(string studyXmlFile)
{
using (Stream fileStream = FileStreamOpener.OpenForRead(studyXmlFile, FileMode.Open))
{
XmlDocument theDoc = new XmlDocument();
StudyXmlIo.Read(theDoc, fileStream);
_studyXml = new StudyXml(_storageLocation.StudyInstanceUid);
_studyXml.SetMemento(theDoc);
fileStream.Close();
}
}
示例5: LoadStudyStream
/// <summary>
/// Load a <see cref="StudyXml"/> file for a given <see cref="StudyStorageLocation"/>
/// </summary>
/// <param name="location">The location a study is stored.</param>
/// <returns>The <see cref="StudyXml"/> instance for <paramref name="location"/></returns>
private StudyXml LoadStudyStream(string location)
{
StudyXml theXml = new StudyXml();
if (File.Exists(location))
{
using (Stream fileStream = new FileStream(location, FileMode.Open))
{
XmlDocument theDoc = new XmlDocument();
StudyXmlIo.Read(theDoc, fileStream);
theXml.SetMemento(theDoc);
fileStream.Close();
}
}
return theXml;
}
示例6: GetFirstInstanceInEachStudySeries
/// <summary>
/// Get a list of paths to the first image in each series within the study being processed.
/// </summary>
/// <returns></returns>
private List<string> GetFirstInstanceInEachStudySeries()
{
var fileList = new List<string>();
if (_studyXml == null)
{
string studyXml = _location.GetStudyXmlPath();
if (!File.Exists(studyXml))
{
return fileList;
}
_studyXml = new StudyXml();
using (FileStream stream = FileStreamOpener.OpenForRead(studyXml, FileMode.Open))
{
var theMemento = new StudyXmlMemento();
StudyXmlIo.Read(theMemento, stream);
stream.Close();
_studyXml.SetMemento(theMemento);
}
}
// Note, we try and force ourselves to have an uncompressed
// image, if one exists. That way the rules will be reapplied on the object
// if necessary for compression.
foreach (SeriesXml seriesXml in _studyXml)
{
InstanceXml saveInstance = null;
foreach (InstanceXml instance in seriesXml)
{
if (instance.TransferSyntax.Encapsulated)
{
if (saveInstance == null)
saveInstance = instance;
}
else
{
saveInstance = instance;
break;
}
}
if (saveInstance != null)
{
string path = Path.Combine(_location.GetStudyPath(), seriesXml.SeriesInstanceUid);
path = Path.Combine(path, saveInstance.SopInstanceUid + ServerPlatform.DicomFileExtension);
fileList.Add(path);
}
}
return fileList;
}
示例7: TestMultipleSerializations
public void TestMultipleSerializations()
{
List<DicomFile> images = SetupImages(4);
XmlDocument doc = null;
StudyXml xml;
int i;
for(i = 0; i < images.Count; ++i)
{
xml = new StudyXml();
if (doc != null)
xml.SetMemento(doc);
xml.AddFile(images[i]);
StudyXmlOutputSettings settings = new StudyXmlOutputSettings();
doc = xml.GetMemento(settings);
}
xml = new StudyXml();
xml.SetMemento(doc);
List<InstanceXmlDicomAttributeCollection> dataSets = GetInstanceXmlDataSets(xml);
i = 0;
foreach (DicomFile file in images)
ValidateEqualExceptExclusions(file.DataSet, dataSets[i++], DicomTags.ImageComments, DicomTags.PixelData);
}
示例8: TestExcludeBinaryTags
public void TestExcludeBinaryTags()
{
List<DicomFile> images = SetupImages(3);
images[2].DataSet[DicomTags.SpectroscopyData].Values = new float[6];
StudyXml xml = new StudyXml();
foreach (DicomFile file in images)
{
file.DataSet[DicomTags.RedPaletteColorLookupTableData].Values = new byte[256];
file.DataSet[DicomTags.GreenPaletteColorLookupTableData].Values = new byte[256];
file.DataSet[DicomTags.BluePaletteColorLookupTableData].Values = new byte[256];
xml.AddFile(file);
}
StudyXmlOutputSettings settings = new StudyXmlOutputSettings();
settings.MaxTagLength = 100;
XmlDocument doc = xml.GetMemento(settings);
//SaveStudyXml(doc, @"C:\stewart\testxml.xml");
List<InstanceXmlDicomAttributeCollection> dataSets = GetInstanceXmlDataSets(xml);
foreach (InstanceXmlDicomAttributeCollection dataSet in dataSets)
{
Assert.IsTrue(dataSet.IsTagExcluded(DicomTags.RedPaletteColorLookupTableData));
Assert.IsTrue(dataSet.IsTagExcluded(DicomTags.GreenPaletteColorLookupTableData));
Assert.IsTrue(dataSet.IsTagExcluded(DicomTags.BluePaletteColorLookupTableData));
}
//This attribute has a short value, so it should not be excluded.
Assert.IsFalse(dataSets[2].IsTagExcluded(DicomTags.SpectroscopyData));
xml = new StudyXml();
xml.SetMemento(doc);
dataSets = GetInstanceXmlDataSets(xml);
foreach (InstanceXmlDicomAttributeCollection dataSet in dataSets)
{
Assert.IsTrue(dataSet.IsTagExcluded(DicomTags.RedPaletteColorLookupTableData));
Assert.IsTrue(dataSet.IsTagExcluded(DicomTags.GreenPaletteColorLookupTableData));
Assert.IsTrue(dataSet.IsTagExcluded(DicomTags.BluePaletteColorLookupTableData));
}
//This attribute has a short value, so it should not be excluded.
Assert.IsFalse(dataSets[2].IsTagExcluded(DicomTags.SpectroscopyData));
}
示例9: TestExcludePrivateTags
public void TestExcludePrivateTags()
{
List<DicomFile> images = SetupImages(2);
StudyXml xml = new StudyXml();
DicomTag privateTag =
new DicomTag(0x00210010, "Private Tag", "Private Tag", DicomVr.LTvr, false, 1, uint.MaxValue, false);
foreach (DicomFile file in images)
{
file.DataSet[privateTag].SetStringValue("My Private Tag");
xml.AddFile(file);
}
StudyXmlOutputSettings settings = new StudyXmlOutputSettings();
XmlDocument doc = xml.GetMemento(settings);
List<InstanceXmlDicomAttributeCollection> dataSets = GetInstanceXmlDataSets(xml);
foreach (InstanceXmlDicomAttributeCollection dataSet in dataSets)
Assert.IsFalse(dataSet.Contains(privateTag));
xml = new StudyXml();
xml.SetMemento(doc);
dataSets = GetInstanceXmlDataSets(xml);
foreach (InstanceXmlDicomAttributeCollection dataSet in dataSets)
Assert.IsFalse(dataSet.Contains(privateTag));
}
示例10: TestBaseInstanceTagsPastEnd
public void TestBaseInstanceTagsPastEnd()
{
//NOTE: previously, this test failed because, during xml serialization, only the
//instance's own attributes were iterated over; if there were tags in the base instance
//that went past the end of the individual instances, no 'EmptyAttributes' got added
//to the xml and there would be extra attributes in the instances on deserialization.
List<DicomFile> images = SetupImages(2);
DicomFile smallFile = new DicomFile(null);
images.Add(smallFile);
base.SetupMetaInfo(smallFile);
DicomAttributeCollection theSet = smallFile.DataSet;
theSet[DicomTags.SpecificCharacterSet].SetStringValue("ISO_IR 100");
theSet[DicomTags.ImageType].SetStringValue("ORIGINAL\\PRIMARY\\OTHER\\M\\FFE");
theSet[DicomTags.InstanceCreationDate].SetStringValue("20070618");
theSet[DicomTags.InstanceCreationTime].SetStringValue("133600");
theSet[DicomTags.SopClassUid].SetStringValue(SopClass.MrImageStorageUid);
theSet[DicomTags.SopInstanceUid].SetStringValue(DicomUid.GenerateUid().UID);
theSet[DicomTags.StudyDate].SetStringValue("20070618");
theSet[DicomTags.StudyTime].SetStringValue("133600");
theSet[DicomTags.SeriesDate].SetStringValue("20070618");
theSet[DicomTags.SeriesTime].SetStringValue("133700");
theSet[DicomTags.AccessionNumber].SetStringValue("A1234");
theSet[DicomTags.Modality].SetStringValue("MR");
theSet[DicomTags.Manufacturer].SetStringValue("ClearCanvas");
theSet[DicomTags.ManufacturersModelName].SetNullValue();
theSet[DicomTags.InstitutionName].SetStringValue("Mount Sinai Hospital");
theSet[DicomTags.ReferringPhysiciansName].SetStringValue("Last^First");
theSet[DicomTags.StudyDescription].SetStringValue("HEART");
theSet[DicomTags.SeriesDescription].SetStringValue("Heart 2D EPI BH TRA");
theSet[DicomTags.StudyInstanceUid].SetStringValue(images[0].DataSet[DicomTags.StudyInstanceUid].ToString());
theSet[DicomTags.SeriesInstanceUid].SetStringValue(images[0].DataSet[DicomTags.SeriesInstanceUid].ToString());
theSet[DicomTags.SopInstanceUid].SetStringValue(DicomUid.GenerateUid().ToString());
StudyXml xml = new StudyXml();
foreach (DicomFile file in images)
xml.AddFile(file);
StudyXmlOutputSettings settings = new StudyXmlOutputSettings();
XmlDocument doc = xml.GetMemento(settings);
List<InstanceXmlDicomAttributeCollection> dataSets = GetInstanceXmlDataSets(xml);
int i = 0;
foreach (DicomFile file in images)
ValidateEqualExceptExclusions(file.DataSet, dataSets[i++], DicomTags.ImageComments, DicomTags.PixelData);
xml = new StudyXml();
xml.SetMemento(doc);
dataSets = GetInstanceXmlDataSets(xml);
i = 0;
foreach (DicomFile file in images)
ValidateEqualExceptExclusions(file.DataSet, dataSets[i++], DicomTags.ImageComments, DicomTags.PixelData);
}
示例11: TestExclusionsImmediatelyAfterSerialization
public void TestExclusionsImmediatelyAfterSerialization()
{
//NOTE: previously, this test failed because the excluded tags were not added to the
//xml collection until after it had been deserialized at least once from the xml.
foreach (string[] testSet in _overlappingTagTestSets)
{
List<DicomFile> images = SetupImages(testSet.Length);
SetTestAttribute(images, testSet);
StudyXml xml = new StudyXml();
foreach (DicomFile file in images)
xml.AddFile(file);
StudyXmlOutputSettings settings = new StudyXmlOutputSettings();
settings.MaxTagLength = 1024;
XmlDocument doc = xml.GetMemento(settings);
List<InstanceXmlDicomAttributeCollection> dataSets = GetInstanceXmlDataSets(xml);
ValidateSimpleDataSets(testSet, dataSets, settings);
//do a little extra validation, what the hay.
xml = new StudyXml();
xml.SetMemento(doc);
dataSets = GetInstanceXmlDataSets(xml);
ValidateSimpleDataSets(testSet, dataSets, settings);
}
}
示例12: TestEqualAfterSerialization
public void TestEqualAfterSerialization()
{
foreach (string[] testSet in _overlappingTagTestSets)
{
List<DicomFile> images = SetupImages(testSet.Length);
SetTestAttribute(images, testSet);
StudyXml xml = new StudyXml();
foreach (DicomFile file in images)
xml.AddFile(file);
StudyXmlOutputSettings settings = new StudyXmlOutputSettings();
settings.MaxTagLength = 1024;
XmlDocument doc = xml.GetMemento(settings);
List<InstanceXmlDicomAttributeCollection> dataSets = GetInstanceXmlDataSets(xml);
int i = 0;
foreach (DicomFile file in images)
ValidateEqualExceptExclusions(file.DataSet, dataSets[i++], DicomTags.ImageComments, DicomTags.PixelData);
xml = new StudyXml();
xml.SetMemento(doc);
dataSets = GetInstanceXmlDataSets(xml);
i = 0;
foreach (DicomFile file in images)
ValidateEqualExceptExclusions(file.DataSet, dataSets[i++], DicomTags.ImageComments, DicomTags.PixelData);
}
}
示例13: LoadStudyXml
/// <summary>
/// Load a <see cref="StudyXml"/> file for the <see cref="StudyLocation"/>
/// </summary>
/// <returns>The <see cref="StudyXml"/> instance</returns>
public StudyXml LoadStudyXml()
{
var theXml = new StudyXml();
string streamFile = GetStudyXmlPath();
if (File.Exists(streamFile))
{
using (Stream fileStream = FileStreamOpener.OpenForRead(streamFile, FileMode.Open))
{
var theDoc = new XmlDocument();
StudyXmlIo.Read(theDoc, fileStream);
theXml.SetMemento(theDoc);
fileStream.Close();
}
}
return theXml;
}
示例14: GetInstanceXmlDataSets
private static List<InstanceXmlDicomAttributeCollection> GetInstanceXmlDataSets(IEnumerable<DicomFile> images, out StudyXml newStudyXml, StudyXmlOutputSettings settings)
{
StudyXml xml = new StudyXml();
foreach (DicomFile image in images)
xml.AddFile(image);
XmlDocument doc = xml.GetMemento(settings);
//SaveStudyXml(doc, @"c:\stewart\LastStudyXml.xml");
newStudyXml = new StudyXml();
newStudyXml.SetMemento(doc);
doc = newStudyXml.GetMemento(settings);
//SaveStudyXml(doc, @"c:\stewart\LastStudyXml2.xml");
return GetInstanceXmlDataSets(newStudyXml);
}
示例15: TestSameSequenceWithExclusionsMultipleSerializations
public void TestSameSequenceWithExclusionsMultipleSerializations()
{
List<DicomFile> images = SetupImagesWithVoiLutSequenceA(3);
StudyXml newStudyXml;
StudyXmlOutputSettings settings = new StudyXmlOutputSettings();
settings.MaxTagLength = 1024;
List<DicomFile> first2Images = new List<DicomFile>();
first2Images.AddRange(images.GetRange(0, 2));
List<InstanceXmlDicomAttributeCollection> dataSets1 = GetInstanceXmlDataSets(first2Images, out newStudyXml, settings);
for (int i = 0; i < first2Images.Count; ++i)
{
DicomAttributeSQ sequence = (DicomAttributeSQ)dataSets1[i][DicomTags.VoiLutSequence];
for (int j = 0; j < sequence.Count; ++j)
Assert.IsTrue(((InstanceXmlDicomSequenceItem)sequence[j]).ExcludedTags[0].TagValue == DicomTags.LutData);
}
Assert.AreEqual(dataSets1[0][DicomTags.VoiLutSequence], dataSets1[1][DicomTags.VoiLutSequence]);
newStudyXml.AddFile(images[2]);
XmlDocument document = newStudyXml.GetMemento(settings);
//SaveStudyXml(document, @"c:\stewart\studyxml3.xml");
newStudyXml = new StudyXml();
newStudyXml.SetMemento(document);
List<InstanceXmlDicomAttributeCollection> dataSets2 = GetInstanceXmlDataSets(newStudyXml);
for (int i = 0; i < first2Images.Count; ++i)
{
DicomAttributeSQ sequence = (DicomAttributeSQ)dataSets2[i][DicomTags.VoiLutSequence];
for (int j = 0; j < sequence.Count; ++j)
Assert.IsTrue(((InstanceXmlDicomSequenceItem)sequence[j]).ExcludedTags[0].TagValue == DicomTags.LutData);
}
Assert.AreEqual(dataSets1[0][DicomTags.VoiLutSequence], dataSets2[0][DicomTags.VoiLutSequence]);
Assert.AreEqual(dataSets1[1][DicomTags.VoiLutSequence], dataSets2[1][DicomTags.VoiLutSequence]);
Assert.AreEqual(dataSets2[0][DicomTags.VoiLutSequence], dataSets2[1][DicomTags.VoiLutSequence]);
Assert.AreEqual(dataSets2[0][DicomTags.VoiLutSequence], dataSets2[2][DicomTags.VoiLutSequence]);
}