static private void AddEllipse(DicomPre pre, float x, float y, float width, float height, float thickness, ColorMine.ColorSpaces.ColorSpace lineColor, int fileIndex = 0, int layerIndex = 0) { float x1 = x + width * 0.5F; float y1 = y; float x2 = x + width * 0.5F; float y2 = y + height; float x3 = x; float y3 = y + height * 0.5F; float x4 = x + width; float y4 = y + height * 0.5F; var graphicObjectItem = new DicomDataset { { DicomTag.GraphicAnnotationUnits, "PIXEL" }, { DicomTag.GraphicDimensions, (ushort)2 }, { DicomTag.NumberOfGraphicPoints, (ushort)4 }, { DicomTag.GraphicType, "ELLIPSE" }, { DicomTag.GraphicFilled, "N" }, { DicomTag.GraphicData, x1, y1, x2, y2, x3, y3, x4, y4 }, }; AddLineStyleSequence(graphicObjectItem, thickness, lineColor); pre.GraphicObjectSequences[fileIndex][layerIndex].Items.Add(graphicObjectItem); }
static private void AddPoint(DicomPre pre, float x, float y, float thickness, ColorMine.ColorSpaces.ColorSpace lineColor, int fileIndex = 0, int layerIndex = 0) { var graphicObjectItem = new DicomDataset { { DicomTag.GraphicAnnotationUnits, "PIXEL" }, { DicomTag.GraphicDimensions, (ushort)2 }, { DicomTag.NumberOfGraphicPoints, (ushort)1 }, { DicomTag.GraphicType, "POINT" }, { DicomTag.GraphicFilled, "N" }, { DicomTag.GraphicData, x, y }, }; AddLineStyleSequence(graphicObjectItem, thickness, lineColor); pre.GraphicObjectSequences[fileIndex][layerIndex].Items.Add(graphicObjectItem); }
static private void AddCircle(DicomPre pre, float x, float y, float diameter, float thickness, ColorMine.ColorSpaces.ColorSpace lineColor, int fileIndex = 0, int layerIndex = 0) { float x1 = x + diameter * 0.5F; float y1 = y + diameter * 0.5F; float x2 = x; float y2 = y; var graphicObjectItem = new DicomDataset { { DicomTag.GraphicAnnotationUnits, "PIXEL" }, { DicomTag.GraphicDimensions, (ushort)2 }, { DicomTag.NumberOfGraphicPoints, (ushort)2 }, { DicomTag.GraphicType, "CIRCLE" }, { DicomTag.GraphicFilled, "N" }, { DicomTag.GraphicData, x1, y1, x2, y2 }, }; AddLineStyleSequence(graphicObjectItem, thickness, lineColor); pre.GraphicObjectSequences[fileIndex][layerIndex].Items.Add(graphicObjectItem); }
static private void AddText(DicomPre pre, string text, float x, float y, float width, float height, int horizontalAlignment, int verticalAlignment, bool useBoundingBox, bool showAnchor, ColorMine.ColorSpaces.ColorSpace color, int fileIndex = 0, int layerIndex = 0) { float x1 = x; float y1 = y; float x2 = x + width; float y2 = y + height; var textObjectItem = new DicomDataset(); if (useBoundingBox) { textObjectItem.Add(DicomTag.BoundingBoxAnnotationUnits, "PIXEL"); textObjectItem.Add(DicomTag.BoundingBoxTopLeftHandCorner, x1, y1); textObjectItem.Add(DicomTag.BoundingBoxBottomRightHandCorner, x2, y2); textObjectItem.Add(DicomTag.BoundingBoxTextHorizontalJustification, horizontalAlignment == 0 ? "LEFT" : horizontalAlignment == 1 ? "RIGHT" : "CENTER"); } else { textObjectItem.Add(DicomTag.AnchorPointAnnotationUnits, "PIXEL"); textObjectItem.Add(DicomTag.AnchorPointVisibility, showAnchor ? "Y" : "N"); textObjectItem.Add(DicomTag.AnchorPoint, x1, y1); textObjectItem.Add(DicomTag.BoundingBoxTextHorizontalJustification, horizontalAlignment == 0 ? "LEFT" : horizontalAlignment == 1 ? "RIGHT" : "CENTER"); } textObjectItem.Add(DicomTag.UnformattedTextValue, Encoding.UTF8, text); var textStyleSequence = new DicomSequence(DicomTag.TextStyleSequence); var textStyleSequenceItem = new DicomDataset(); textStyleSequenceItem.Add(DicomTag.HorizontalAlignment, horizontalAlignment == 0 ? "LEFT" : horizontalAlignment == 1 ? "RIGHT" : "CENTER"); textStyleSequenceItem.Add(DicomTag.VerticalAlignment, verticalAlignment == 0 ? "BOTTOM" : verticalAlignment == 1 ? "TOP" : "CENTER"); if (color != null) { var dicomColor = GetDicomColor(color); textStyleSequenceItem.Add(DicomTag.TextColorCIELabValue, dicomColor.l, dicomColor.a, dicomColor.b); } textStyleSequence.Items.Add(textStyleSequenceItem); textObjectItem.Add(textStyleSequence); pre.TextObjectSequences[fileIndex][layerIndex].Items.Add(textObjectItem); }
static private DicomPre CreatePresentationState(string[] sourceFilePaths, bool colorSoftcopy, string seriesDescription, int layerCount = 1) { DicomPre pre = default; DicomSource[] sources = new DicomSource[sourceFilePaths.Length]; for (int sourceFileIndex = 0; sourceFileIndex != sourceFilePaths.Length; sourceFileIndex++) { DicomDataset sourceDataset = DicomFile.Open(sourceFilePaths[sourceFileIndex]).Dataset; sources[sourceFileIndex].StudyInstanceUid = sourceDataset.GetSingleValue <string>(DicomTag.StudyInstanceUID); sources[sourceFileIndex].SeriesInstanceUid = sourceDataset.GetSingleValue <string>(DicomTag.SeriesInstanceUID); sources[sourceFileIndex].SopInstanceUid = sourceDataset.GetSingleValue <string>(DicomTag.SOPInstanceUID); sources[sourceFileIndex].SopClassUid = sourceDataset.GetSingleValue <string>(DicomTag.SOPClassUID); sources[sourceFileIndex].Columns = sourceDataset.GetSingleValue <ushort>(DicomTag.Columns); sources[sourceFileIndex].Rows = sourceDataset.GetSingleValue <ushort>(DicomTag.Rows); sources[sourceFileIndex].PixelSpacings = sourceDataset.GetValues <double>(DicomTag.PixelSpacing); sources[sourceFileIndex].WindowCenters = sourceDataset.GetValues <double>(DicomTag.WindowCenter); sources[sourceFileIndex].WindowWidths = sourceDataset.GetValues <double>(DicomTag.WindowWidth); } pre.PresentationStateDataset = new DicomDataset(); pre.Columns = sources[0].Columns; pre.Rows = sources[0].Rows; pre.PresentationStateDataset.Add(DicomTag.StudyInstanceUID, sources[0].StudyInstanceUid); pre.PresentationStateDataset.Add(DicomTag.SeriesInstanceUID, DicomUIDGenerator.GenerateDerivedFromUUID().UID); pre.PresentationStateDataset.Add(DicomTag.SOPInstanceUID, DicomUIDGenerator.GenerateDerivedFromUUID().UID); pre.PresentationStateDataset.Add(DicomTag.SOPClassUID, colorSoftcopy ? DicomUID.ColorSoftcopyPresentationStateStorage : DicomUID.GrayscaleSoftcopyPresentationStateStorage); pre.PresentationStateDataset.Add(DicomTag.Modality, "PR"); pre.PresentationStateDataset.Add(DicomTag.SpecificCharacterSet, "ISO_IR 192"); pre.PresentationStateDataset.AddOrUpdate(DicomTag.SeriesDescription, seriesDescription); DicomSequence referencedSeriesSequence = new DicomSequence(DicomTag.ReferencedSeriesSequence); DicomDataset[] referencedSeriesDatasets = new DicomDataset[sourceFilePaths.Length]; for (int sourceFileIndex = 0; sourceFileIndex != sourceFilePaths.Length; sourceFileIndex++) { referencedSeriesDatasets[sourceFileIndex] = new DicomDataset().NotValidated(); referencedSeriesDatasets[sourceFileIndex].Add(DicomTag.SeriesInstanceUID, sources[0].SeriesInstanceUid); DicomSequence referencedImageSequence = new DicomSequence(DicomTag.ReferencedImageSequence); DicomDataset referencedImageDataset = new DicomDataset(); referencedImageDataset.Add(DicomTag.ReferencedSOPClassUID, sources[sourceFileIndex].SopClassUid); referencedImageDataset.Add(DicomTag.ReferencedSOPInstanceUID, sources[sourceFileIndex].SopInstanceUid); referencedImageSequence.Items.Add(referencedImageDataset); referencedSeriesDatasets[sourceFileIndex].Add(referencedImageSequence); referencedSeriesSequence.Items.Add(referencedSeriesDatasets[sourceFileIndex]); } pre.PresentationStateDataset.Add(referencedSeriesSequence); DicomSequence graphicLayerSequence = new DicomSequence(DicomTag.GraphicLayerSequence); for (int layerIndex = 0; layerIndex != layerCount; layerIndex++) { DicomDataset graphicLayerDataset = new DicomDataset(); graphicLayerDataset.Add(DicomTag.GraphicLayer, layerIndex.ToString()); graphicLayerDataset.Add(DicomTag.GraphicLayerOrder, layerIndex); graphicLayerSequence.Items.Add(graphicLayerDataset); } pre.PresentationStateDataset.Add(graphicLayerSequence); DicomSequence graphicAnnotationSequence = new DicomSequence(DicomTag.GraphicAnnotationSequence); pre.GraphicObjectSequences = new DicomSequence[sourceFilePaths.Length][]; pre.TextObjectSequences = new DicomSequence[sourceFilePaths.Length][]; for (int sourceFileIndex = 0; sourceFileIndex != sourceFilePaths.Length; sourceFileIndex++) { pre.GraphicObjectSequences[sourceFileIndex] = new DicomSequence[layerCount]; pre.TextObjectSequences[sourceFileIndex] = new DicomSequence[layerCount]; for (int layerIndex = 0; layerIndex != layerCount; layerIndex++) { DicomDataset graphicAnnotationDataset = new DicomDataset(); graphicAnnotationDataset.Add(referencedSeriesDatasets[sourceFileIndex].GetSequence(DicomTag.ReferencedImageSequence)); pre.GraphicObjectSequences[sourceFileIndex][layerIndex] = new DicomSequence(DicomTag.GraphicObjectSequence); pre.TextObjectSequences[sourceFileIndex][layerIndex] = new DicomSequence(DicomTag.TextObjectSequence); graphicAnnotationDataset.Add(pre.GraphicObjectSequences[sourceFileIndex][layerIndex]); graphicAnnotationDataset.Add(pre.TextObjectSequences[sourceFileIndex][layerIndex]); graphicAnnotationDataset.Add(DicomTag.GraphicLayer, layerIndex.ToString()); graphicAnnotationSequence.Items.Add(graphicAnnotationDataset); } } pre.PresentationStateDataset.Add(graphicAnnotationSequence); DicomSequence displayedAreaSelectionSequence = new DicomSequence(DicomTag.DisplayedAreaSelectionSequence); for (int sourceFileIndex = 0; sourceFileIndex != sourceFilePaths.Length; sourceFileIndex++) { DicomDataset displayedAreaSelectionDataset = new DicomDataset(); displayedAreaSelectionDataset.Add(referencedSeriesDatasets[sourceFileIndex].GetSequence(DicomTag.ReferencedImageSequence)); displayedAreaSelectionDataset.Add(DicomTag.DisplayedAreaTopLeftHandCorner, 1, 1); displayedAreaSelectionDataset.Add(DicomTag.DisplayedAreaBottomRightHandCorner, (int)pre.Columns, (int)pre.Rows); displayedAreaSelectionDataset.Add(DicomTag.PresentationSizeMode, "SCALE TO FIT"); displayedAreaSelectionDataset.Add(DicomTag.PresentationPixelSpacing, sources[sourceFileIndex].PixelSpacings); displayedAreaSelectionSequence.Items.Add(displayedAreaSelectionDataset); } pre.PresentationStateDataset.Add(displayedAreaSelectionSequence); DicomSequence softcopyVoiLutSequence = new DicomSequence(DicomTag.SoftcopyVOILUTSequence); DicomDataset softcopyVoiLutDataset = new DicomDataset(); softcopyVoiLutDataset.Add(DicomTag.WindowCenter, sources[0].WindowCenters); softcopyVoiLutDataset.Add(DicomTag.WindowWidth, sources[0].WindowWidths); softcopyVoiLutSequence.Items.Add(softcopyVoiLutDataset); pre.PresentationStateDataset.Add(softcopyVoiLutSequence); return(pre); }