Example #1
0
        public static List <List <TriMesh.Face> > RetrieveFacePatchBySelectedEdge(TriMesh mesh)
        {
            bool[] faceFlag = new bool[mesh.Faces.Count];
            bool[] hfFlag   = new bool[mesh.HalfEdges.Count];
            List <List <TriMesh.Face> > all = new List <List <TriMesh.Face> >();

            foreach (TriMesh.HalfEdge hf in mesh.HalfEdges)
            {
                if (!hfFlag[hf.Index])
                {
                    List <TriMesh.Face>      list  = new List <HalfEdgeMesh.Face>();
                    Stack <TriMesh.HalfEdge> stack = new Stack <HalfEdgeMesh.HalfEdge>();
                    stack.Push(hf);
                    while (stack.Count != 0)
                    {
                        TriMesh.HalfEdge cur = stack.Pop();
                        hfFlag[cur.Index] = true;

                        if (!faceFlag[cur.Face.Index])
                        {
                            list.Add(cur.Face);
                            faceFlag[cur.Face.Index] = true;
                        }

                        TriMesh.HalfEdge[] arr = new HalfEdgeMesh.HalfEdge[]
                        {
                            cur.Opposite,
                            cur.Next,
                            cur.Previous
                        };
                        foreach (var item in arr)
                        {
                            if (!hfFlag[item.Index] &&
                                item.Face != null &&
                                item.Edge.Traits.SelectedFlag == 0)
                            {
                                stack.Push(item);
                            }
                        }
                    }
                    if (list.Count != 0)
                    {
                        all.Add(list);
                    }
                }
            }

            return(all);
        }
Example #2
0
        public static TriMesh.HalfEdge[] Sort(LinkedList <TriMesh.Edge> src)
        {
            LinkedList <TriMesh.HalfEdge> dst = new LinkedList <HalfEdgeMesh.HalfEdge>();

            dst.AddLast(src.First.Value.HalfEdge0);
            src.RemoveFirst();
            LinkedListNode <TriMesh.Edge> node = src.First;
            int count = 0;

            while (node != null)
            {
                TriMesh.Vertex first = dst.First.Value.FromVertex;
                TriMesh.Vertex last  = dst.Last.Value.ToVertex;

                if (node.Value.Vertex0 == first)
                {
                    dst.AddFirst(node.Value.HalfEdge0);
                    src.Remove(node);
                    count++;
                }
                else if (node.Value.Vertex1 == first)
                {
                    dst.AddFirst(node.Value.HalfEdge1);
                    src.Remove(node);
                    count++;
                }
                else if (node.Value.Vertex0 == last)
                {
                    dst.AddLast(node.Value.HalfEdge1);
                    src.Remove(node);
                    count++;
                }
                else if (node.Value.Vertex1 == last)
                {
                    dst.AddLast(node.Value.HalfEdge0);
                    src.Remove(node);
                    count++;
                }
                node = node.Next;
                if (node == null && count != 0)
                {
                    node  = src.First;
                    count = 0;
                }
            }
            TriMesh.HalfEdge[] arr = new HalfEdgeMesh.HalfEdge[dst.Count];
            dst.CopyTo(arr, 0);
            return(arr);
        }
Example #3
0
        public static TriMesh.HalfEdge[] Sort(LinkedList<TriMesh.Edge> src)
        {
            LinkedList<TriMesh.HalfEdge> dst = new LinkedList<HalfEdgeMesh.HalfEdge>();
            dst.AddLast(src.First.Value.HalfEdge0);
            src.RemoveFirst();
            LinkedListNode<TriMesh.Edge> node = src.First;
            int count = 0;
            while (node != null)
            {
                TriMesh.Vertex first = dst.First.Value.FromVertex;
                TriMesh.Vertex last = dst.Last.Value.ToVertex;

                if (node.Value.Vertex0 == first)
                {
                    dst.AddFirst(node.Value.HalfEdge0);
                    src.Remove(node);
                    count++;
                }
                else if (node.Value.Vertex1 == first)
                {
                    dst.AddFirst(node.Value.HalfEdge1);
                    src.Remove(node);
                    count++;
                }
                else if (node.Value.Vertex0 == last)
                {
                    dst.AddLast(node.Value.HalfEdge1);
                    src.Remove(node);
                    count++;
                }
                else if (node.Value.Vertex1 == last)
                {
                    dst.AddLast(node.Value.HalfEdge0);
                    src.Remove(node);
                    count++;
                }
                node = node.Next;
                if (node == null && count != 0)
                {
                    node = src.First;
                    count = 0;
                }
            }
            TriMesh.HalfEdge[] arr = new HalfEdgeMesh.HalfEdge[dst.Count];
            dst.CopyTo(arr, 0);
            return arr;
        }
