public LRBuilder(Point3D[] vertices, Triangle[] triangles) { IFLTriangleMesh iflTriangleMesh = new IFLTriangleMesh(); iflTriangleMesh.V = vertices; iflTriangleMesh.Triangles = triangles; IConverter<CTTriangleMesh> iflToCt = Converter.Converter.GetSpecificConverter<IFLTriangleMesh, CTTriangleMesh>(iflTriangleMesh); DateTime startTime = DateTime.Now; this.ctTriangleMesh = iflToCt.Convert(); DateTime endTime = DateTime.Now; TimeSpan span = endTime.Subtract(startTime); Init(); }
private void T0LookUp(int currIndex, int[] faces) { //Look through all the faces, the vertex is incident with and find all T0-triangles for (int j = 0; j < faces.Length; j++) { if (!tProcessed[faces[j]]) //Only look at faces, which haven't been already processed { //Get the specific corner for the vertex and current face and get the next and previous corners of the triangle int c = ctTriangleMesh.GetSpecificCorner(faces[j], currIndex); int cn = ctTriangleMesh.N(c); int cp = ctTriangleMesh.P(c); //Happens if theres a vertex defined which is not used in the mesh if (c == -1) return; //Check if face has no ring edge at all -> then it's a T0 if (!IsRingEdge(c, cn) && !IsRingEdge(c, cp) && !IsRingEdge(cn, cp)) { CheckAndResolveIsolatedVertex(ctTriangleMesh.V(cn)); CheckAndResolveIsolatedVertex(ctTriangleMesh.V(cp)); //Create and add triangle Triangle triangle = new Triangle { Vertex1 = vertexMapping[ctTriangleMesh.V(c)], Vertex2 = vertexMapping[ctTriangleMesh.V(cp)], Vertex3 = vertexMapping[ctTriangleMesh.V(cn)] }; t.Add(triangle); //Get opposite entries, for each corner int co = ctTriangleMesh.Opposite[c]; int cno = ctTriangleMesh.Opposite[cn]; int cpo = ctTriangleMesh.Opposite[cp]; //Check if any of those opposite vertices is an isolated one and create an entry if necessary CheckAndResolveIsolatedVertex(ctTriangleMesh.V(co)); CheckAndResolveIsolatedVertex(ctTriangleMesh.V(cno)); CheckAndResolveIsolatedVertex(ctTriangleMesh.V(cpo)); //Get all adjacent, expensive Triangles of the T0 (Expensive triangles are those adjacent with the T0, which are not a T0 themselves) if(!tProcessed[co/3]) ExpensiveTriangleLookup(co); if (!tProcessed[cpo / 3]) ExpensiveTriangleLookup(cpo); if (!tProcessed[cno / 3]) ExpensiveTriangleLookup(cno); //resolve the corners, which need to be stored explicitly //lrCornerResolver.UpdateLrMesh(lrTriangleMesh); lrCornerResolver.ResolveCorners(c, co); lrCornerResolver.ResolveCorners(cp, cpo); lrCornerResolver.ResolveCorners(cn, cno); //Mark this triangle as processed tProcessed[faces[j]] = true; } } } }
private void drawTriangle(Triangle t, Point3D[] points, GraphicsDevice d, Color c) { VertexPositionColor[] tri = {new VertexPositionColor(Vector3Extension.CreateV3FromP3(points[t.Vertex1]), c), new VertexPositionColor(Vector3Extension.CreateV3FromP3(points[t.Vertex2]), c), new VertexPositionColor(Vector3Extension.CreateV3FromP3(points[t.Vertex3]), c)}; d.DrawUserPrimitives<VertexPositionColor>(PrimitiveType.TriangleList, tri, 0, 1); }
/// <summary> /// Loads the input file. /// I property values remain unchanged since the last run, then the file is not reloaded, unless the Realod property is set to true. /// </summary> public IFLTriangleMesh Execute(string fn) { // first pass determines the number of vertices and the number of triangles StreamReader sr; try { sr = new StreamReader(fn); } catch (FileNotFoundException fnfe) { throw new Exception(fnfe.Message); } int triangleCount = 0; int vertexCount = 0; int lineCount = 0; int textureCoordinateCount = 0; string line = sr.ReadLine(); bool normalsFound = false; while (line != null) { line = line.Trim(); if (line.StartsWith("v ")) vertexCount++; if (line.StartsWith("vt ")) textureCoordinateCount++; if (line.StartsWith("vn ")) normalsFound = true; if ((line.StartsWith("f ")) || (line.StartsWith("fo ")) || line.StartsWith("f\t")) { triangleCount++; if (line.Split(new char[] { ' ', '\t' }).Length == 5) triangleCount++; } line = sr.ReadLine(); lineCount++; } sr.Close(); // second pass performs the actual parsing sr = new StreamReader(fn); Point3D[] vertices = new Point3D[vertexCount]; Triangle[] triangles = new Triangle[triangleCount]; int vi = 0; int ti = 0; int ni = 0; int tci = 0; Point3D point; Triangle triangle, textureTriangle; NumberFormatInfo nfi = new NumberFormatInfo(); nfi.NumberDecimalSeparator = "."; nfi.NumberGroupSeparator = ","; int linePos = 0; line = sr.ReadLine(); while (line != null) { line = line.Trim(); //parsing of a vertex if (line.StartsWith("v ")) { string[] coords = line.Split(new char[] { ' ' }, 4, StringSplitOptions.RemoveEmptyEntries); double c1 = double.Parse(coords[1], nfi); double c2 = double.Parse(coords[2], nfi); double c3 = double.Parse(coords[3], nfi); point = new Point3D { X = c1, Y = c2, Z = c3 }; vertices[vi] = point; vi++; } // parsing of a triangle if ((line.StartsWith("f ")) || (line.StartsWith("fo ")) || (line.StartsWith("f\t"))) { string[] indices = line.Split(new char[] { ' ', '\t' }, 5, StringSplitOptions.RemoveEmptyEntries); int t1 = 0; int t2 = 0; int t3 = 0; string[] parts = indices[1].Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries); int v1 = int.Parse(parts[0]) - 1; if (parts.Length > 1) t1 = int.Parse(parts[1]) - 1; parts = indices[2].Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries); int v2 = int.Parse(parts[0]) - 1; if (parts.Length > 1) t2 = int.Parse(parts[1]) - 1; parts = indices[3].Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries); int v3 = int.Parse(parts[0]) - 1; if (parts.Length > 1) t3 = int.Parse(parts[1]) - 1; if (flipNormals) { triangle = new Triangle { Vertex1 = v1, Vertex2 = v3, Vertex3 = v2 }; textureTriangle = new Triangle { Vertex1 = t1, Vertex2 = t3, Vertex3 = t2 }; } else { triangle = new Triangle { Vertex1 = v1, Vertex2 = v2, Vertex3 = v3 }; textureTriangle = new Triangle { Vertex1 = t1, Vertex2 = t2, Vertex3 = t3 }; } if (indices.Length == 4) { triangles[ti] = triangle; ti++; } if (indices.Length == 5) { parts = indices[4].Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries); v2 = int.Parse(parts[0]) - 1; if (parts.Length > 1) t2 = int.Parse(parts[1]) - 1; if (flipNormals) { triangle = new Triangle { Vertex1 = v1, Vertex2 = v3, Vertex3 = v2 }; textureTriangle = new Triangle { Vertex1 = t1, Vertex2 = t2, Vertex3 = t3 }; } else { triangle = new Triangle { Vertex1 = v1, Vertex2 = v3, Vertex3 = v2 }; textureTriangle = new Triangle { Vertex1 = t1, Vertex2 = t2, Vertex3 = t3 }; } triangles[ti] = triangle; ti++; } } line = sr.ReadLine(); linePos++; } // creating an output Mesh instance output = new IFLTriangleMesh(); output.V = vertices; output.Triangles = triangles; return (output); }
private void drawTriangle(Triangle t, Point3D[] points, GraphicsDevice d) { drawTriangle(t, points, d, nextColor()); }