public static List <aim_dotnet.Annotation> LoadAimAnnotations(IEnumerable <string> studyInstanceUids)
        {
            var annotationList = new List <aim_dotnet.Annotation>();

            using (var dcmModel = new aim_dotnet.DcmModel())
            {
                foreach (var studyInstanceUID in studyInstanceUids)
                {
                    var aimInstanceDictionary = GetAimInstanceDictionaryForStudy(studyInstanceUID);
                    var annotationSopsInfo    = aimInstanceDictionary[studyInstanceUID];
                    if (annotationSopsInfo == null)
                    {
                        continue;
                    }

                    foreach (var information in annotationSopsInfo)
                    {
                        try
                        {
                            annotationList.AddRange(dcmModel.ReadAnnotationsFromFile(information.InstanceFileName));
                        }
                        catch (Exception ex)
                        {
                            Platform.Log(LogLevel.Error, ex);
                        }
                    }
                }
            }

            return(annotationList.Count > 0 ? annotationList : null);
        }
        private void OnDisplaySetChanged(object sender, DisplaySetChangedEventArgs e)
        {
            if (e.NewDisplaySet != null && e.NewDisplaySet.Visible)
            {
                var uidCnt = new Dictionary <string, int>();
                foreach (var img in e.NewDisplaySet.PresentationImages)
                {
                    var imageSopPrivider = img as IImageSopProvider;
                    if (imageSopPrivider != null)
                    {
                        var studyInstanceUID = imageSopPrivider.ImageSop.StudyInstanceUid;
                        if (uidCnt.ContainsKey(studyInstanceUID))
                        {
                            uidCnt[studyInstanceUID] += 1;
                        }
                        else
                        {
                            uidCnt[studyInstanceUID] = 1;
                        }
                    }
                }

                var annotationList = new List <aim_dotnet.Annotation>();
                var dcmModel       = new aim_dotnet.DcmModel();
                foreach (var studyInstanceUID in uidCnt.Keys)
                {
                    InitializeAnnotationList(studyInstanceUID);
                    var annotationSopsInfo = _annotationDictionary[studyInstanceUID];
                    if (annotationSopsInfo == null)
                    {
                        continue;
                    }

                    foreach (var information in annotationSopsInfo)
                    {
                        try
                        {
                            annotationList.AddRange(dcmModel.ReadAnnotationsFromFile(information.InstanceFileName));
                        }
                        catch (Exception ex)
                        {
                            Platform.Log(LogLevel.Error, ex);
                        }
                    }
                }

                foreach (var annotation in annotationList)
                {
                    foreach (var img in e.NewDisplaySet.PresentationImages)
                    {
                        AimHelpers.ReadGraphicsFromAnnotation(annotation, img);
                    }
                }
            }
        }
