Exemplo n.º 1
0
        public void FragmentImage_blockSizeGreatedThanRealSize()
        {
            FragmentationResult results = Fragmenter.FragmentImage(
                testImage,
                new SizeF(200, 100),
                300, 50
                );

            Assert.IsNull(results);
        }
Exemplo n.º 2
0
        public void FragmentImage_downscale()
        {
            FragmentationResult results = Fragmenter.FragmentImage(
                testImage,
                new SizeF(200, 100),
                50, 6
                );

            Assert.AreEqual(1, results.Blocks.Rows);
            Assert.AreEqual(3, results.Blocks.Cols);
            Assert.AreEqual(19, results.MarginTop);
            Assert.AreEqual(13, results.MarginLeft);
        }
Exemplo n.º 3
0
        public void FragmentImage_upscale()
        {
            FragmentationResult results = Fragmenter.FragmentImage(
                testImage,
                new SizeF(200, 100),
                12, 2
                );

            Assert.AreEqual(7, results.Blocks.Rows);
            Assert.AreEqual(14, results.Blocks.Cols);
            Assert.AreEqual(0, results.MarginTop);
            Assert.AreEqual(1, results.MarginLeft);

            // Color values are not tested, as they are mainly dependend on 3-party code
        }
Exemplo n.º 4
0
        private bool AddFrames(Image <Bgr, byte> i)
        {
            Sizes sizes = ReadSizes();

            if (sizes.IsInvalid())
            {
                return(false);
            }

            int pixelsPerBlock = 4;
            int pixelsPerFrame = (int)Math.Ceiling(pixelsPerBlock * sizes.frameSize / sizes.blockSize);

            framedImage = Fragmenter.DrawWithFrames(i, pixelsPerBlock, pixelsPerFrame, Color.White);
            return(true);
        }
Exemplo n.º 5
0
        public void DrawWithFrames()
        {
            Color             frameColor = Color.FromArgb(1, 1, 1);
            Image <Bgr, byte> result     = Fragmenter.DrawWithFrames(testImage, 2, 1, frameColor);

            Assert.AreEqual(13, result.Rows);
            Assert.AreEqual(13, result.Cols);

            Assert.AreEqual(new Bgr(frameColor), result[0, 0]);
            Assert.AreEqual(new Bgr(frameColor), result[12, 12]);
            Assert.AreEqual(new Bgr(frameColor), result[3, 2]);

            Assert.AreEqual(new Bgr(255, 0, 0), result[7, 1]);
            Assert.AreEqual(new Bgr(0, 0, 0), result[11, 11]);
            Assert.AreEqual(new Bgr(0, 255, 0), result[7, 7]);
        }
    private void DeprocessDestroyable(List <DestroyableGameObject> destroyable, List <DestroyableGameObject> processing, bool isMisc)
    {
        for (int i = processing.Count - 1; i >= 0; --i)
        {
            DestroyableGameObject toProcess = processing[i];

            if (toProcess.fragmenterStat != null && toProcess.fragmenterStat.isDone)
            {
                if (toProcess.state == DestroyableGameObject.StateType.fragmenting)
                {
                    Fragmenter.Stats fs = new Fragmenter.Stats();
                    toProcess.gameObject     = toProcess.fragmenterStat.fragmentedGameObject;
                    toProcess.fragmenterStat = fs;
                    toProcess.state          = DestroyableGameObject.StateType.exploding;

                    Debug.Log($"Exploding {toProcess.gameObject.name}");

                    StartCoroutine(Fragmenter.Explode(
                                       CalculateExplosionPoint(toProcess.gameObject, true),
                                       isMisc ? Constants.MiscExplosionRadius : Constants.BuildExplosionRadius,
                                       isMisc ? Constants.MiscExplosionForce  : Constants.BuildExplosionForce,
                                       fs,
                                       isMisc)
                                   );
                }
                else if (toProcess.state == DestroyableGameObject.StateType.exploding)
                {
                    processing.RemoveAt(i);

                    if (toProcess.fragmenterStat.destroyedAll)
                    {
                        toProcess.state = DestroyableGameObject.StateType.destroyed;
                    }
                    else
                    {
                        toProcess.state = DestroyableGameObject.StateType.fragmented;
                        destroyable.Add(toProcess);
                    }
                }
            }
        }
    }
    private void ProcessDestroyable(List <DestroyableGameObject> destroyable, List <DestroyableGameObject> processing, bool isMisc)
    {
        if (Random.Range(0.0f, 1.0f) < 0.25f && destroyable.Count > 0)
        {
            int index = Random.Range(0, destroyable.Count - 1);
            DestroyableGameObject toDestroy = destroyable[index];

            if (toDestroy.state == DestroyableGameObject.StateType.decaying)
            {
                Debug.Log($"Fragmenting {toDestroy.gameObject.name}");
                Fragmenter.Stats fs = new Fragmenter.Stats();
                toDestroy.fragmenterStat = fs;
                toDestroy.state          = DestroyableGameObject.StateType.fragmenting;

                destroyable.RemoveAt(index);
                processing.Add(toDestroy);

                StartCoroutine(Fragmenter.Fragment(toDestroy.gameObject, fs, isMisc));
            }
            else if (toDestroy.state == DestroyableGameObject.StateType.fragmented)
            {
                Debug.Log($"Exploding {toDestroy.gameObject.name}");
                Fragmenter.Stats fs = new Fragmenter.Stats();
                toDestroy.fragmenterStat = fs;
                toDestroy.state          = DestroyableGameObject.StateType.exploding;

                destroyable.RemoveAt(index);
                processing.Add(toDestroy);

                StartCoroutine(Fragmenter.Explode(
                                   CalculateExplosionPoint(toDestroy.gameObject),
                                   isMisc ? Constants.MiscExplosionRadius : Constants.BuildExplosionRadius,
                                   isMisc ? Constants.MiscExplosionForce  : Constants.BuildExplosionForce,
                                   fs)
                               );
            }
            else
            {
                Debug.Log("Oops");
            }
        }
    }
