//public void ChangeCoordinates(TopoVertex vertex, RHVector3 newPos) //{ // Remove(vertex); // vertex.pos = new RHVector3(newPos); // Add(vertex); //} //public void Add(TopoVertex vertex) //{ // Add(vertex, 0); //} //<Carson(Taipei)><12-14-2018><Modified> public void Add(TopoVertex vertex, bool checkHash = true) { if (checkHash) { Int64 temp = Convert.ToInt64(Math.Floor(vertex.pos.x * 100000)) * 5915587277 + Convert.ToInt64(Math.Floor(vertex.pos.y * 100000)) * 1500450271 + Convert.ToInt64(Math.Floor(vertex.pos.z * 100000)) * 3267000013; if (hash[temp] == null) { if ((count & 0x7FF) == 0) { v.Add(new List <TopoVertex>(listCapacity)); } hash.Add(temp, count); v[v.Count - 1].Add(vertex); count++; } } else { if ((count & 0x7FF) == 0) { v.Add(new List <TopoVertex>(listCapacity)); } v[v.Count - 1].Add(vertex); count++; } }
public TopoTriangle(TopoModel model, TopoVertex v1, TopoVertex v2, TopoVertex v3) { vertices[0] = v1; vertices[1] = v2; vertices[2] = v3; RecomputeNormal(); }
//--- public TopoTriangle(TopoModel model, TopoVertex v1, TopoVertex v2, TopoVertex v3, double nx, double ny, double nz) { vertices[0] = v1; vertices[1] = v2; vertices[2] = v3; normal = new RHVector3(nx, ny, nz); }
public TopoEdge EdgeWithVertices(TopoVertex v1, TopoVertex v2) { /*foreach (TopoEdge e in edges) * { * if ((e.v1 == v1 && e.v2 == v2) || (e.v2 == v1 && e.v1 == v2)) * return e; * }*/ return(null); }
//<Carson(Taipei)><11-23-2018><Modified> public TopoTriangle(TopoVertex v1, TopoVertex v2, TopoVertex v3, double nx, double ny, double nz, int index1, int index2, int index3) { vertices[0] = v1; vertices[1] = v2; vertices[2] = v3; normal = new RHVector3(nx, ny, nz); //indices[0] = index1 - 1; //indices[1] = index2 - 1; //indices[2] = index3 - 1; }
public void FlipDirection() { normal.Scale(-1); TopoVertex v = vertices[0]; vertices[0] = vertices[1]; vertices[1] = v; //TopoEdge e = edges[1]; //edges[1] = edges[2]; //edges[2] = e; }
void TestRightAngle() { TopoModel model = new TopoModel(); TopoVertex v1 = model.addVertex(new RHVector3(0, 0, 0)); TopoVertex v2 = model.addVertex(new RHVector3(10, 0, 0)); TopoVertex v3 = model.addVertex(new RHVector3(5, 5, 0)); TopoVertex v4 = model.addVertex(new RHVector3(0, 0, -5)); TopoVertex v5 = model.addVertex(new RHVector3(10, 0, -5)); TopoVertex v6 = model.addVertex(new RHVector3(5, 0, 5)); TopoTriangle t1 = model.AddTriangle(new TopoTriangle(model, v1, v2, v3)); TopoTriangle t2 = model.AddTriangle(new TopoTriangle(model, v4, v5, v6)); }
void TestInplaneOutside() { TopoModel model = new TopoModel(); TopoVertex v1 = model.addVertex(new RHVector3(0, 0, 0)); TopoVertex v2 = model.addVertex(new RHVector3(10, 0, 0)); TopoVertex v3 = model.addVertex(new RHVector3(10, 10, 0)); TopoVertex v4 = model.addVertex(new RHVector3(11, 1, 0)); TopoVertex v5 = model.addVertex(new RHVector3(17, 1, 0)); TopoVertex v6 = model.addVertex(new RHVector3(11, 7, 0)); TopoTriangle t1 = model.AddTriangle(new TopoTriangle(model, v1, v2, v3)); TopoTriangle t2 = model.AddTriangle(new TopoTriangle(model, v4, v5, v6)); }
void TestInplane3D_1() { TopoModel model = new TopoModel(); TopoVertex v1 = model.addVertex(new RHVector3(3.67848944664001, -2.6547646522522, 1.38814495312454E-14)); TopoVertex v2 = model.addVertex(new RHVector3(1.62981510162354, -1.05116808414459, 1.83297828141877E-14)); TopoVertex v3 = model.addVertex(new RHVector3(2.29873323440552, -0.79055267572403, 2.11497486191092E-14)); TopoVertex v4 = model.addVertex(new RHVector3(1.63205575942993, -1.05116808414459, 2.78849697113037)); TopoVertex v5 = model.addVertex(new RHVector3(0.916237592697144, -1.1297744512558, 1.83297828141877E-14)); TopoVertex v6 = model.addVertex(new RHVector3(1.38571500778198, -1.07829427719116, 2.67316389083862)); TopoTriangle t1 = model.AddTriangle(new TopoTriangle(model, v1, v2, v3)); TopoTriangle t2 = model.AddTriangle(new TopoTriangle(model, v4, v5, v6)); }
void TestInplaneInsideSameEdgeIntersects() { TopoModel model = new TopoModel(); TopoVertex v1 = model.addVertex(new RHVector3(0, 0, 0)); TopoVertex v2 = model.addVertex(new RHVector3(10, 0, 0)); TopoVertex v3 = model.addVertex(new RHVector3(10, 10, 0)); TopoVertex v4 = model.addVertex(new RHVector3(1, 1, 0)); TopoVertex v5 = model.addVertex(new RHVector3(7, 1, 0)); TopoVertex v6 = model.addVertex(new RHVector3(5, 3, 0)); TopoTriangle t1 = model.AddTriangle(new TopoTriangle(model, v1, v2, v3)); TopoTriangle t2 = model.AddTriangle(new TopoTriangle(model, v1, v2, v6)); }
void TestInplaneSameVertex() { TopoModel model = new TopoModel(); TopoVertex v1 = model.addVertex(new RHVector3(0, 0, 0)); TopoVertex v2 = model.addVertex(new RHVector3(10, 0, 0)); TopoVertex v3 = model.addVertex(new RHVector3(10, 10, 0)); TopoVertex v4 = model.addVertex(new RHVector3(10, -1, 0)); TopoVertex v5 = model.addVertex(new RHVector3(7, 1, 0)); TopoVertex v6 = model.addVertex(new RHVector3(1, -7, 0)); TopoTriangle t1 = model.AddTriangle(new TopoTriangle(model, v1, v2, v3)); TopoTriangle t2 = model.AddTriangle(new TopoTriangle(model, v1, v4, v6)); }
public int VertexIndexFor(TopoVertex test) { if (test == vertices[0]) { return(0); } if (test == vertices[1]) { return(1); } if (test == vertices[2]) { return(2); } return(-1); }
/*public TopoEdge CommonThirdEdge() * { * TopoVertex v1 = edgeA.v1; * if (edgeB.v1 == v1 || edgeB.v2 == v1) * v1 = edgeA.v2; * TopoVertex v2 = edgeB.v1; * if (edgeA.v1 == v2 || edgeA.v2 == v2) * v2 = edgeB.v2; * foreach (TopoTriangle t in v1.connectedFacesList) * { * TopoEdge e = t.EdgeWithVertices(v1, v2); * if (e != null) * return e; * } * return null; * }*/ public TopoTriangle BuildTriangle(TopoModel model) { TopoVertex sharedPoint = null; TopoVertex p1 = null, p2 = null; if (edgeA.v1 == edgeB.v1) { sharedPoint = edgeA.v1; p1 = edgeA.v2; p2 = edgeB.v2; } else if (edgeA.v1 == edgeB.v2) { sharedPoint = edgeA.v1; p1 = edgeA.v2; p2 = edgeB.v1; } else if (edgeA.v2 == edgeB.v1) { sharedPoint = edgeA.v1; p1 = edgeA.v1; p2 = edgeB.v2; } else if (edgeA.v2 == edgeB.v2) { sharedPoint = edgeA.v2; p1 = edgeA.v1; p2 = edgeB.v1; } TopoTriangle faceA = edgeA.faces.First.Value; TopoTriangle newTriangle = new TopoTriangle(model, sharedPoint, p1, p2, 0, 0, 1); if (newTriangle.SameNormalOrientation(faceA) == false) { newTriangle.FlipDirection(); } //newTriangle.RecomputeNormal(); model.AddTriangle(newTriangle); return(newTriangle); }
/*public void MarkConnectedFacesBad() * { * foreach (TopoTriangle triangle in faces) * triangle.bad = true; * } * * public double DihedralAngle() * { * if (faces.Count != 2) throw new Exception("DihedralAngle requires edge with 2 faces"); * return faces.First.Value.normal.AngleForNormalizedVectors(faces.Last.Value.normal); * }*/ public bool ContainsVertex(TopoVertex v) { return(v1 == v || v2 == v); }
public bool isBuildOf(TopoVertex _v1, TopoVertex _v2) { return((v1 == _v1 && v2 == _v2) || (v1 == _v2 && v2 == _v1)); }
/// <summary> /// Splits an edge and changes the connected triangles to maintain /// a topological correct system. /// </summary> /// <param name="model"></param> /// <param name="vertex"></param> public void InsertVertex(TopoModel model, TopoVertex vertex) { LinkedList <TopoTriangle> delList = new LinkedList <TopoTriangle>(); LinkedList <TopoTriangle> testFaces = new LinkedList <TopoTriangle>(); foreach (TopoTriangle oldTriangle in faces) { testFaces.AddLast(oldTriangle); } foreach (TopoTriangle oldTriangle in testFaces) { delList.AddLast(oldTriangle); for (int i = 0; i < 3; i++) { if (oldTriangle.vertices[i] != v1 && oldTriangle.vertices[i] != v2) { TopoTriangle newTriangle = new TopoTriangle(model, v1, vertex, oldTriangle.vertices[i]); if (newTriangle.IsDegenerated()) { newTriangle.Unlink(model); } else { // Test orientation /*for (int e = 0; e < 3; e++) * { * TopoTriangle neigbour = newTriangle.edges[i].GetFaceExcept(newTriangle); * if (neigbour != null) * { * if(!newTriangle.SameNormalOrientation(neigbour)) * newTriangle.FlipDirection(); * break; * } * }*/ model.AddTriangle(newTriangle); } newTriangle = new TopoTriangle(model, vertex, v2, oldTriangle.vertices[i]); if (newTriangle.IsDegenerated()) { newTriangle.Unlink(model); } else { // Test orientation /*for (int e = 0; e < 3; e++) * { * TopoTriangle neigbour = newTriangle.edges[i].GetFaceExcept(newTriangle); * if (neigbour != null) * { * if (!newTriangle.SameNormalOrientation(neigbour)) * newTriangle.FlipDirection(); * break; * } * }*/ model.AddTriangle(newTriangle); } } } } foreach (TopoTriangle tri in delList) { tri.Unlink(model); model.removeTriangle(tri); } }
public TopoEdge(TopoVertex _v1, TopoVertex _v2) { v1 = _v1; v2 = _v2; }
public double distance(TopoVertex vertex) { return(pos.Distance(vertex.pos)); }