示例#1
0
        public void Should_Throw_InitializationException_When_No_Image_Was_Added()
        {
            // Arrange
            var    pyramidBuilder = new PyramidBuilder();
            Action act            = () => pyramidBuilder.Build(2);

            // Act & Assert
            act.ShouldThrow <InitializationException>();
        }
示例#2
0
        public void Should_Throw_ArgumentOutOfRangeException_When_Levels_Amount_Less_Then_1()
        {
            // Arrange
            byte   levelsAmount   = 0;
            var    pyramidBuilder = new PyramidBuilder();
            Action act            = () => pyramidBuilder.Build(levelsAmount);

            // Act & Assert
            act.ShouldThrow <ArgumentOutOfRangeException>();
        }
示例#3
0
        public void Should_Not_Throw_When_Can_Be_Divided_Levels_Amount_Times(int width, int height, byte levelsAmount)
        {
            // Arrange
            var image          = CreateImage(width, height);
            var markup         = CreateImage(width / 2, height / 2);
            var pyramidBuilder = new PyramidBuilder();

            pyramidBuilder.Init(image, markup);
            Action act = () => pyramidBuilder.Build(levelsAmount);

            // Act & Assert
            act.ShouldNotThrow();
        }
示例#4
0
        public void Should_Throw_WrongImageSizeException_When_Image_Downscaled_To_1px_On_Any_Side(int width, int height, byte levelsAmount)
        {
            // Arrange
            var image          = CreateImage(width, height);
            var markup         = CreateImage(width / 2, height);
            var pyramidBuilder = new PyramidBuilder();

            pyramidBuilder.Init(image, markup);
            Action act = () => pyramidBuilder.Build(levelsAmount);

            // Act & Assert
            act.ShouldThrow <WrongImageSizeException>();
        }
示例#5
0
        public void Should_Build_Pyramid_Of_Required_Level_High(int width, int height, byte levelsAmount)
        {
            // Arrange
            var image          = CreateImage(width, height);
            var markup         = CreateImage(width / 2, height / 2);
            var pyramidBuilder = new PyramidBuilder();

            pyramidBuilder.Init(image, markup);

            // Act
            var pyramid = pyramidBuilder.Build(levelsAmount);

            // Assert
            pyramid.LevelsAmount.ShouldBe <byte>(levelsAmount);
        }
示例#6
0
        public void Should_Throw_AreaRemovedException_When_Markup_Covers_Whole_Image()
        {
            // Arrange
            int  width        = 128;
            int  height       = 128;
            byte levelsAmount = 3;

            var image          = CreateImage(width, height);
            var markup         = CreateImage(width, height);
            var pyramidBuilder = new PyramidBuilder();

            pyramidBuilder.Init(image, markup);
            Action act = () => pyramidBuilder.Build(levelsAmount);

            // Act & Assert
            act.ShouldThrow <AreaRemovedException>();
        }
示例#7
0
        public void Should_Throw_NoAreaToInpaintException_When_Markup_In_Image_Area_Empty()
        {
            // Arrange
            int  width        = 128;
            int  height       = 128;
            byte levelsAmount = 3;

            var image          = CreateImage(width, height);
            var markup         = Create3pixBiggerMarkupNotEmptyOutsideOfTheImage(width, height);
            var pyramidBuilder = new PyramidBuilder();

            pyramidBuilder.Init(image, markup);
            Action act = () => pyramidBuilder.Build(levelsAmount);

            // Act & Assert
            act.ShouldThrow <NoAreaToInpaintException>();
        }
示例#8
0
        public void Should_Use_Last_Set_Image(int width1, int height1, int width2, int height2, byte levelsAmount)
        {
            // Arrange
            var image1         = CreateImage(width1, height1);
            var image2         = CreateImage(width2, height2);
            var markup1        = CreateImage(width1 / 2, height1 / 2);
            var markup2        = CreateImage(width2 / 2, height2 / 2);
            var pyramidBuilder = new PyramidBuilder();

            pyramidBuilder.Init(image1, markup1);
            pyramidBuilder.Init(image2, markup2);

            // Act
            var pyramid = pyramidBuilder.Build(levelsAmount);

            // Assert
            pyramid.LevelsAmount.ShouldBe <byte>(levelsAmount);
        }
