public IAimObjectReference ReadXmlAnnotationFromString(AimVersion aimVersion, string xmlString) { IAimObjectReference aimObjectReference = null; switch (aimVersion) { case AimVersion.AimVersion3: { using (var aim3NativeHelper = new Aim3.Aim3NativeXmlHelper()) { aimObjectReference = aim3NativeHelper.ReadAnnotationFromString(xmlString); } } break; case AimVersion.AimVersion4: { using (var aim4NativeHelper = new Aim4.Aim4NativeXmlHelper()) { aimObjectReference = aim4NativeHelper.ReadAnnotationFromString(xmlString); } } break; default: Debug.Assert(false, "AimManager.ReadXmlAnnotationFromString: Unexpected AIM version"); break; } return(aimObjectReference); }
public AimFileInfo(AimVersion aimVersion, string studyInstanceUid, string seriesInstanceUid, string sopInstanceUid) : this() { AimVersion = aimVersion; StudyInstanceUid = studyInstanceUid; SeriesInstanceUid = seriesInstanceUid; SopInstanceUid = sopInstanceUid; }
public static List <string> ConvertAnnotationsFromXmlToDicomFiles(AimVersion aimVersion, List <string> xmlAnnotationsFilePathNames, IBackgroundTaskContext context, out List <string> invalidFiles) { Platform.CheckForNullReference(xmlAnnotationsFilePathNames, "xmlAnnotationsFilePathNames"); var convertedAnnotations = new List <string>(); invalidFiles = new List <string>(); switch (aimVersion) { case AimVersion.AimVersion3: { int cnt = 0; using (var aim3NativeXmlHelper = new Aim3.Aim3NativeXmlHelper()) { using (var aim3NativeDcmHelper = new Aim3.Aim3NativeDcmHelper()) { foreach (string aimFile in xmlAnnotationsFilePathNames.Where(pathName => pathName != null)) { // Read XML file ReportTaskProgress(context, cnt, xmlAnnotationsFilePathNames.Count, String.Format("Reading file {0}", Path.GetFileName(aimFile))); var annotations = aim3NativeXmlHelper.ReadAnnotationsFromFile(aimFile); if (annotations.IsNullOrEmpty()) { Platform.Log(LogLevel.Info, "No annotation is read from file {0}", Path.GetFileName(aimFile)); invalidFiles.Add(Path.GetFileName(aimFile)); } else { // Write to temp file ReportTaskProgress(context, cnt, xmlAnnotationsFilePathNames.Count, String.Format("Read {0} annotations from file {1}", annotations.Count, Path.GetFileName(aimFile))); int dcmFileCnt = 0; foreach (var annotation in annotations) { ReportTaskProgress(context, cnt, xmlAnnotationsFilePathNames.Count, String.Format("Writing converted annotation to temporary file [{0} of {1}]", ++dcmFileCnt, annotations.Count)); var tempFileName = aim3NativeDcmHelper.WriteAnnotationToTempFile(annotation); convertedAnnotations.Add(tempFileName); ReportTaskProgress(context, cnt, xmlAnnotationsFilePathNames.Count, String.Format("Wrote converted annotation to file {0} [{1} of {2}]", tempFileName, dcmFileCnt, annotations.Count)); } } if (context != null && context.CancelRequested) { break; } cnt++; } } } } break; case AimVersion.AimVersion4: { int cnt = 0; using (var aim4NativeXmlHelper = new Aim4.Aim4NativeXmlHelper()) { using (var aim4NativeDcmHelper = new Aim4.Aim4NativeDcmHelper()) { foreach (string aimFile in xmlAnnotationsFilePathNames.Where(pathName => pathName != null)) { // Read XML file ReportTaskProgress(context, cnt, xmlAnnotationsFilePathNames.Count, String.Format("Reading file {0}", Path.GetFileName(aimFile))); var annotation = aim4NativeXmlHelper.ReadAnnotationFromFile(aimFile); if (annotation == null) { Platform.Log(LogLevel.Info, "No annotation is read from file {0}", Path.GetFileName(aimFile)); invalidFiles.Add(Path.GetFileName(aimFile)); } else { // Write to temp file ReportTaskProgress(context, cnt, xmlAnnotationsFilePathNames.Count, String.Format("Read annotation collection from file {0}", Path.GetFileName(aimFile))); var tempFileName = aim4NativeDcmHelper.WriteAnnotationToTempFile(annotation); convertedAnnotations.Add(tempFileName); ReportTaskProgress(context, cnt, xmlAnnotationsFilePathNames.Count, String.Format("Wrote converted annotation collection to file {0}", tempFileName)); } if (context != null && context.CancelRequested) { break; } cnt++; } } } } break; default: Debug.Assert(false, "AimManager.ConvertAnnotationsFromXmlToDicomFiles: Unexpected AIM version"); break; } return(convertedAnnotations); }
/// <summary> /// Reads given AIM XML documents into memory /// </summary> /// <param name="aimVersion">Version of AIM given files are expected to be</param> /// <param name="filePaths">List of AIM XML documents on disk</param> /// <returns>Returns a dictionary of AIM file names mapped to the AIM XML document content</returns> public Dictionary <string, string> ReadXmlAnnotationsToMemory(AimVersion aimVersion, List <string> filePaths) { var uidToAnnotationDictionary = new Dictionary <string, string>(); if (filePaths.IsNullOrEmpty()) { return(uidToAnnotationDictionary); } switch (aimVersion) { case AimVersion.AimVersion3: { using (var aim3NativeHelper = new Aim3.Aim3NativeXmlHelper()) { foreach (var filePath in filePaths) { var annotations = aim3NativeHelper.ReadAnnotationsFromFile(filePath); if (annotations != null) { Debug.Assert(annotations.Count < 2, "AIM 3 XML Annotation document cannot have more than one annotation"); foreach (var annotation in annotations.Where(ann => ann != null)) { var strAnnotation = aim3NativeHelper.WriteXmlAnnotationToString(annotation); if (!String.IsNullOrEmpty(strAnnotation)) { uidToAnnotationDictionary.Add(filePath, strAnnotation); } } } } } } break; case AimVersion.AimVersion4: { using (var aim4NativeHelper = new Aim4.Aim4NativeXmlHelper()) { foreach (var filePath in filePaths) { var annotation = aim4NativeHelper.ReadAnnotationFromFile(filePath); if (annotation != null) { var strAnnotation = aim4NativeHelper.WriteXmlAnnotationToString(annotation); if (!String.IsNullOrEmpty(strAnnotation)) { uidToAnnotationDictionary.Add(filePath, strAnnotation); } } } } } break; default: Debug.Assert(false, "AimManager.ReadXmlAnnotationsToMemory: Unexpected AIM version"); break; } return(uidToAnnotationDictionary); }