Пример #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 PixMapToBitmapHelper32bpp()
        {
            // Load Pixmap
            var refFile    = Path.Combine(TestData.TestDataDirectory, @"Misc\OcctHelper_PixMapToBitmap32bpp.png");
            var resultFile = Path.Combine(TestData.TestDataDirectory, @"Misc\OcctHelper_PixMapToBitmap32bpp_TestResult.png");

            var pixmap = new Image_AlienPixMap();

            Assume.That(pixmap.Load(new TCollection_AsciiString(refFile)), "Inconclusive: Reference image file could not be loaded.");

            // Convert to Bitmap
            var bitmap = Occt.Helper.PixMapHelper.ConvertToBitmap(pixmap);

            bitmap.Save(resultFile);

            // Compare
            AssertHelper.IsSameFile(refFile, resultFile, 0x53);
            File.Delete(resultFile);
        }
Пример #4
0
        //--------------------------------------------------------------------------------------------------

        #endregion

        #region Image

        public Bitmap RenderToBitmap(uint width, uint height)
        {
            if (V3dView == null || width == 0 || height == 0)
            {
                return(null);
            }

            try
            {
                _ShowTriedron(false);
                var pixmap = new Image_AlienPixMap();
                pixmap.InitZero(Image_Format.Image_Format_RGB, width, height);
                V3dView.ToPixMap(pixmap, (int)width, (int)height);
                _ShowTriedron(true);

                return(Occt.Helper.PixMapHelper.ConvertToBitmap(pixmap));
            }
            catch (Exception)
            {
                _ShowTriedron(true);
                return(null);
            }
        }