示例#1
0
        private void Menu_ClusterBatch_Click(object sender, EventArgs e)
        {
            // string inputFolder = @"D:\\__gDrive\\__PHD\\Input\\Generated\\_Vtx\\Test-Vtx";
            string outputFolder = @"D:\\__gDrive\\__PHD\\Input\\Generated\\_Vtx\\Output-CMeans";

            string[] inputFolder = new string[] {
                "D:\\__gDrive\\__PHD\\Input\\Generated\\_Vtx\\Test-Vtx\\arc50000_1r.vtx",
                "D:\\__gDrive\\__PHD\\Input\\Generated\\_Vtx\\Test-Vtx\\clus50000_4r.vtx",
                "D:\\__gDrive\\__PHD\\Input\\Generated\\_Vtx\\Test-Vtx\\gaus50000_4.vtx",
                "D:\\__gDrive\\__PHD\\Input\\Generated\\_Vtx\\Test-Vtx\\grid50000_0.vtx",
                "D:\\__gDrive\\__PHD\\Input\\Generated\\_Vtx\\Test-Vtx\\grid50000_4.vtx",
                "D:\\__gDrive\\__PHD\\Input\\Generated\\_Vtx\\Test-Vtx\\Unif50000_0.vtx",
                "D:\\__gDrive\\__PHD\\Input\\Generated\\_Vtx\\Test-Vtx\\Unif50000_4.vtx",
                "D:\\__gDrive\\__PHD\\Input\\Generated\\_Vtx\\Test-Vtx\\arc50000_0.vtx"
            };

            //if ( Dialog_InputFolder.ShowDialog() == DialogResult.OK &&
            //     Dialog_OutputFolder.ShowDialog() == DialogResult.OK )
            //{
            IClustering algorithm = new CMeans();


            foreach (string f in inputFolder)
            {
                //foreach ( string f in Directory.GetFiles(inputFolder) )
                //{
                string outputFile = Path.Combine(outputFolder, Path.GetFileNameWithoutExtension(f));


                Vertex[] vertices         = Loader.LoadVertices(f);
                int      numberOfClusters = vertices.Length / 100;


                BoundingBox boundingBox = new BoundingBox();
                boundingBox.Initialize(vertices[0].Dimension);
                boundingBox.AddVertices(vertices);

                Dictionary <string, object> properties = new Dictionary <string, object>();
                properties.Add("boundingBox", boundingBox);
                properties.Add("numberOfClusters", numberOfClusters);
                properties.Add("treshold", 0.5);

                Array.Resize <Vertex>(ref vertices, vertices.Length + numberOfClusters);

                algorithm.SetProperties(properties);
                algorithm.ComputeClustering(vertices);

                List <Facility> fac = algorithm.GetFacilities();
                ClusterSolution.SaveClusteringSolution(algorithm, f, outputFile, fac);
            }
            //}

            MessageBox.Show("Batch clustering is done!", "Clustering", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
示例#2
0
        public static List <Facility> Cluster(string outputFile, double param1, double param2)
        {
            IClustering fac = new MShift();

            // add some properties to particular clustering algorithms
            Dictionary <string, object> properties = new Dictionary <string, object>();

            properties.Add("boundingBox", BoundingCluster);
            properties.Add("PARAM_1", param1);
            properties.Add("PARAM_2", param2);

            fac.SetProperties(properties);
            fac.ComputeClustering(VerticesToCluster);

            // save clustering result
            List <Facility> facilities = fac.GetFacilities();

            // ClusterSolution.SaveClusteringSolution(fac, inputFile, Dialog_SaveCluster.FileName, facilities);
            ClusterSolution.SaveClusteringToMeshLab(fac, outputFile, facilities, VerticesToCluster);

            return(facilities);
        }
示例#3
0
        private void Menu_ClusterLoad_Click(object sender, EventArgs e)
        {
            if (Dialog_OpenClusterResult.ShowDialog() == DialogResult.OK)
            {
                string inputFileVertices;
                facilities = ClusterSolution.LoadClusteringSolution(Dialog_OpenClusterResult.FileName, out inputFileVertices);

                DataSet vert = Loader.LoadVtx(inputFileVertices, int.MaxValue);

                vertices = vert.points;

                if (vertices == null)
                {
                    return;
                }
                foreach (Facility fac in facilities)
                {
                    // set reference to facility
                    foreach (int i in fac.VertexIndices)
                    {
                        vertices[i].Facility = fac;
                    }

                    vertices[fac.VertexIndex].IsFacility = true;
                }

                bBox.Initialize(vertices[0].Dimension);
                bBox.AddVertices(vertices);

                ScaleVertices();
                ShowCalculateClusterConvexHull();
                CalculateFacilitiesPosition();

                Menu_Cluster.Enabled = true;
                showPoints           = false;
                Graph.Draw();
            }
        }
示例#4
0
        private void Main_Cluster_Click(object sender, EventArgs e)
        {
            //int numberOfClusters = 9;
            //Vertex[] extendedVertices = new Vertex[vertices.Length + numberOfClusters];
            //for (int i = 0; i < vertices.Length; i++)
            //{
            //    extendedVertices[i] = vertices[i];
            //}
            //vertices = extendedVertices;
            // IClustering fac = new MShift();
            // IClustering fac = new KMeans();
            // IClustering fac = new CMeans();
            IClustering fac = new MShift();

            // add some properties to particular clustering algorithms
            Dictionary <string, object> properties = new Dictionary <string, object>();

            properties.Add("boundingBox", bBoxToCluster);
            properties.Add("PARAM_1", double.Parse(TextBox_Param1.Text));
            properties.Add("PARAM_2", double.Parse(TextBox_Param2.Text));
            // properties.Add("weights", new double[] { 1, 1, 1, 1, 1, 1, 1, 1 });

            fac.SetProperties(properties);

            // cluster again!
            //if ( facilities != null && facilities.Count > 0 )
            //{
            //    Vertex[] ret = new Vertex[facilities.Count];

            //    int index = -1;
            //    foreach (Facility f in facilities)
            //    {
            //        ret[++index] = new Vertex(vertices[f.VertexIndex].Coords);
            //    }

            //    Array.Clear(vertices, 0, vertices.Length);
            //    vertices = ret;
            //}

            fac.ComputeClustering(verticesToCluster);

            showPoints = false;

            // save clustering result
            facilities = fac.GetFacilities();

            ShowCalculateClusterConvexHull();

            CalculateFacilitiesPosition();

            Graph.Draw();


            if (Dialog_SaveCluster.ShowDialog() == DialogResult.OK)
            {
                // ClusterSolution.SaveClusteringSolution(fac, inputFile, Dialog_SaveCluster.FileName, facilities);
                ClusterSolution.SaveClusteringToMeshLab(fac, Dialog_SaveCluster.FileName, facilities, verticesToCluster);
            }

            // show debug window
            // new Statistics(bBox, fac.GetFacilities(), vertices);
        }