private static void Execute(IImageBox imageBox, object unexplodeMemento)
			{
				MemorableUndoableCommand memorableCommand = new MemorableUndoableCommand(imageBox);
				memorableCommand.BeginState = imageBox.CreateMemento();

				IDisplaySet displaySet = imageBox.DisplaySet;
				IPresentationImage selectedImage;
				if (imageBox.SelectedTile != null)
					selectedImage = imageBox.SelectedTile.PresentationImage;
				else
					selectedImage = imageBox.TopLeftPresentationImage;

				imageBox.SetMemento(unexplodeMemento);

				//TODO (architecture): this wouldn't be necessary if we had a SetImageBoxGrid(imageBox[,]).
				//This stuff with mementos is actually a hacky workaround.

				bool locked = imageBox.DisplaySetLocked;
				imageBox.DisplaySetLocked = false;
				imageBox.DisplaySet = displaySet;
				imageBox.DisplaySetLocked = locked;

				if (selectedImage != null)
					imageBox.TopLeftPresentationImage = selectedImage;

				imageBox.Draw();
                imageBox.SelectDefaultTile();

				memorableCommand.EndState = imageBox.CreateMemento();

				DrawableUndoableCommand historyCommand = new DrawableUndoableCommand(imageBox);
				historyCommand.Name = SR.CommandExplodeTile;
				historyCommand.Enqueue(memorableCommand);
				imageBox.ParentPhysicalWorkspace.ImageViewer.CommandHistory.AddCommand(historyCommand);
			}
			public UnexplodeTileCommand(IImageBox imageBox, object unexplodeMemento, NotifyRemoveUnexplodedTileCommand remove)
			{
				_imageBox = imageBox;
				_unexplodeMemento = unexplodeMemento;
				_remove = remove;
				_listObserver = new ListObserver<ITile>(imageBox.Tiles, OnTilesChanged);
			}
Exemple #3
0
			public CrossHair(IImageBox imageBox, SpatialLocatorTool spatialLocatorTool)
			{
				ImageBox = imageBox;
				_spatialLocatorTool = spatialLocatorTool;

				_crosshairGraphic = new CrosshairGraphic();
				_crosshairGraphic.Drawing += OnGraphicDrawing;
			}
        public ImageBoxFrameSelectionStrategy(IImageBox imageBox, int window, NotifyChangedDelegate notifyChanged)
        {
            _notifyChanged = notifyChanged;
            _imageBox = imageBox;
            _imageBox.Drawing += OnImageBoxDrawing;

            _window = window;
            _frames = new Queue<Frame>();
            Refresh(true);
        }
Exemple #5
0
		private void CreateObjects()
		{
			_viewer = new ImageViewerComponent();
			_imageBox = new ImageBox();
			_tile1 = new Tile();
			_tile2 = new Tile();

			_imageSet = new ImageSet();
			_displaySet = new DisplaySet();
			_image1 = new TestPresentationImage();
			_image2 = new TestPresentationImage();
		}
