void detectHoles() { renderTexture.DiscardContents(); RenderTexture.active = camera.GetComponent <Camera> ().targetTexture; camera.GetComponent <Camera> ().Render(); texture.filterMode = FilterMode.Point; texture.wrapMode = TextureWrapMode.Clamp; texture.ReadPixels(new Rect(0, 0, renderTexture.width, renderTexture.height), 0, 0); texture.Apply(); for (int i = 0; i < 4; i++) { TextureScale.Half(texture); } FloodFill.Fill(texture, 0, 0); FloodFill.Fill(texture, texture.width - 1, 0); FloodFill.Fill(texture, texture.width - 1, texture.height - 1); FloodFill.Fill(texture, 0, texture.height - 1); // holes ConnectedComponentLabeling ccl = new ConnectedComponentLabeling(); ccl.Process(texture, texture, false, false); holesPositions = ccl.holesAveragePositions; holesPositions.Add(new Vector2(0f, 0f)); holesPositions.Add(new Vector2((float)texture.width, 0f)); holesPositions.Add(new Vector2(0f, (float)texture.height)); holesPositions.Add(new Vector2((float)texture.width, (float)texture.height)); }
public override float Evaluate(Representation representation) { int texSize = 1024; RenderTexture renderTexture = new RenderTexture(texSize, texSize, 0); RenderTexture renderTextureTemp = RenderTexture.active; GameObject camera = new GameObject("Camera"); camera.transform.position = new Vector3(0, 150f, -300f); camera.AddComponent <Camera> (); camera.GetComponent <Camera> ().backgroundColor = Color.white; camera.GetComponent <Camera> ().orthographic = true; camera.GetComponent <Camera> ().orthographicSize = 150; camera.GetComponent <Camera> ().targetTexture = renderTexture; camera.AddComponent <GrayscaleBinary> (); camera.GetComponent <GrayscaleBinary> ().shader = Shader.Find("Hidden/GrayscaleBinary"); RenderTexture.active = renderTexture; camera.GetComponent <Camera> ().Render(); Texture2D texture = new Texture2D(renderTexture.width, renderTexture.height, TextureFormat.RGB24, false); texture.filterMode = FilterMode.Point; texture.wrapMode = TextureWrapMode.Clamp; texture.ReadPixels(new Rect(0, 0, renderTexture.width, renderTexture.height), 0, 0); texture.Apply(); TextureScale.Half(texture); texSize /= 2; // texture to copy Texture2D tempTex = new Texture2D(texture.width, texture.height); tempTex.SetPixels(texture.GetPixels()); // fill FloodFill.Fill(tempTex, 0, 0); FloodFill.Fill(tempTex, tempTex.width - 1, 0); FloodFill.Fill(tempTex, tempTex.width - 1, tempTex.height - 1); FloodFill.Fill(tempTex, 0, tempTex.height - 1); // holes ConnectedComponentLabeling ccl = new ConnectedComponentLabeling(); int holes = ccl.Process(tempTex, texture, false); RenderTexture.active = renderTextureTemp; GameObject.DestroyImmediate(camera); return(holes * (1f + Mathf.Exp(2f)) / (28.4103f * Mathf.Exp(2f)) + 43.9867f / 28.4103f); }
public override float Evaluate(Representation representation) { int boxSize = 1; int texSize = 512; RenderTexture renderTexture = new RenderTexture(texSize, texSize, 0); RenderTexture renderTextureTemp = RenderTexture.active; GameObject camera = new GameObject("Camera"); camera.transform.position = new Vector3(0, 150f, -290f); camera.AddComponent <Camera> (); camera.GetComponent <Camera> ().backgroundColor = Color.white; camera.GetComponent <Camera> ().orthographic = true; camera.GetComponent <Camera> ().orthographicSize = 150; camera.GetComponent <Camera> ().targetTexture = renderTexture; camera.AddComponent <GrayscaleBinary> (); Shader shd = Shader.Find("Hidden/GrayscaleBinary"); camera.GetComponent <GrayscaleBinary> ().shader = shd; RenderTexture.active = camera.GetComponent <Camera> ().targetTexture; camera.GetComponent <Camera> ().Render(); Texture2D texture = new Texture2D(renderTexture.width, renderTexture.height, TextureFormat.RGB24, false); texture.filterMode = FilterMode.Point; texture.wrapMode = TextureWrapMode.Clamp; texture.ReadPixels(new Rect(0, 0, renderTexture.width, renderTexture.height), 0, 0); texture.Apply(); GameObject debugPlane = GameObject.Find("DebugPlane") as GameObject; debugPlane.GetComponent <Renderer> ().material.mainTexture = texture; for (int i = 0; i < 3; i++) { TextureScale.Half(texture); boxSize *= 2; } // symmetry - new float minTreshold = 0.0f; float maxTreshold = 100.0f; float tryTreshold = 50.0f; for (int j = 0; j < 8; j++) { tryTreshold = (minTreshold + maxTreshold) / 2; TextureSymmertyDetector tsd = new TextureSymmertyDetector(); tsd.scoreThreshold = 0.8f + (tryTreshold / 500.0f); Symmetry symmetry = tsd.detectSymmetry(texture); bool tryTresholdValue = symmetry.getAngles().Length > 0; if (tryTresholdValue) { minTreshold = tryTreshold; } else { maxTreshold = tryTreshold; } } RenderTexture.active = renderTextureTemp; GameObject.DestroyImmediate(camera); return(tryTreshold / 100f); }
public override float Evaluate(Representation representation) { RepresentationMesh repre = representation as RepresentationMesh; if (repre == null) { return(0); } Vector4 structSize = getStructureSize(repre.goList); Vector2 minPoint = new Vector2(structSize.x, structSize.y); Vector2 maxPoint = new Vector2(structSize.z, structSize.w); Vector2 ivySize = maxPoint - minPoint; float cameraSize = Mathf.Max(ivySize.x, ivySize.y) / 2f; Vector3 cameraPosition = (maxPoint + minPoint) / 2f; cameraPosition.z = -10f; int texSize = 1024; float boxSize = 1f / (float)texSize; RenderTexture renderTexture = new RenderTexture(texSize, texSize, 0); RenderTexture renderTextureTemp = null; GameObject camera = new GameObject("Camera"); camera.transform.position = cameraPosition; camera.AddComponent <Camera> (); camera.GetComponent <Camera> ().backgroundColor = Color.white; camera.GetComponent <Camera> ().orthographic = true; camera.GetComponent <Camera> ().orthographicSize = cameraSize; camera.GetComponent <Camera> ().targetTexture = renderTexture; camera.AddComponent <GrayscaleBinary> (); camera.GetComponent <GrayscaleBinary> ().shader = Shader.Find("Hidden/GrayscaleBinary"); renderTextureTemp = RenderTexture.active; RenderTexture.active = renderTexture; camera.GetComponent <Camera> ().Render(); Texture2D texture = new Texture2D(renderTexture.width, renderTexture.height, TextureFormat.RGB24, false); texture.filterMode = FilterMode.Point; texture.wrapMode = TextureWrapMode.Clamp; texture.ReadPixels(new Rect(0, 0, renderTexture.width, renderTexture.height), 0, 0); texture.Apply(); TextureCount.Count(texture); List <Vector2> logValues = new List <Vector2> (); logValues.Add(new Vector2(Mathf.Log10(1f / boxSize), Mathf.Log10((float)TextureCount.boxCount))); while (texture.width > 8) { TextureScale.Half(texture); boxSize *= 2; if (TextureScale.newBoxCount == 0) { UnityEditor.EditorApplication.isPlaying = false; } logValues.Add(new Vector2(Mathf.Log10(1f / boxSize), Mathf.Log10((float)TextureScale.newBoxCount))); } float averageSlope = 0f; for (int i = 0; i < logValues.Count - 1; i++) { averageSlope += (logValues[i].y - logValues[i + 1].y) / (logValues[i].x - logValues[i + 1].x); } averageSlope /= (logValues.Count - 1); RenderTexture.active = renderTextureTemp; GameObject.DestroyImmediate(camera); return(averageSlope); }