示例#1
0
        void bProcess_Click(object sender, EventArgs e)
        {
            // cancel whatever task is in progress
            if (currentTask != null)
            {
                runAfterCancel = true;
                worker.CancelAsync();
                currentTask.CancelAsync();
                return;
            }

            SortAlgorithm algo          = (SortAlgorithm)cAlgorithm.SelectedIndex;
            SortOrder     order         = (SortOrder)cOrder.SelectedIndex;
            SortMetric    metric        = (SortMetric)cMetric.SelectedIndex;
            SamplingMode  sampling      = (SamplingMode)cSampling.SelectedIndex;
            int           segmentWidth  = (int)nSegmentWidth.Value;
            int           segmentHeight = (int)nSegmentHeight.Value;
            double        threshold     = tbThreshold.Value / 100d;

            pbProgress.Value = 0;
            SetProgressVisible(true);

            currentTask = new SortingTask(algo,
                                          order,
                                          metric,
                                          sampling,
                                          segmentWidth,
                                          segmentHeight,
                                          (Bitmap)originalImage.Clone(),
                                          threshold);
            currentTask.ProgressChanged += (o, args) => worker.ReportProgress(args.ProgressPercentage);

            worker.RunWorkerAsync();
        }
示例#2
0
        public SortingTask(SortAlgorithm algorithm, SortOrder order, SortMetric metric, SamplingMode sampling,
                           int segmentWidth, int segmentHeight, Bitmap originalImage, double threshold)
        {
            Algorithm      = algorithm;
            Order          = order;
            Metric         = metric;
            Sampling       = sampling;
            SegmentWidth   = segmentWidth;
            SegmentHeight  = segmentHeight;
            OriginalImage  = originalImage;
            Threshold      = threshold;
            segmentRows    = OriginalImage.Height / SegmentHeight;
            segmentColumns = OriginalImage.Width / SegmentWidth;

            switch (Algorithm)
            {
            case SortAlgorithm.WholeImage:
                segments    = new Segment[1][];
                segments[0] = new Segment[segmentRows * segmentColumns];
                break;

            case SortAlgorithm.Column:
                segments = new Segment[segmentColumns][];
                for (int col = 0; col < segmentColumns; ++col)
                {
                    segments[col] = new Segment[segmentRows];
                }
                break;

            case SortAlgorithm.Row:
                segments = new Segment[segmentRows][];
                for (int row = 0; row < segmentRows; ++row)
                {
                    segments[row] = new Segment[segmentColumns];
                }
                break;

            case SortAlgorithm.Segment:
                segments = new Segment[segmentRows * segmentColumns][];
                for (int i = 0; i < segments.Length; ++i)
                {
                    segments[i] = new Segment[segmentWidth * segmentHeight];
                }
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
示例#3
0
        // Like GetMetricsTable, but takes two lists of metrics and includes diffs.
        public static string GetMetricsDiffTable(
            int totalSamplesA,
            List <SampleMetrics> metricsObjectsA,
            int totalSamplesB,
            List <SampleMetrics> metricsObjectsB,
            SortMetric sortMetric)
        {
            StringBuilder tableStringBuilder = new StringBuilder();

            tableStringBuilder.AppendLine(metricsDiffHeader);

            switch (sortMetric)
            {
            case SortMetric.Exclusive:
                metricsObjectsA.Sort((a, b) => b.ExclusiveSamples.CompareTo(a.ExclusiveSamples));
                break;

            case SortMetric.Inclusive:
                metricsObjectsA.Sort((a, b) => b.InclusiveSamples.CompareTo(a.InclusiveSamples));
                break;
            }

            SampleMetrics emptyMetrics = new SampleMetrics();

            emptyMetrics.InclusiveSamples = 0;
            emptyMetrics.ExclusiveSamples = 0;

            HashSet <string> foundIdentifiers = new HashSet <string>();

            foreach (var currMetrics in metricsObjectsA)
            {
                bool foundInBaseline = false;
                foreach (var currBaselineMetrics in metricsObjectsB)
                {
                    if (currMetrics.Identifier == currBaselineMetrics.Identifier)
                    {
                        foundInBaseline = true;
                        foundIdentifiers.Add(currMetrics.Identifier);

                        tableStringBuilder.AppendLine(GetMetricsDiffString(totalSamplesA, currMetrics, totalSamplesB, currBaselineMetrics));
                        break;
                    }
                }

                if (!foundInBaseline)
                {
                    tableStringBuilder.AppendLine(GetMetricsDiffString(totalSamplesA, currMetrics, 1, emptyMetrics));
                }
            }

            // Also get everything in B that wasn't in A
            foreach (var currBaselineMetrics in metricsObjectsB)
            {
                if (!foundIdentifiers.Contains(currBaselineMetrics.Identifier))
                {
                    tableStringBuilder.AppendLine(GetMetricsDiffString(1, emptyMetrics, totalSamplesB, currBaselineMetrics));
                }
            }

            return(tableStringBuilder.ToString());
        }
示例#4
0
        /// <summary>
        /// Get a table representing the list of metrics passed in
        /// </summary>
        /// <param name="totalSamples">The total count of samples (used for calculating percentages)</param>
        /// <param name="metricsObjects">The set of metrics to include in the table</param>
        /// <param name="sortMetric">What to sort the table by</param>
        /// <returns>A string containing the table represented in plaintext</returns>
        public static string GetMetricsTable(int totalSamples, List <SampleMetrics> metricsObjects, SortMetric sortMetric)
        {
            StringBuilder tableStringBuilder = new StringBuilder();

            tableStringBuilder.AppendLine(metricsHeader);

            switch (sortMetric)
            {
            case SortMetric.Exclusive:
                metricsObjects.Sort((a, b) => b.ExclusiveSamples.CompareTo(a.ExclusiveSamples));
                break;

            case SortMetric.Inclusive:
                metricsObjects.Sort((a, b) => b.InclusiveSamples.CompareTo(a.InclusiveSamples));
                break;
            }

            foreach (var currMetrics in metricsObjects)
            {
                tableStringBuilder.AppendLine(GetMetricsString(totalSamples, currMetrics));
            }

            return(tableStringBuilder.ToString());
        }