Exemplo n.º 1
0
        private IEnumerable <Frame> GetAcquisitionTimeTestFrames()
        {
            int i = 0;

            foreach (DateTime dateTime in GetAquisitionDateTimes())
            {
                ImageSop sop   = NewImageSop("123", "123", i++);
                Frame    frame = sop.Frames[1];
                DicomMessageSopDataSource dataSource = ((DicomMessageSopDataSource)frame.ParentImageSop.DataSource);

                if (i % 2 == 0)
                {
                    dataSource.SourceMessage.DataSet[DicomTags.AcquisitionDate].SetStringValue(dateTime.Date.ToString(DateParser.DicomDateFormat));
                    dataSource.SourceMessage.DataSet[DicomTags.AcquisitionTime].SetStringValue(dateTime.ToString(TimeParser.DicomFullTimeFormat));
                }
                else
                {
                    dataSource.SourceMessage.DataSet[DicomTags.AcquisitionDatetime].SetStringValue(dateTime.ToString(DateTimeParser.DicomFullDateTimeFormat));
                }

                yield return(frame);

                sop.Dispose();
            }
        }
Exemplo n.º 2
0
        private static void TryGrayscalePixelNormalization(byte[] input, byte[] expected, int highBit, int bitsStored, int bitsAllocated, bool signed)
        {
            DicomAttributeCollection coll = new DicomAttributeCollection();

            coll[DicomTags.BitsAllocated].SetInt32(0, bitsAllocated);
            coll[DicomTags.BitsStored].SetInt32(0, bitsStored);
            coll[DicomTags.HighBit].SetInt32(0, highBit);
            coll[DicomTags.PixelRepresentation].SetInt32(0, signed ? 1 : 0);

            byte[] output = new byte[input.Length];
            input.CopyTo(output, 0);

            var bigEndian = ByteBuffer.LocalMachineEndian == Endian.Big;

            if (bigEndian)
            {
                // if the local machine is big endian, swap the bytes of input and expected around, as the tests were written for little endian

                var bb = new ByteBuffer(output, Endian.Little);
                bb.Swap2();

                var swappedExpected = new byte[expected.Length];
                input.CopyTo(swappedExpected, 0);
                bb = new ByteBuffer(swappedExpected, Endian.Little);
                bb.Swap2();
                expected = swappedExpected;
            }

            DicomMessageSopDataSource.NormalizeGrayscalePixels(coll, output);
            AssertArrayEquals(expected, output, string.Format("{0} Stored, {1} Allocated, High={2}, BigEndian={3}", bitsStored, bitsAllocated, highBit, bigEndian));
        }
Exemplo n.º 3
0
        private static void TryGrayscalePixelNormalization(byte[] input, byte[] expected, int highBit, int bitsStored, int bitsAllocated, bool bigEndian, bool signed)
        {
            DicomAttributeCollection coll = new DicomAttributeCollection();

            coll[DicomTags.BitsAllocated].SetInt32(0, bitsAllocated);
            coll[DicomTags.BitsStored].SetInt32(0, bitsStored);
            coll[DicomTags.HighBit].SetInt32(0, highBit);
            coll[DicomTags.PixelRepresentation].SetInt32(0, signed ? 1 : 0);

            byte[] output = new byte[input.Length];
            input.CopyTo(output, 0);
            DicomMessageSopDataSource.TestNormalizeGrayscalePixels(coll, output, bigEndian ? Endian.Big : Endian.Little);
            AssertArrayEquals(expected, output, string.Format("{0} Stored, {1} Allocated, High={2}, BigEndian={3}", bitsStored, bitsAllocated, highBit, bigEndian));
        }
Exemplo n.º 4
0
        private void TestSortingDisplaySetsBySeriesNumber(bool reverse)
        {
            DisplaySetCollection orderedCollection    = new DisplaySetCollection();
            DisplaySetCollection nonOrderedCollection = new DisplaySetCollection();

            for (int i = 1; i <= 20; ++i)
            {
                string             id         = i.ToString();
                DisplaySet         displaySet = new DisplaySet(id, id);
                ImageSop           sop        = NewImageSop(id, id, i);
                IPresentationImage image      = new DicomGrayscalePresentationImage(sop.Frames[1]);
                sop.Dispose();
                IImageSopProvider         sopProvider = (IImageSopProvider)image;
                DicomMessageSopDataSource dataSource  = ((DicomMessageSopDataSource)sopProvider.ImageSop.DataSource);
                dataSource.SourceMessage.DataSet[DicomTags.SeriesNumber].SetInt32(0, i);

                displaySet.PresentationImages.Add(image);
                orderedCollection.Add(displaySet);
            }

            Randomize(orderedCollection, nonOrderedCollection);

            Debug.WriteLine("Before Sort\n------------------------\n");
            CollectionUtils.ForEach(nonOrderedCollection, delegate(IDisplaySet displaySet) { Debug.WriteLine(String.Format("name: {0}", displaySet.Name)); });

            nonOrderedCollection.Sort(new SeriesNumberComparer(reverse));

            Debug.WriteLine("\nAfter Sort\n------------------------\n");
            CollectionUtils.ForEach(nonOrderedCollection, delegate(IDisplaySet displaySet) { Debug.WriteLine(String.Format("name: {0}", displaySet.Name)); });

            int j = reverse ? 20 : 1;

            foreach (IDisplaySet set in nonOrderedCollection)
            {
                Assert.AreEqual(j.ToString(), set.Name);
                j += reverse ? -1 : 1;
            }

            foreach (DisplaySet set in nonOrderedCollection)
            {
                set.Dispose();
            }
            foreach (DisplaySet set in orderedCollection)
            {
                set.Dispose();
            }
        }
