forked from andrewkirillov/AForge.NET
-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathHistogramView.cs
103 lines (86 loc) · 3.35 KB
/
HistogramView.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
// AForge debugging visualizers
// AForge.NET framework
// http://www.aforgenet.com/framework/
//
// Copyright © AForge.NET, 2011
// contacts@aforgenet.com
//
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Windows.Forms;
using AForge.Math;
namespace AForge.DebuggerVisualizers
{
public partial class HistogramView : Form
{
private const int HistogramHeight = 100;
private Histogram histogram;
public HistogramView( )
{
InitializeComponent( );
}
public void SetHistogram( Histogram histogram )
{
this.histogram = histogram;
histogramControl.Values = histogram.Values;
int length = histogram.Values.Length;
Text = string.Format( "Histogram - {0} values", length );
statsBox.Text = string.Format( "Min: {0} Max: {1} Mean: {2:F2} Std.Dev.: {3:F2}",
histogram.Min, histogram.Max, histogram.Mean, histogram.StdDev );
// set form size
int formWidth = System.Math.Min( 800, length ) + 40;
int formHeight = HistogramHeight + 120;
this.Size = new Size( formWidth, formHeight );
// set histogram control size
int width = length + 2;
int height = HistogramHeight + 2;
int x = ( width > mainPanel.ClientSize.Width ) ? 0 : ( mainPanel.ClientSize.Width - width ) / 2;
int y = ( height > mainPanel.ClientSize.Height ) ? 0 : ( mainPanel.ClientSize.Height - height ) / 2;
histogramControl.SuspendLayout( );
histogramControl.Size = new Size( width, height );
histogramControl.Location = new System.Drawing.Point( x, y );
histogramControl.ResumeLayout( );
}
// Mouse cursor's position has changed within histogram control
private void histogramControl_PositionChanged( object sender, AForge.Controls.HistogramEventArgs e )
{
if ( histogram != null )
{
int pos = e.Position;
if ( pos != -1 )
{
textBox.Text = string.Format( "Value: {0} Count: {1} Percent: {2:F2}",
pos, histogram.Values[pos], ( (float) histogram.Values[pos] * 100 / histogram.TotalCount ) );
}
else
{
textBox.Text = string.Empty;
}
}
}
// Selection has changed within histogram control
private void histogramControl_SelectionChanged( object sender, AForge.Controls.HistogramEventArgs e )
{
if ( histogram != null )
{
int min = e.Min;
int max = e.Max;
int count = 0;
// count pixels
for ( int i = min; i <= max; i++ )
{
count += histogram.Values[i];
}
textBox.Text = string.Format( "Values: {0}...{1} Count: {2} Percent: {3:F2}",
min, max, count, ( (float) count * 100 / histogram.TotalCount ) );
}
}
private void logCheck_CheckedChanged( object sender, EventArgs e )
{
histogramControl.IsLogarithmicView = logCheck.Checked;
}
}
}