I am using a colorgrid to generate an image where the number of points can be large (i.e. 1000x1000 or 2000x2000). The color grid takes a long time to generate the plot and also every time I resize the plot it also takes a long time. I recall a version back in 2007 that did this faster. See attached example code.
Code: Select all
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Steema.TeeChart;
using Steema.TeeChart.Styles;
using Steema.TeeChart.Tools;
namespace ColorGridExample
{
public partial class Form1 : Form
{
TChart _chart;
private ColorGrid _colorGrid;
private LegendPalette _legendPalette;
private Color[] _rainbowLowBlackPalette;
private double _colorBarMax;
private double _colorBarMin;
private double _colorBarStep;
private double[] _xData;
private double[] _yData;
private double[] _zData;
public Form1()
{
InitializeComponent();
_colorBarMax = 0.0;
_colorBarMin = -50.0;
_colorBarStep = 5.0;
SetupColorGrid();
GenerateData();
_colorGrid.Add(_xData, _zData, _yData);
_colorGrid.IrregularGrid = true;
_legendPalette.Series = _colorGrid;
_legendPalette.Gradient.Visible = false;
}
public void SetupColorGrid()
{
this.SuspendLayout();
this._chart = new Steema.TeeChart.TChart();
this._chart.Aspect.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.Default;
this._chart.Aspect.TextRenderingHint = System.Drawing.Text.TextRenderingHint.SystemDefault;
this._chart.Aspect.View3D = false;
this._chart.Dock = System.Windows.Forms.DockStyle.Fill;
this._chart.Location = new System.Drawing.Point(0, 0);
this._chart.Name = "tChart1";
this._chart.Size = new System.Drawing.Size(700, 500);
this._chart.TabIndex = 0;
this.Controls.Add(this._chart);
_chart.Header.Visible = false;
_chart.Legend.Visible = false;
_chart.Panel.MarginUnits = Steema.TeeChart.PanelMarginUnits.Pixels;
_chart.Panel.MarginRight = 80;
_chart.Axes.Bottom.Automatic = false;
_chart.Axes.Bottom.AutomaticMaximum = false;
_chart.Axes.Bottom.AutomaticMinimum = false;
_chart.Axes.Bottom.Increment = 0.2;
_chart.Axes.Bottom.Maximum = 1.0;
_chart.Axes.Bottom.Minimum = -1.0;
_chart.Axes.Left.Automatic = false;
_chart.Axes.Left.AutomaticMaximum = false;
_chart.Axes.Left.AutomaticMinimum = false;
_chart.Axes.Left.Increment = 0.2;
_chart.Axes.Left.Maximum = 1.0;
_chart.Axes.Left.Minimum = -1.0;
this._colorGrid = new ColorGrid();
this._colorGrid.Pen.Visible = false;
this._colorGrid.Title = "colorGrid1";
this._colorGrid.UseColorRange = false;
this._colorGrid.UsePalette = true;
this._colorGrid.XStep = 1;
this._chart.Series.Add(this._colorGrid);
LoadColorPalette();
_legendPalette = new LegendPalette(_chart.Chart);
_legendPalette.Axis = LegendPaletteAxis.laOther;
_legendPalette.Width = 60;
_legendPalette.Pen.Visible = false;
_legendPalette.Series = _colorGrid;
this.ResumeLayout(false);
_chart.SizeChanged += new System.EventHandler(this.Chart_SizeChanged);
}
private void Chart_SizeChanged(object sender, EventArgs e)
{
_chart.AutoRepaint = false;
_legendPalette.Left = _chart.Width - _legendPalette.Width - 10;
_legendPalette.Top = (_chart.Height - _legendPalette.Height) / 2;
_chart.AutoRepaint = true;
_chart.Refresh();
}
private void LoadColorPalette()
{
double minValue = _colorBarMin;
double maxValue = _colorBarMax;
double delta = _colorBarMax - _colorBarMin;
_colorGrid.ClearPalette();
_rainbowLowBlackPalette = new Color[256];
int redIndex;
int greenIndex;
int blueIndex;
for (int i = 0; i < 256; i++)
{
if (i == 0)
{
redIndex = 0;
greenIndex = 0;
blueIndex = 0;
}
else if (i > 0 && i <= 32)
{
redIndex = -255 / 32 * i + 255;
greenIndex = 0;
blueIndex = 255;
}
else if (i > 32 && i <= 85)
{
redIndex = 0;
greenIndex = (255 / (85 - 32)) * (i - 32);
blueIndex = 255;
}
else if (i > 85 && i <= 143)
{
redIndex = 0;
greenIndex = 255;
blueIndex = (-255 / (143 - 86)) * (i - 143);
}
else if (i > 143 && i <= 199)
{
redIndex = (255 / (199 - 143)) * (i - 143);
greenIndex = 255;
blueIndex = 0;
}
else
{
redIndex = 255;
greenIndex = (-255 / (255 - 199)) * (i - 255);
blueIndex = 0;
}
_rainbowLowBlackPalette[i] = Color.FromArgb(redIndex, greenIndex, blueIndex);
_colorGrid.AddPalette(((delta / 255.0) * (double)i + minValue), _rainbowLowBlackPalette[i]);
}
}
private void GenerateData()
{
var Nx = 50;
var Ny = 25;
var Nu = 1001;
var Nv = 1001;
_xData = new double[Nu*Nv];
_yData = new double[Nu*Nv];
_zData = new double[Nu*Nv];
var du = 2.0 / (Nu - 1);
var dv = 2.0 / (Nv - 1);
int k = 0;
for (int i=0; i<Nu; i++)
{
var v = -1.0 + dv * i;
for (int j=0; j<Nv; j++)
{
var u = -1.0 + du * j;
var argx = 0.5*Nx*u;
var argy = 0.5*Ny*v;
_xData[k] = u;
_yData[k] = v;
_zData[k] = 20.0 * Math.Log10(Math.Abs(sinc(argx) * sinc(argy)));
k++;
}
}
}
private double sinc(double x)
{
if (Math.Abs(x) < 1.0e-7)
{
return 1.0;
}
else
{
return (Math.Sin(Math.PI * x) / (Math.PI * x));
}
}
}
}
namespace ColorGridExample
{
partial class Form1
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(600, 500);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);
}
#endregion
}
}