예제 #1
0
        public void DrawVertexPrincipleDirection(TriMesh mesh)
        {
            OpenGLManager.Instance.SetColor(GlobalSetting.DisplaySetting.NormalColor);
            double avgLength = TriMeshUtil.ComputeEdgeAvgLength(mesh);

            avgLength *= GlobalSetting.DisplaySetting.NormalLength;
            foreach (TriMesh.Vertex item in mesh.Vertices)
            {
                Vector3D maxnormal =
                    item.Traits.MaxCurvatureDirection.Normalize() * avgLength;
                Vector3D minnormal =
                    item.Traits.MinCurvatureDirection.Normalize() * avgLength;
                double x = item.Traits.Position.x;
                double y = item.Traits.Position.y;
                double z = item.Traits.Position.z;
                GL.Material(MaterialFace.Front, MaterialParameter.Diffuse,
                            GlobalSetting.DisplaySetting.FirstPricipalColor);
                GL.Begin(BeginMode.Lines);

                GL.Vertex3(x, y, z);
                GL.Vertex3(x + maxnormal.x, y + maxnormal.y, z + maxnormal.z);
                GL.End();

                GL.Material(MaterialFace.Front, MaterialParameter.Diffuse,
                            GlobalSetting.DisplaySetting.SecondPricipalColor);
                GL.Begin(BeginMode.Lines);

                GL.Vertex3(x, y, z);
                GL.Vertex3(x + minnormal.x, y + minnormal.y, z + minnormal.z);
                GL.End();
            }
        }
예제 #2
0
        public static void AddNoiseTwo(TriMesh Mesh, double rate, int iter)
        {
            Random random = new Random();

            double[] scale     = new double[Mesh.Vertices.Count];
            double   max       = TriMeshUtil.ComputeBoundingSphere(Mesh).Radius *rate;
            double   avglength = TriMeshUtil.ComputeEdgeAvgLength(Mesh);

            foreach (var v in Mesh.Vertices)
            {
                scale[v.Index] = max * (random.NextDouble() - 0.5f) * 2;
            }

            for (int i = 0; i < max / avglength * iter; i++)
            {
                foreach (var v in Mesh.Vertices)
                {
                    double sum   = 0;
                    int    count = 0;
                    foreach (var r in v.Vertices)
                    {
                        sum += scale[r.Index];
                        count++;
                    }
                    double weight = 0.5;
                    scale[v.Index] = scale[v.Index] * weight + sum / count * (1 - weight);
                }
            }
            foreach (var v in Mesh.Vertices)
            {
                Vector3D normal = v.Traits.Normal.Normalize();
                v.Traits.Position += normal * scale[v.Index];
            }
        }
예제 #3
0
        private void Cut_Click(object sender, EventArgs e)
        {
            TriMeshModify.ComputeSelectedEdgeFromColor(Mesh);
            double move = TriMeshUtil.ComputeEdgeAvgLength(Mesh) * 0.1;
            TriMeshEdgeCutFromBoundary cut = new TriMeshEdgeCutFromBoundary(Mesh);

            cut.Cut(move);

            TriMeshUtil.ClearMeshColor(Mesh);
            TriMeshUtil.ShowBoundary(Mesh);
            TriMeshUtil.FixIndex(Mesh);
            TriMeshUtil.SetUpNormalVertex(Mesh);
            OnChanged(EventArgs.Empty);
        }
예제 #4
0
        public static void AddNoise(TriMesh Mesh, double threshold)
        {
            Random random    = new Random();
            double avglength = TriMeshUtil.ComputeEdgeAvgLength(Mesh);

            threshold *= avglength;
            foreach (TriMesh.Vertex item in Mesh.Vertices)
            {
                Vector3D normal = item.Traits.Normal.Normalize();
                double   scale  = threshold * (random.NextDouble() - 0.5f);
                item.Traits.Position.x += normal.x * scale;
                item.Traits.Position.y += normal.y * scale;
                item.Traits.Position.z += normal.z * scale;
            }
        }
