public void Setup()
        {
            var mockCluster1 = new Mock <ICluster>();

            mockCluster1.Setup(x => x.Id).Returns(_cluster1Guid);
            mockCluster1.Setup(x => x.Name).Returns("cluster1");
            mockCluster1.Setup(x => x.Type).Returns("cluster");

            var mockCluster2 = new Mock <ICluster>();

            mockCluster2.Setup(x => x.Id).Returns(_cluster2Guid);
            mockCluster2.Setup(x => x.Name).Returns("cluster2");
            mockCluster2.Setup(x => x.Type).Returns("cluster");

            _clusters = new ClusterCollection
            {
                mockCluster1.Object,
                mockCluster2.Object
            };

            _dao = new InMemoryDataAccessObject();
            _dao.AddAsync(new ClusterConnectionEntity
            {
                Id          = _clusterConnection1Guid,
                ClusterType = "cluster",
                Description = "fake cluster connection",
                Name        = "FakeClusterConnection",
            });

            _controller = new ClusterConnectionsController(_logger, _clusters, _dao);
        }
        public Bitmap PaintRGB(Bitmap srcimg, KMeansParallel kMeans, ClusterCollection clusters)
        {
            int        width   = srcimg.Width;
            int        height  = srcimg.Height;
            BitmapData srcData = srcimg.LockBits(
                new Rectangle(0, 0, width, height),
                ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);
            int srcOffset = srcData.Stride - width * 3;

            unsafe
            {
                byte *src = (byte *)srcData.Scan0.ToPointer();
                for (int y = 0; y < height; y++)
                {
                    for (int x = 0; x < width; x++, src += 3)
                    {
                        int rgb = src[RGB.R] * 256 * 256 + src[RGB.G] * 256 + src[RGB.B];
                        int rgb_mean;

                        if (color_table.ContainsKey(rgb))
                        {
                            rgb_mean = (int)color_table[rgb];
                        }
                        else
                        {
                            double[] yiq = new double[3];
                            yiq[0] = src[RGB.R]; yiq[1] = src[RGB.G]; yiq[2] = src[RGB.B];

                            double min_dist = Double.MaxValue;
                            int    idx      = 0;

                            for (int i = 0; i < clusters.Count; i++)
                            {
                                double dist = kMeans.EuclideanDistance(yiq, clusters[i].ClusterMean);
                                if (dist < min_dist)
                                {
                                    min_dist = dist;
                                    idx      = i;
                                }
                            }
                            rgb_mean = (int)(clusters[idx].ClusterMean[0]) * 256 * 256 +
                                       (int)(clusters[idx].ClusterMean[1]) * 256 +
                                       (int)(clusters[idx].ClusterMean[2]);

                            color_table.Add(rgb, rgb_mean);
                        }
                        src[RGB.R] = (byte)((rgb_mean & 0xFF0000) >> 16);
                        src[RGB.G] = (byte)((rgb_mean & 0xFF00) >> 8);
                        src[RGB.B] = (byte)(rgb_mean & 0xFF);
                    }
                    src += srcOffset;
                }
            }
            srcimg.UnlockBits(srcData);
            return(srcimg);
        }
Exemple #3
0
        public ShapeCollection Create(ClusterCollection clusterData)
        {
            var result = new ShapeCollection();

            foreach (var cluster in clusterData.Clusters)
            {
                var convexHull = new GrahamScan(cluster.Points).FindHull();
                var map        = CreateMap(cluster);
                var contour    = CreateContour(map, cluster);

                if (contour.Count >= settings.MinimalPointsInContour)
                {
                    result.Shapes.Add(new Shape(cluster.Center, cluster.Volume, contour, convexHull, cluster.Points));
                }
            }
            return(result);
        }
