/// <summary> /// Disposes all resources being used by this <see cref="Sop"/>. /// </summary> /// <param name="disposing"></param> protected virtual void Dispose(bool disposing) { if (disposing && _dataSource != null) { _dataSource.Dispose(); _dataSource = null; } }
protected override void Dispose(bool disposing) { if (_sopDataSource != null) { _sopDataSource.Dispose(); _sopDataSource = null; } base.Dispose(disposing); }
/// <summary> /// Creates either a <see cref="Sop"/> or <see cref="ImageSop"/> based /// on the <see cref="SopClass"/> of the given <see cref="ISopDataSource"/>. /// </summary> public static Sop Create(ISopDataSource dataSource) { if (dataSource.IsImage) { return(new ImageSop(dataSource)); } else { return(new Sop(dataSource)); } }
private void Initialize(ISopDataSource dataSource) { //We want to explicitly enforce that image data sources are wrapped in ImageSops. IsImage = this is ImageSop; if (dataSource.IsImage != IsImage) { throw new ArgumentException("Data source/Sop type mismatch.", "dataSource"); } _dataSource = dataSource; }
protected override void Dispose(bool disposing) { if (disposing) { if (_sopDataSource != null) { _sopDataSource.Dispose(); _sopDataSource = null; } } base.Dispose(disposing); }
private void Initialize(ISopDataSource dataSource) { //We want to explicitly enforce that image data sources are wrapped in ImageSops. IsImage = this is ImageSop; if (dataSource.IsImage != IsImage) { throw new ArgumentException("Data source/Sop type mismatch.", "dataSource"); } //silently use shared/cached data source. _dataSourceReference = SopDataCache.Add(dataSource); }
public FusionSopDataSource(ISopDataSource realSopDataSource, PETFusionType type, IEnumerable<IDicomAttributeProvider> overlayFrames) { _realSopDataSource = realSopDataSource; _fusionHeaders = new DicomAttributeCollection() {ValidateVrLengths = false, ValidateVrValues = false}; var scEquipment = new ScEquipmentModuleIod(_fusionHeaders); scEquipment.ConversionType = @"WSD"; scEquipment.SecondaryCaptureDeviceManufacturer = @"ClearCanvas Inc."; scEquipment.SecondaryCaptureDeviceManufacturersModelName = ProductInformation.GetName(false, false); scEquipment.SecondaryCaptureDeviceSoftwareVersions = new[] {ProductInformation.GetVersion(true, true, true, true)}; // generate values for the General Image Module _fusionHeaders[DicomTags.ImageType].SetStringValue(@"DERIVED\SECONDARY"); _fusionHeaders[DicomTags.SourceImageSequence].Values = UpdateSourceImageSequence(realSopDataSource, overlayFrames); UpdateDerivationType(type); }
public static ISopDataCacheItemReference Add(ISopDataSource dataSource) { lock (_itemsLock) { CleanupDeadItems(); WeakReference weakReference = null; Item item = null; if (_items.ContainsKey(dataSource.SopInstanceUid)) { weakReference = _items[dataSource.SopInstanceUid]; try { item = weakReference.Target as Item; } catch (InvalidOperationException) { weakReference = null; item = null; } } if (weakReference == null) { weakReference = new WeakReference(null); _items[dataSource.SopInstanceUid] = weakReference; } if (item != null && weakReference.IsAlive) { if (!ReferenceEquals(item.RealDataSource, dataSource)) { dataSource.Dispose(); //silently dispose the new one, we already have it. } } else { item = new Item(dataSource); weakReference.Target = item; } return(new ItemReference(item)); } }
public FusionSopDataSource(ISopDataSource realSopDataSource, PETFusionType type, IEnumerable <IDicomAttributeProvider> overlayFrames) { _realSopDataSource = realSopDataSource; _fusionHeaders = new DicomAttributeCollection(); var scEquipment = new ScEquipmentModuleIod(_fusionHeaders); scEquipment.ConversionType = @"WSD"; scEquipment.SecondaryCaptureDeviceManufacturer = @"ClearCanvas Inc."; scEquipment.SecondaryCaptureDeviceManufacturersModelName = ProductInformation.GetName(false, false); scEquipment.SecondaryCaptureDeviceSoftwareVersions = new[] { ProductInformation.GetVersion(true, true, true, true) }; // generate values for the General Image Module _fusionHeaders[DicomTags.ImageType].SetStringValue(@"DERIVED\SECONDARY"); _fusionHeaders[DicomTags.SourceImageSequence].Values = UpdateSourceImageSequence(realSopDataSource, overlayFrames); UpdateDerivationType(type); }
private MockImageSop(ISopDataSource sopDataSource) : base(sopDataSource) { _sopDataSource = sopDataSource; }
/// <summary> /// Initializes a new instance of <see cref="ImageSop"/>. /// </summary> public ImageSop(ISopDataSource dataSource) : base(dataSource) { _functionalGroups = GetFunctionalGroupMap(DataSource); }
/// <summary> /// Initializes a new instance of <see cref="ImageSop"/>. /// </summary> public ImageSop(ISopDataSource dataSource) : base(dataSource) { _functionalGroups = new FunctionalGroupMapCache(DataSource, DataSource.SopClassUid); }
public void Dispose() { _dataSource = null; }
public Item(ISopDataSource realDataSource) { _realDataSource = realDataSource; }
/// <summary> /// Creates a <see cref="Sop"/> from the given <see cref="ISopDataSource"/>. /// </summary> protected virtual Sop CreateSop(ISopDataSource dataSource) { return(Sop.Create(dataSource)); }
public void Initialize(ISopDataSource sopDataSource) { sopDataSource[DicomTags.ImageOrientationPatient].SetStringValue(this.ImageOrientationPatient); sopDataSource[DicomTags.ImagePositionPatient].SetStringValue(this.NextImagePositionPatient()); }
public SopArgumentHint(ISopDataSource dataSource) { _dataSource = dataSource; }
/// <summary> /// Creates either a <see cref="Sop"/> or <see cref="ImageSop"/> based /// on the <see cref="SopClass"/> of the given <see cref="ISopDataSource"/>. /// </summary> public static Sop Create(ISopDataSource dataSource) { return(dataSource.IsImage ? new ImageSop(dataSource) : new Sop(dataSource)); }
protected override void InitializeSopDataSource(ISopDataSource sopDataSource) { base.InitializeSopDataSource(sopDataSource); _dataSetOrientation.Initialize(sopDataSource); }
private static IDictionary <uint, FunctionalGroupDescriptor> GetFunctionalGroupMap(ISopDataSource sopDataSource) { return(new MultiFrameFunctionalGroupsModuleIod(sopDataSource).HasValues() ? FunctionalGroupDescriptor.GetFunctionalGroupMap(sopDataSource.SopClassUid) : null); }
/// <summary> /// Creates a <see cref="Sop"/> from the given <see cref="ISopDataSource"/>. /// </summary> protected virtual Sop CreateSop(ISopDataSource dataSource) { return Sop.Create(dataSource); }
public static List <OverlayPlaneGraphic> CreateOverlayPlaneGraphics(Frame frame, OverlayPlaneModuleIod overlaysFromPresentationState) { ISopDataSource dataSource = frame.ParentImageSop.DataSource; OverlayPlaneModuleIod overlaysIod = new OverlayPlaneModuleIod(dataSource); List <OverlayPlaneGraphic> overlayPlaneGraphics = new List <OverlayPlaneGraphic>(); bool failedOverlays = false; foreach (var overlayPlane in overlaysIod) { // DICOM 2009 PS 3.3 Section C.9.3.1.1 specifies the rule: NumberOfFramesInOverlay+ImageFrameOrigin-1 must be <= NumberOfFrames if (!overlayPlane.IsValidMultiFrameOverlay(frame.ParentImageSop.NumberOfFrames)) { failedOverlays = true; Platform.Log(LogLevel.Warn, new DicomOverlayDeserializationException(overlayPlane.Group, OverlayPlaneSource.Image), "Encoding error encountered while reading overlay from image headers."); continue; } try { byte[] overlayData = dataSource.GetFrameData(frame.FrameNumber).GetNormalizedOverlayData(overlayPlane.Index + 1); overlayPlaneGraphics.Add(new OverlayPlaneGraphic(overlayPlane, overlayData, OverlayPlaneSource.Image)); // if overlay data is null, the data source failed to retrieve the overlay data for some reason, so we also treat it as an encoding error // this is different from if the overlay data is zero-length, which indicates that the retrieval succeeded, but that the overlay data for the frame is empty if (overlayData == null) { throw new NullReferenceException(); } } catch (Exception ex) { failedOverlays = true; Platform.Log(LogLevel.Warn, new DicomOverlayDeserializationException(overlayPlane.Group, OverlayPlaneSource.Image, ex), "Failed to load overlay from the image header."); } } if (overlaysFromPresentationState != null) { foreach (var overlayPlane in overlaysFromPresentationState) { // if overlay data is missing, treat as an encoding error if (!overlayPlane.HasOverlayData) { failedOverlays = true; Platform.Log(LogLevel.Warn, new DicomOverlayDeserializationException(overlayPlane.Group, OverlayPlaneSource.PresentationState), "Encoding error encountered while reading overlay from softcopy presentation state."); continue; } try { byte[] overlayData; // try to compute the offset in the OverlayData bit stream where we can find the overlay frame that applies to this image frame int overlayFrame, bitOffset; if (overlayPlane.TryGetRelevantOverlayFrame(frame.FrameNumber, frame.ParentImageSop.NumberOfFrames, out overlayFrame) && overlayPlane.TryComputeOverlayDataBitOffset(overlayFrame, out bitOffset)) { // offset found - unpack only that overlay frame var od = new OverlayData(bitOffset, overlayPlane.OverlayRows, overlayPlane.OverlayColumns, overlayPlane.IsBigEndianOW, overlayPlane.OverlayData); overlayData = od.Unpack(); } else { // no relevant overlay frame found - i.e. the overlay for this image frame is blank overlayData = new byte[0]; } overlayPlaneGraphics.Add(new OverlayPlaneGraphic(overlayPlane, overlayData, OverlayPlaneSource.PresentationState)); } catch (Exception ex) { failedOverlays = true; Platform.Log(LogLevel.Warn, new DicomOverlayDeserializationException(overlayPlane.Group, OverlayPlaneSource.PresentationState, ex), "Failed to load overlay from softcopy presentation state."); } } } if (failedOverlays) { // add an error graphic if any overlays are not being displayed due to deserialization errors. overlayPlaneGraphics.Add(new ErrorOverlayPlaneGraphic(SR.MessageErrorDisplayingOverlays)); } return(overlayPlaneGraphics); }
public IImageProperty[] GetProperties(IPresentationImage image) { List <IImageProperty> properties = new List <IImageProperty>(); if (image != null && image.ParentDisplaySet != null) { IImageViewer viewer = image.ImageViewer; if (viewer != null) { IDicomDisplaySetDescriptor descriptor = image.ParentDisplaySet.Descriptor as IDicomDisplaySetDescriptor; if (descriptor != null && descriptor.SourceSeries != null) { string uid = descriptor.SourceSeries.SeriesInstanceUid; if (!String.IsNullOrEmpty(uid)) { StudyTree studyTree = viewer.StudyTree; Series keyObjectSeries = studyTree.GetSeries(uid); if (keyObjectSeries != null && keyObjectSeries.Sops.Count > 0) { Sop keyObjectSop = keyObjectSeries.Sops[0]; if (keyObjectSop.SopClassUid == SopClass.KeyObjectSelectionDocumentStorageUid) { ISopDataSource dataSource = keyObjectSop.DataSource; KeyObjectSelectionDocumentIod iod = new KeyObjectSelectionDocumentIod(dataSource); SrDocumentContentModuleIod content = iod.SrDocumentContent; GeneralEquipmentModuleIod equipment = iod.GeneralEquipment; if (content != null) { string codeValue = ""; CodeSequenceMacro conceptSequence = content.ConceptNameCodeSequence; if (conceptSequence != null) { KeyObjectSelectionDocumentTitle documentTitle = KeyObjectSelectionDocumentTitleContextGroup.LookupTitle(conceptSequence); if (documentTitle != null) { codeValue = documentTitle.ToString(); } } string documentDescription = ""; IContentSequence[] contentSequences = content.ContentSequence ?? new IContentSequence[0]; for (int i = contentSequences.Length - 1; i >= 0; --i) { IContentSequence contentSequence = contentSequences[i]; CodeSequenceMacro sequenceMacro = contentSequence.ConceptNameCodeSequence; if (sequenceMacro != null && sequenceMacro.CodeValue == KeyObjectSelectionCodeSequences.KeyObjectDescription.CodeValue) { documentDescription = contentSequence.TextValue; break; } } properties.Add( new ImageProperty("KeyImageDocumentTitle", SR.CategoryKeyImageSeries, SR.NameKeyImageDocumentTitle, SR.DescriptionKeyImageDocumentTitle, codeValue)); properties.Add( new ImageProperty("KeyImageDocumentDescription", SR.CategoryKeyImageSeries, SR.NameKeyImageDocumentDescription, SR.DescriptionKeyImageDocumentDescription, documentDescription)); properties.Add( new ImageProperty("KeyImageEquipmentManufacturer", SR.CategoryKeyImageEquipment, SR.NameManufacturer, SR.DescriptionManufacturer, equipment.Manufacturer ?? "")); properties.Add( new ImageProperty("KeyImageEquipmentManufacturersModelName", SR.CategoryKeyImageEquipment, SR.NameManufacturersModelName, SR.DescriptionManufacturersModelName, equipment.ManufacturersModelName ?? "")); properties.Add( new ImageProperty("KeyImageEquipmentSoftwareVersions", SR.CategoryKeyImageEquipment, SR.NameSoftwareVersions, SR.DescriptionSoftwareVersions, equipment.SoftwareVersions ?? "")); } } } } } } } return(properties.ToArray()); }
/// <summary> /// Creates a new instance of <see cref="Sop"/>. /// </summary> public Sop(ISopDataSource dataSource) { Initialize(dataSource); }
public IImageProperty[] GetProperties(IPresentationImage image) { List <IImageProperty> properties = new List <IImageProperty>(); if (image == null || !(image is IImageSopProvider)) { return(properties.ToArray()); } ISopDataSource dataSource = ((IImageSopProvider)image).ImageSop.DataSource; try { XmlDocument document = ImagePropertiesSettings.Default.StandardImagePropertiesXml; if (document == null) { Platform.Log(LogLevel.Debug, "StandardImagePropertiesXml setting document is null."); document = LoadDocumentFromResources(); } XmlNodeList groupNodes = document.SelectNodes("//standard-image-properties/image-property-group"); if (groupNodes == null || groupNodes.Count == 0) { Platform.Log(LogLevel.Debug, "StandardImagePropertiesXml setting document is empty or incorrectly formatted."); document = LoadDocumentFromResources(); groupNodes = document.SelectNodes("//standard-image-properties/image-property-group"); } if (groupNodes == null || groupNodes.Count == 0) { Platform.Log(LogLevel.Debug, "StandardImagePropertiesXml setting document is empty or incorrectly formatted."); return(properties.ToArray()); } foreach (XmlElement groupNode in groupNodes) { string category = ""; XmlAttribute categoryAttribute = groupNode.Attributes["name"]; if (categoryAttribute != null) { category = LookupCategory(categoryAttribute.Value); } XmlNodeList propertyNodes = groupNode.SelectNodes("image-property"); if (propertyNodes == null) { Platform.Log(LogLevel.Debug, "image-property-group element does not define any image-property elements"); continue; } foreach (XmlElement propertyNode in propertyNodes) { string tagVariableName = null; XmlAttribute tagVariableNameAttribute = propertyNode.Attributes["tag-variable-name"]; if (tagVariableNameAttribute != null) { tagVariableName = tagVariableNameAttribute.Value; } if (String.IsNullOrEmpty(tagVariableName)) { Platform.Log(LogLevel.Debug, "tag-variable-name attribute is empty"); continue; } var tag = LookupDicomTag(tagVariableName); if (tag == null) { Platform.Log(LogLevel.Debug, "tag-variable-name doesn't match a valid DicomTag"); continue; } string tagName = null; XmlAttribute attribute = propertyNode.Attributes["label"]; if (attribute != null) { tagName = attribute.Value; } string description = null; attribute = propertyNode.Attributes["description"]; if (attribute != null) { description = attribute.Value; } string separator = null; attribute = propertyNode.Attributes["separator"]; if (attribute != null) { separator = attribute.Value; } try { ImageProperty property = ImageProperty.Create(dataSource[tag], category, tagName, description, separator); properties.Add(property); } catch (Exception e) { Platform.Log(LogLevel.Debug, e, "Failed to create image property '{0}'.", tagName); } } } } catch (Exception e) { Platform.Log(LogLevel.Debug, e, "Failed to read in image properties xml."); } return(properties.ToArray()); }
public static ISopDataCacheItemReference Add(ISopDataSource dataSource) { lock(_itemsLock) { CleanupDeadItems(); WeakReference weakReference = null; Item item = null; if (_items.ContainsKey(dataSource.SopInstanceUid)) { weakReference = _items[dataSource.SopInstanceUid]; try { item = weakReference.Target as Item; } catch (InvalidOperationException) { weakReference = null; item = null; } } if (weakReference == null) { weakReference = new WeakReference(null); _items[dataSource.SopInstanceUid] = weakReference; } if (item != null && weakReference.IsAlive) { if (!ReferenceEquals(item.RealDataSource, dataSource)) dataSource.Dispose(); //silently dispose the new one, we already have it. } else { item = new Item(dataSource); weakReference.Target = item; } return new ItemReference(item); } }
/// <summary> /// Creates either a <see cref="Sop"/> or <see cref="ImageSop"/> based /// on the <see cref="SopClass"/> of the given <see cref="ISopDataSource"/>. /// </summary> public static Sop Create(ISopDataSource dataSource) { return dataSource.IsImage ? new ImageSop(dataSource) : new Sop(dataSource); }
protected virtual void InitializeSopDataSource(ISopDataSource sopDataSource) { }
private static IDictionary<uint, FunctionalGroupDescriptor> GetFunctionalGroupMap(ISopDataSource sopDataSource) { return new MultiFrameFunctionalGroupsModuleIod(sopDataSource).HasValues() ? FunctionalGroupDescriptor.GetFunctionalGroupMap(sopDataSource.SopClassUid) : null; }
private void Initialize(ISopDataSource dataSource) { //We want to explicitly enforce that image data sources are wrapped in ImageSops. IsImage = this is ImageSop; if (dataSource.IsImage != IsImage) throw new ArgumentException("Data source/Sop type mismatch.", "dataSource"); _dataSource = dataSource; }
public MprSliceSop(ISopDataSource dataSource) : base(dataSource) { }
/// <summary> /// Initializes a new instance of <see cref="ImageSop"/>. /// </summary> public ImageSop(ISopDataSource dataSource) : base(dataSource) { }
public SopDataSourceAdapter(ISopDataSource sopDataSource) { _sopDataSource = sopDataSource; }
protected override Sop CreateSop(ISopDataSource dataSource) { return(base.CreateSop(dataSource)); }