Example #3
0
        protected void RetrieveAnnotationsFromAimService(object[] searchResults)
        {
            string         errorMsg = null;
            BackgroundTask task     = new BackgroundTask(
                delegate(IBackgroundTaskContext context)
            {
                try
                {
                    int cnt = 0;
                    BackgroundTaskProgress progress;
                    List <string> tmpAnnotations = new List <string>();
                    aim_dotnet.DcmModel dcmModel = new aim_dotnet.DcmModel();
                    foreach (AIMSearchResult result in searchResults)
                    {
                        cnt++;

                        if (result.RetrievedAnnotation == null)
                        {
                            continue;
                        }

                        progress = new BackgroundTaskProgress(cnt, searchResults.Length + 1, "Saving Annotation " + cnt);
                        context.ReportProgress(progress);

                        string tmpFileName = System.IO.Path.GetTempFileName();
                        dcmModel.WriteAnnotationToFile(result.RetrievedAnnotation, tmpFileName);
                        tmpAnnotations.Add(tmpFileName);
                    }
                    dcmModel = null;

                    if (tmpAnnotations.Count > 0)
                    {
                        progress = new BackgroundTaskProgress(searchResults.Length, searchResults.Length + 1, "Importing Annotations");
                        context.ReportProgress(progress);

                        this.ImportDicomFiles(tmpAnnotations);
                    }
                }
                catch (Exception ex)
                {
                    errorMsg = ex.Message;
                    Platform.Log(LogLevel.Error, ex, "Failed to import annotation(s)");
                }

                context.Complete(null);
            }, true);

            ProgressDialog.Show(task, this.Context.DesktopWindow, true, ProgressBarStyle.Blocks);

            if (!string.IsNullOrEmpty(errorMsg))
            {
                this.Context.DesktopWindow.ShowMessageBox(errorMsg, MessageBoxActions.Ok);
            }
        }
        protected void RetrieveAnnotationsFromAimService(object[] searchResults)
        {
            string errorMsg = null;
            BackgroundTask task = new BackgroundTask(
                delegate(IBackgroundTaskContext context)
                {
                    try
                    {
                        int cnt = 0;
                        BackgroundTaskProgress progress;
                        List<string> tmpAnnotations = new List<string>();
                        aim_dotnet.DcmModel dcmModel = new aim_dotnet.DcmModel();
                        foreach (AIMSearchResult result in searchResults)
                        {
                            cnt++;

                            if (result.RetrievedAnnotation == null)
                                continue;

                            progress = new BackgroundTaskProgress(cnt, searchResults.Length + 1, "Saving Annotation " + cnt);
                            context.ReportProgress(progress);

                            string tmpFileName = System.IO.Path.GetTempFileName();
                            dcmModel.WriteAnnotationToFile(result.RetrievedAnnotation, tmpFileName);
                            tmpAnnotations.Add(tmpFileName);
                        }
                        dcmModel = null;

                        if (tmpAnnotations.Count > 0)
                        {
                            progress = new BackgroundTaskProgress(searchResults.Length, searchResults.Length + 1, "Importing Annotations");
                            context.ReportProgress(progress);

                            this.ImportDicomFiles(tmpAnnotations);
                        }
                    }
                    catch (Exception ex)
                    {
                        errorMsg = ex.Message;
                        Platform.Log(LogLevel.Error, ex, "Failed to import annotation(s)");
                    }

                    context.Complete(null);

                }, true);

            ProgressDialog.Show(task, this.Context.DesktopWindow, true, ProgressBarStyle.Blocks);

            if (!string.IsNullOrEmpty(errorMsg))
                this.Context.DesktopWindow.ShowMessageBox(errorMsg, MessageBoxActions.Ok);
        }
        public static List<aim_dotnet.Annotation> LoadAimAnnotations(IEnumerable<string> studyInstanceUids)
        {
            var annotationList = new List<aim_dotnet.Annotation>();
            using (var dcmModel = new aim_dotnet.DcmModel())
            {
                foreach (var studyInstanceUID in studyInstanceUids)
                {
                    var aimInstanceDictionary = GetAimInstanceDictionaryForStudy(studyInstanceUID);
                    var annotationSopsInfo = aimInstanceDictionary[studyInstanceUID];
                    if (annotationSopsInfo == null)
                        continue;

                    foreach (var information in annotationSopsInfo)
                    {
                        try
                        {
                            annotationList.AddRange(dcmModel.ReadAnnotationsFromFile(information.InstanceFileName));
                        }
                        catch (Exception ex)
                        {
                            Platform.Log(LogLevel.Error, ex);
                        }
                    }
                }
            }

            return annotationList.Count > 0 ? annotationList : null;
        }
