unit sommespectre2D;
{sommation sur des spectres 2D type PAPOL
à jour le 30/10/00}

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, CheckLst, Buttons, xyGraph,xydesign,xyDatWiz, ExtCtrls,editdata;

type mat2d128=array[0..127,0..127] of real;

type
  TSommeSpectre2DForm = class(TForm)
    Panel1: TPanel;
    xyGraph1: TxyGraph;
    SpeedButton1: TSpeedButton;
    SpeedButton3: TSpeedButton;
    SpeedButton4: TSpeedButton;
    choix: TComboBox;
    ToggleLinLog: TButton;
    SpeedButton7: TSpeedButton;
    procedure FormCreate(Sender: TObject);
    procedure sommecirculaire(tab:mat2d128;X0,Y0:integer;g:real);
    procedure choixChange(Sender: TObject);
    procedure SpeedButton4Click(Sender: TObject);
    procedure ToggleLinLogClick(Sender: TObject);
    procedure SpeedButton7Click(Sender: TObject);
  private
    { Déclarations privées}
  public
  cax,cay {axe rouge},cbx,cby {axe bleu},ccx,ccy {centre}:integer;
  spectreindex:integer;
    { Déclarations publiques}
    procedure redessine;
  end;

implementation 



{$R *.DFM}

{***********************************************
}
procedure TSommeSpectre2DForm.FormCreate(Sender: TObject);
begin
{xygraph1.Addmark(1,xygraph1.xAxis.Min,xygraph1.YAxis.Min,xygraph1.xAxis.Min,xygraph1.YAxis.Max,clred,'1',mtxmark ,mpUpLeft, dtAfter);
xygraph1.Addmark(2,xygraph1.xAxis.Max,xygraph1.YAxis.Min,xygraph1.xAxis.Max,xygraph1.YAxis.Max,clblue,'2',mtxmark ,mpUpLeft, dtAfter);}
end;
{************************************
somme circulaire
INPUT tab 0..127,0..127 of real
      X0,Y0: centre avec 0<=X<=127
      g:facteur d'echelle sur la distance
      }
procedure TSommeSpectre2DForm.sommecirculaire(tab:mat2d128;X0,Y0:integer;g:real);
var R,total:real; {rayon et total/rayon}
    nx0,ny0,nx,ny:integer; {point courants}
    nxmax,nymax:integer; {max}
    nbr:integer;
begin
{calcul des dim nx et ny max}
nxmax:=127-X0;
if nxmax<X0 then nxmax:=X0;
nymax:=127-Y0;
if nymax<Y0 then nymax:=Y0;
{calcul}
for nx0:=0 to nxmax do
  for ny0:=0 to nymax do   {balayage R^2=nx^2+ny^2}
    begin
    {somme pour un R }
    total:=0;
    nbr:=0;
    R:=sqrt(sqr(nx0)+sqr(ny0));
    for nx:=-trunc(R) to trunc(R) do
      begin
      if int(sqrt(sqr(nx0)+sqr(ny0)-sqr(nx)))=sqrt(sqr(nx0)+sqr(ny0)-sqr(nx)) then
        begin
        {ny est entier}
        ny:=trunc(sqrt(sqr(nx0)+sqr(ny0)-sqr(nx)));
        if (X0+nx>=0) and (X0+nx<=127) then
           begin  {X0+nx est dans le detecteur}
           if (Y0+ny>=0) and (Y0+ny<=127) then
             begin {Y0+ny est dans le detecteur}
             total:=total+tab[X0+nx,Y0+ny];
             nbr:=nbr+1;
             end;

           if (Y0-ny>=0) and (Y0-ny<=127) then
             begin {Y0-ny est dans le detecteur}
             total:=total+tab[X0+nx,Y0-ny];
             nbr:=nbr+1;
             end;
             
           end;
        end;
      end;
    total:=total/nbr;
    xygraph1.series[1].add(g*R,total);
    end;

end;
{***********************************************
}
procedure TSommeSpectre2DForm.redessine;
var
i,j:integer;
u:real;
tab:mat2d128;

begin
xygraph1.series[1].holdupdates:=true;
xygraph1.series[2].holdupdates:=true;
xygraph1.series[1].clear;
xygraph1.series[2].clear;
 xygraph1.series[1].linecolor:=clred;
 xygraph1.series[1].drawpoints:=false;
 xygraph1.series[2].linecolor:=clblue;
 xygraph1.series[2].drawpoints:=false;
 xygraph1.series[1]. linestyle:=pssolid;
 xygraph1.series[2]. linestyle:=pssolid;
{ligne}
if choix.text='ligne' then begin
 for i:=0 to deuxd.spect[spectreindex].x-1 do begin
  xygraph1.series[1].add(i,deuxd.spect[spectreindex].data[i,cay,0].z);
  xygraph1.series[2].add(i,deuxd.spect[spectreindex].data[i,cby,0].z);
 end;
end;
{colonne}
if choix.text='colonne' then begin
 for i:=0 to deuxd.spect[spectreindex].y-1 do begin
  xygraph1.series[1].add(i,deuxd.spect[spectreindex].data[cax,i,0].z);
  xygraph1.series[2].add(i,deuxd.spect[spectreindex].data[cbx,i,0].z);
 end;
end;
{somme ligne}
if choix.text='somme ligne' then begin
 for i:=0 to deuxd.spect[spectreindex].x-1 do begin
  u:=0;
  for j:=cay to cby do u:=u+deuxd.spect[spectreindex].data[i,j,0].z;
  xygraph1.series[1].add(i,u);
 end;
end;
{somme colonne}
if choix.text='somme colonne' then begin
 for i:=0 to deuxd.spect[spectreindex].y-1 do begin
  u:=0;
  for j:=cax to cbx do u:=u+deuxd.spect[spectreindex].data[j,i,0].z;
  xygraph1.series[1].add(i,u);
 end;
end;
{somme circulaire}
if choix.text='somme circulaire' then begin
for i:=0 to 127 do
    for j:=0 to 127 do
        tab[i,j]:=deuxd.spect[spectreindex].data[i,j,0].z;
sommecirculaire(tab,ccx,ccy,1);
end;


xygraph1.series[1].holdupdates:=false;
xygraph1.series[2].holdupdates:=false;
end;

procedure TSommeSpectre2DForm.choixChange(Sender: TObject);
begin
redessine
end;

procedure TSommeSpectre2DForm.SpeedButton4Click(Sender: TObject);
begin
ShowxyDataWizard(self, xyGraph1);
end;

procedure TSommeSpectre2DForm.ToggleLinLogClick(Sender: TObject);
begin
If ToggleLinLog.caption='Lin'
     then begin
          xygraph1.Yaxis.Logscale:=True;
          ToggleLinLog.caption:='Log'
          end
     else begin
          xyGraph1.Yaxis.Logscale:=False;
          ToggleLinLog.caption:='Lin'
          end;
     redessine
end;

procedure TSommeSpectre2DForm.SpeedButton7Click(Sender: TObject);
begin
if xygraph1.yaxis.autosizing then begin
xygraph1.yaxis.autosizing:=false;
speedbutton7.caption:='Man';
end else begin
xygraph1.yaxis.autosizing:=true;
speedbutton7.caption:='Auto';
end;
end;

end.