Exemple #6
0
		public TestTree()
		{
			_viewer = new ImageViewerComponent();

			_imageBox1 = new ImageBox();
			_imageBox2 = new ImageBox();

			_tile1 = new Tile();
			_tile2 = new Tile();
			_tile3 = new Tile();
			_tile4 = new Tile();

			_imageSet1 = new ImageSet();

			_displaySet1 = new DisplaySet();
			_displaySet2 = new DisplaySet();

			_image1 = new TestPresentationImage();
			_image2 = new TestPresentationImage();
			_image3 = new TestPresentationImage();
			_image4 = new TestPresentationImage();

			_viewer.PhysicalWorkspace.ImageBoxes.Add(_imageBox1);
			_viewer.PhysicalWorkspace.ImageBoxes.Add(_imageBox2);

			_imageBox1.Tiles.Add(_tile1);
			_imageBox1.Tiles.Add(_tile2);
			_imageBox2.Tiles.Add(_tile3);
			_imageBox2.Tiles.Add(_tile4);

			_viewer.LogicalWorkspace.ImageSets.Add(_imageSet1);

			_imageSet1.DisplaySets.Add(_displaySet1);
			_imageSet1.DisplaySets.Add(_displaySet2);

			_displaySet1.PresentationImages.Add(_image1);
			_displaySet1.PresentationImages.Add(_image2);
			_displaySet2.PresentationImages.Add(_image3);
			_displaySet2.PresentationImages.Add(_image4);

			_imageBox1.DisplaySet = _displaySet1;
			_imageBox2.DisplaySet = _displaySet2;
		}
			internal static void AssignDisplaySetToImageBox(IImageBox imageBox, IDisplaySet displaySet)
			{
                MemorableUndoableCommand memorableCommand = new MemorableUndoableCommand(imageBox);
                memorableCommand.BeginState = imageBox.CreateMemento();

                // always create a 'fresh copy' to show in the image box.  We never want to show
                // the 'originals' (e.g. the ones in IImageSet.DisplaySets) because we want them 
                // to remain clean and unaltered - consider them to be templates for what actually
                // gets shown.
                imageBox.DisplaySet = displaySet.CreateFreshCopy();

                imageBox.Draw();
                //this.ImageViewer.SelectedImageBox[0, 0].Select();

                memorableCommand.EndState = imageBox.CreateMemento();

                DrawableUndoableCommand historyCommand = new DrawableUndoableCommand(imageBox);
                historyCommand.Enqueue(memorableCommand);
                imageBox.ImageViewer.CommandHistory.AddCommand(historyCommand);
            }
            private IAction[] CreateDisplaySetActions(IActionFactoryContext context)
            {
                List <IAction> actions = new List <IAction>();

                IImageBox imageBox = context.ImageViewer.SelectedImageBox;

                if (imageBox != null && !imageBox.DisplaySetLocked)
                {
                    foreach (IDisplaySet displaySet in context.ImageSet.DisplaySets)
                    {
                        IDisplaySet theDisplaySet = displaySet;
                        MenuAction  action        = CreateMenuAction(context, displaySet.Name,
                                                                     () => AssignDisplaySetToImageBox(context.ImageViewer, theDisplaySet));

                        action.Checked = context.ImageViewer.SelectedImageBox != null &&
                                         context.ImageViewer.SelectedImageBox.DisplaySet != null &&
                                         context.ImageViewer.SelectedImageBox.DisplaySet.Uid == theDisplaySet.Uid;

                        actions.Add(action);
                    }
                }

                return(actions.ToArray());
            }
		private bool CanUnexplodeImageBox(IImageBox imageBox)
		{
			if (imageBox == null)
				return false;

			IPhysicalWorkspace workspace = imageBox.ParentPhysicalWorkspace;
			if (workspace == null)
				return false;

			if (imageBox.DisplaySet == null)
			{
				CancelExplodeMode();
				return false;
			}

			return true;
		}
		private void ExplodeImageBox()
		{
			IImageBox imageBox = ImageViewer.SelectedImageBox;
			if (!CanExplodeImageBox(imageBox))
				return;

			IPhysicalWorkspace workspace = imageBox.ParentPhysicalWorkspace;
			MemorableUndoableCommand memorableCommand = new MemorableUndoableCommand(workspace);
			memorableCommand.BeginState = workspace.CreateMemento();

			_imageBoxesObserver.SuppressChangedEvent = true;

			//set this here so checked will be correct.
			_unexplodeMemento = memorableCommand.BeginState;
			_oldImageBox = imageBox;
			IDisplaySet displaySet = _oldImageBox.DisplaySet;
			IPresentationImage selectedImage = _oldImageBox.SelectedTile.PresentationImage;

			object imageBoxMemento = _oldImageBox.CreateMemento();
			workspace.SetImageBoxGrid(1, 1);
			IImageBox newImageBox = workspace.ImageBoxes[0];
			newImageBox.SetMemento(imageBoxMemento);

			//TODO (architecture): this wouldn't be necessary if we had a SetImageBoxGrid(imageBox[,]).
			//This stuff with mementos is actually a hacky workaround.

			bool locked = newImageBox.DisplaySetLocked;
			newImageBox.DisplaySetLocked = false;
			newImageBox.DisplaySet = displaySet;
			newImageBox.TopLeftPresentationImage = selectedImage;
			newImageBox.DisplaySetLocked = locked;

			_imageBoxesObserver.SuppressChangedEvent = false;

			workspace.Draw();
            workspace.SelectDefaultImageBox();

			memorableCommand.EndState = workspace.CreateMemento();
			DrawableUndoableCommand historyCommand = new DrawableUndoableCommand(workspace);
			historyCommand.Name = SR.CommandSurveyExplode;
			historyCommand.Enqueue(memorableCommand);
			base.ImageViewer.CommandHistory.AddCommand(historyCommand);

			OnCheckedChanged();
			UpdateEnabled();
		}
		private void ExplodeSelectedTile(IImageBox imageBox)
		{
			MemorableUndoableCommand memorableCommand = new MemorableUndoableCommand(imageBox);
			memorableCommand.BeginState = imageBox.CreateMemento();

			//set this here so checked will be correct.
			object unexplodeMemento = memorableCommand.BeginState;
			_unexplodeCommands[imageBox] = new UnexplodeTileCommand(imageBox, unexplodeMemento, RemoveUnexplodeCommand);
			
			IDisplaySet displaySet = imageBox.DisplaySet;
			IPresentationImage selectedImage = imageBox.SelectedTile.PresentationImage;
			imageBox.SetTileGrid(1, 1);

			//TODO (architecture): this wouldn't be necessary if we had a SetImageBoxGrid(imageBox[,]).
			//This stuff with mementos is actually a hacky workaround.

			bool locked = imageBox.DisplaySetLocked;
			imageBox.DisplaySetLocked = false;
			imageBox.DisplaySet = displaySet;
			imageBox.DisplaySetLocked = locked;

			imageBox.TopLeftPresentationImage = selectedImage;

			memorableCommand.EndState = imageBox.CreateMemento();

			DrawableUndoableCommand historyCommand = new DrawableUndoableCommand(imageBox);
			historyCommand.Name = SR.CommandExplodeTile;
			historyCommand.Enqueue(memorableCommand);
			imageBox.ParentPhysicalWorkspace.ImageViewer.CommandHistory.AddCommand(historyCommand);
		
			imageBox.Draw();
            imageBox.SelectDefaultTile();
        }
		private IEnumerable<IImageBox> GetTargetImageBoxes(IImageBox referenceImageBox)
		{
			foreach (IImageBox imageBox in this.Context.Viewer.PhysicalWorkspace.ImageBoxes)
			{
				if (imageBox != referenceImageBox && imageBox.DisplaySet != null && imageBox.DisplaySet.PresentationImages.Count > 1)
					yield return imageBox;
			}
		}
