Пример #1
0
        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];
            }
        }
Пример #2
0
        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();
        }
Пример #3
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);
        }
Пример #4
0
        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);
        }
Пример #5
0
 public void ComputeTraits()
 {
     AvgLength = TetMeshUtil.ComputeEdgeAvgLength(this);
 }