示例#9
0
        public void Should_Use_Last_Set_Markup()
        {
            // Arrange
            int  width        = 128;
            int  height       = 128;
            byte levelsAmount = 3;

            var image          = CreateImage(width, height);
            var markup1        = Create3pixBiggerMarkupNotEmptyOutsideOfTheImage(width, height);
            var pyramidBuilder = new PyramidBuilder();

            var markup2 = CreateImage(width / 2, height / 2);

            // Act
            pyramidBuilder.Init(image, markup1);
            pyramidBuilder.Init(image, markup2);
            var pyramid = pyramidBuilder.Build(levelsAmount);

            // Assert
            pyramid.LevelsAmount.ShouldBe(levelsAmount);
        }
示例#10
0
        public static async Task<CloudPyramid> GeneratePyramids([ActivityTrigger] InpaintRequest inpaintRequest)
        {
            var levelDetector = new PyramidLevelsDetector();
            var pyramidBuilder = new PyramidBuilder();
            var settings = new InpaintSettings();

            var container = BlobHelper.OpenBlobContainer(inpaintRequest.Container);
            var imageBlob = container.GetBlockBlobReference(inpaintRequest.Image);
            var removeMaskBlob = container.GetBlockBlobReference(inpaintRequest.RemoveMask);

            var imageArgb = await BlobHelper.ConvertBlobToArgbImage(imageBlob);
            var removeMaskArgb = await BlobHelper.ConvertBlobToArgbImage(removeMaskBlob);

            var levelsAmount = levelDetector.CalculateLevelsAmount(imageArgb, removeMaskArgb, settings.PatchSize);
            pyramidBuilder.Init(imageArgb, removeMaskArgb);
            var pyramid = pyramidBuilder.Build(levelsAmount, settings.PatchSize);
            var cloudPyramid = new CloudPyramid
            {
                Levels = new CloudPyramidLevel[pyramid.LevelsAmount]
            };

            for (byte levelIndex = 0; levelIndex < pyramid.LevelsAmount; levelIndex++)
            {
                var image = pyramid.GetImage(levelIndex);
                var fileName = $"{levelIndex}.png";
                await BlobHelper.SaveImageLabToBlob(image, container, fileName);
                cloudPyramid.Levels[levelIndex].ImageName = fileName;

                var inpaintArea = pyramid.GetInpaintArea(levelIndex);
                var inpaintAreaState = inpaintArea.GetState();
                var inpaintAreaFileName = $"ia{levelIndex}.json";
                var inpaintAreaData = JsonConvert.SerializeObject(inpaintAreaState);
                BlobHelper.SaveJsonToBlob(inpaintAreaData, container, inpaintAreaFileName);
                cloudPyramid.Levels[levelIndex].InpaintArea = inpaintAreaFileName;

                cloudPyramid.Levels[levelIndex].Nnf = $"nnf{levelIndex}.json";

                var mapping = pyramid.GetMapping(levelIndex);
                var mappingFileName = $"map{levelIndex}.json";
                var mapState = mapping.GetState();
                var mappingData = JsonConvert.SerializeObject(mapState);
                BlobHelper.SaveJsonToBlob(mappingData, container, mappingFileName);
                cloudPyramid.Levels[levelIndex].Mapping = mappingFileName;

                var mappings = SplitMapping(mapping, inpaintRequest.Settings.MaxPointsAmountPerFunction, settings.PatchSize).ToArray();
                cloudPyramid.Levels[levelIndex].SplittedMappings = new string[mappings.Length];
                cloudPyramid.Levels[levelIndex].SplittedNnfs = new string[mappings.Length];
                for (var i = 0; i < mappings.Length; i++)
                {
                    var map = mappings[i];
                    mappingFileName = $"map{levelIndex}_p{i}.json";
                    mapState = map.GetState();
                    mappingData = JsonConvert.SerializeObject(mapState);
                    BlobHelper.SaveJsonToBlob(mappingData, container, mappingFileName);
                    cloudPyramid.Levels[levelIndex].SplittedMappings[i] = mappingFileName;
                    cloudPyramid.Levels[levelIndex].SplittedNnfs[i] = $"nnf{levelIndex}_p{i}.json";
                }
            }

            return cloudPyramid;
        }
示例#11
0
 public override void BuildGeometry()
 {
     PyramidBuilder.Build(gameObject, this);
 }