/// <summary>
        /// Gets the list of clusters.
        /// </summary>
        /// <returns>Returns the list of clusters.</returns>
        public List <GenericCluster> GetClusters()
        {
            List <GenericCluster> genClusters = new List <GenericCluster>(clusters.Count);

            // copy all clusters
            foreach (LinkedCluster cluster in clusters)
            {
                GenericCluster genClus = new GenericCluster(cluster.CentreIndex);

                foreach (int vertexIndex in cluster.MemberIndices)
                {
                    genClus.AddVertex(vertexIndex);
                }

                genClusters.Add(genClus);
            }

            return(genClusters);
        }
        /// <summary>
        /// Gets the list of clusters. Cluster centre is the vertex closest to the geometric centre of the cluster.
        /// </summary>
        /// <returns>Returns the list of clusters.</returns>
        public List <GenericCluster> GetCenteredClusters()
        {
            List <GenericCluster> centeredClusters = new List <GenericCluster>(clusters.Count);

            // rebuild all clusters
            foreach (LinkedCluster cluster in clusters)
            {
                //double sumX = 0, sumY = 0, sumZ = 0;
                //// find the centre of mass
                //foreach (int vertexIndex in cluster.linkedVertices)
                //{
                //    sumX += vertices[vertexIndex].X;
                //    sumY += vertices[vertexIndex].Y;
                //    sumZ += vertices[vertexIndex].Z;
                //}
                //double count = cluster.linkedVertices.Count;
                //Vertex perfectCentre = new Vertex(sumX / count, sumY / count, sumZ / count);

                double minX, minY, minZ;
                minX = minY = minZ = double.PositiveInfinity;
                double maxX, maxY, maxZ;
                maxX = maxY = maxZ = double.NegativeInfinity;
                // find the bounding box
                foreach (int vertexIndex in cluster.MemberIndices)
                {
                    double x = vertices[vertexIndex].X;
                    double y = vertices[vertexIndex].Y;
                    double z = vertices[vertexIndex].Z;

                    if (x < minX)
                    {
                        minX = x;
                    }
                    if (x > maxX)
                    {
                        maxX = x;
                    }

                    if (y < minY)
                    {
                        minY = y;
                    }
                    if (y > maxY)
                    {
                        maxY = y;
                    }

                    if (z < minZ)
                    {
                        minZ = z;
                    }
                    if (z > maxZ)
                    {
                        maxZ = z;
                    }
                }
                // find the geometric centre
                Vertex perfectCentre = new Vertex((maxX + minX) / 2.0, (maxY + minY) / 2.0, (maxZ + minZ) / 2.0);

                int    closestIndex = -1;
                double minDist      = double.PositiveInfinity;
                // find the closest vertex
                foreach (int vertexIndex in cluster.MemberIndices)
                {
                    // compute the distance to the centre of mass
                    double dist = perfectCentre.WeightedDistance(vertices[vertexIndex]);

                    if (dist < minDist)
                    {
                        // the vertex is closer
                        minDist      = dist;
                        closestIndex = vertexIndex;
                    }
                }

                GenericCluster genClus = new GenericCluster(closestIndex);
                foreach (int vertexIndex in cluster.MemberIndices)
                {
                    genClus.AddVertex(vertexIndex);
                }
                centeredClusters.Add(genClus);
            }

            return(centeredClusters);
        }