Exemplo n.º 1
0
        private void ColorPoints(Graphics g, int currentLevel)
        {
            int           point_color_index;
            Random        random_color      = new Random();
            ColorSelector point_color       = new ColorSelector();
            List <Color>  point_colors      = new List <Color>();
            SolidBrush    defaultPointBrush = new SolidBrush(pt_drawing_color);

            if (drawingPts.Count > 0 && drawingPts.Count > 0 && show_points)
            {
                if (viewed_level <= drawingPts[0].gaussian_idx.Count && fit_ran)
                {
                    // Creating a list of colors based on the number of gaussians present in a level. Each gaussian holds a cluster of points with a different color.
                    for (int parent_count = 0; parent_count < (int)Math.Pow(num_of_fits, currentLevel); parent_count++)
                    {
                        if (use_random_colors)
                        {
                            point_colors.Add(Color.FromArgb(random_color.Next(256), random_color.Next(256), random_color.Next(256)));
                        }
                        else
                        {
                            point_colors.Add(point_color.NextColor());
                        }
                    }

                    // cumulative stores a value used in indexing the gaussian_idx list in order to determine what color a point should be
                    int cumulative = 0;
                    if (currentLevel > 1)
                    {
                        for (int layer = 1; layer < currentLevel; layer++)
                        {
                            cumulative += (int)Math.Pow(num_of_fits, layer);
                        }
                    }
                    else
                    {
                        cumulative = 0;
                    }

                    foreach (Vector2 pt in drawingPts)
                    {
                        if (pt.gaussian_idx[currentLevel - 1] == -1) // A point will have this value if the parent gaussian at the viewed level is dropped
                        {
                            SolidBrush brush = new SolidBrush(Color.Black);
                            g.FillRectangle(brush, pt.x - 1, pt.y - 1, 3, 3); //a 9 pixel dot
                        }
                        else
                        {
                            if (currentLevel == 1)
                            {
                                point_color_index = pt.gaussian_idx[0];
                            }
                            else
                            {
                                int check = pt.gaussian_idx[0];
                                point_color_index = pt.gaussian_idx[currentLevel - 1] - cumulative;
                            }
                            SolidBrush brush = new SolidBrush(point_colors[point_color_index]);
                            g.FillRectangle(brush, pt.x - 1, pt.y - 1, 3, 3); //a 9 pixel dot
                        }
                    }
                }
                else
                {
                    foreach (Vector2 pt in drawingPts)
                    {
                        g.FillRectangle(defaultPointBrush, pt.x - 1, pt.y - 1, 3, 3); //a 9 pixel dot
                    }
                }
            }
        }
Exemplo n.º 2
0
        private void CompleteColoring(Graphics g)
        {
            ColorSelector ellipse_colors = new ColorSelector();
            Color         ellipse_color  = ellipse_colors.NextColor();

            ColorPoints(g, viewed_level);

            foreach (BaseModel model in gmm.baseModels)
            {
                if (model == null)
                {
                    continue;
                }
                switch (model.GetType().ToString())
                {
                case "GMMDemo.LineModel":
                    ColorLines(g, model);
                    break;

                case "GMMDemo.CircleModel":
                    ColorCircles(g, model);
                    break;
                }
            }

            if (drawingGaussians.Count > 0 && show_fits)
            {
                if (!fit_ran)
                {
                    Pen ground_truth_pen = new Pen(ground_truth_color, 2);
                    foreach (Gaussian_2D gaussian in drawingGaussians)
                    {
                        if (!gaussian.dropped)
                        {
                            Draw3SigmaEllipse(g, gaussian, ground_truth_pen);
                        }
                    }
                }
                else
                {
                    Pen ellipse_pen      = new Pen(ellipse_color, 2);
                    int gaussian_count   = 0;
                    int layer_count      = 1;
                    int cumulative_limit = num_of_fits;


                    List <int> level_gaussians = gmm.GetLevel(viewed_level - 1);

                    foreach (int i in level_gaussians)
                    {
                        if (gaussian_count >= cumulative_limit)
                        {
                            layer_count++;
                            ellipse_color     = ellipse_colors.NextColor();
                            ellipse_pen       = new Pen(ellipse_color, 2);
                            cumulative_limit += (int)Math.Pow(num_of_fits, layer_count);
                        }

                        if (!drawingGaussians[i].dropped)
                        {
                            Draw3SigmaEllipse(g, drawingGaussians[i], ellipse_pen);
                        }
                        gaussian_count++;
                    }
                }
            }
        }