public void FragmentImage_blockSizeGreatedThanRealSize() { FragmentationResult results = Fragmenter.FragmentImage( testImage, new SizeF(200, 100), 300, 50 ); Assert.IsNull(results); }
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); }
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 }
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); }
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"); } } }
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); }
public void Setup() { fragmenter = new Fragmenter(); }
public void CreateAndDestroyFragmenter_NoLeaks() { Fragmenter f = new Fragmenter(); f.Dispose(); }
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); * } * } */ }
/// <param name="">fragmenter /// </param> public virtual void SetTextFragmenter(Fragmenter fragmenter) { textFragmenter = fragmenter; }