Exemple #13
0
        // Note: this algorithm is not bulletproof, but will always work when the workspace is completely visible
        // on any combination of monitors.  More specifically, where it starts to fail is when the center of the (default positioned)
        // image box falls off of all of the screens.  In those rare/extreme cases, we don't try to do any optimization
        // and use the simple rectangle calculation.
        private bool OptimizeImageBoxGrid()
        {
            Rectangle usableWorkspaceArea = GetUsableArea();

            if (usableWorkspaceArea.IsEmpty || usableWorkspaceArea.Width < 20 || usableWorkspaceArea.Height < 20)
            {
                return(false);
            }

            float rectangleWidth  = usableWorkspaceArea.Width / (float)_columns;
            float rectangleHeight = usableWorkspaceArea.Height / (float)_rows;

            var imageBoxesSet = new List <IImageBox>();

            foreach (Screen screen in Screen.AllScreens)
            {
                int firstRow    = -1;
                int lastRow     = -1;
                int firstColumn = -1;
                int lastColumn  = -1;

                //Find the first and last row/column defining a sub-grid that will be kept on this screen.
                //We use the center of each image box in the non-optimized case to determine what screen
                //a particular image box should be on.
                for (int row = 0; row < _rows; ++row)
                {
                    for (int column = 0; column < _columns; ++column)
                    {
                        int rectangleCentreX = usableWorkspaceArea.Left + (int)(rectangleWidth * (column + 0.5F));
                        int rectangleCentreY = usableWorkspaceArea.Top + (int)(rectangleHeight * (row + 0.5F));

                        if (screen.Bounds.Contains(rectangleCentreX, rectangleCentreY))
                        {
                            if (firstRow < 0)
                            {
                                firstRow = row;
                            }

                            lastRow = row;

                            if (firstColumn < 0)
                            {
                                firstColumn = column;
                            }

                            lastColumn = column;
                        }
                    }
                }

                Rectangle workspaceArea    = ScreenRectangle;
                Rectangle screenUsableArea = Rectangle.Intersect(workspaceArea, screen.WorkingArea);

                //Subdivide the occupied screen area into a grid based on the start/end row/column determined above.
                if (!screenUsableArea.IsEmpty && firstRow >= 0 && firstColumn >= 0)
                {
                    RectangleF normalizedScreenUsableArea = RectangleUtilities.CalculateNormalizedSubRectangle(workspaceArea, screenUsableArea);

                    int screenRows    = lastRow - firstRow + 1;
                    int screenColumns = lastColumn - firstColumn + 1;

                    float adjustedWidth  = normalizedScreenUsableArea.Width / screenColumns;
                    float adjustedHeight = normalizedScreenUsableArea.Height / screenRows;

                    for (int screenRow = 0; screenRow < screenRows; ++screenRow)
                    {
                        for (int screenColumn = 0; screenColumn < screenColumns; ++screenColumn)
                        {
                            IImageBox imageBox = this[firstRow + screenRow, firstColumn + screenColumn];

                            //same one was already set; fail.
                            if (imageBoxesSet.Contains(imageBox))
                            {
                                return(false);
                            }

                            imageBoxesSet.Add(imageBox);

                            float x = normalizedScreenUsableArea.Left + screenColumn * adjustedWidth;
                            float y = normalizedScreenUsableArea.Top + screenRow * adjustedHeight;

                            imageBox.NormalizedRectangle = new RectangleF(x, y, adjustedWidth, adjustedHeight);
                        }
                    }
                }
            }

            //Success only if every image box's rectangle was set exactly once.
            return(imageBoxesSet.Count == ImageBoxes.Count);
        }
		private static bool CanExplodeTiles(IImageBox imageBox)
		{
			return imageBox.Tiles.Count > 1 && !imageBox.ParentPhysicalWorkspace.Locked;
		}
