/// <summary>
        /// Creates a 100x100x100 volume using the specified volume function using 100 frames of dimensions 100x100.
        /// </summary>
        /// <param name="function">The function with which to generate frame data - 0-99 in each dimension.</param>
        /// <param name="initializer">A delegate to initialize additional SOP attributes for each of the 100 frames.</param>
        /// <param name="testMethod">A test routine with which to exercise the volume. The volume is disposed automatically afterwards.</param>
        /// <param name="signed">Whether or not the source frames should have signed pixel data.</param>
        /// <param name="bpp8">Whether or not the source frames should have 8 bit allocated/stored pixel data.</param>
        protected static void TestVolume(VolumeFunction function, InitializeSopDataSourceDelegate initializer, TestVolumeDelegate testMethod, bool signed = false, bool bpp8 = false)
        {
            function = function.Normalize(100);
            List <ImageSop> images = new List <ImageSop>();

            try
            {
                foreach (ISopDataSource sopDataSource in function.CreateSops(100, 100, 100, signed, bpp8))
                {
                    if (initializer != null)
                    {
                        initializer.Invoke(sopDataSource);
                    }
                    images.Add(new ImageSop(sopDataSource));
                }

                using (Volume volume = Volume.Create(EnumerateFrames(images)))
                {
                    if (testMethod != null)
                    {
                        testMethod.Invoke(volume);
                    }
                }
            }
            catch (Exception ex)
            {
                Trace.WriteLine(string.Format("Thrown: {0}", ex.GetType().Name));
                throw;
            }
            finally
            {
                DisposeAll(images);
            }
        }
Exemple #2
0
        public void TestInsufficientFramesSource()
        {
            // it doesn't really matter what function we use
            VolumeFunction function = VolumeFunction.Void.Normalize(100);

            List <ImageSop> images = new List <ImageSop>();

            try
            {
                // create only 2 slices!!
                images.AddRange(function.CreateSops(100, 100, 2).Select(sopDataSource => new ImageSop(sopDataSource)));

                // this line *should* throw an exception
                using (Volume volume = Volume.Create(EnumerateFrames(images)))
                {
                    Assert.Fail("Expected an exception of type {0}, instead got {1}", typeof(InsufficientFramesException), volume);
                }
            }
            catch (InsufficientFramesException) {}
            finally
            {
                DisposeAll(images);
            }
        }