Example #4
0
        public static List<List<TriMesh.Face>> RetrieveFacePatchBySelectedEdge(TriMesh mesh)
        {
            bool[] faceFlag = new bool[mesh.Faces.Count];
            bool[] hfFlag = new bool[mesh.HalfEdges.Count];
            List<List<TriMesh.Face>> all = new List<List<TriMesh.Face>>();

            foreach (TriMesh.HalfEdge  hf in mesh.HalfEdges)
            {
                if (!hfFlag[hf.Index])
                {
                    List<TriMesh.Face> list = new List<HalfEdgeMesh.Face>();
                    Stack<TriMesh.HalfEdge> stack = new Stack<HalfEdgeMesh.HalfEdge>();
                    stack.Push(hf);
                    while (stack.Count != 0)
                    {
                        TriMesh.HalfEdge cur = stack.Pop();
                        hfFlag[cur.Index] = true;

                        if (!faceFlag[cur.Face.Index])
                        {
                            list.Add(cur.Face);
                            faceFlag[cur.Face.Index] = true;
                        }

                        TriMesh.HalfEdge[] arr = new HalfEdgeMesh.HalfEdge[]
                        {
                            cur.Opposite,
                            cur.Next,
                            cur.Previous
                        };
                        foreach (var item in arr)
                        {
                            if (!hfFlag[item.Index] &&
                                item.Face != null &&
                                item.Edge.Traits.SelectedFlag == 0)
                            {
                                stack.Push(item);
                            }
                        }
                    }
                    if (list.Count != 0)
                    {
                        all.Add(list);
                    }
                }
            }

            return all;
        }
Example #5
0
        public static void ComputeCornerArea(TriMesh mesh,out double[] CornerArea, out double[] PointArea)
        {
            CornerArea = new double[mesh.HalfEdges.Count];
            PointArea = new double[mesh.Vertices.Count];

            foreach (var face in  mesh.Faces)
            {
                double area = TriMeshUtil.ComputeAreaFace(face);

                TriMesh.HalfEdge[] hf = new HalfEdgeMesh.HalfEdge[]
                {
                    face.HalfEdge,
                    face.HalfEdge.Next,
                    face.HalfEdge.Previous
                };

                int[] index = new int[3];
                for (int i = 0; i < 3; i++)
                {
                    index[i] = hf[i].Index;
                }

                Vector3D[] e = new Vector3D[3];
                for (int i = 0; i < 3; i++)
                {
                    e[i] = TriMeshUtil.GetHalfEdgeVector(hf[i].Previous);
                }

                double[] l2 = new double[3];
                for (int i = 0; i < 3; i++)
                {
                    l2[i] = e[i].LengthSquared;
                }

                double[] ew = new double[3];
                for (int i = 0; i < 3; i++)
                {
                    ew[i] = l2[i] * (l2[(i + 1) % 3] + l2[(i + 2) % 3] - l2[i]);
                }

                bool flag = false;
                for (int i = 0; i < 3; i++)
                {
                    if (ew[i] < 0d)
                    {
                        int a = (i + 1) % 3;
                        int b = (i + 2) % 3;
                        CornerArea[index[a]] = -0.25d * l2[b] * area / e[i].Dot(e[b]);
                        CornerArea[index[b]] = -0.25d * l2[a] * area / e[i].Dot(e[a]);
                        CornerArea[index[i]] = area -  CornerArea[index[a]] -  CornerArea[index[b]];
                        flag = true;
                    }
                }
                if (!flag)
                {
                    double ewscale = 0.5d * area / (ew[0] + ew[1] + ew[2]);
                    for (int i = 0; i < 3; i++)
                    {
                        CornerArea[index[i]] = ewscale * (ew[(i + 1) % 3] + ew[(i + 2) % 3]);
                    }
                }

                for (int i = 0; i < 3; i++)
                {
                     PointArea[hf[i].ToVertex.Index] += CornerArea[index[i]];
                }
            }
        }
Example #6
0
        public static void ComputeCornerArea(TriMesh mesh, out double[] CornerArea, out double[] PointArea)
        {
            CornerArea = new double[mesh.HalfEdges.Count];
            PointArea  = new double[mesh.Vertices.Count];

            foreach (var face in  mesh.Faces)
            {
                double area = TriMeshUtil.ComputeAreaFace(face);

                TriMesh.HalfEdge[] hf = new HalfEdgeMesh.HalfEdge[]
                {
                    face.HalfEdge,
                    face.HalfEdge.Next,
                    face.HalfEdge.Previous
                };

                int[] index = new int[3];
                for (int i = 0; i < 3; i++)
                {
                    index[i] = hf[i].Index;
                }

                Vector3D[] e = new Vector3D[3];
                for (int i = 0; i < 3; i++)
                {
                    e[i] = TriMeshUtil.GetHalfEdgeVector(hf[i].Previous);
                }

                double[] l2 = new double[3];
                for (int i = 0; i < 3; i++)
                {
                    l2[i] = e[i].LengthSquared;
                }

                double[] ew = new double[3];
                for (int i = 0; i < 3; i++)
                {
                    ew[i] = l2[i] * (l2[(i + 1) % 3] + l2[(i + 2) % 3] - l2[i]);
                }

                bool flag = false;
                for (int i = 0; i < 3; i++)
                {
                    if (ew[i] < 0d)
                    {
                        int a = (i + 1) % 3;
                        int b = (i + 2) % 3;
                        CornerArea[index[a]] = -0.25d * l2[b] * area / e[i].Dot(e[b]);
                        CornerArea[index[b]] = -0.25d * l2[a] * area / e[i].Dot(e[a]);
                        CornerArea[index[i]] = area - CornerArea[index[a]] - CornerArea[index[b]];
                        flag = true;
                    }
                }
                if (!flag)
                {
                    double ewscale = 0.5d * area / (ew[0] + ew[1] + ew[2]);
                    for (int i = 0; i < 3; i++)
                    {
                        CornerArea[index[i]] = ewscale * (ew[(i + 1) % 3] + ew[(i + 2) % 3]);
                    }
                }

                for (int i = 0; i < 3; i++)
                {
                    PointArea[hf[i].ToVertex.Index] += CornerArea[index[i]];
                }
            }
        }