Exemplo n.º 8
0
        private bool FragmentImage(Image <Bgr, byte> i)
        {
            Sizes sizes = ReadSizes();

            if (sizes.IsInvalid())
            {
                return(false);
            }

            Emgu.CV.CvEnum.Inter interpolationMethod = (Emgu.CV.CvEnum.Inter)interpolationMethodInput.SelectedItem;

            FragmentationResult result = Fragmenter.FragmentImage(
                i,
                new SizeF((float)sizes.realWidth, (float)sizes.realHeight),
                sizes.blockSize, sizes.frameSize,
                interpolationMethod
                );

            fragmentedImage = result.Blocks;
            return(true);
        }
Exemplo n.º 9
0
 public void Setup()
 {
     fragmenter = new Fragmenter();
 }
Exemplo n.º 10
0
        public void CreateAndDestroyFragmenter_NoLeaks()
        {
            Fragmenter f = new Fragmenter();

            f.Dispose();
        }
Exemplo n.º 11
0
    void Update()
    {
        // Check if user clicked on a mesh with active collider
        if (Input.GetMouseButtonDown(0) &&
            Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out RaycastHit hit, Mathf.Infinity) &&
            !runningFragmentations.ContainsKey(hit) && !runningExplosions.ContainsKey(hit))
        {
            if (!Fragmenter.IsFragmented(hit.transform.gameObject))
            {
                Fragmenter.Stats fs = new Fragmenter.Stats();
                runningFragmentations.Add(hit, fs);
                Debug.Log($"Fragmentation Start Time: {Time.timeSinceLevelLoad}");
                StartCoroutine(Fragmenter.Fragment(hit.transform.gameObject, fs));
            }
            else
            {
                Fragmenter.Stats fs = new Fragmenter.Stats();
                runningExplosions.Add(hit, fs);
                StartCoroutine(Fragmenter.Explode(hit.point, radius, force, fs));
            }
        }

        // When fragmentation finishes, create an explosion where user clicked
        List <RaycastHit> toRemove = new List <RaycastHit>();

        foreach (KeyValuePair <RaycastHit, Fragmenter.Stats> entry in runningFragmentations)
        {
            if (entry.Value.isDone)
            {
                Debug.Log($"Fragmentation Total Time: {entry.Value.totalTime / 1000.0f}");
                toRemove.Add(entry.Key);
            }
        }
        foreach (RaycastHit rhit in toRemove)
        {
            Fragmenter.Stats fs = new Fragmenter.Stats();
            runningFragmentations.Remove(rhit);
            runningExplosions.Add(rhit, fs);
            StartCoroutine(Fragmenter.Explode(rhit.point, radius, force, fs));
        }


        toRemove.Clear();
        foreach (KeyValuePair <RaycastHit, Fragmenter.Stats> entry in runningExplosions)
        {
            if (entry.Value.isDone)
            {
                toRemove.Add(entry.Key);
            }
        }
        foreach (RaycastHit rhit in toRemove)
        {
            runningExplosions.Remove(rhit);
        }

        /*
         * for (int i = runningFragmentations.Count - 1; i >= 0; --i)
         * {
         *  (Fragmenter.Stats stats, RaycastHit rhit) = runningFragmentations[i];
         *
         *  if (stats.isDone)
         *  {
         *      StartCoroutine(Fragmenter.Explode(rhit.point, radius, force, null));
         *      runningFragmentations.RemoveAt(i);
         *  }
         * }
         */
    }
Exemplo n.º 12
0
		/// <param name="">fragmenter
		/// </param>
		public virtual void  SetTextFragmenter(Fragmenter fragmenter)
		{
			textFragmenter = fragmenter;
		}
Exemplo n.º 13
0
 /// <param name="">fragmenter
 /// </param>
 public virtual void  SetTextFragmenter(Fragmenter fragmenter)
 {
     textFragmenter = fragmenter;
 }