Exemple #15
0
		private bool CaptureEndState()
		{
			if (_memorableCommand == null || _currentImageBox == null)
			{
				_currentImageBox = null;
                return false;
			}

            bool commandAdded = false;

			// If nothing's changed then just return
			if (_initialPresentationImageIndex != _currentImageBox.SelectedTile.PresentationImageIndex)
			{
				// Capture state after stack
				_memorableCommand.EndState = _currentImageBox.CreateMemento();
				if (!_memorableCommand.EndState.Equals(_memorableCommand.BeginState))
				{
					var historyCommand = new DrawableUndoableCommand(_currentImageBox) {Name = SR.CommandStack};
				    historyCommand.Enqueue(_memorableCommand);
                    Context.Viewer.CommandHistory.AddCommand(historyCommand);
				    commandAdded = true;
				}
			}

			_memorableCommand = null;
			_currentImageBox = null;

		    return commandAdded;
		}
		internal ImageBoxSelectedEventArgs(
			IImageBox selectedImageBox)
		{
			Platform.CheckForNullReference(selectedImageBox, "selectedImageBox");
			_selectedImageBox = selectedImageBox;
		}
		private static IEnumerable<DicomImagePlane> GetAllImagePlanes(IImageBox imageBox)
		{
			if (imageBox.DisplaySet != null)
			{
				for (int index = imageBox.DisplaySet.PresentationImages.Count - 1; index >= 0; --index)
				{
					DicomImagePlane targetPlane = DicomImagePlane.FromImage(imageBox.DisplaySet.PresentationImages[index]);
					if (targetPlane != null)
						yield return targetPlane;
				}
			}
		}
        /// <summary>
        /// Checks whether the specified series is loaded into the current ImageViewer.
        /// If not loaded, the method will load the series into the currently selected ImageBox.
        /// </summary>
        /// <param name="seriesInstanceUid">Series Instance UID to validate</param>
        /// <param name="imagePositionPatient">Image Position Patient from an image in the series</param>
        /// <param name="imageOrientationPatient">Image Orientation Patient from an image in the series</param>
        /// <param name="frameOfReferenceUid">Frame of Reference UID of the given series</param>
        /// <returns><value>true</value> is series now loaded, or <value>false</value> if no matching
        /// series could be found or loaded</returns>
        /// <remarks>Either <paramref name="seriesInstanceUid"/> or <paramref name="imagePositionPatient"/> and
        ///  <paramref name="imageOrientationPatient"/> must be not null</remarks>
        private bool EnsureSeriesIsLoaded(string seriesInstanceUid, double[] imagePositionPatient,
                                          double[] imageOrientationPatient, string frameOfReferenceUid)
        {
            if (string.IsNullOrEmpty(seriesInstanceUid) &&
                (imagePositionPatient == null || imageOrientationPatient == null))
            {
                return(false);
            }

            bool isLoaded = false;

            foreach (IImageBox imageBox in ImageViewer.PhysicalWorkspace.ImageBoxes.Where(
                         imageBox =>
                         imageBox != null && imageBox.DisplaySet != null && imageBox.DisplaySet.PresentationImages != null))
            {
                if (string.IsNullOrEmpty(seriesInstanceUid))
                {
                    IPresentationImage segPresentationImage = SegmentationGraphicsHelpers.
                                                              PresentationImageFromPositionOrientation(
                        imagePositionPatient,
                        imageOrientationPatient,
                        imageBox.DisplaySet,
                        frameOfReferenceUid);
                    if (segPresentationImage != null)
                    {
                        isLoaded = true;
                        break;
                    }
                }
                else
                {
                    IImageSopProvider imageSopProvider =
                        imageBox.DisplaySet.PresentationImages.OfType <IImageSopProvider>().FirstOrDefault();
                    if (imageSopProvider != null && imageSopProvider.Frame.SeriesInstanceUid == seriesInstanceUid)
                    {
                        isLoaded = true;
                        break;
                    }
                }
            }
            if (!isLoaded)
            {
                IImageBox targetImageBox = ImageViewer.PhysicalWorkspace.SelectedImageBox ??
                                           (ImageViewer.PhysicalWorkspace.ImageBoxes.Count > 0
                                                ? ImageViewer.PhysicalWorkspace.ImageBoxes[0]
                                                : null);
                if (targetImageBox == null)
                {
                    Platform.Log(LogLevel.Error, "Failed to find an ImageBox in which to load segmentation's series.");
                }
                else
                {
                    foreach (IImageSet imageSet in ImageViewer.LogicalWorkspace.ImageSets.Where(
                                 imageSet => imageSet != null && imageSet.DisplaySets != null))
                    {
                        foreach (IDisplaySet displaySet in imageSet.DisplaySets.Where(
                                     displaySet => displaySet != null && displaySet.PresentationImages != null))
                        {
                            if (string.IsNullOrEmpty(seriesInstanceUid))
                            {
                                IPresentationImage segPresentationImage = SegmentationGraphicsHelpers.
                                                                          PresentationImageFromPositionOrientation(
                                    imagePositionPatient,
                                    imageOrientationPatient,
                                    displaySet,
                                    frameOfReferenceUid);
                                if (segPresentationImage != null)
                                {
                                    IDisplaySet targetDisplaySet = displaySet.CreateFreshCopy();
                                    targetImageBox.DisplaySet = targetDisplaySet;
                                    // TODO - verify whether any of the Selected properties need re-setting
                                    isLoaded = true;
                                    break;
                                }
                            }
                            else
                            {
                                IImageSopProvider imageSopProvider =
                                    displaySet.PresentationImages.OfType <IImageSopProvider>().FirstOrDefault();
                                if (imageSopProvider != null &&
                                    imageSopProvider.Frame.SeriesInstanceUid == seriesInstanceUid)
                                {
                                    IDisplaySet targetDisplaySet = displaySet.CreateFreshCopy();
                                    targetImageBox.DisplaySet = targetDisplaySet;
                                    // TODO - verify whether any of the Selected properties need re-setting
                                    isLoaded = true;
                                    break;
                                }
                            }
                        }
                        if (isLoaded)
                        {
                            break;
                        }
                    }
                }
            }

            return(isLoaded);
        }
 internal ImageBoxSelectedEventArgs(
     IImageBox selectedImageBox)
 {
     Platform.CheckForNullReference(selectedImageBox, "selectedImageBox");
     _selectedImageBox = selectedImageBox;
 }
 internal ImageBoxDrawingEventArgs(IImageBox imageBox)
 {
     Platform.CheckForNullReference(imageBox, "imageBox");
     _imageBox = imageBox;
 }
 public void SetTileLayout(IImageBox imageBox)
 {
     _setTileLayout(imageBox);
 }
 private static bool CanExplodeTiles(IImageBox imageBox)
 {
     return(imageBox.Tiles.Count > 1 && !imageBox.ParentPhysicalWorkspace.Locked);
 }
 private void CancelExplodeMode()
 {
     _unexplodeMemento = null;
     _oldImageBox      = null;
     OnCheckedChanged();
 }
Exemple #24
0
		private void CaptureBeginState(IImageBox imageBox)
		{
			_memorableCommand = new MemorableUndoableCommand(imageBox) {BeginState = imageBox.CreateMemento()};
			// Capture state before stack
		    _currentImageBox = imageBox;

			_initialPresentationImageIndex = imageBox.SelectedTile.PresentationImageIndex;
		}
