示例#1
0
        /// <summary>
        /// window after the opengl host was initialized
        /// </summary>
        /// <param name="app"></param>
        /// <param name="window"></param>
        public Models(App app, MainWindow window, WindowViewModel viewModel)
        {
            this.App  = new AppModel(app, window);
            GlContext = new OpenGlContext(window, viewModel);
            GlContext.Enable();

            Images      = new ImagesModel(GlContext, App);
            GlData      = new OpenGlModel(GlContext, Images);
            Display     = new DisplayModel(Images, GlContext);
            Equations   = new ImageEquationsModel(Images);
            Progress    = new ProgressModel();
            FinalImages = new FinalImagesModel(GlData.TextureCache, Images);
            Filter      = new FiltersModel();
            Statistics  = new StatisticsModel();
            Export      = new ExportModel(Images, Display);

            GlContext.Disable();
        }
示例#2
0
        /// <summary>
        /// tries to add the image to the current collection.
        /// Throws an exception if the image cannot be added
        /// </summary>
        /// <param name="imgs">images that should be added</param>
        public void AddImages(List <ImageLoader.Image> imgs)
        {
            Debug.Assert(!context.GlEnabled);
            context.Enable();
            foreach (var image in imgs)
            {
                if (images.Count == 0)
                {
                    images.Add(new ImageData(image));

                    // intialize dimensions
                    dimensions = new Dimension[image.NumMipmaps];
                    for (var i = 0; i < image.NumMipmaps; ++i)
                    {
                        dimensions[i] = new Dimension()
                        {
                            Height = image.GetHeight(i),
                            Width  = image.GetWidth(i)
                        };
                    }

                    // a lot has changed
                    PrevNumImages = NumImages - 1;
                    OnPropertyChanged(nameof(NumImages));
                    OnPropertyChanged(nameof(NumLayers));
                    OnPropertyChanged(nameof(NumMipmaps));
                    OnPropertyChanged(nameof(IsAlpha));
                    OnPropertyChanged(nameof(IsGrayscale));
                    OnPropertyChanged(nameof(IsHdr));
                    OnPropertyChanged(nameof(Width));
                    OnPropertyChanged(nameof(Height));
                }
                else // test if image compatible with previous images
                {
                    if (image.Layers.Count != NumLayers)
                    {
                        throw new Exception($"{image.Filename}: Inconsistent amount of layers. Expected {NumLayers} got {image.Layers.Count}");
                    }

                    ImageData imgData = null;
                    if (image.NumMipmaps != NumMipmaps)
                    {
                        // try to generate/discard mipmaps if the dimensions match
                        // first layer MUST be of the same size
                        if (image.GetWidth(0) != GetWidth(0) || image.GetHeight(0) != GetHeight(0))
                        {
                            throw new Exception($"{image.Filename}: Mismatching image resolution. Expected {GetWidth(0)}x{GetHeight(0)}" +
                                                $" got {image.GetWidth(0)}x{image.GetHeight(0)}");
                        }

                        // either generate or remove mipmaps
                        if (NumMipmaps == 1)
                        {
                            // TODO inform the user? offer to generate mipmaps for the other images instead?
                            // remove mipmaps from the new image
                            imgData = new ImageData(image);
                            imgData.DeleteMipmaps();
                        }
                        else if (image.NumMipmaps == 1)
                        {
                            // generate mipmaps for the new image (silent)
                            imgData = new ImageData(image);
                            imgData.GenerateMipmaps(NumMipmaps);
                        }
                        else
                        {
                            throw new Exception($"{image.Filename}: Inconsistent amount of mipmaps. Expected {NumMipmaps} got {image.NumMipmaps}");
                        }
                    }
                    else // mipmaps are present in both images
                    {
                        // test mipmaps
                        for (var level = 0; level < NumMipmaps; ++level)
                        {
                            if (image.GetWidth(level) != GetWidth(level) || image.GetHeight(level) != GetHeight(level))
                            {
                                throw new Exception(
                                          $"{image.Filename}: Inconsistent mipmaps dimension. Expected {GetWidth(level)}x{GetHeight(level)}" +
                                          $" got {image.GetWidth(level)}x{image.GetHeight(level)}");
                            }
                        }
                        imgData = new ImageData(image);
                    }

                    Add(imgData);
                }
            }
            context.Disable();
        }