Exemplo n.º 1
0
        public static int RemoveDuplicates <T>(T[] data) where T : IComparable <T>
        {
            QuickSorter <T> sorter = new QuickSorter <T>();

            sorter.A = data;
            sorter.Sort();
            int lastIndex = 0;

            for (int i = 0; i < data.Length; i++)
            {
                if (data[i].CompareTo(data[lastIndex]) == 0)
                {
                    continue;
                }
                else
                {
                    data[lastIndex + 1] = data[i];
                    lastIndex++;
                }
            }
            return(lastIndex + 1);
        }//remove duplicates in an T array
Exemplo n.º 2
0
        }//remove duplicates in an T array

        public static Mesh WeldingVertices(List <OriginalTriangle> triangleSoup)
        {
            Mesh mesh = new Mesh();

            Point3dWithIndex[] pointArray = new Point3dWithIndex[triangleSoup.Count * 3];
            int lindex = 0;

            for (int i = 0; i < triangleSoup.Count; i++)
            {
                pointArray[lindex].P         = triangleSoup[i].P0;
                pointArray[lindex + 1].P     = triangleSoup[i].P1;
                pointArray[lindex + 2].P     = triangleSoup[i].P2;
                pointArray[lindex].Index     = lindex;
                pointArray[lindex + 1].Index = lindex + 1;
                pointArray[lindex + 2].Index = lindex + 2;
                Triangle t = new Triangle();
                t.P0Index = lindex;
                t.P1Index = lindex + 1;
                t.P2Index = lindex + 2;
                mesh.AddFace(t);
                lindex += 3;
            }
            QuickSorter <Point3dWithIndex> sorter = new QuickSorter <Point3dWithIndex>();

            sorter.A = pointArray;
            sorter.Sort();
            int[] tempArray = new int[pointArray.Length];
            for (int i = 0; i < pointArray.Length; i++)
            {
                tempArray[pointArray[i].Index] = i;
            }
            int lastIndex = 0;

            for (int i = 0; i < pointArray.Length; i++)
            {
                if (pointArray[i].CompareTo(pointArray[lastIndex]) == 0)
                {
                    continue;
                }
                else
                {
                    pointArray[lastIndex + 1]      = pointArray[i];
                    tempArray[pointArray[i].Index] = lastIndex + 1;
                    lastIndex++;
                }
            }
            for (int i = 0; i < lastIndex; i++)
            {
                mesh.AddVertex(pointArray[i].P);
            }
            for (int i = 0; i < mesh.Faces.Count; i++)
            {
                Triangle t = mesh.Faces[i];
                t.P0Index     = tempArray[mesh.Faces[i].P0Index];
                t.P1Index     = tempArray[mesh.Faces[i].P1Index];
                t.P2Index     = tempArray[mesh.Faces[i].P2Index];
                mesh.Faces[i] = t;
            }

            return(mesh);
        }