Exemple #25
0
			protected virtual void OnSliceSetChanged()
			{
				_sliceImageBox = null;
				EventsHelper.Fire(this.SliceSetChanged, this, EventArgs.Empty);
			}
Exemple #26
0
		private static void AdvanceImage(int increment, IImageBox selectedImageBox)
		{
		    int prevTopLeftPresentationImageIndex = selectedImageBox.TopLeftPresentationImageIndex;
			selectedImageBox.TopLeftPresentationImageIndex += increment;

            if (selectedImageBox.TopLeftPresentationImageIndex != prevTopLeftPresentationImageIndex)
                selectedImageBox.Draw(); 
		}
Exemple #27
0
		private CrossHair GetCrosshair(IImageBox imageBox)
		{
			CrossHair crossHair = _crosshairs.Find(
				delegate(CrossHair test)
					{
						return test.ImageBox == imageBox;
					});

			if (crossHair == null)
			{
				crossHair = new CrossHair(imageBox, this);
				_crosshairs.Add(crossHair);
			}

			return crossHair;
		}
Exemple #28
0
        public void ShowImageWithAnnotation(string aimUid)
        {
            if (_activeViewer == null)
            {
                return;
            }

            // Find Annotation
            aim_dotnet.Annotation annotationToShow = null;
            foreach (aim_dotnet.Annotation annotation in AvailableAnnotations)
            {
                if (annotation.UniqueIdentifier == aimUid)
                {
                    annotationToShow = annotation;
                    break;
                }
            }

            if (annotationToShow == null)
            {
                _activeViewer.DesktopWindow.ShowMessageBox("Could not locate annotation (UID = " + aimUid + ").", MessageBoxActions.Ok);
                return;
            }

            aim_dotnet.ImageStudy studyToOpen = AimStudyFromAnnotation(annotationToShow);
            if (studyToOpen == null)
            {
                _activeViewer.DesktopWindow.ShowMessageBox("Error reading image information (annotation UID = " + aimUid + ").", MessageBoxActions.Ok);
                return;
            }

            // Search displayed images first
            foreach (IImageBox imageBox in _activeViewer.PhysicalWorkspace.ImageBoxes)
            {
                if (imageBox.DisplaySet == null || imageBox.DisplaySet.PresentationImages == null || imageBox.DisplaySet.PresentationImages.Count == 0)
                {
                    continue;
                }

                IImageSopProvider imageSopProvider = imageBox.DisplaySet.PresentationImages[0] as IImageSopProvider;
                if (imageSopProvider == null)
                {
                    continue;
                }

                if (imageSopProvider.ImageSop.StudyInstanceUid == studyToOpen.InstanceUID &&
                    imageSopProvider.ImageSop.SeriesInstanceUid == studyToOpen.Series.InstanceUID)
                {
                    foreach (IPresentationImage presentationImage in imageBox.DisplaySet.PresentationImages)
                    {
                        imageSopProvider = presentationImage as IImageSopProvider;
                        if (imageSopProvider == null)
                        {
                            continue;
                        }
                        if (imageSopProvider.ImageSop.SopInstanceUid == studyToOpen.Series.ImageCollection[0].SopInstanceUID)
                        {
                            try
                            {
                                imageBox.TopLeftPresentationImage = presentationImage;
                                imageBox.Tiles[0].Select();
                                this.SelectAimGraphic(presentationImage, aimUid);
                                imageBox.Draw();

                                return;
                            }
                            catch (Exception ex)
                            {
                                ExceptionHandler.Report(ex, _desktopWindow);
                            }
                        }
                    }
                }
            }

            // Search other available images
            foreach (IImageSet imageSet in _activeViewer.LogicalWorkspace.ImageSets)
            {
                foreach (IDisplaySet displaySet in imageSet.DisplaySets)
                {
                    if (displaySet.PresentationImages.Count > 0)
                    {
                        IImageSopProvider imageSopProvider = displaySet.PresentationImages[0] as IImageSopProvider;
                        if (imageSopProvider == null)
                        {
                            continue;
                        }

                        if (imageSopProvider.ImageSop.StudyInstanceUid == studyToOpen.InstanceUID &&
                            imageSopProvider.ImageSop.SeriesInstanceUid == studyToOpen.Series.InstanceUID)
                        {
                            foreach (IPresentationImage presentationImage in displaySet.PresentationImages)
                            {
                                imageSopProvider = presentationImage as IImageSopProvider;
                                if (imageSopProvider == null)
                                {
                                    continue;
                                }
                                if (imageSopProvider.ImageSop.SopInstanceUid == studyToOpen.Series.ImageCollection[0].SopInstanceUID)
                                {
                                    try
                                    {
                                        IImageBox targetImageBox = _activeViewer.PhysicalWorkspace.SelectedImageBox ??
                                                                   (_activeViewer.PhysicalWorkspace.ImageBoxes.Count > 0 ? _activeViewer.PhysicalWorkspace.ImageBoxes[0] : null);
                                        if (targetImageBox == null)
                                        {
                                            _activeViewer.DesktopWindow.ShowMessageBox("Failed to find available display", MessageBoxActions.Ok);
                                            Platform.Log(LogLevel.Error, "Failed to locate a target ImageBox to display requested annotation (aimUID=" + aimUid + ").");
                                            return;
                                        }

                                        IDisplaySet        targetDisplaySet        = displaySet.CreateFreshCopy();
                                        IPresentationImage targetPresentationImage = FindRequiredImage(targetDisplaySet.PresentationImages,
                                                                                                       studyToOpen.InstanceUID, studyToOpen.Series.InstanceUID,
                                                                                                       studyToOpen.Series.ImageCollection[0].SopInstanceUID);
                                        if (targetPresentationImage == null)
                                        {
                                            _activeViewer.DesktopWindow.ShowMessageBox("Failed to find required image", MessageBoxActions.Ok);
                                            Platform.Log(LogLevel.Error, "Failed to locate a target ImageBox to display requested annotation (aimUID=" + aimUid + ").");
                                            return;
                                        }

                                        targetImageBox.DisplaySet = targetDisplaySet;
                                        targetImageBox.TopLeftPresentationImage = targetPresentationImage;
                                        targetImageBox.Tiles[0].Select();
                                        this.SelectAimGraphic(targetPresentationImage, aimUid);
                                        targetImageBox.Draw();

                                        return;
                                    }
                                    catch (Exception ex)
                                    {
                                        ExceptionHandler.Report(ex, _desktopWindow);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        private static void UnselectCurrentGraphics(IImageBox imageBox)
        {
            if (imageBox == null)
                return;

            if (imageBox.TopLeftPresentationImage != null)
            {
                imageBox.TopLeftPresentationImage.SelectedGraphic = null;
                imageBox.Draw();
            }
        }
Exemple #30
0
 protected virtual void OnSliceSetChanged()
 {
     _sliceImageBox = null;
     EventsHelper.Fire(this.SliceSetChanged, this, EventArgs.Empty);
 }
        public void AdvanceDisplaySet(int direction)
        {
            if (!Enabled)
            {
                return;
            }

            IDisplaySet sourceDisplaySet = GetSourceDisplaySet();

            if (sourceDisplaySet == null)
            {
                return;
            }

            IImageBox imageBox       = base.Context.Viewer.SelectedImageBox;
            IImageSet parentImageSet = sourceDisplaySet.ParentImageSet;

            int sourceDisplaySetIndex = parentImageSet.DisplaySets.IndexOf(sourceDisplaySet);

            sourceDisplaySetIndex += direction;
            try
            {
                if (sourceDisplaySetIndex < 0)
                {
#if SUINING
                    ImageSop sop = ((IImageSopProvider)imageBox.TopLeftPresentationImage).ImageSop;
                    if (sop.Modality == "DX" || sop.Modality == "CR")
                    {
                        return;
                    }
#endif
                    if (base.Context.Viewer.LogicalWorkspace.ImageSets.Count >= 2)
                    {
                        int tempNum = 0;
                        foreach (IImageSet set in base.Context.Viewer.LogicalWorkspace.ImageSets)
                        {
                            if (set.Equals(parentImageSet))
                            {
                                tempNum++;
                                break;
                            }
                            tempNum++;
                        }
                        if (tempNum >= base.Context.Viewer.LogicalWorkspace.ImageSets.Count)
                        {
                            tempNum = 0;
                        }
                        parentImageSet        = base.Context.Viewer.LogicalWorkspace.ImageSets[tempNum];
                        sourceDisplaySetIndex = 0;
                    }
                    else
                    {
                        sourceDisplaySetIndex = parentImageSet.DisplaySets.Count - 1;
                    }
                }
                else if (sourceDisplaySetIndex >= parentImageSet.DisplaySets.Count)
                {
#if SUINING
                    ImageSop sop = ((IImageSopProvider)imageBox.TopLeftPresentationImage).ImageSop;
                    if (sop.Modality == "DX" || sop.Modality == "CR" || sop.Modality == "RF")
                    {
                        return;
                    }
#endif

                    if (base.Context.Viewer.LogicalWorkspace.ImageSets.Count >= 2)
                    {
                        int tempNum = 0;
                        foreach (IImageSet set in base.Context.Viewer.LogicalWorkspace.ImageSets)
                        {
                            if (set.Equals(parentImageSet))
                            {
                                tempNum++;
                                break;
                            }
                            tempNum++;
                        }

                        if (tempNum >= base.Context.Viewer.LogicalWorkspace.ImageSets.Count)
                        {
                            tempNum = 0;
                        }
                        parentImageSet        = base.Context.Viewer.LogicalWorkspace.ImageSets[tempNum];
                        sourceDisplaySetIndex = 0;
                    }
                    else
                    {
                        sourceDisplaySetIndex = 0;
                    }
                }
                //MemorableUndoableCommand memorableCommand = new MemorableUndoableCommand(imageBox);
                //memorableCommand.BeginState = imageBox.CreateMemento();

                imageBox.DisplaySet = parentImageSet.DisplaySets[sourceDisplaySetIndex].CreateFreshCopy();
                if (direction < 0)
                {
                    imageBox.TopLeftPresentationImageIndex = imageBox.DisplaySet.PresentationImages.Count - 1;
                }

                thumbileChanged(imageBox.DisplaySet);

                imageBox.Draw();
            }
            catch (Exception ex)
            {
            }
            //memorableCommand.EndState = imageBox.CreateMemento();

            //DrawableUndoableCommand historyCommand = new DrawableUndoableCommand(imageBox);
            //historyCommand.Enqueue(memorableCommand);
            //base.Context.Viewer.CommandHistory.AddCommand(historyCommand);
        }
		private void RemoveUnexplodeCommand(IImageBox imageBox)
		{
			if (_unexplodeCommands.ContainsKey(imageBox))
			{
				_unexplodeCommands[imageBox].Dispose();
				_unexplodeCommands.Remove(imageBox);
			}
		}
Exemple #33
0
        public void ShowImageWithAnnotation(string aimUid)
        {
            if (_activeViewer == null)
            {
                return;
            }

            // Find Annotation
            IAimAnnotationInstance annotationToShow = AvailableAnnotations.FirstOrDefault(annotation => annotation.UniqueIdentifier == aimUid);

            if (annotationToShow == null)
            {
                _activeViewer.DesktopWindow.ShowMessageBox("Could not locate annotation (UID = " + aimUid + ").", MessageBoxActions.Ok);
                return;
            }

            string studyInstanceUid;
            string seriesInstanceUid;
            string sopInstanceUid = null;
            int    frameNumber    = 1;

            if (annotationToShow is IAimImageAnnotationInstace)
            {
                var imageAnnotationToShow = (IAimImageAnnotationInstace)annotationToShow;
                studyInstanceUid  = imageAnnotationToShow.ImageStudyUid;
                seriesInstanceUid = imageAnnotationToShow.ImageSeriesUid;
                sopInstanceUid    = imageAnnotationToShow.FirstImageSopInstanceUid;
                frameNumber       = imageAnnotationToShow.FirstFrameNumber;
            }
            else
            {
                studyInstanceUid  = annotationToShow.ParentAimDocument.StudyInstanceUid;
                seriesInstanceUid = annotationToShow.ParentAimDocument.SeriesInstanceUid;
            }

            if (studyInstanceUid == null || seriesInstanceUid == null)
            {
                _activeViewer.DesktopWindow.ShowMessageBox("Error reading image information (annotation UID = " + aimUid + ").", MessageBoxActions.Ok);
                return;
            }

            // Search displayed images first
            foreach (IImageBox imageBox in _activeViewer.PhysicalWorkspace.ImageBoxes)
            {
                if (imageBox.DisplaySet == null || imageBox.DisplaySet.PresentationImages == null || imageBox.DisplaySet.PresentationImages.Count == 0)
                {
                    continue;
                }

                IImageSopProvider imageSopProvider = imageBox.DisplaySet.PresentationImages[0] as IImageSopProvider;
                if (imageSopProvider == null)
                {
                    continue;
                }

                if (imageSopProvider.ImageSop.StudyInstanceUid == studyInstanceUid &&
                    imageSopProvider.ImageSop.SeriesInstanceUid == seriesInstanceUid)
                {
                    foreach (IPresentationImage presentationImage in imageBox.DisplaySet.PresentationImages)
                    {
                        imageSopProvider = presentationImage as IImageSopProvider;
                        if (imageSopProvider == null)
                        {
                            continue;
                        }
                        // Note: will select the first image if there is no SOP Instance UID
                        if (sopInstanceUid == null ||
                            (imageSopProvider.ImageSop.SopInstanceUid == sopInstanceUid && imageSopProvider.Frame.FrameNumber == frameNumber))
                        {
                            try
                            {
                                // Unselect selected in a different image box
                                if (!imageBox.Selected)
                                {
                                    UnselectCurrentGraphics(_activeViewer.PhysicalWorkspace.SelectedImageBox);
                                }

                                imageBox.TopLeftPresentationImage = presentationImage;
                                imageBox.Tiles[0].Select();
                                SelectAimGraphic(presentationImage, aimUid);
                                imageBox.Draw();

                                return;
                            }
                            catch (Exception ex)
                            {
                                ExceptionHandler.Report(ex, _desktopWindow);
                            }
                        }
                    }
                }
            }

            // Search other available images
            foreach (IImageSet imageSet in _activeViewer.LogicalWorkspace.ImageSets)
            {
                foreach (IDisplaySet displaySet in imageSet.DisplaySets)
                {
                    if (displaySet.PresentationImages.Count > 0)
                    {
                        IImageSopProvider imageSopProvider = displaySet.PresentationImages[0] as IImageSopProvider;
                        if (imageSopProvider == null)
                        {
                            continue;
                        }

                        if (imageSopProvider.ImageSop.StudyInstanceUid == studyInstanceUid &&
                            imageSopProvider.ImageSop.SeriesInstanceUid == seriesInstanceUid)
                        {
                            foreach (IPresentationImage presentationImage in displaySet.PresentationImages)
                            {
                                imageSopProvider = presentationImage as IImageSopProvider;
                                if (imageSopProvider == null)
                                {
                                    continue;
                                }
                                // Note: will select the first image if there is no SOP Instance UID
                                if (sopInstanceUid == null ||
                                    (imageSopProvider.ImageSop.SopInstanceUid == sopInstanceUid && imageSopProvider.Frame.FrameNumber == frameNumber))
                                {
                                    try
                                    {
                                        IImageBox targetImageBox = _activeViewer.PhysicalWorkspace.SelectedImageBox ??
                                                                   (_activeViewer.PhysicalWorkspace.ImageBoxes.Count > 0 ? _activeViewer.PhysicalWorkspace.ImageBoxes[0] : null);
                                        if (targetImageBox == null)
                                        {
                                            _activeViewer.DesktopWindow.ShowMessageBox("Failed to find available display", MessageBoxActions.Ok);
                                            Platform.Log(LogLevel.Error, "Failed to locate a target ImageBox to display requested annotation (aimUID=" + aimUid + ").");
                                            return;
                                        }

                                        IDisplaySet        targetDisplaySet        = displaySet.CreateFreshCopy();
                                        IPresentationImage targetPresentationImage = FindRequiredImage(targetDisplaySet.PresentationImages,
                                                                                                       studyInstanceUid, seriesInstanceUid,
                                                                                                       sopInstanceUid, frameNumber);
                                        if (targetPresentationImage == null)
                                        {
                                            _activeViewer.DesktopWindow.ShowMessageBox("Failed to find required image", MessageBoxActions.Ok);
                                            Platform.Log(LogLevel.Error, "Failed to locate a target ImageBox to display requested annotation (aimUID=" + aimUid + ").");
                                            return;
                                        }

                                        // Unselect selected in a different image box
                                        if (!targetImageBox.Selected)
                                        {
                                            UnselectCurrentGraphics(_activeViewer.PhysicalWorkspace.SelectedImageBox);
                                        }

                                        targetImageBox.DisplaySet = targetDisplaySet;
                                        targetImageBox.TopLeftPresentationImage = targetPresentationImage;
                                        targetImageBox.Tiles[0].Select();
                                        SelectAimGraphic(targetPresentationImage, aimUid);
                                        targetImageBox.Draw();

                                        return;
                                    }
                                    catch (Exception ex)
                                    {
                                        ExceptionHandler.Report(ex, _desktopWindow);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
Exemple #34
0
		private IEnumerable<DicomImagePlane> GetTargetImagePlanes(IImageBox imageBox)
		{
			for (int i = imageBox.DisplaySet.PresentationImages.Count - 1; i >= 0; --i)
			{
				DicomImagePlane targetImagePlane = DicomImagePlane.FromImage(imageBox.DisplaySet.PresentationImages[i]);
				if (targetImagePlane != null && _referencePlane.IsInSameFrameOfReference(targetImagePlane))
					yield return targetImagePlane;
			}
		}
		private void SynchronizeImageBox(IImageBox referenceImageBox, IImageBox targetImageBox)
		{
			if (referenceImageBox.TopLeftPresentationImage == null)
				return;

			if (targetImageBox.TopLeftPresentationImage == null)
				return;

			DicomImagePlane referenceImagePlane = DicomImagePlane.FromImage(referenceImageBox.TopLeftPresentationImage);
			if (referenceImagePlane == null)
				return;

			IEnumerable<DicomImagePlane> targetImagePlanes = GetAllImagePlanes(targetImageBox);
			DicomImagePlane targetImagePlane = GetClosestParallelImagePlane(referenceImagePlane, targetImagePlanes);
			if (targetImagePlane == null)
				return;

			int lastIndex = targetImageBox.TopLeftPresentationImageIndex;
			targetImageBox.TopLeftPresentationImage = targetImagePlane.SourceImage;

			if (lastIndex != targetImageBox.TopLeftPresentationImageIndex)
			{
				if (!_imageBoxesToDraw.Contains(targetImageBox))
					_imageBoxesToDraw.Add(targetImageBox);
			}
		}
 private bool IsReferenceImageBox(IImageBox imageBox)
 {
     return(imageBox == _referencePlane.SourceImage.ParentDisplaySet.ImageBox);
 }
Exemple #37
0
		private bool IsReferenceImageBox(IImageBox imageBox)
		{
			return imageBox == _referencePlane.SourceImage.ParentDisplaySet.ImageBox;
		}
        //private static void AdvanceImage(int increment, IImageBox selectedImageBox)
        private void AdvanceImage(int increment, IImageBox selectedImageBox)
        {
            if (increment > 0)
            {
                GlobalData.direct = 1;
            }
            else
            {
                GlobalData.direct = -1;
            }

            int prevTopLeftPresentationImageIndex = selectedImageBox.TopLeftPresentationImageIndex;

            selectedImageBox.TopLeftPresentationImageIndex += increment;


            if (selectedImageBox.TopLeftPresentationImageIndex != prevTopLeftPresentationImageIndex)
            {
                selectedImageBox.Draw();
            }

            else
            {
                ImageViewerComponent view = this.ImageViewer as ImageViewerComponent;
                ActionModelNode      node = view.ToolbarModel;

                ActionModelNode tempNode = null;
                IAction []      action   = null;
                foreach (ActionModelNode tempnode in node.ChildNodes)
                {
                    if (tempnode.PathSegment.ResourceKey == "ToolbarSynchronizeStacking")
                    {
                        tempNode = tempnode;
                        break;
                    }
                }
                if (tempNode != null)
                {
                    action = tempNode.GetActionsInOrder();
                }
                if ((action != null) && (action.Count() > 0))
                {
                    ButtonAction ac = action[0] as ButtonAction;
                    if (ac.Checked == true)
                    {
                        return;
                    }
                }
                if (selectedImageBox.TopLeftPresentationImage == null)
                {
                    return;
                }
#if SUINING
                ImageSop sop = ((IImageSopProvider)selectedImageBox.TopLeftPresentationImage).ImageSop;
                if (sop.Modality == "CT" || sop.Modality == "MR")
                {
                    return;
                }
#endif
                if (increment > 0)
                {
                    AdvanceDisplaySet(1);
                }
                else
                {
                    AdvanceDisplaySet(-1);
                }
            }
        }
		private void CancelExplodeMode()
		{
			_unexplodeMemento = null;
			_oldImageBox = null;
			OnCheckedChanged();
		}
		private static bool CanExplodeImageBox(IImageBox imageBox)
		{
			if (imageBox == null)
				return false;

			if (imageBox.ParentPhysicalWorkspace == null)
				return false;

			if (imageBox.DisplaySet == null || imageBox.SelectedTile == null || imageBox.SelectedTile.PresentationImage == null)
				return false;

			return true;
		}
		internal ImageBoxDrawingEventArgs(IImageBox imageBox)
		{
			Platform.CheckForNullReference(imageBox, "imageBox");
			_imageBox = imageBox;
		}