I was recently updating to TChart 2015 and faced a different behavior regarding custom custom color palettes in TSurfaceSeries compared to TChart 2014.
In general my code was working well - i.e. the surface color was changing dependent on the y value according to the colors I added to the custom palette. After updating to TChart 2015 - the surface color is all black independent of the y value.
Creating the TSurfaceSeries:
Code: Select all
Chart3D.Render.AmbientLight:=64;
with Chart3D.Chart do
begin
Aspect.Orthogonal:=FALSE;
Chart3DPercent:=100;
Aspect.Zoom:=75;
Legend.Visible:=false;
FSurfaceSeries:=TSurfaceSeries(AddSeries(TSurfaceSeries));
FSurfaceSeries.IrregularGrid:=TRUE;
FSurfaceSeries.UseColorRange:= FALSE; //???
FSurfaceSeries.UsePalette:= TRUE;
FSurfaceSeries.PaletteStyle:=VCLTee.TeeSurfa.psCustom;
end;
Setting up the custom color palette - ACOlorPalette contains 9 colors, so we have (9-1) x INTERPOLATEDCOLORCOUNT different colors that are added to the custom palette:
Code: Select all
procedure TFView3D.ApplySelectedPalette;
const INTERPOLATEDCOLORCOUNT = 128;
var i, j: integer;
FromColor, ToColor: TColor;
PaletteCounter: integer;
dr,dg,db:Extended;
R1,R2,G1,G2,B1,B2:Byte;
R,G,B:Byte;
AColorPalette: TColorPalette;
begin
if((FSelectedPalette>=0) and (FSelectedPalette<FColorPalettes.Count))then
begin
AColorPalette:=TColorPalette(FColorPalettes.Items[FSelectedPalette]);
if(AColorPalette.PaletteColors.Count>0)then
begin
FSurfaceSeries.ClearPalette;
FSurfaceSeries.UsePaletteMin:=TRUE;
FSurfaceSeries.UseColorRange:=FALSE;
FSurfaceSeries.PaletteMin:=0;
FSurfaceSeries.PaletteSteps:=(AColorPalette.PaletteColors.Count-1)*INTERPOLATEDCOLORCOUNT;
FSurfaceSeries.PaletteStep:= round(65536 / ((AColorPalette.PaletteColors.Count-1) * INTERPOLATEDCOLORCOUNT));
PaletteCounter:=0;
for i:= 1 to AColorPalette.PaletteColors.Count-1 do
begin
FromColor:=TPaletteColor(AColorPalette.PaletteColors.Items[i-1]).color;
ToColor:=TPaletteColor(AColorPalette.PaletteColors.Items[i]).Color;
R1 := GetRValue(FromColor);
G1 := GetGValue(FromColor);
B1 := GetBValue(FromColor);
R2 := GetRValue(ToColor);
G2 := GetGValue(ToColor);
B2 := GetBValue(ToColor);
dr := (R2-R1) / INTERPOLATEDCOLORCOUNT;
dg := (G2-G1) / INTERPOLATEDCOLORCOUNT;
db := (B2-B1) / INTERPOLATEDCOLORCOUNT;
j:=0;
while (j<INTERPOLATEDCOLORCOUNT) do
begin
R := R1+Ceil(dr*j) ;
G := G1+Ceil(dg*j) ;
B := B1+Ceil(db*j) ;
FSurfaceSeries.AddPalette(PaletteCounter, RGB(R, G, B));
inc(PaletteCounter);
inc(j);
end;
end;
end;
FColorDisplay.Clear;
for i:=0 to AColorPalette.PaletteColors.Count-1 do
begin
FColorDisplay.AddColor(TPaletteColor((AColorPalette.PaletteColors.Items[i])).Color, -i*10);
end;
Update3DSurface;
end;
end;
Updating the Surface:
Code: Select all
FSurfaceSeries.BeginUpdate;
try
if FBitMap.PixelFormat=pf16Bit then //if in 16 bit Pixelformat grayscale
begin
for z:=0 to FBitMap.Height-1 do
begin
A16BitRow:=FBitMap.ScanLine[z];
for x:=0 to FBitMap.width-1 do
begin
FSurfaceSeries.YValues.Items[z*FBitMap.Width+x]:=A16BitRow[x];
end;
end;
end;
finally
FSurfaceSeries.EndUpdate;
FSurfaceSeries.Repaint;
end;
Do have any idea what might cause the surface not showing up according to the palette colors in TChart 2015 although it was working with 2014 version ?
Best regards,
Klaus