Exemplo n.º 5
0
        private IEnumerable <ImageSop> GetSliceLocationTestImageSops()
        {
            int i = 0;
            int instanceNumber = 1;

            foreach (ImageOrientationPatient orientation in GetSliceLocationOrientations())
            {
                for (int j = -3; j <= 3; ++j)
                {
                    //we're not testing the study, series etc grouping because the 'instance and frame number one does that'
                    ImageSop sop = NewImageSop("123", "1", instanceNumber++);

                    DicomMessageSopDataSource dataSource = ((DicomMessageSopDataSource)sop.Frames[1].ParentImageSop.DataSource);
                    dataSource.SourceMessage.DataSet[DicomTags.ImagePositionPatient].SetStringValue(GetSliceLocationPosition(i, j).ToString());
                    dataSource.SourceMessage.DataSet[DicomTags.ImageOrientationPatient].SetStringValue(orientation.ToString());
                    yield return(sop);
                }

                ++i;
            }
        }
Exemplo n.º 6
0
        private void TestSortingImageSetsByStudyDate(bool reverse, bool useSops, bool testLayoutManagerSort)
        {
            ImageSetCollection orderedCollection    = new ImageSetCollection();
            ImageSetCollection nonOrderedCollection = new ImageSetCollection();
            StudyTree          studyTree            = new StudyTree();

            for (int i = 0; i <= 20; ++i)
            {
                string   id       = i.ToString();
                ImageSet imageSet = new ImageSet();
                imageSet.Name = id;

                string studyDate;
                if (i == 0)
                {
                    studyDate = "";
                }
                else
                {
                    studyDate = String.Format("200801{0}", i.ToString("00"));
                }

                if (useSops)
                {
                    DisplaySet displaySet = new DisplaySet(id, id);
                    ImageSop   sop        = NewImageSop(id, id, i);
                    imageSet.Uid = sop.StudyInstanceUid;
                    studyTree.AddSop(sop);

                    IPresentationImage image       = new DicomGrayscalePresentationImage(sop.Frames[1]);
                    IImageSopProvider  sopProvider = (IImageSopProvider)image;

                    DicomMessageSopDataSource dataSource = ((DicomMessageSopDataSource)sopProvider.ImageSop.DataSource);
                    dataSource.SourceMessage.DataSet[DicomTags.StudyDate].SetString(0, studyDate);
                    imageSet.DisplaySets.Add(displaySet);
                    displaySet.PresentationImages.Add(image);
                }
                else
                {
                    StudyRootStudyIdentifier identifier = new StudyRootStudyIdentifier();
                    identifier.StudyDate        = studyDate;
                    identifier.StudyInstanceUid = id;
                    ImageSetDescriptor descriptor = new DicomImageSetDescriptor(identifier);
                    imageSet.Descriptor = descriptor;
                }

                orderedCollection.Add(imageSet);
            }

            if (reverse)
            {
                List <IImageSet> temp = new List <IImageSet>();
                temp.AddRange(orderedCollection);
                temp.Reverse();
                orderedCollection.Clear();
                foreach (IImageSet imageSet in temp)
                {
                    orderedCollection.Add(imageSet);
                }
            }

            Randomize(orderedCollection, nonOrderedCollection);

            Debug.WriteLine("Before Sort\n------------------------\n");
            CollectionUtils.ForEach(nonOrderedCollection,
                                    imageSet => Debug.WriteLine(String.Format("name: {0}, date: {1}", imageSet.Name,
                                                                              ((IImageSopProvider)(imageSet.DisplaySets[0].PresentationImages[0])).
                                                                              ImageSop.StudyDate)));

            if (testLayoutManagerSort)
            {
                LayoutManager.SortImageSets(nonOrderedCollection, GetStudies(orderedCollection, studyTree));
            }
            else
            {
                nonOrderedCollection.Sort(new StudyDateComparer(reverse));
            }

            Debug.WriteLine("\nAfter Sort\n------------------------\n");
            CollectionUtils.ForEach(nonOrderedCollection,
                                    imageSet => Debug.WriteLine(String.Format("name: {0}, date: {1}", imageSet.Name,
                                                                              ((IImageSopProvider)(imageSet.DisplaySets[0].PresentationImages[0])).
                                                                              ImageSop.StudyDate)));

            if (reverse)
            {
                nonOrderedCollection.RemoveAt(20);
            }
            else
            {
                nonOrderedCollection.RemoveAt(0);
            }

            int j = reverse ? 20 : 1;

            foreach (IImageSet set in nonOrderedCollection)
            {
                Assert.AreEqual(j.ToString(), set.Name);
                j += reverse ? -1 : 1;
            }

            foreach (IImageSet set in nonOrderedCollection)
            {
                set.Dispose();
            }
            foreach (IImageSet set in orderedCollection)
            {
                set.Dispose();
            }

            studyTree.Dispose();
        }