public void ComputeNormal() { foreach (var face in this.faces) { face.Normal = TetMeshUtil.ComputeNormal(face); } Vector3D[] vn = TetMeshUtil.ComputeNormalUniformWeight(this); foreach (var v in this.vertices) { v.Normal = vn[v.Index]; } }
public void DrawSelectedFaceNormal(TetMesh mesh) { OpenGLManager.Instance.SetColorMesh(GlobalSetting.DisplaySetting.NormalColor); double l = mesh.AvgLength * GlobalSetting.DisplaySetting.NormalLength; GL.Begin(BeginMode.Lines); foreach (var face in mesh.Faces) { if (face.SelectedNormal != Vector3D.Zero) { Vector3D mid = TetMeshUtil.GetMidPoint(face); Vector3D normal = face.SelectedNormal * l; GL.Vertex3(mid.ToArray()); GL.Vertex3((mid + normal).ToArray()); } } GL.End(); }
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 ChangePlane() { TetMesh mesh = GlobalData.Instance.TetMesh; foreach (var tet in mesh.Tetras) { PlaneIntersectionType intersect = TetMeshUtil.Intersect(this.plane, tet); if (intersect == PlaneIntersectionType.Front || (intersecting && intersect == PlaneIntersectionType.Intersecting)) { tet.Flag = 1; } else { tet.Flag = 0; } } mesh.ComputeSelectedNormal(); GlobalData.Instance.OnChanged(EventArgs.Empty); }
public void ComputeTraits() { AvgLength = TetMeshUtil.ComputeEdgeAvgLength(this); }