private void InitializeNecessaryLuts(Luts luts) { if (luts >= Luts.Modality && LutComposer.ModalityLut == null) { IModalityLut modalityLut = this.LutFactory.GetModalityLutLinear(this.BitsStored, this.IsSigned, _rescaleSlope, _rescaleIntercept); this.LutComposer.ModalityLut = modalityLut; } if (luts >= Luts.Voi && LutComposer.VoiLut == null) { IVoiLut lut = null; if (_voiLutFactory != null) { lut = _voiLutFactory.CreateVoiLut(this); } if (lut == null) { lut = new IdentityVoiLinearLut(); } (this as IVoiLutInstaller).InstallVoiLut(lut); } }
public override void Apply(IPresentationImage presentationImage) { if (!AppliesTo(presentationImage)) { throw new InvalidOperationException("The input presentation image is not supported."); } IVoiLutManager manager = ((IVoiLutProvider)presentationImage).VoiLutManager; IVoiLut currentLut = manager.VoiLut; if (currentLut is MinMaxPixelCalculatedLinearLut) { return; } GrayscalePixelData pixelData = (GrayscalePixelData)((IImageGraphicProvider)presentationImage).ImageGraphic.PixelData; IModalityLutProvider modalityLutProvider = presentationImage as IModalityLutProvider; if (modalityLutProvider != null) { manager.InstallVoiLut(new MinMaxPixelCalculatedLinearLut(pixelData, modalityLutProvider.ModalityLut)); } else { manager.InstallVoiLut(new MinMaxPixelCalculatedLinearLut(pixelData)); } }
public override bool ApplyNextLut() { IVoiLut currentLut = CurrentLut; State currentState = State.GetState(currentLut); if (currentLut is IAutoVoiLut) { var autoVoiLut = (IAutoVoiLut)currentLut; if (autoVoiLut.IsLast) { int nextState = _stateProgression.IndexOf(currentState) + 1; for (int n = nextState; n < nextState + _stateProgression.Count; n++) { IVoiLut lut = _stateProgression[(n % _stateProgression.Count)].GetLut(this); if (lut != null) { VoiLutManager.InstallVoiLut(lut); return(true); } } } else { autoVoiLut.ApplyNext(); return(true); } } else { ApplyInitialLut(); return(true); } return(false); }
public VoiLutMemento(IVoiLut originatingLut, bool invert) { Platform.CheckForNullReference(originatingLut, "originatingLut"); _originatingLut = originatingLut; _innerMemento = originatingLut.CreateMemento(); _invert = invert; }
void IVoiLutInstaller.InstallVoiLut(IVoiLut voiLut) { Platform.CheckForNullReference(voiLut, "voiLut"); InitializeNecessaryLuts(Luts.Modality); this.LutComposer.VoiLut = voiLut; }
private static IVoiLut GetInitialVoiLut(IGraphic graphic) { GrayscaleImageGraphic grayImageGraphic = (GrayscaleImageGraphic)graphic; IVoiLut lut = InitialVoiLutProvider.Instance.GetLut(graphic.ParentPresentationImage); if (lut == null) { lut = new MinMaxPixelCalculatedLinearLut(grayImageGraphic.PixelData, grayImageGraphic.ModalityLut); } return(lut); }
/// <summary> /// Installs a new Voi Lut. /// </summary> /// <param name="lut">The Lut to be installed.</param> public void InstallVoiLut(IVoiLut lut) { IVoiLut existingLut = GetLut(); if (existingLut is IGeneratedDataLut) { //Clear the data in the data lut so it's not hanging around using up memory. ((IGeneratedDataLut)existingLut).Clear(); } _voiLutInstaller.InstallVoiLut(lut); }
void IVoiLutManager.InstallLut(IVoiLut voiLut) { if (_realVoiLutManager != null) { _realVoiLutManager.InstallLut(voiLut); } else { _placeholderVoiLutManager.InstallLut(voiLut); } }
/// <summary> /// Determines and returns the initial Voi Lut that should be applied to the input <see cref="IPresentationImage"/>. /// </summary> /// <param name="presentationImage">The <see cref="IPresentationImage"/> whose intial Lut is to be determined.</param> /// <returns>The Voi Lut as an <see cref="IVoiLut"/>.</returns> public IVoiLut GetLut(IPresentationImage presentationImage) { IVoiLut lut = null; if (_extensionProvider != null) { lut = _extensionProvider.GetLut(presentationImage); } return(lut); }
public override IVoiLut GetInitialLut() { foreach (State state in _stateProgression) { IVoiLut lut = state.GetLut(this); if (lut != null) { return(lut); } } return(null); }
private static IVoiLut CloneVoiLut(IVoiLut source) { var clone = source.Clone(); if (clone == null) { var linearLut = source as IVoiLutLinear; if (linearLut != null) { clone = new BasicVoiLutLinear(linearLut.WindowWidth, linearLut.WindowCenter); } } return(clone); }
/// <summary> /// Attempts to install an appropriate equivalent of the specified <paramref name="sourceVoiLut"/> to a fusion image. If the LUT is not linear, computes a dummy LUT. /// </summary> private static void InstallVoiLut(FusionPresentationImage fusionImage, IVoiLut sourceVoiLut, Frame sourceFrame, bool applyToOverlay) { IVoiLut newVoiLut; if (sourceVoiLut is MinMaxPixelCalculatedLinearLut) { if (applyToOverlay) { // if the overlay source image is using a min/max calculated LUT, install a custom calculated LUT that delay-computes min/max from the fusion data // we need to delay-compute this because the fusion image graphic is delay-generated, and thus not necessarily available until just before rendering! var skipModalityLut = sourceFrame.ParentImageSop.Modality == @"PT" && sourceFrame.IsSubnormalRescale; newVoiLut = new FusionOverlayMinMaxVoiLutLinear(fusionImage, !skipModalityLut); } else { // if the base source image is using a min/max calculated LUT, install a similarly min/max calculated LUT for the base of the fusion image newVoiLut = new MinMaxPixelCalculatedLinearLut(fusionImage.ImageGraphic.PixelData); } } else if (sourceVoiLut is IVoiLutLinear) { var voiLutLinear = (IVoiLutLinear)sourceVoiLut; var normalizedVoiSlope = 1.0; var normalizedVoiIntercept = 0.0; if (applyToOverlay && sourceFrame.ParentImageSop.Modality == @"PT" && sourceFrame.IsSubnormalRescale) { // for subnormal PET rescale slope cases, the original VOI windows must be transformed through the same process as what MPR did to the pixel data normalizedVoiSlope = sourceFrame.RescaleSlope / fusionImage.OverlayFrameData.OverlayRescaleSlope; normalizedVoiIntercept = (sourceFrame.RescaleIntercept - fusionImage.OverlayFrameData.OverlayRescaleIntercept) / fusionImage.OverlayFrameData.OverlayRescaleSlope; } newVoiLut = new BasicVoiLutLinear(voiLutLinear.WindowWidth * normalizedVoiSlope, voiLutLinear.WindowCenter * normalizedVoiSlope + normalizedVoiIntercept); } else { // if the source image is using some non-linear LUT, just install a default pass-through LUT newVoiLut = new IdentityVoiLinearLut(); } if (applyToOverlay) { fusionImage.OverlayVoiLutManager.InstallVoiLut(newVoiLut); } else { fusionImage.BaseVoiLutManager.InstallVoiLut(newVoiLut); } }
protected void SerializeSoftcopyVoiLut(SoftcopyVoiLutModuleIod module, DicomPresentationImageCollection <T> images) { List <SoftcopyVoiLutModuleIod.SoftcopyVoiLutSequenceItem> voiLutSequenceItems = new List <SoftcopyVoiLutModuleIod.SoftcopyVoiLutSequenceItem>(); foreach (T image in images) { if (!image.VoiLutManager.Enabled) { continue; } SoftcopyVoiLutModuleIod.SoftcopyVoiLutSequenceItem sequenceItem = new SoftcopyVoiLutModuleIod.SoftcopyVoiLutSequenceItem(); sequenceItem.InitializeAttributes(); sequenceItem.ReferencedImageSequence = new ImageSopInstanceReferenceMacro[] { CreateImageSopInstanceReference(image.Frame) }; IVoiLut lut = image.VoiLutManager.VoiLut; if (lut is IDataLut) { IDataLut voiLut = (IDataLut)lut; sequenceItem.VoiLutSequence = new VoiLutSequenceItem[] { SerializeDataLut(voiLut) }; } else if (lut is IVoiLutLinear) { IVoiLutLinear voiLut = (IVoiLutLinear)lut; sequenceItem.WindowWidth = new double[] { voiLut.WindowWidth }; sequenceItem.WindowCenter = new double[] { voiLut.WindowCenter }; sequenceItem.WindowCenterWidthExplanation = new string[] { SR.LabelPresentationVoiLinearLut }; sequenceItem.VoiLutFunction = VoiLutFunction.Linear; // we don't support sigmoid } else { // should never happen - all VOI LUT object should implement either interface continue; } voiLutSequenceItems.Add(sequenceItem); } if (voiLutSequenceItems.Count > 0) { module.SoftcopyVoiLutSequence = voiLutSequenceItems.ToArray(); } }
private void InitializeNecessaryLuts(Luts luts) { if (luts >= Luts.Voi && LutComposer.VoiLut == null) { IVoiLut lut = null; if (_voiLutFactory != null) { lut = _voiLutFactory.CreateVoiLut(this); } if (lut == null) { lut = new IdentityVoiLinearLut(); } InstallVoiLut(lut); } }
public override IVoiLut GetInitialLut() { foreach (State state in _stateProgression) { IVoiLut lut = state.GetLut(this); if (lut != null) { if (lut is AutoVoiLutLinear) { if ((((AutoVoiLutLinear)lut).WindowCenter == 1600) && (((AutoVoiLutLinear)lut).WindowWidth == 2800)) { return(GetDefaultMinMaxLut()); } } return(lut); } } return(GetDefaultMinMaxLut()); }
public override string GetAnnotationText(IPresentationImage presentationImage) { if (presentationImage == null) { return(String.Empty); } IVoiLutProvider image = presentationImage as IVoiLutProvider; if (image == null || !image.VoiLutManager.Enabled) { return(String.Empty); } IVoiLut voiLut = image.VoiLutManager.VoiLut; if (voiLut == null) { return(String.Empty); } return(voiLut.GetDescription()); }
public static State GetState(IVoiLut currentLut) { if (currentLut is AdjustableDataLut) { var adj = (AdjustableDataLut)currentLut; if (adj.DataLut is AutoPresentationVoiDataLut) { return(PresentationData); } else if (adj.DataLut is AutoImageVoiDataLut) { return(ImageData); } } else if (currentLut is AutoPresentationVoiLutLinear) { return(PresentationLinear); } else if (currentLut is AutoImageVoiLutLinear) { return(ImageLinear); } return(null); }
private void InstallVoiLut(IVoiLut voiLut) { Platform.CheckForNullReference(voiLut, "voiLut"); this.LutComposer.VoiLut = voiLut; }
public XVoiLutInstaller(IVoiLutInstaller source) { DefaultInvert = this.Invert = source.Invert; this.VoiLut = source.VoiLut.Clone(); }
public XVoiLutInstaller() { DefaultInvert = this.Invert = false; this.VoiLut = new BasicVoiLutLinear(ushort.MaxValue + 1, 0); }
void IVoiLutInstaller.InstallVoiLut(IVoiLut voiLut) { InstallVoiLut(voiLut); }
private static IVoiLut CloneVoiLut(IVoiLut source) { var clone = source.Clone(); if (clone == null) { var linearLut = source as IVoiLutLinear; if (linearLut != null) clone = new BasicVoiLutLinear(linearLut.WindowWidth, linearLut.WindowCenter); } return clone; }
private void OnDisplaySetChanged(object sender, DisplaySetChangedEventArgs e) { if (e.OldDisplaySet != null) { _fusionDisplaySets.Remove(e.OldDisplaySet); } if (e.NewDisplaySet != null && e.NewDisplaySet.Descriptor is PETFusionDisplaySetDescriptor) { if (e.NewDisplaySet.ImageBox != null) { _fusionDisplaySets.Add(e.NewDisplaySet); // no point doing all this to find an appropriate VOI LUT if there are no images in the display set - but do update the fusionDisplaySets list! if (e.NewDisplaySet.PresentationImages.Count == 0) { return; } // find any available display set containing the same series as the individual layers and capture its VOI LUT IVoiLut baseVoiLut = null, overlayVoiLut = null; Frame baseFrame = null, overlayFrame = null; var descriptor = (PETFusionDisplaySetDescriptor)e.NewDisplaySet.Descriptor; foreach (IImageBox imageBox in ImageViewer.PhysicalWorkspace.ImageBoxes) { var selectedImage = imageBox.TopLeftPresentationImage; if (imageBox.DisplaySet == null || imageBox.DisplaySet.Descriptor is PETFusionDisplaySetDescriptor || !(selectedImage is IImageSopProvider && selectedImage is IVoiLutProvider)) { continue; } var seriesUid = ((IImageSopProvider)selectedImage).ImageSop.SeriesInstanceUid; if (baseVoiLut == null && seriesUid == descriptor.SourceSeries.SeriesInstanceUid) { baseVoiLut = ((IVoiLutProvider)selectedImage).VoiLutManager.VoiLut; baseFrame = ((IImageSopProvider)selectedImage).Frame; } else if (overlayVoiLut == null && seriesUid == descriptor.PETSeries.SeriesInstanceUid) { overlayVoiLut = ((IVoiLutProvider)selectedImage).VoiLutManager.VoiLut; overlayFrame = ((IImageSopProvider)selectedImage).Frame; } if (baseVoiLut != null && overlayVoiLut != null) { break; } } if (baseVoiLut == null || overlayVoiLut == null) { var fusionImage = (FusionPresentationImage)e.NewDisplaySet.PresentationImages[0]; if (baseVoiLut == null) { baseVoiLut = GetInitialVoiLut(baseFrame = fusionImage.Frame); } if (overlayVoiLut == null) { overlayVoiLut = GetInitialVoiLut(overlayFrame = fusionImage.OverlayFrameData.OverlayData.Frames[0]); } } // replicate the captured VOI LUTs to the fusion images foreach (FusionPresentationImage image in e.NewDisplaySet.PresentationImages) { if (baseVoiLut != null) { InstallVoiLut(image, baseVoiLut, baseFrame, false); } if (overlayVoiLut != null) { InstallVoiLut(image, overlayVoiLut, overlayFrame, true); } } } } }
public void InstallVoiLut(IVoiLut voiLut) { this.VoiLut = voiLut; }
/// <summary> /// Installs a new Voi Lut. /// </summary> /// <param name="lut">The Lut to be installed.</param> public void InstallLut(IVoiLut lut) { InstallVoiLut(lut); }
/// <summary> /// Attempts to install an appropriate equivalent of the specified <paramref name="sourceVoiLut"/> to a fusion image. If the LUT is not linear, computes a dummy LUT. /// </summary> private static void InstallVoiLut(FusionPresentationImage fusionImage, IVoiLut sourceVoiLut, Frame sourceFrame, bool applyToOverlay) { IVoiLut newVoiLut; if (sourceVoiLut is MinMaxPixelCalculatedLinearLut) { if (applyToOverlay) { // if the overlay source image is using a min/max calculated LUT, install a custom calculated LUT that delay-computes min/max from the fusion data // we need to delay-compute this because the fusion image graphic is delay-generated, and thus not necessarily available until just before rendering! var skipModalityLut = sourceFrame.ParentImageSop.Modality == @"PT" && sourceFrame.IsSubnormalRescale; newVoiLut = new FusionOverlayMinMaxVoiLutLinear(fusionImage, !skipModalityLut); } else { // if the base source image is using a min/max calculated LUT, install a similarly min/max calculated LUT for the base of the fusion image newVoiLut = new MinMaxPixelCalculatedLinearLut(fusionImage.ImageGraphic.PixelData); } } else if (sourceVoiLut is IVoiLutLinear) { var voiLutLinear = (IVoiLutLinear) sourceVoiLut; var normalizedVoiSlope = 1.0; var normalizedVoiIntercept = 0.0; if (applyToOverlay && sourceFrame.ParentImageSop.Modality == @"PT" && sourceFrame.IsSubnormalRescale) { // for subnormal PET rescale slope cases, the original VOI windows must be transformed through the same process as what MPR did to the pixel data normalizedVoiSlope = sourceFrame.RescaleSlope/fusionImage.OverlayFrameData.OverlayRescaleSlope; normalizedVoiIntercept = (sourceFrame.RescaleIntercept - fusionImage.OverlayFrameData.OverlayRescaleIntercept)/fusionImage.OverlayFrameData.OverlayRescaleSlope; } newVoiLut = new BasicVoiLutLinear(voiLutLinear.WindowWidth*normalizedVoiSlope, voiLutLinear.WindowCenter*normalizedVoiSlope + normalizedVoiIntercept); } else { // if the source image is using some non-linear LUT, just install a default pass-through LUT newVoiLut = new IdentityVoiLinearLut(); } if (applyToOverlay) fusionImage.OverlayVoiLutManager.InstallVoiLut(newVoiLut); else fusionImage.BaseVoiLutManager.InstallVoiLut(newVoiLut); }
public static State GetState(IVoiLut currentLut) { if (currentLut is AdjustableDataLut) { var adj = (AdjustableDataLut) currentLut; if (adj.DataLut is AutoPresentationVoiDataLut) return PresentationData; else if (adj.DataLut is AutoImageVoiDataLut) return ImageData; } else if (currentLut is AutoPresentationVoiLutLinear) { return PresentationLinear; } else if (currentLut is AutoImageVoiLutLinear) { return ImageLinear; } return null; }