private void AddIntersectionPoints([CanBeNull] IPointCollection pointCollection) { if (pointCollection == null || ((IGeometry)pointCollection).IsEmpty) { return; } if (IntersectionPoints == null) { IntersectionPoints = (IPointCollection)GeometryFactory.CreateMultipoint(pointCollection); } else { IntersectionPoints.AddPointCollection(pointCollection); } }
public void drawFaceOnTex() //This is where magic happens { if (this.GetComponent <ARFaceMeshVisualizer>().mesh.vertexCount > 0 && !isDoFile) //This block converts the world space of face mesh to screen points { s = "Face Found"; GameObject.Find("detailsLabel").GetComponent <TextMeshProUGUI>().text = s; checkingOfFiles(); faceMesh = Instantiate(this.GetComponent <ARFaceMeshVisualizer>().mesh); screenPointInfo = new Vector2[faceMesh.vertexCount]; ScreenCapture.CaptureScreenshot("screenshot.png"); for (int i = 0; i < faceMesh.vertexCount; i++) { screenPoint = cam.WorldToScreenPoint(transform.TransformPoint((Vector3)faceMesh.vertices.GetValue(i))); screenPointInfo[i].x = Mathf.RoundToInt(screenPoint.x); screenPointInfo[i].y = Mathf.RoundToInt(screenPoint.y); } s = "Face processing is Done"; GameObject.Find("detailsLabel").GetComponent <TextMeshProUGUI>().text = s; isDoFile = !isDoFile; } if (!isDoFile) { s = "Face processing Not Yet Done"; GameObject.Find("detailsLabel").GetComponent <TextMeshProUGUI>().text = s; return; } if (!System.IO.File.Exists(Application.persistentDataPath + "/screenshot.png")) { s = "Face data is not yet saved.\nPlease press again."; GameObject.Find("detailsLabel").GetComponent <TextMeshProUGUI>().text = s; return; } if (System.IO.File.Exists(Application.persistentDataPath + "/screenshot.png")) { byte[] screeshotImage = File.ReadAllBytes(Application.persistentDataPath + "/screenshot.png"); ImageConversion.LoadImage(screenshotTex, screeshotImage); } s = "Face data saving Started."; GameObject.Find("detailsLabel").GetComponent <TextMeshProUGUI>().text = s; Color color; Vector2 scale = new Vector2(texSize, texSize); //This block converts takes a triangle of the face mesh and rasterizes the face of user to texture for (int i = 0; i < faceMesh.triangles.Length; i = i + 3) { //for facetexture Vector2 p1 = faceMesh.uv[faceMesh.triangles[i]]; Vector2 p2 = faceMesh.uv[faceMesh.triangles[i + 1]]; Vector2 p3 = faceMesh.uv[faceMesh.triangles[i + 2]]; //for screenshot Vector2 ps1 = screenPointInfo[faceMesh.triangles[i]]; Vector2 ps2 = screenPointInfo[faceMesh.triangles[i + 1]]; Vector2 ps3 = screenPointInfo[faceMesh.triangles[i + 2]]; float Hscale; float Vscale; p1.Scale(scale); p2.Scale(scale); p3.Scale(scale); Line l1 = new Line(p1, p2); Line l2 = new Line(p2, p3); Line l3 = new Line(p3, p1); Line ls1 = new Line(ps1, ps2); Line ls2 = new Line(ps2, ps3); Line ls3 = new Line(ps3, ps1); Line l4 = l1.getPerpendicularLine(p3); Line ls4 = ls1.getPerpendicularLine(ps3); IntersectionPoints ip1 = new IntersectionPoints(l1, l4); IntersectionPoints ips1 = new IntersectionPoints(ls1, ls4); Vscale = getDistance(ps3, ips1.getInteresectionPoint()) / getDistance(p3, ip1.getInteresectionPoint()); List <Vector2> altLinePoints = l4.getBoundingPoints(p3, ip1.getInteresectionPoint()); foreach (Vector2 point in altLinePoints) { Line l5 = l1.getParallelLine(point); IntersectionPoints ip2 = new IntersectionPoints(l5, l2); IntersectionPoints ip3 = new IntersectionPoints(l5, l3); Vector2 point1 = ls4.getPointOnLineByDistance(ps3, ips1.getInteresectionPoint(), getDistance(p3, point) * Vscale); Line ls5 = ls1.getParallelLine(point1); IntersectionPoints ips2 = new IntersectionPoints(ls5, ls2); IntersectionPoints ips3 = new IntersectionPoints(ls5, ls3); Hscale = getDistance(ips2.getInteresectionPoint(), ips3.getInteresectionPoint()) / getDistance(ip2.getInteresectionPoint(), ip3.getInteresectionPoint()); List <Vector2> parallelLinePoints = l5.getBoundingPoints(ip2.getInteresectionPoint(), ip3.getInteresectionPoint()); foreach (Vector2 subPoint in parallelLinePoints) { Vector2 subPoint1 = ls5.getPointOnLineByDistance(ips2.getInteresectionPoint(), ips3.getInteresectionPoint(), getDistance(ip2.getInteresectionPoint(), subPoint) * Hscale); color = screenshotTex.GetPixel(Mathf.RoundToInt(subPoint1.x), Mathf.RoundToInt(subPoint1.y)); tex.SetPixel(Mathf.RoundToInt(subPoint.x), Mathf.RoundToInt(subPoint.y), color); } } } tex.Apply(); System.IO.File.WriteAllBytes(Application.persistentDataPath + "/screenpointinfo.png", tex.EncodeToPNG()); s = "Face data is saved."; GameObject.Find("detailsLabel").GetComponent <TextMeshProUGUI>().text = s; writeMeshData(); }
public IntersectionPoints getIntersectionpoints(Line l2) { IntersectionPoints ip1 = new IntersectionPoints(this, l2); return(ip1); }