internal void OnCreatingSeg() { _selectedSeg.OnCreatingSeg(); // Refreshes seg name in WPF control var selectedSeg = SelectedSeg; SelectedSeg = null; OnPropertyChanged("SelectedSeg"); SelectedSeg = selectedSeg; OnPropertyChanged("SelectedSeg"); }
public static void CreateSeriesGraphicsForSeg(IPresentationImage presentationImage, Seg seg, SegmentationDocument segmentationDocument, IDicomMessageSopDataSource dicomMessageSopDataSourceSop) { Platform.CheckForNullReference(presentationImage, "presentationImage"); Platform.CheckForNullReference(seg, "seg"); Platform.CheckForNullReference(segmentationDocument, "segmentationDocument"); SegmentImageData segImageData = seg.SegmentImageData; if (segImageData == null) { Platform.Log(LogLevel.Error, "Cannot create segmentation graphics when no segmentation imaging data is provided"); return; } var imageSopProvider = presentationImage as IImageSopProvider; if (imageSopProvider == null) { Platform.Log(LogLevel.Error, "Failed to populate SegFrameGraphics collection. Image is not an ImageSopProvider"); return; } DicomPixelData segmentationPixelData = DicomPixelData.CreateFrom(dicomMessageSopDataSourceSop.SourceMessage); var rawPixelData = (byte[]) dicomMessageSopDataSourceSop.SourceMessage.DataSet.GetAttribute(DicomTags.PixelData).Values; var pixelDataGetter = new Func<int, byte[]>(frameIndex => { if (segImageData.BitsStored == 1) { // Do unpacking int frameLength = segImageData.Rows* segImageData.Columns; var overlayData = new OverlayData(frameIndex*frameLength, segImageData.Rows, segImageData.Columns, false, rawPixelData); return overlayData.Unpack(); } if (segImageData.BitsStored == 8) { return segmentationPixelData.GetFrame(frameIndex); } throw new InvalidDataException( "Segmentation objects need to have BitsStored as either 1 or 8"); }); // NOTE: SegmentFrameData was already sorted foreach (SegmentFrameData segmentFrameData in segImageData.SegmentFrameData) { IPresentationImage segPresentationImage = null; // Get the presentation image if we have an image reference string referencedSopInstanceUid = segmentFrameData.ReferencedSopInstanceUid; int referencedImageFrameNumber = segmentFrameData.ReferencedFrameNumber ?? 1; if (!string.IsNullOrEmpty(referencedSopInstanceUid)) { segPresentationImage = presentationImage.ParentDisplaySet.PresentationImages.OfType<IImageSopProvider>() .FirstOrDefault(curImageSopProvider => curImageSopProvider != null && curImageSopProvider.ImageSop.SopInstanceUid == referencedSopInstanceUid && curImageSopProvider.Frame.FrameNumber == referencedImageFrameNumber) as IPresentationImage; } // Location defaults to 0, 0 unless determined otherwise from image position and image orientation var segLocation = new PointF(); // Get the presentation image from the image position and orientation if (segmentFrameData.ImagePositionPatient != null && segmentFrameData.ImagePositionPatient.Count() > 2 && segmentFrameData.ImageOrientationPatient != null && segmentFrameData.ImageOrientationPatient.Count() > 5) { var imagePositionPatient = new ImagePositionPatient( segmentFrameData.ImagePositionPatient[0], segmentFrameData.ImagePositionPatient[1], segmentFrameData.ImagePositionPatient[2]); var imageOrientationPatient = new ImageOrientationPatient( segmentFrameData.ImageOrientationPatient[0], segmentFrameData.ImageOrientationPatient[1], segmentFrameData.ImageOrientationPatient[2], segmentFrameData.ImageOrientationPatient[3], segmentFrameData.ImageOrientationPatient[4], segmentFrameData.ImageOrientationPatient[5]); IDisplaySet displaySet = presentationImage.ParentDisplaySet; if (segPresentationImage == null) { segPresentationImage = PresentationImageFromPositionOrientation( imagePositionPatient, imageOrientationPatient, displaySet, segImageData.FrameOfReferenceUid); } var imageSop = segPresentationImage as IImageSopProvider; if (imageSop != null) { Vector3D segImageLocation = imageSop.Frame.ImagePlaneHelper.ConvertToImagePlane(new Vector3D( (float) imagePositionPatient.X, (float) imagePositionPatient.Y, (float) imagePositionPatient.Z)); PointF? segPixelLocation = imageSop.Frame.ImagePlaneHelper.ConvertToImage( new PointF(segImageLocation.X, segImageLocation.Y)); if (segPixelLocation.HasValue) segLocation = segPixelLocation.Value; } } if (segPresentationImage != null) { SegFrameImageGraphic newGraphic = AddSegFrameImageGraphicToPresentationImage( segPresentationImage, segImageData.Rows, segImageData.Columns, segLocation.X, segLocation.Y, seg.Color, referencedImageFrameNumber, seg.Label, seg.Description, pixelDataGetter.Invoke(segmentFrameData.FrameNumber - 1), new SegmentationDocumentReference(segmentationDocument, seg.SegmentationNumber)); if (newGraphic != null && segPresentationImage == segPresentationImage.ParentDisplaySet.ImageBox.TopLeftPresentationImage) { newGraphic.Draw(); } } else { Platform.Log(LogLevel.Error, "Failed to find Presentation Image to display a segment on"); } } }
private SegmentationMenuInfo MenuInfoFromDocumentAndSeg(SegmentationDocument segmentationDocument, Seg seg, Sop sop) { if (seg.SegmentImageData != null && seg.SegmentImageData.SegmentFrameData != null && seg.SegmentImageData.SegmentFrameData.Count > 0) { return new SegmentationMenuInfo { DisplayLabel = seg.DisplayLabel, DisplayImageSeriesUid = seg.ImageSeriesUid, SegmentationNumber = seg.SegmentationNumber, SegmentationDocumentUid = segmentationDocument.SopInstanceUid, SeriesNumber = segmentationDocument.SeriesNumber, ImagePositionPatient = seg.SegmentImageData.SegmentFrameData[0].ImagePositionPatient, ImageOrientationPatient = seg.SegmentImageData.SegmentFrameData[0].ImageOrientationPatient, FrameOfReferenceUid = seg.SegmentImageData.FrameOfReferenceUid, PatientId = sop.PatientId, PatientsName = sop.PatientsName, StudyAccessionNumber = sop.AccessionNumber, StudyDate = sop.StudyDate, StudyTime = sop.StudyTime, StudyDescription = sop.StudyDescription, StudyInstanceUid = sop.StudyInstanceUid }; } return null; }
private void AddSegmentationMenuInfo(SegmentationDocument segmentationDocument, Seg seg, Sop sop) { if ( !_segmentationMenuInfos.ContainsKey( segmentationDocument.SopInstanceUid + seg.SegmentationNumber)) { SegmentationMenuInfo info = MenuInfoFromDocumentAndSeg(segmentationDocument, seg, sop); if (info != null) _segmentationMenuInfos.Add( segmentationDocument.SopInstanceUid + seg.SegmentationNumber, info); } }
internal static IEnumerable<SegFrameImageGraphic> GetSegmentationImageGraphicsFromSeg(IImageViewer imageViewer, Seg seg) { var segGraphics = new List<SegFrameImageGraphic>(); foreach (IImageBox imageBox in imageViewer.PhysicalWorkspace.ImageBoxes) { if (imageBox != null && imageBox.DisplaySet != null) { foreach (IPresentationImage presentationImage in imageBox.DisplaySet.PresentationImages) { var graphicsProvider = presentationImage as IOverlayGraphicsProvider; if (graphicsProvider != null) { segGraphics.AddRange(graphicsProvider.OverlayGraphics.OfType<SegFrameImageGraphic>().Where( segGraphic => segGraphic.SegmentationDocumentReference.SegmentationDocument.Segs.Contains(seg)).Where( segGraphic => segGraphic.SegmentationDocumentReference.SegmentNumber == seg.SegmentationNumber)); } } } } return segGraphics; }
internal static IEnumerable<ISegGraphic> GetAllSegmentationGraphicsFromSeg(IImageViewer imageViewer, Seg seg) { var graphics = new List<ISegGraphic>(); graphics.AddRange(seg.SegGraphics); graphics.AddRange(GetSegmentationImageGraphicsFromSeg(imageViewer, seg)); return graphics; }