Exemplo n.º 1
0
            /// <summary>
            /// Creates the <see cref="VolumeHeaderData"/> for the builder's source frames.
            /// </summary>
            /// <returns></returns>
            public VolumeHeaderData BuildVolumeHeader()
            {
                if (_volumeHeaderData != null)
                {
                    return(_volumeHeaderData);
                }

                PrepareFrames(_frames);                 // this also sorts the frames into order by slice location

                // compute modality LUT parameters normalized for all frames
                double normalizedSlope, normalizedIntercept;
                var    normalizedUnits = _frames[0].Frame.RescaleUnits;

                ComputeNormalizedModalityLut(_frames, out normalizedSlope, out normalizedIntercept);

                // determine an appropriate pixel padding value
                var pixelPaddingValue = ComputePixelPaddingValue(_frames, normalizedSlope, normalizedIntercept);

                // get the laterality of the anatomy being constructed
                var laterality = _frames[0].Frame.Laterality;

                // Construct a model SOP data source based on the first frame's DICOM header
                var header = new VolumeHeaderData(_frames.Select(f => (IDicomAttributeProvider)f.Frame).ToList(), VolumeSize, VoxelSpacing, VolumePositionPatient, VolumeOrientationPatient, 16, 16, false, pixelPaddingValue, normalizedSlope, normalizedIntercept, normalizedUnits, laterality);

                // determine how the normalized modality LUT affects VOI windows and update the header
                VoiWindow.SetWindows(ComputeAggregateNormalizedVoiWindows(_frames, normalizedSlope, normalizedIntercept), header);

                return(_volumeHeaderData = header);
            }
Exemplo n.º 2
0
            /// <summary>
            /// Creates and populates a <see cref="Volume"/> from the builder's source frames.
            /// </summary>
            public Volume Build()
            {
                PrepareFrames(_frames);                 // this also sorts the frames into order by slice location

                // Construct a model SOP data source based on the first frame's DICOM header
                var sopDataSourcePrototype = VolumeSopDataSourcePrototype.Create(_frames.Select(f => (IDicomAttributeProvider)f.Sop.DataSource).ToList(), 16, 16, false);

                // compute normalized modality LUT
                double normalizedSlope, normalizedIntercept;

                ComputeNormalizedModalityLut(_frames, out normalizedSlope, out normalizedIntercept);
                sopDataSourcePrototype[DicomTags.RescaleSlope].SetFloat64(0, normalizedSlope);
                sopDataSourcePrototype[DicomTags.RescaleIntercept].SetFloat64(0, normalizedIntercept);
                sopDataSourcePrototype[DicomTags.RescaleType] = _frames[0].Sop.DataSource[DicomTags.RescaleType].Copy();
                sopDataSourcePrototype[DicomTags.Units]       = _frames[0].Sop.DataSource[DicomTags.Units].Copy();           // PET series use this attribute to designate rescale units

                // compute normalized VOI windows
                VoiWindow.SetWindows(ComputeNormalizedVoiWindows(_frames, normalizedSlope, normalizedIntercept), sopDataSourcePrototype);

                // compute the volume padding value
                var pixelPaddingValue = ComputePixelPaddingValue(_frames, normalizedSlope, normalizedIntercept);

                int minVolumeValue, maxVolumeValue;
                var volumeArray = BuildVolumeArray(pixelPaddingValue, normalizedSlope, normalizedIntercept, out minVolumeValue, out maxVolumeValue);
                var volume      = new Volume(null, volumeArray, VolumeSize, VoxelSpacing, ImagePositionPatient, ImageOrientationPatient, sopDataSourcePrototype, pixelPaddingValue, _frames[0].Frame.SeriesInstanceUid, minVolumeValue, maxVolumeValue);

                return(volume);
            }
Exemplo n.º 3
0
        public void TestSetWindowsEmpty()
        {
            var windows = new VoiWindow[0];

            var dataset = new DicomAttributeCollection();

            VoiWindow.SetWindows(windows, dataset);

            Assert.IsTrue(dataset[DicomTags.WindowCenter].IsEmpty);
            Assert.IsTrue(dataset[DicomTags.WindowWidth].IsEmpty);
        }
Exemplo n.º 4
0
        public void TestSetWindows()
        {
            var windows = new[]
            {
                new VoiWindow(1, 2),
                new VoiWindow(100, 200),
                new VoiWindow(100.1, 200.2),
                new VoiWindow(123.1, 456.2),
                new VoiWindow(123.567890123, -23.567890123)
            };

            var dataset = new DicomAttributeCollection();

            VoiWindow.SetWindows(windows, dataset);

            Assert.AreEqual(5, dataset[DicomTags.WindowCenter].Count);
            Assert.AreEqual(dataset[DicomTags.WindowCenter].ToString(), @"2\200\200.2\456.2\-23.567890123");

            Assert.AreEqual(5, dataset[DicomTags.WindowWidth].Count);
            Assert.AreEqual(dataset[DicomTags.WindowWidth].ToString(), @"1\100\100.1\123.1\123.567890123");
        }
Exemplo n.º 5
0
        public void TestSetWindowsWithExplanations()
        {
            var windows = new[]
            {
                new VoiWindow(1, 2, "bob"),
                new VoiWindow(100, 200, "alice"),
                new VoiWindow(100.1, 200.2, "eve"),
                new VoiWindow(123.1, 456.2, "james"),
                new VoiWindow(123.567890123, -23.567890123)
            };

            var dataset = new DicomAttributeCollection();

            VoiWindow.SetWindows(windows, dataset);

            Assert.AreEqual(5, dataset[DicomTags.WindowCenter].Count);
            Assert.AreEqual(dataset[DicomTags.WindowCenter].ToString(), @"2\200\200.2\456.2\-23.567890123");

            Assert.AreEqual(5, dataset[DicomTags.WindowWidth].Count);
            Assert.AreEqual(dataset[DicomTags.WindowWidth].ToString(), @"1\100\100.1\123.1\123.567890123");

            Assert.AreEqual(5, dataset[DicomTags.WindowCenterWidthExplanation].Count);
            Assert.AreEqual(dataset[DicomTags.WindowCenterWidthExplanation].ToString(), @"bob\alice\eve\james\");
        }