Exemple #4
0
        private ClusterCollection DiscoverClusterImplementations()
        {
            var pluginsDirectory       = Path.Combine(AppContext.BaseDirectory, "plugins");
            var loaders                = new List <PluginLoader>();
            var clusterImplementations = new ClusterCollection();

            foreach (var file in Directory.EnumerateFiles(pluginsDirectory, "*.dll", SearchOption.AllDirectories))
            {
                if (File.Exists(file))
                {
                    var loader = PluginLoader.CreateFromAssemblyFile(file,
                                                                     sharedTypes: new[] { typeof(ICluster) },
                                                                     configure: (pc) =>
                    {
                        pc.SharedAssemblies.Add(typeof(JsonConvert).Assembly.GetName());
                    });
                    loaders.Add(loader);
                }
            }

            foreach (var loader in loaders)
            {
                foreach (var clusterType in loader
                         .LoadDefaultAssembly()
                         .GetTypes()
                         .Where(t => typeof(ICluster).IsAssignableFrom(t) && !t.IsAbstract))
                {
                    // This assumes the implementation of IPlugin has a parameterless constructor
                    var cluster = (ICluster?)Activator.CreateInstance(clusterType);
                    if (cluster != null)
                    {
                        clusterImplementations.Add(cluster);
                    }
                }
            }

            return(clusterImplementations);
        }
Exemple #5
0
 private void dataSource_NewDataAvailable(ClusterCollection clusters)
 {
     this.Dispatcher.Invoke(new Action(() => InvalidateVisual()));
 }
Exemple #6
0
 public JobsController(ClusterCollection clusterImplementations,
                       ILogger <ClustersController> logger,
                       IDataAccessObject dao) => (_clusterImplementations, _dao, _logger) = (clusterImplementations, dao, logger);
        // K-Means
        private void Kmeans(Dictionary <int, Dictionary <int, double> > data, int clusters, string type, string codage)
        {
            double[,] db = null;
            if (data.Count > 1)
            {
                if (codage != "Binaire")
                {
                    db = convertData(data);
                }
                else
                {
                    db = convertDataBin(data);
                }
            }
            else
            {
                return;
            }

            Console.WriteLine("Donnees convertie");

            cluster = KMeans.ClusterDataSet(clusters, db, type);
            //MessageBox.Show(this,"Nombre de cluster : " + cluster.Count);
            Console.WriteLine("Kmeans calcule");
            //Dictionary<int, int> stationCluster = new Dictionary<int, int>();
            stationCluster = new Dictionary <int, int>();
            for (int i = 0; i < cluster.Count; i++)
            {
                Console.WriteLine("Cluster : " + i + " - Taille : " + cluster[i].Count);
                //string s = "Cluster " + i + ", taille = " + cluster[i].getValues.Count + " : ";
                foreach (int z in cluster[i].getValues)
                {
                    //Console.WriteLine(stations[z]);
                    int temp = stations[z];
                    stationCluster.Add(temp, i);
                    //string s = stations[z] + " : " + i ;
                }
            }
            ScrollableMaps maps = new ScrollableMaps();

            maps.drawClusters(stationCluster);
            PictureBox map = maps.mapBox;

            map.SizeMode = PictureBoxSizeMode.Zoom;
            map.Dock     = DockStyle.Fill;
            Panel tempPanel = new Panel();

            tempPanel.Dock = DockStyle.Fill;

            combo1      = new ComboBox();
            combo1.Text = "Affichage des statistiques pour les clusters";
            combo1.Items.Add("Tous les clusters");
            combo1.Items.Add("Altitudes");
            combo1.Items.Add("Point of Interest");
            for (int i = 0; i < cluster.Count; i++)
            {
                combo1.Items.Add(i);
            }
            combo1.SelectedIndexChanged += changeCluster;
            combo1.Dock = DockStyle.Top;

            tempPanel.Controls.Add(combo1);
            tempPanel.Controls.Add(map);

            panel.addControls(tempPanel);
        }
Exemple #8
0
 private void ClusterDataSource_NewDataAvailable(ClusterCollection data)
 {
     // todo
 }
 private void dataSource_NewDataAvailable(ClusterCollection clusters)
 {
     this.OnRequestRefresh();
 }