public static Vector3D ComputeNormal(TetFace face) { if (face.Tetras.Count != 1) { return Vector3D.Zero; } Vector3D[] v = new Vector3D[3]; for (int i = 0; i < 3; i++) { v[i] = face.Vertices[i].Pos; } Vector3D n = (v[1] - v[0]).Cross(v[2] - v[0]).Normalize(); foreach (var vt in face.Tetras[0].Vertices) { bool top = true; foreach (var vf in face.Vertices) { if (vt == vf) { top = false; break; } } if (top && n.Dot(vt.Pos - v[0]) > 0) { n = -n; TetVertex temp = face.Vertices[0]; face.Vertices[0] = face.Vertices[2]; face.Vertices[2] = temp; break; } } return n; }
public static Tetrahedron CheckBoundary(TetFace face) { Tetrahedron t0 = face.Tetras.Count > 0 && face.Tetras[0].Flag > 0 ? face.Tetras[0] : null; Tetrahedron t1 = face.Tetras.Count > 1 && face.Tetras[1].Flag > 0 ? face.Tetras[1] : null; if (t0 != null && t1 == null) { return t0; } else if (t0 == null && t1 != null) { return t1; } else { return null; } }
public static Tetrahedron CheckBoundary(TetFace face) { Tetrahedron t0 = face.Tetras.Count > 0 && face.Tetras[0].Flag > 0 ? face.Tetras[0] : null; Tetrahedron t1 = face.Tetras.Count > 1 && face.Tetras[1].Flag > 0 ? face.Tetras[1] : null; if (t0 != null && t1 == null) { return(t0); } else if (t0 == null && t1 != null) { return(t1); } else { return(null); } }
void ReadFaceFile() { string[] all = File.ReadAllLines(faceFile); int[] arr = ReadIntLine(GetFirstLine(all)); foreach (var line in GetRemainingLine(all)) { arr = ReadIntLine(line); TetFace face = new TetFace(); face.Vertices.Add(mesh.Vertices[arr[1]]); face.Vertices.Add(mesh.Vertices[arr[2]]); face.Vertices.Add(mesh.Vertices[arr[3]]); face.Vertices.TrimExcess(); face.Index = mesh.Faces.Count; face.B = arr[4] == 1; mesh.Faces.Add(face); } }
public static Vector3D ComputeNormal(TetFace face) { if (face.OnBoundary) { return(TetMeshUtil.ComputeNormal(face)); } Tetrahedron selected = CheckBoundary(face); if (selected == null) { return(Vector3D.Zero); } Vector3D[] v = new Vector3D[3]; for (int i = 0; i < 3; i++) { v[i] = face.Vertices[i].Pos; } Vector3D n = (v[1] - v[0]).Cross(v[0] - v[2]).Normalize(); foreach (var vt in selected.Vertices) { bool top = true; foreach (var vf in face.Vertices) { if (vt == vf) { top = false; break; } } if (top && n.Dot(vt.Pos - v[0]) > 0) { n = -n; TetVertex temp = face.Vertices[0]; face.Vertices[0] = face.Vertices[2]; face.Vertices[2] = temp; break; } } return(n); }
public static Vector3D ComputeNormal(TetFace face) { if (face.OnBoundary) { return TetMeshUtil.ComputeNormal(face); } Tetrahedron selected = CheckBoundary(face); if (selected == null) { return Vector3D.Zero; } Vector3D[] v = new Vector3D[3]; for (int i = 0; i < 3; i++) { v[i] = face.Vertices[i].Pos; } Vector3D n = (v[1] - v[0]).Cross(v[0] - v[2]).Normalize(); foreach (var vt in selected.Vertices) { bool top = true; foreach (var vf in face.Vertices) { if (vt == vf) { top = false; break; } } if (top && n.Dot(vt.Pos - v[0]) > 0) { n = -n; TetVertex temp = face.Vertices[0]; face.Vertices[0] = face.Vertices[2]; face.Vertices[2] = temp; break; } } return n; }
void RefreshFace() { TetMesh mesh = GlobalData.Instance.TetMesh; this.onLoad = true; this.faceView.Rows.Clear(); this.faceView.Rows.Add(mesh.Faces.Count); for (int i = 0; i < mesh.Faces.Count; i++) { TetFace f = mesh.Faces[i]; DataGridViewRow row = this.faceView.Rows[i]; row.Cells["FIndex"].Value = f.Index; row.Cells["FFlag"].Value = f.Flag; row.Cells["FBoundary"].Value = f.OnBoundary; row.Cells["FV0"].Value = f.Vertices[0].Index; row.Cells["FV1"].Value = f.Vertices[1].Index; row.Cells["FV2"].Value = f.Vertices[2].Index; } this.onLoad = false; }
public static Vector3D ComputeNormal(TetFace face) { if (face.Tetras.Count != 1) { return(Vector3D.Zero); } Vector3D[] v = new Vector3D[3]; for (int i = 0; i < 3; i++) { v[i] = face.Vertices[i].Pos; } Vector3D n = (v[1] - v[0]).Cross(v[2] - v[0]).Normalize(); foreach (var vt in face.Tetras[0].Vertices) { bool top = true; foreach (var vf in face.Vertices) { if (vt == vf) { top = false; break; } } if (top && n.Dot(vt.Pos - v[0]) > 0) { n = -n; TetVertex temp = face.Vertices[0]; face.Vertices[0] = face.Vertices[2]; face.Vertices[2] = temp; break; } } return(n); }
public static Vector3D GetMidPoint(TetFace face) { return((face.Vertices[0].Pos + face.Vertices[1].Pos + face.Vertices[2].Pos) / 3); }
public static Vector3D GetMidPoint(TetFace face) { return (face.Vertices[0].Pos + face.Vertices[1].Pos + face.Vertices[2].Pos) / 3; }