Пример #1
0
        public void BitmapToPixMapHelper32bpp()
        {
            // Load Pixmap
            var refFile    = Path.Combine(TestData.TestDataDirectory, @"Misc\OcctHelper_PixMapToBitmap32bpp.png");
            var resultFile = Path.Combine(TestData.TestDataDirectory, @"Misc\OcctHelper_BitmapToPixMap32bpp_TestResult.png");

            var bitmap = new Bitmap(refFile);

            // Convert to Pixmap
            var pixmap = Occt.Helper.PixMapHelper.ConvertFromBitmap(bitmap);

            Assert.IsNotNull(pixmap);

            // Compare
            var refPixMap = new Image_AlienPixMap();

            refPixMap.Load(new TCollection_AsciiString(refFile));

            var differ = new Image_Diff();

            Assert.True(differ.Init(refPixMap, pixmap, false), "Images comparison init failed");
            differ.SetColorTolerance(0.0);
            differ.SetBorderFilterOn(false);
            Assert.AreEqual(0, differ.Compare());

            File.Delete(resultFile);
        }
Пример #2
0
        //--------------------------------------------------------------------------------------------------

        internal static void IsSameViewport(string referenceFilename, double tolerance = 0.05)
        {
            if (Context.Current.Workspace.NeedsRedraw || Context.Current.Workspace.NeedsImmediateRedraw)
            {
                Context.Current.WorkspaceController.Invalidate(!Context.Current.Workspace.NeedsRedraw, true);
            }

            var fullPath = Path.Combine(TestData.TestDataDirectory, referenceFilename);

            Directory.CreateDirectory(Path.GetDirectoryName(fullPath));

            int width = 0, height = 0;

            Context.Current.Viewport.V3dView.Window().Size(ref width, ref height);

            // Get screenshot
            var screenshot = new Image_AlienPixMap();

            screenshot.InitZero(Image_Format.Image_Format_RGB, (ulong)width, (ulong)height);
            Context.Current.Viewport.V3dView.ToPixMap(screenshot, (int)width, (int)height);

            // Load Reference
            var refshot = new Image_AlienPixMap();

            if (!refshot.Load(new TCollection_AsciiString(fullPath + ".png")))
            {
                // Save test result
                Assert.True(screenshot.Save(new TCollection_AsciiString(fullPath + "_TestResult.png")), "Test result could not be saved.");
                Assert.Fail("Inconclusive: Reference image file could not be loaded: " + fullPath);
                return;
            }

            // Diff
            var differ = new Image_Diff();

            Assert.True(differ.Init(refshot, screenshot, false), "Images comparison init failed");
            differ.SetColorTolerance(tolerance);
            differ.SetBorderFilterOn(false);
            var result = differ.Compare();

            if (result != 0)
            {
                // Save test result
                Assert.True(screenshot.Save(new TCollection_AsciiString(fullPath + "_TestResult.png")), "Test result could not be saved.");
                Assert.True(differ.SaveDiffImage(new TCollection_AsciiString(fullPath + "_Difference.png")), "Difference image could not be saved.");

                Assert.AreEqual(0, result, "The resulted image differs: " + fullPath);
                return;
            }

            // Equality
            // Test was ok, delete result file if any left
            TestData.DeleteTestResult(fullPath + "_TestResult.png");
            TestData.DeleteTestResult(fullPath + "_Difference.png");
        }
Пример #3
0
        public void ImageDiffWithTolerance_OCCT29847()
        {
            var imageNew = new Image_PixMap();

            imageNew.InitTrash(Image_Format.Image_Format_RGB, 1, 1);
            imageNew.SetPixelColor(0, 0, new Quantity_Color(0.5, 0.5, 0.5, Quantity_TypeOfColor.Quantity_TOC_RGB));
            var imageRef = new Image_PixMap();

            imageRef.InitTrash(Image_Format.Image_Format_RGB, 1, 1);
            imageRef.SetPixelColor(0, 0, new Quantity_Color(0.6, 0.6, 0.6, Quantity_TypeOfColor.Quantity_TOC_RGB));

            var imageDiff = new Image_Diff();

            imageDiff.Init(imageRef, imageNew);
            Assert.AreEqual(1, imageDiff.Compare());
            imageDiff.SetColorTolerance(0.2);
            Assert.AreEqual(0, imageDiff.Compare());
        }