Example #6
0
        private void OnDisplaySetChanged(object sender, DisplaySetChangedEventArgs e)
        {
            // toDO - init annotation dictionary here!
            Console.WriteLine("OnDisplaySetChanged");

            // TODO - add/remove DisplaySet.PresentationImages.ItemAdded event handlers

            if (e.NewDisplaySet != null && e.NewDisplaySet.Visible)
            {
                Dictionary <string, int> uidCnt = new Dictionary <string, int>();
                foreach (IPresentationImage img in e.NewDisplaySet.PresentationImages)
                {
                    IImageSopProvider imageSopPrivider = img as IImageSopProvider;
                    if (imageSopPrivider != null)
                    {
                        string studyInstanceUID = imageSopPrivider.ImageSop.StudyInstanceUid;
                        if (uidCnt.ContainsKey(studyInstanceUID))
                        {
                            uidCnt[studyInstanceUID] += 1;
                        }
                        else
                        {
                            uidCnt[studyInstanceUID] = 1;
                        }
                    }
                }

                // 1. Init annotation objects
                List <aim_dotnet.Annotation> annotationList = new List <aim_dotnet.Annotation>();
                aim_dotnet.DcmModel          dcmModel       = new aim_dotnet.DcmModel();
                foreach (string studyInstanceUID in uidCnt.Keys)
                {
                    InitializeAnnotationList(studyInstanceUID);
                    List <AimSopInstanceInformation> annotationSopsInfo = _annotationDictionary[studyInstanceUID];
                    if (annotationSopsInfo == null)
                    {
                        continue;
                    }

                    foreach (AimSopInstanceInformation information in annotationSopsInfo)
                    {
                        try
                        {
                            annotationList.AddRange(dcmModel.ReadAnnotationsFromFile(information.InstanceFileName));
                        }
                        catch (Exception ex)
                        {
                            Platform.Log(LogLevel.Error, ex);
                        }
                    }
                }

                // 2. put markup on the images
                foreach (aim_dotnet.Annotation annotation in annotationList)
                {
                    foreach (IPresentationImage img in e.NewDisplaySet.PresentationImages)
                    {
                        AimHelpers.ReadGraphicsFromAnnotation(annotation, img);
                    }
                }
            }
        }
        private void OnDisplaySetChanged(object sender, DisplaySetChangedEventArgs e)
        {
            if (e.NewDisplaySet != null && e.NewDisplaySet.Visible)
            {
                var uidCnt = new Dictionary<string, int>();
                foreach (var img in e.NewDisplaySet.PresentationImages)
                {
                    var imageSopPrivider = img as IImageSopProvider;
                    if (imageSopPrivider != null)
                    {
                        var studyInstanceUID = imageSopPrivider.ImageSop.StudyInstanceUid;
                        if (uidCnt.ContainsKey(studyInstanceUID))
                            uidCnt[studyInstanceUID] += 1;
                        else
                            uidCnt[studyInstanceUID] = 1;
                    }
                }

                var annotationList = new List<aim_dotnet.Annotation>();
                var dcmModel = new aim_dotnet.DcmModel();
                foreach (var studyInstanceUID in uidCnt.Keys)
                {
                    InitializeAnnotationList(studyInstanceUID);
                    var annotationSopsInfo = _annotationDictionary[studyInstanceUID];
                    if (annotationSopsInfo == null)
                        continue;

                    foreach (var information in annotationSopsInfo)
                    {
                        try
                        {
                            annotationList.AddRange(dcmModel.ReadAnnotationsFromFile(information.InstanceFileName));
                        }
                        catch (Exception ex)
                        {
                            Platform.Log(LogLevel.Error, ex);
                        }
                    }
                }

                foreach (var annotation in annotationList)
                {
                    foreach (var img in e.NewDisplaySet.PresentationImages)
                    {
                        AimHelpers.ReadGraphicsFromAnnotation(annotation, img);
                    }
                }
            }
        }
		private void OnDisplaySetChanged(object sender, DisplaySetChangedEventArgs e)
		{
			// toDO - init annotation dictionary here!
			Console.WriteLine("OnDisplaySetChanged");

			// TODO - add/remove DisplaySet.PresentationImages.ItemAdded event handlers

			if (e.NewDisplaySet != null && e.NewDisplaySet.Visible)
			{
				Dictionary<string, int> uidCnt = new Dictionary<string, int>();
				foreach (IPresentationImage img in e.NewDisplaySet.PresentationImages)
				{
					IImageSopProvider imageSopPrivider = img as IImageSopProvider;
					if (imageSopPrivider != null)
					{
						string studyInstanceUID = imageSopPrivider.ImageSop.StudyInstanceUid;
						if (uidCnt.ContainsKey(studyInstanceUID))
							uidCnt[studyInstanceUID] += 1;
						else
							uidCnt[studyInstanceUID] = 1;
					}
				}

				// 1. Init annotation objects
				List<aim_dotnet.Annotation> annotationList = new List<aim_dotnet.Annotation>();
				aim_dotnet.DcmModel dcmModel = new aim_dotnet.DcmModel();
				foreach (string studyInstanceUID in uidCnt.Keys)
				{
					InitializeAnnotationList(studyInstanceUID);
					List<AimSopInstanceInformation> annotationSopsInfo = _annotationDictionary[studyInstanceUID];
					if (annotationSopsInfo == null)
						continue;

					foreach (AimSopInstanceInformation information in annotationSopsInfo)
					{
						try
						{
							annotationList.AddRange(dcmModel.ReadAnnotationsFromFile(information.InstanceFileName));
						}
						catch (Exception ex)
						{
							Platform.Log(LogLevel.Error, ex);
						}
					}
				}

				// 2. put markup on the images
				foreach (aim_dotnet.Annotation annotation in annotationList)
				{
					foreach (IPresentationImage img in e.NewDisplaySet.PresentationImages)
					{
						AimHelpers.ReadGraphicsFromAnnotation(annotation, img);
					}
				}
			}
		}