protected MultiframeDisplaySetDescriptor(MultiframeDisplaySetDescriptor source, ICloningContext context)
     : base(source, context)
 {
     context.CloneFields(source, this);
 }
        /// <summary>
        /// Creates zero or more <see cref="IDisplaySet"/>s from the given <see cref="Series"/>.
        /// </summary>
        /// <remarks>When the input series does not contain a mixture of single and multiframe
        /// images, no <see cref="IDisplaySet"/>s will be returned.</remarks>
        public override List <IDisplaySet> CreateDisplaySets(Series series)
        {
            List <IDisplaySet> displaySets = new List <IDisplaySet>();

            List <ImageSop> singleFrames = new List <ImageSop>();
            List <ImageSop> multiFrames  = new List <ImageSop>();

            foreach (Sop sop in series.Sops)
            {
                if (sop.IsImage)
                {
                    ImageSop imageSop = (ImageSop)sop;
                    if (imageSop.NumberOfFrames > 1)
                    {
                        multiFrames.Add(imageSop);
                    }
                    else
                    {
                        singleFrames.Add(imageSop);
                    }
                }
            }

            if (multiFrames.Count > 1 || (singleFrames.Count > 0 && multiFrames.Count > 0))
            {
                if (singleFrames.Count > 0)
                {
                    List <IPresentationImage> singleFrameImages = new List <IPresentationImage>();
                    foreach (ImageSop singleFrame in singleFrames)
                    {
                        singleFrameImages.AddRange(PresentationImageFactory.CreateImages(singleFrame));
                    }

                    if (singleFrameImages.Count > 0)
                    {
                        var descriptor             = new SingleImagesDisplaySetDescriptor(series.GetIdentifier(), PresentationImageFactory);
                        var singleImagesDisplaySet = new DisplaySet(descriptor);

                        foreach (IPresentationImage singleFrameImage in singleFrameImages)
                        {
                            singleImagesDisplaySet.PresentationImages.Add(singleFrameImage);
                        }

                        singleImagesDisplaySet.PresentationImages.Sort();
                        displaySets.Add(singleImagesDisplaySet);
                    }
                }

                foreach (ImageSop multiFrame in multiFrames)
                {
                    List <IPresentationImage> multiFrameImages = PresentationImageFactory.CreateImages(multiFrame);
                    if (multiFrameImages.Count > 0)
                    {
                        MultiframeDisplaySetDescriptor descriptor =
                            new MultiframeDisplaySetDescriptor(multiFrame.ParentSeries.GetIdentifier(), multiFrame.SopInstanceUid, multiFrame.InstanceNumber);
                        DisplaySet displaySet = new DisplaySet(descriptor);

                        foreach (IPresentationImage multiFrameImage in multiFrameImages)
                        {
                            displaySet.PresentationImages.Add(multiFrameImage);
                        }

                        displaySet.PresentationImages.Sort();
                        displaySets.Add(displaySet);
                    }
                }
            }

            return(displaySets);
        }
        private List <IDisplaySet> DoCreateSingleImageDisplaySets(Series series)
        {
            List <IDisplaySet> displaySets = new List <IDisplaySet>();
            int position = 0;

            foreach (Sop sop in series.Sops)
            {
                List <IPresentationImage> images = PresentationImageFactory.CreateImages(sop);
                if (images.Count == 0)
                {
                    continue;
                }

                if (sop.IsImage)
                {
                    ImageSop imageSop = (ImageSop)sop;
                    DicomDisplaySetDescriptor descriptor;

                    if (imageSop.NumberOfFrames == 1)
                    {
                        descriptor = new SingleImageDisplaySetDescriptor(series.GetIdentifier(), imageSop, position++);
                    }
                    else
                    {
                        descriptor = new MultiframeDisplaySetDescriptor(series.GetIdentifier(), sop.SopInstanceUid, sop.InstanceNumber);
                    }

                    DisplaySet displaySet = new DisplaySet(descriptor);
                    foreach (IPresentationImage image in images)
                    {
                        displaySet.PresentationImages.Add(image);
                    }

                    displaySets.Add(displaySet);
                }
                else
                {
                    //The sop is actually a container for other referenced sops, like key images.
                    foreach (IPresentationImage image in images)
                    {
                        DisplaySetDescriptor descriptor = null;
                        if (image is IImageSopProvider)
                        {
                            IImageSopProvider provider = (IImageSopProvider)image;
                            if (provider.ImageSop.NumberOfFrames == 1)
                            {
                                descriptor = new SingleImageDisplaySetDescriptor(series.GetIdentifier(), provider.ImageSop, position++);
                            }
                            else
                            {
                                descriptor = new SingleFrameDisplaySetDescriptor(series.GetIdentifier(), provider.Frame, position++);
                            }
                        }
                        else
                        {
                            //TODO (CR Jan 2010): this because the design here is funny... the factory here should actually know something about the key object series it is building for
                            ISeriesIdentifier sourceSeries = series.GetIdentifier();
                            descriptor             = new BasicDisplaySetDescriptor();
                            descriptor.Description = sourceSeries.SeriesDescription;
                            descriptor.Name        = string.Format("{0}: {1}", sourceSeries.SeriesNumber, sourceSeries.SeriesDescription);
                            descriptor.Number      = sourceSeries.SeriesNumber.GetValueOrDefault(0);
                            descriptor.Uid         = sourceSeries.SeriesInstanceUid;
                        }

                        DisplaySet displaySet = new DisplaySet(descriptor);
                        displaySet.PresentationImages.Add(image);
                        displaySets.Add(displaySet);
                    }
                }
            }

            if (displaySets.Count == 1)
            {
                //Degenerate case; single image series, which we're not supposed to create.
                displaySets[0].Dispose();
                displaySets.Clear();
            }

            return(displaySets);
        }