ColorSeries.AddPalette

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
hgg
Newbie
Newbie
Posts: 4
Joined: Fri Aug 03, 2001 4:00 am
Location: Denmark
Contact:

ColorSeries.AddPalette

Post by hgg » Thu Mar 18, 2004 10:36 am

Hi

For starters: Im running Delphi 6, Teechart version 5.01.
I'm experiencing a bug when using the TColorGridSeries AddPalette functionality. The error occurs when I use large numer of entries in the AddPalette (e.g. 5000). Im using the series for a colorscale editor, where I want to be able to interpolate colorscales into "smooth" scales, therefor the need to use many entries in AddPalette.

The exception occurs in the unit TeeSurfa line 1154 : SearchValue(XCount,XVals,XValues.Value[t]); and i think it is a pointer error. (the array XVals has both 0+ values, NaN's, 0 and accepptable values in it nad in the SearchValue procedure you make a comparison Values[t]=AValue which I'm guessing is the problem). What am I doing wrong ?

Below is an example. Run it first with number of colours set to 1000 - it works fine, then try setting it to 5000 and you get the exception. The main form has a chart on it (Chart 1) and 3 edit boxes (eMin, eMax,eNumberOfColours) and a button (bGreyScale) :


unit Main_;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ExtCtrls, ComCtrls, TeEngine, TeeSurfa, TeeProcs, Chart;

type
TLevel = record //Type holding individual colour scale record
Level : Real;
Red : Byte; //Red [0-255]
Green : Byte; //Green [0-255]
Blue : Byte; //Blue [0-255]
end;

TLevels = array of TLevel; //Type holding colorscales and contours

TdfmColorBarTest = class(TForm)
Panel1: TPanel;
GroupBox1: TGroupBox;
eMin: TEdit;
eMax: TEdit;
Label1: TLabel;
Label2: TLabel;
eNumberOfColours: TEdit;
Label3: TLabel;
bGreyScale: TButton;
Chart1: TChart;
Series1: TColorGridSeries;
StatusBar1: TStatusBar;
procedure bGreyScaleClick(Sender: TObject);
private
function FillLevels(MinVal, MaxVal: Real; NLevels : Integer) : TLevels;
procedure ApplyLevels(Levels : TLevels);
public
{ Public declarations }
end;

var
dfmColorBarTest : TdfmColorBarTest;
implementation

{$R *.DFM}


//******************************************************************************
procedure TdfmColorBarTest.bGreyScaleClick(Sender: TObject);
var
MinVal : Real;
MaxVal : Real;
NLevels : Integer;
Levels : TLevels;
begin
MinVal := StrToFloat(eMin.Text);
MaxVal := StrToFloat(eMax.Text);
NLevels := StrToInt(eNumberOfColours.Text);
Levels := FillLevels(MinVal, MaxVal, NLevels);
ApplyLevels(Levels);
end;

//******************************************************************************
procedure TdfmColorBarTest.ApplyLevels(Levels : TLevels);
//Add color levels to chart
var
ColorSeries : TColorGridSeries;
I : Integer;
NLevels : Integer;
begin
//Init colorseries
Chart1.FreeAllSeries(TColorGridSeries);
ColorSeries := TColorGridSeries.Create(Self);
ColorSeries.Clear;
ColorSeries.ClearPalette;
ColorSeries.IrregularGrid := True;
ColorSeries.ParentChart := Chart1;
ColorSeries.Pen.Visible := False;
ColorSeries.UsePalette := True;
ColorSeries.UseColorRange := False;

//Add pallette to colorseries
NLevels := Length(Levels);
ColorSeries.PaletteSteps := NLevels;
for I := 0 to NLevels-1 do begin
ColorSeries.AddPalette(Levels.Level, RGB(Levels.Red, Levels.Green, Levels.Blue));
end;

//Add data points to colorbar plot
Chart1.LeftAxis.SetMinMax(1, 2);
Chart1.BottomAxis.SetMinMax(Levels[0].Level, Levels[NLevels-1].Level);
for I := 0 to NLevels-1 do begin
ColorSeries.AddXYZ(Levels.Level, Levels.Level,1);
ColorSeries.AddXYZ(Levels.Level, Levels.Level,2);
end;
end;

//******************************************************************************
function TdfmColorBarTest.FillLevels(MinVal, MaxVal: Real; NLevels: Integer) : TLevels;
//Fill colorleves - greyscale
var
I : Integer;
LStep : Real;
R0, G0, B0 : byte;
R1, G1, B1 : byte;
AR, AG, AB : Real; //slope
begin
R0 := 0; G0 := 0; B0 := 0; //Start color
R1 := 255; G1 := 255; B1 := 255; //End color
AR := (R1-R0)/(MaxVal-MinVal);
AG := (B1-B0)/(MaxVal-MinVal);
AB := (G1-G0)/(MaxVal-MinVal);
LStep := (MaxVal-MinVal)/(NLevels-1);
SetLength(Result, NLevels);

for I := 0 to NLevels-1 do begin
Result.Level := MinVal + LStep*I;
Result.Red := Trunc((Result[I].Level-MinVal) * AR + R0);
Result[I].Green := Trunc((Result[I].Level-MinVal) * AG + G0);
Result[I].Blue := Trunc((Result[I].Level-MinVal) * AB + B0);
end;
end;

end.

SteveP
Advanced
Posts: 132
Joined: Sun Sep 07, 2003 4:00 am

Post by SteveP » Thu Mar 18, 2004 4:11 pm

Using Delphi 7 with TChart 7, I get an access violation for 2001 colors. 2000 colors is ok.

Steve

hgg
Newbie
Newbie
Posts: 4
Joined: Fri Aug 03, 2001 4:00 am
Location: Denmark
Contact:

Post by hgg » Thu Mar 18, 2004 4:41 pm

Strange....

Post Reply