/// <summary> /// Get the film box size in inches. /// </summary> /// <param name="filmBox">Film box object.</param> /// <returns>Size in inches of film box.</returns> public static SizeF GetSizeInInch(this FilmBox filmBox) { // ReSharper disable once InconsistentNaming const float CM_PER_INCH = 2.54f; var filmSizeId = filmBox.FilmSizeID; if (filmSizeId.Contains("IN")) { var parts = filmSizeId.Split(new[] { "IN" }, StringSplitOptions.RemoveEmptyEntries); if (parts.Length == 2) { var width = parts[0].Replace('_', '.'); var height = parts[1].TrimStart('X').Replace('_', '.'); return(new SizeF(Single.Parse(width), Single.Parse(height))); } } else if (filmSizeId.Contains("CM")) { var parts = filmSizeId.Split(new[] { "CM" }, StringSplitOptions.RemoveEmptyEntries); if (parts.Length == 2) { var width = parts[0].Replace('_', '.'); var height = parts[1].TrimStart('X').Replace('_', '.'); return(new SizeF(Single.Parse(width) / CM_PER_INCH, Single.Parse(height) / CM_PER_INCH)); } } else if (filmSizeId == "A3") { return(new SizeF(29.7f / CM_PER_INCH, 42.0f / CM_PER_INCH)); } return(new SizeF(210 / CM_PER_INCH, 297 / CM_PER_INCH)); }
/// <summary> /// Print a film box on specified graphics. /// </summary> /// <param name="filmBox">Film box.</param> /// <param name="graphics">Graphics on which to draw the film box.</param> /// <param name="marginBounds">Margin bounds.</param> /// <param name="imageResolution">Image resolution.</param> public static void Print(this FilmBox filmBox, Graphics graphics, Rectangle marginBounds, int imageResolution) { var parts = filmBox.ImageDisplayFormat.Split('\\', ','); if (parts.Length > 0) { RectF[] boxes = null; if (parts[0] == "STANDARD") { boxes = FilmBox.PrintStandardFormat(parts, ToRectF(marginBounds)); } else if (parts[0] == "ROW") { boxes = FilmBox.PrintRowFormat(parts, ToRectF(marginBounds)); } else if (parts[0] == "COL") { boxes = FilmBox.PrintColumnFormat(parts, ToRectF(marginBounds)); } if (boxes == null) { throw new InvalidOperationException( string.Format("ImageDisplayFormat {0} invalid", filmBox.ImageDisplayFormat)); } for (var i = 0; i < filmBox.BasicImageBoxes.Count; i++) { filmBox.BasicImageBoxes[i].Print(graphics, boxes[i], imageResolution); } } }
private void PresentationLut_NoReferencedPresentationLutSequence_GetterReturnsNull() { var session = new FilmSession(DicomUID.BasicFilmSession); var box = new FilmBox(session, null, DicomTransferSyntax.ImplicitVRLittleEndian); Assert.Null(box.PresentationLut); }
public FilmBox StartFilmBox(string format, string orientation, string filmSize) { var filmBox = new FilmBox(FilmSession, null, DicomTransferSyntax.ExplicitVRLittleEndian) { ImageDisplayFormat = format, FilmOrienation = orientation, FilmSizeID = filmSize, MagnificationType = "NONE", BorderDensity = "BLACK", EmptyImageDensity = "BLACK" }; filmBox.Initialize(); FilmSession.BasicFilmBoxes.Add(filmBox); _currentFilmBox = filmBox; return filmBox; }
public void ImageSequence_NoSequenceInImageBox_ReturnsNull(DicomUID sopClassUid) { var session = new FilmSession(DicomUID.BasicFilmSession); var filmBox = new FilmBox(session, null, DicomTransferSyntax.ImplicitVRLittleEndian); var imageBox = new ImageBox(filmBox, sopClassUid, null); Assert.Null(imageBox.ImageSequence); }
/// <summary> /// Create basic film box clone for specfifed film box instance /// </summary> /// <param name="filmBox">Basic film box instance to clone</param> private FilmBox(FilmBox filmBox) : this(filmBox._filmSession.CloneFilmSession(), filmBox.SOPInstanceUID, filmBox) { foreach (var imageBox in filmBox.BasicImageBoxes) { BasicImageBoxes.Add(imageBox.Clone(this)); } }
void OnPrintPage(object sender, PrintPageEventArgs e) { _currentFilmBox.Print(e.Graphics, e.MarginBounds, 100); _currentFilmBox = null; _currentPage++; e.HasMorePages = _currentPage < FilmBoxFolderList.Count; }
public static ImageBox Load(FilmBox filmBox, string imageBoxFile) { var file = DicomFile.Open(imageBoxFile); var imageBox = new ImageBox(filmBox, file.FileMetaInfo.MediaStorageSOPClassUID, file.FileMetaInfo.MediaStorageSOPInstanceUID); file.Dataset.CopyTo(imageBox); return(imageBox); }
/// <summary> /// If requested, fill the box with black color. /// </summary> /// <param name="filmBox">Film box.</param> /// <param name="box">Rectangle.</param> /// <param name="graphics">Graphics.</param> private static void FillBox(FilmBox filmBox, RectF box, Graphics graphics) { if (filmBox.EmptyImageDensity == "BLACK") { RectF fillBox = box; if (filmBox.BorderDensity == "WHITE" && filmBox.Trim == "YES") { fillBox.Inflate(-BORDER, -BORDER); } using (var brush = new SolidBrush(Color.Black)) { graphics.FillRectangle(brush, fillBox.X, fillBox.Y, fillBox.Width, fillBox.Height); } } }
/// <summary> /// Create new basic film box and add it to the film session /// </summary> /// <param name="sopInstance">The new film box SOP instance UID</param> /// <param name="dataset">The new film box dataset</param> /// <returns>The created film box instance</returns> public FilmBox CreateFilmBox(DicomUID sopInstance, DicomDataset dataset) { DicomUID uid = sopInstance; if (uid == null || uid.UID == string.Empty) { uid = DicomUID.Generate(); } var filmBox = new FilmBox(this, uid, dataset); BasicFilmBoxes.Add(filmBox); return(filmBox); }
void OnQueryPageSettings(object sender, QueryPageSettingsEventArgs e) { OnStatusUpdate(string.Format("Printing film {0} of {1}", _currentPage + 1, FilmBoxFolderList.Count)); var filmBoxFolder = string.Format("{0}\\{1}", FullPrintJobFolder, FilmBoxFolderList[_currentPage]); var filmSession = FilmSession.Load(string.Format("{0}\\FilmSession.dcm", filmBoxFolder)); _currentFilmBox = FilmBox.Load(filmSession, filmBoxFolder); e.PageSettings.Margins.Left = 25; e.PageSettings.Margins.Right = 25; e.PageSettings.Margins.Top = 25; e.PageSettings.Margins.Bottom = 25; e.PageSettings.Landscape = _currentFilmBox.FilmOrienation == "LANDSCAPE"; }
public void Save_BasicFilmBox_CreatesRelevantFilesAndFolders() { var path = @".\Test Data\Film Box Test 1"; if (Directory.Exists(path)) Directory.Delete(path, true); Directory.CreateDirectory(path); var session = new FilmSession(DicomUID.BasicFilmSessionSOPClass); var box = new FilmBox(session, null, DicomTransferSyntax.ImplicitVRLittleEndian); box.BasicImageBoxes.Add(new ImageBox(box, DicomUID.BasicGrayscaleImageBoxSOPClass, null)); box.Save(path); Assert.True(File.Exists(Path.Combine(path, "FilmBox.dcm"))); Assert.True(File.Exists(Path.Combine(path, "FilmBox.txt"))); Assert.True(Directory.Exists(Path.Combine(path, "Images"))); Assert.True(Directory.GetFiles(Path.Combine(path, "Images")).Length > 0); }
/// <summary> /// Construct new ImageBox for specified filmBox using specified SOP class UID and SOP instance UID /// </summary> /// <param name="filmBox"></param> /// <param name="sopClass"></param> /// <param name="sopInstance"></param> public ImageBox(FilmBox filmBox, DicomUID sopClass, DicomUID sopInstance) { InternalTransferSyntax = DicomTransferSyntax.ExplicitVRLittleEndian; FilmBox = filmBox; SOPClassUID = sopClass; if (sopInstance == null || sopInstance.UID == string.Empty) { SOPInstanceUID = DicomUID.Generate(); } else { SOPInstanceUID = sopInstance; } Add(DicomTag.SOPClassUID, SOPClassUID); Add(DicomTag.SOPInstanceUID, SOPInstanceUID); }
/// <summary> /// Load a film box for a specific session from a specific folder. /// </summary> /// <param name="filmSession">Film session.</param> /// <param name="filmBoxFolder">Folder in which film box is stored.</param> /// <returns>Film box for the specified <paramref name="filmSession"/> located in the <paramref name="filmBoxFolder"/>.</returns> public static FilmBox Load(FilmSession filmSession, string filmBoxFolder) { var filmBoxFile = string.Format(@"{0}\FilmBox.dcm", filmBoxFolder); var file = DicomFile.Open(filmBoxFile); var filmBox = new FilmBox(filmSession, file.FileMetaInfo.MediaStorageSOPInstanceUID, file.Dataset); var imagesFolder = IOManager.CreateDirectoryReference(string.Format(@"{0}\Images", filmBoxFolder)); foreach (var image in imagesFolder.EnumerateFileNames("*.dcm")) { var imageBox = ImageBox.Load(filmBox, image); filmBox.BasicImageBoxes.Add(imageBox); } return(filmBox); }
/// <summary> /// Construct new ImageBox for specified filmBox using specified SOP class UID and SOP instance UID /// </summary> /// <param name="filmBox"></param> /// <param name="sopClass"></param> /// <param name="sopInstance"></param> public ImageBox(FilmBox filmBox, DicomUID sopClass, DicomUID sopInstance) : base() { this.InternalTransferSyntax = DicomTransferSyntax.ExplicitVRLittleEndian; FilmBox = filmBox; SOPClassUID = sopClass; if (sopInstance == null || sopInstance.UID == string.Empty) { SOPInstanceUID = DicomUID.Generate(); } else { SOPInstanceUID = sopInstance; } this.Add(DicomTag.SOPClassUID, SOPClassUID); this.Add(DicomTag.SOPInstanceUID, SOPInstanceUID); }
public void Load_BasicFilmBox_ExpectedSopClassFound() { var path = @".\Test Data\Film Box Test 2"; if (Directory.Exists(path)) Directory.Delete(path, true); Directory.CreateDirectory(path); var expected = DicomUID.Generate(); var session = new FilmSession(DicomUID.BasicFilmSessionSOPClass); var box = new FilmBox(session, expected, DicomTransferSyntax.ImplicitVRLittleEndian); box.BasicImageBoxes.Add(new ImageBox(box, DicomUID.BasicGrayscaleImageBoxSOPClass, null)); box.Save(path); var loaded = FilmBox.Load(session, path); var actual = loaded.SOPInstanceUID; Assert.Equal(expected, actual); Assert.True(loaded.BasicImageBoxes.Count > 0); }
public void Save_BasicFilmBox_CreatesRelevantFilesAndFolders() { var path = @".\Test Data\Film Box Test 1"; if (Directory.Exists(path)) { Directory.Delete(path, true); } Directory.CreateDirectory(path); var session = new FilmSession(DicomUID.BasicFilmSession); var box = new FilmBox(session, null, DicomTransferSyntax.ImplicitVRLittleEndian); box.BasicImageBoxes.Add(new ImageBox(box, DicomUID.BasicGrayscaleImageBox, null)); box.Save(path); Assert.True(File.Exists(Path.Combine(path, "FilmBox.dcm"))); Assert.True(File.Exists(Path.Combine(path, "FilmBox.txt"))); Assert.True(Directory.Exists(Path.Combine(path, "Images"))); Assert.True(Directory.GetFiles(Path.Combine(path, "Images")).Length > 0); }
public void Load_BasicFilmBox_ExpectedSopClassFound() { var path = @".\Test Data\Film Box Test 2"; if (Directory.Exists(path)) { Directory.Delete(path, true); } Directory.CreateDirectory(path); var expected = DicomUID.Generate(); var session = new FilmSession(DicomUID.BasicFilmSession); var box = new FilmBox(session, expected, DicomTransferSyntax.ImplicitVRLittleEndian); box.BasicImageBoxes.Add(new ImageBox(box, DicomUID.BasicGrayscaleImageBox, null)); box.Save(path); var loaded = FilmBox.Load(session, path); var actual = loaded.SOPInstanceUID; Assert.Equal(expected, actual); Assert.True(loaded.BasicImageBoxes.Count > 0); }
/// <summary> /// Load a film box for a specific session from a specific folder. /// </summary> /// <param name="filmSession">Film session.</param> /// <param name="filmBoxFolder">Folder in which film box is stored.</param> /// <returns>Film box for the specified <paramref name="filmSession"/> located in the <paramref name="filmBoxFolder"/>.</returns> public static FilmBox Load(FilmSession filmSession, string filmBoxFolder) { var filmBoxFile = string.Format(@"{0}\FilmBox.dcm", filmBoxFolder); var file = DicomFile.Open(filmBoxFile); var filmBox = new FilmBox(filmSession, file.FileMetaInfo.MediaStorageSOPInstanceUID, file.Dataset); var imagesFolder = IOManager.CreateDirectoryReference(string.Format(@"{0}\Images", filmBoxFolder)); foreach (var image in imagesFolder.EnumerateFileNames("*.dcm")) { var imageBox = ImageBox.Load(filmBox, image); filmBox.BasicImageBoxes.Add(imageBox); } return filmBox; }
private void OpenFilmBox() { var filmBox = new FilmBox(FilmSession, null, DicomTransferSyntax.ExplicitVRLittleEndian) { AnnotationDisplayFormatID = AnnotationDisplayFormatID, ConfigurationInformation = ConfigurationInformation, BorderDensity = BorderDensity, FilmOrientation = FilmOrientation, FilmSizeID = FilmSizeID, Illumination = Illumination, ImageDisplayFormat = ImageDisplayFormat, MagnificationType = MagnificationType, MaxDensity = MaxDensity, MinDensity = MinDensity, ReflectedAmbientLight = ReflectedAmbientLight, RequestedResolutionID = RequestedResolutionID, SmoothingType = SmoothingType, Trim = Trim }; if (!SpecifyReferenceSequance) { filmBox.EmptyImageDensity = EmptyImageDensity; } filmBox.Initialize(); FilmSession.BasicFilmBoxes.Add(filmBox); _currentFilmBox = filmBox; }
/// <summary> /// Construct new ImageBox cloned from another imagebox /// </summary> /// <param name="imageBox">The source ImageBox instance to clone</param> private ImageBox(ImageBox imageBox, FilmBox filmBox) : this(filmBox, imageBox.SOPClassUID, imageBox.SOPInstanceUID) { imageBox.CopyTo(this); this.InternalTransferSyntax = imageBox.InternalTransferSyntax; }
private void CloseFilmBox() { _currentFilmBox = null; }
public void EndFilmBox() { _currentFilmBox = null; }
private void OnPrintPage(object sender, PrintPageEventArgs e) { _currentFilmBox.Print(e.Graphics, e.MarginBounds, 100); _currentFilmBox = null; _currentPage++; e.HasMorePages = _currentPage < FilmBoxFolderList.Count; }
void OnQueryPageSettings(object sender, QueryPageSettingsEventArgs e) { OnStatusUpdate(string.Format("Printing film {0} of {1}", _currentPage + 1, FilmBoxList.Count)); _currentFilmBox = FilmBoxList[_currentPage]; e.PageSettings.Margins.Left = 25; e.PageSettings.Margins.Right = 25; e.PageSettings.Margins.Top = 25; e.PageSettings.Margins.Bottom = 25; e.PageSettings.Landscape = _currentFilmBox.FilmOrienation == "LANDSCAPE"; }
/// <summary> /// Clone the current IamgeBox and return new object /// </summary> /// <returns>Cloned ImageBox</returns> public ImageBox Clone(FilmBox filmBox) { return(new ImageBox(this, filmBox)); }
/// <summary> /// Clone the current IamgeBox and return new object /// </summary> /// <returns>Cloned ImageBox</returns> public ImageBox Clone(FilmBox filmBox) { return new ImageBox(this, filmBox); }
private void OnQueryPageSettings(object sender, QueryPageSettingsEventArgs e) { OnStatusUpdate(string.Format("Printing film {0} of {1}", _currentPage + 1, FilmBoxFolderList.Count)); var filmBoxFolder = string.Format("{0}\\{1}", FullPrintJobFolder, FilmBoxFolderList[_currentPage]); var filmSession = FilmSession.Load(string.Format("{0}\\FilmSession.dcm", filmBoxFolder)); _currentFilmBox = FilmBox.Load(filmSession, filmBoxFolder); e.PageSettings.Margins.Left = 25; e.PageSettings.Margins.Right = 25; e.PageSettings.Margins.Top = 25; e.PageSettings.Margins.Bottom = 25; e.PageSettings.Landscape = _currentFilmBox.FilmOrienation == "LANDSCAPE"; }
/// <summary> /// Construct new ImageBox cloned from another imagebox /// </summary> /// <param name="imageBox">The source ImageBox instance to clone</param> /// <param name="filmBox">The film box.</param> private ImageBox(ImageBox imageBox, FilmBox filmBox) : this(filmBox, imageBox.SOPClassUID, imageBox.SOPInstanceUID) { imageBox.CopyTo(this); InternalTransferSyntax = imageBox.InternalTransferSyntax; }
public static ImageBox Load(FilmBox filmBox, string imageBoxFile) { var file = DicomFile.Open(imageBoxFile); var imageBox = new ImageBox(filmBox, file.FileMetaInfo.MediaStorageSOPClassUID, file.FileMetaInfo.MediaStorageSOPInstanceUID); file.Dataset.CopyTo(imageBox); return imageBox; }
/// <summary> /// Create new basic film box and add it to the film session /// </summary> /// <param name="sopInstance">The new film box SOP instance UID</param> /// <param name="dataset">The new film box dataset</param> /// <returns>The created film box instance</returns> public FilmBox CreateFilmBox(DicomUID sopInstance, DicomDataset dataset) { DicomUID uid = sopInstance; if (uid == null || uid.UID == string.Empty) { uid = DicomUID.Generate(); } var filmBox = new FilmBox(this, uid, dataset); BasicFilmBoxes.Add(filmBox); return filmBox; }
void OnPrintPage(object sender, PrintPageEventArgs e) { e.Graphics.InterpolationMode = _currentFilmBox.MagnificationType == "CUBIC" ? InterpolationMode.HighQualityBicubic : InterpolationMode.HighQualityBilinear; var format = _currentFilmBox.ImageDisplayFormat; if (String.IsNullOrEmpty(format)) return; var parts = _currentFilmBox.ImageDisplayFormat.Split('\\', ','); if (parts.Length >= 3) { var columns = int.Parse(parts[1]); var rows = int.Parse(parts[2]); var boxSize = new SizeF(e.MarginBounds.Width / columns, e.MarginBounds.Height / rows); var boxes = new List<RectangleF>(); for (int r = 0; r < rows; r++) { for (int c = 0; c < columns; c++) { boxes.Add(new RectangleF { X = e.MarginBounds.X + c * boxSize.Width, Y = e.MarginBounds.Y + r * boxSize.Height, Width = boxSize.Width, Height = boxSize.Height }); } } for (int i = 0; i < _currentFilmBox.BasicImageBoxes.Count; i++) { DrawImageBox(_currentFilmBox.BasicImageBoxes[i], e.Graphics, boxes[i], 100); } } _currentFilmBox = null; _currentPage++; e.HasMorePages = _currentPage < FilmBoxList.Count; }