예제 #1
0
        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;
        }
예제 #2
0
 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;
     }
 }
예제 #3
0
        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);
            }
        }
예제 #4
0
        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);
            }
        }
예제 #5
0
        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);
        }
예제 #6
0
        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;
        }
예제 #7
0
        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;
        }
예제 #8
0
        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);
        }
예제 #9
0
 public static Vector3D GetMidPoint(TetFace face)
 {
     return((face.Vertices[0].Pos + face.Vertices[1].Pos + face.Vertices[2].Pos) / 3);
 }
예제 #10
0
        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);
            }
        }
예제 #11
0
 public static Vector3D GetMidPoint(TetFace face)
 {
     return (face.Vertices[0].Pos + face.Vertices[1].Pos + face.Vertices[2].Pos) / 3;
 }