예제 #5
0
        public void DrawVertexNormal(TriMesh mesh)
        {
            OpenGLManager.Instance.SetColor(GlobalSetting.DisplaySetting.NormalColor);
            double avgLength = TriMeshUtil.ComputeEdgeAvgLength(mesh);

            avgLength *= GlobalSetting.DisplaySetting.NormalLength;
            foreach (TriMesh.Vertex item in mesh.Vertices)
            {
                Vector3D normal = item.Traits.Normal.Normalize() * avgLength;
                double   x      = item.Traits.Position.x;
                double   y      = item.Traits.Position.y;
                double   z      = item.Traits.Position.z;
                GL.Begin(BeginMode.Lines);
                GL.Vertex3(x, y, z);
                GL.Vertex3(x + normal.x, y + normal.y, z + normal.z);
                GL.End();
            }
        }
예제 #6
0
        public static void BoundaryExpand(TriMesh mesh)
        {
            double length = TriMeshUtil.ComputeEdgeAvgLength(mesh);
            List <List <TriMesh.HalfEdge> > holes = TriMeshUtil.RetrieveBoundaryEdgeAll(mesh);

            foreach (var hole in holes)
            {
                TriMesh.Vertex[] arr = new HalfEdgeMesh.Vertex[hole.Count];
                for (int i = 0; i < hole.Count; i++)
                {
                    Vector3D normal = Vector3D.UnitX;
                    if (hole[i].Opposite.Face != null)
                    {
                        normal = TriMeshUtil.ComputeNormalFace(hole[i].Opposite.Face);
                    }
                    Vector3D toPos   = hole[i].ToVertex.Traits.Position;
                    Vector3D fromPos = hole[i].FromVertex.Traits.Position;
                    Vector3D hfDir   = toPos - fromPos;
                    Vector3D hfMid   = (toPos + fromPos) / 2;
                    Vector3D pos     = hfMid + normal.Cross(hfDir).Normalize() * length;
                    arr[i] = mesh.Vertices.Add(new VertexTraits(pos));
                }
                for (int i = 0; i < hole.Count; i++)
                {
                    int          next = (i + 1) % hole.Count;
                    TriMesh.Face face = mesh.Faces.Add(arr[i],
                                                       hole[i].ToVertex,
                                                       hole[next].ToVertex);
                    face.Traits.SelectedFlag = 1;
                    face = mesh.Faces.Add(arr[i],
                                          hole[next].ToVertex,
                                          arr[next]);
                    face.Traits.SelectedFlag = 1;
                }
            }
        }
예제 #7
0
        public void DrawFaceNormal(TriMesh mesh)
        {
            OpenGLManager.Instance.SetColor(GlobalSetting.DisplaySetting.NormalColor);
            double avgLength = TriMeshUtil.ComputeEdgeAvgLength(mesh);

            avgLength *= GlobalSetting.DisplaySetting.NormalLength;
            foreach (TriMesh.Face item in mesh.Faces)
            {
                double x = (item.GetVertex(0).Traits.Position.x +
                            item.GetVertex(1).Traits.Position.x +
                            item.GetVertex(2).Traits.Position.x) / 3;
                double y = (item.GetVertex(0).Traits.Position.y +
                            item.GetVertex(1).Traits.Position.y +
                            item.GetVertex(2).Traits.Position.y) / 3;
                double z = (item.GetVertex(0).Traits.Position.z +
                            item.GetVertex(1).Traits.Position.z +
                            item.GetVertex(2).Traits.Position.z) / 3;
                Vector3D normal = item.Traits.Normal.Normalize() * avgLength;
                GL.Begin(BeginMode.Lines);
                GL.Vertex3(x, y, z);
                GL.Vertex3(x + normal.x, y + normal.y, z + normal.z);
                GL.End();
            }
        }