???: Mars (FangQ), ??: MathTools ? ?: 3D FDTD[ToyFDTD4 by Bai Ming][Delphi](main.pas) ???: The Big Green (Tue Jun 18 22:27:40 2002) , ?? ToyFDTD4 What is this? ToyFDTD4, developed by Bai Ming, is a 3D FDTD code implementing a point source in a free-space mesh with Mur absorbing boundaries. Output is to V iz5D. Like other ToyFDTD codes, ToyFDTD4 is published under the GNU General Public License. Unlike the other Toycodes, it has not been tested here, since w e don't have the correct compiler and platform. It's also not heavily commented. Language: Pascal Author: Bai Ming Why it's cool: Demonstrates Viz5D, a remarkable visualization tool Demonstrates 3D FDTD in Pascal More practical coding style: ToyFDTD1 was written to be read, not developed as a tool. The Toycode style is great for trying out new capabilities or demonstrati ng them to others, but ToyFDTD4 is written more in a style a programmer would us e when planning to seriously develop the features of the code over time. unit main; interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, Buttons, ExtCtrls,Math, ComCtrls, jpeg; const rangei=100; //range of colomn (x) rangej=100; //range of row (y) rangek=100; //range of level (z) dir='C:\data'; //the dir of all the files N_water=1.33; //the refractive index of water N_glass=1.7; //the refractive index of glass qeCu=5.9 ; //the conductance of Cu as 5.9x10E7 ohm*m //if other materials are needed, add here CD=0.5; //the factor of the FDTD formula C=3*100000000; //light speed type {in this section some definitions are made,such as the 6 elements of the electro-magnetic wave.} //the array allocated for the image Imagearray=array [1..rangek-1,1..rangeI-1,1..rangeJ-1] of single; //the array allocated to the 6 elements of the electro-magnetic wave Hxarray=array [1..rangeK-1,1..rangeI,1..rangeJ-1] of single; Hyarray=array [1..rangeK-1,1..rangeI-1,1..rangeJ] of single; Hzarray=array [1..rangeK,1..rangeI-1,1..rangeJ-1] of single; Exarray=array [1..rangeK,1..rangeI-1,1..rangeJ] of single; Eyarray=array [1..rangeK,1..rangeI,1..rangeJ-1] of single; Ezarray=array [1..rangeK-1,1..rangeI,1..rangeJ] of single; //below is the pointer for the arrays. Pimagearray=^imagearray; PHx=^Hxarray; PHy=^Hyarray; PHz=^Hzarray; PEx=^Exarray; PEy=^Eyarray; PEz=^Ezarray; type TDistribution = class(TForm) calculateb: TBitBtn; Zdrawb: TBitBtn; pauseb: TBitBtn; exitb: TBitBtn; CreateFileb: TButton; OpenFileb: TButton; XYZdrawb: TButton; ydrawb: TButton; XDrawb: TButton; rangetxt: TLabel; stepntxt: TLabel; precisiontxt: TLabel; Wavetxt: TLabel; Processtxt: TLabel; SaveDialog1: TSaveDialog; Timer1: TTimer; OpenDialog1: TOpenDialog; mesgSB: TStatusBar; ImageX: TImage; ImageZ: TImage; ImageY: TImage; Imageinfor: TImage; XpageE: TEdit; YPagee: TEdit; ZPageE: TEdit; imagexL: TLabel; ImageYL: TLabel; ImageZL: TLabel; Image3dL: TLabel; Label5: TLabel; Label6: TLabel; Label7: TLabel; imageRGroup: TRadioGroup; XEdit: TEdit; YEdit: TEdit; ZEdit: TEdit; DrawallB: TButton; MovXB: TButton; MovYb: TButton; MovZB: TButton; PageTxt: TLabel; Mov3DB: TButton; Mov3DxB: TButton; Mov3DYB: TButton; Mov3DzB: TButton; StretchB: TButton; procedure exitbClick(Sender: TObject); procedure calculatebClick(Sender: TObject); procedure pausebClick(Sender: TObject); procedure ZdrawbClick(Sender: TObject); procedure FormCreate(Sender: TObject); procedure CreateFilebClick(Sender: TObject); procedure OpenFilebClick(Sender: TObject); procedure Timer1Timer(Sender: TObject); procedure XYZdrawbClick(Sender: TObject); procedure XpageEKeyPress(Sender: TObject; var Key: Char); procedure ZPageEKeyPress(Sender: TObject; var Key: Char); procedure YPageeKeyPress(Sender: TObject; var Key: Char); procedure XDrawbClick(Sender: TObject); procedure ydrawbClick(Sender: TObject); procedure FormDestroy(Sender: TObject); procedure DrawallBClick(Sender: TObject); procedure MovXBClick(Sender: TObject); procedure MovYbClick(Sender: TObject); procedure MovZBClick(Sender: TObject); procedure StretchBClick(Sender: TObject); procedure Mov3DBClick(Sender: TObject); procedure Mov3DxBClick(Sender: TObject); procedure Mov3DYBClick(Sender: TObject); procedure Mov3DzBClick(Sender: TObject); private { Private declarations } public procedure FileJudge(); //reading files and parameters procedure predraw(); //the preparation before drawing procedure getFileReady(); //After OPen,create procedure Loadfile(); //the last step of GetFileReady { Public declarations } end; var Distribution: TDistribution; StepN :integer; //the currently time step precision :single; //the precision of the space step wavelength :single; //wavelength for the EM wave mesg :string[40]; //the content of the message Calculating:Boolean; //the flag for calculation savefree : Boolean; //the flag for whether to save files fileready :Boolean; //the flag to show the file is ready newwork :boolean; //the flag for data updata process :integer; //to show the procession in one time step Page :integer; //the page to be currently processed pageX,pagey,pagez:integer;//the page number to draw RGBTable :array [0..1024] of integer; //the color table datafile :file; //the file pointer to open file infornamer :string; //the information file name pic :Tbitmap; Hxmem,Hymem,Hzmem:TmemoryStream; //files Exmem,Eymem,Ezmem:TmemoryStream; Ex:PEx; //pointer Ey:PEy; Ez:PEz; Hx:PHx; Hy:PHy; Hz:PHz; implementation uses createfile,calculate; {$R *.DFM} procedure TDistribution.FormCreate(Sender: TObject); begin newwork:=true; //newwork=true means data has not been modified. fileready:=false; //the file is not ready now calculating:=false; //Calculation is not processing now. //here you can change you directory of the saved files. //or you can use some other methods such as use the Opendialogs //in Delphi to indicate the directory of all the data file. page:=0; pic:=Tbitmap.Create; //create the canvas named "pic" as buffer for draw i mage pic.Canvas.Brush.Color:=clblack; predraw; XpageE.Text:=inttostr(rangeI div 2); YpageE.Text:=inttostr(rangeJ div 2); ZpageE.Text:=inttostr(rangek div 2); Xedit.Text :=inttostr(rangeI-1); Yedit.Text :=inttostr(rangeJ-1); Zedit.Text :=inttostr(rangeK-1); //Construct the Stream parameters Hxmem :=TmemoryStream.Create; //create Hx memorystream Hymem :=TmemoryStream.Create; Hzmem :=TmemoryStream.Create; Exmem :=TmemoryStream.Create; Eymem :=TmemoryStream.Create; Ezmem :=TmemoryStream.Create; ExBorderY:=Tmemorystream.Create; //create ExBorder memorystream ExBorderZ:=Tmemorystream.Create; EyBorderX:=Tmemorystream.Create; EyBorderZ:=Tmemorystream.Create; EzBorderX:=Tmemorystream.Create; EzBorderY:=Tmemorystream.Create; end; procedure TDistribution.exitbClick(Sender: TObject); var inforfile:file; begin if newwork=false then begin if calculation.suspended=true{ if paused} then calculation.Resume; calculating:=false; {transfer the stop signal to the calculation thread} while not(savefree) do //if savefree=true, a complete time step just fini shed. //and the data can be saved. begin mesgSB.SimpleText :='Please waiting until calculation finished at 7. Process= '+inttostr(process); end; calculation.suspend; //stop the calculation //below is the steps to save the data Hxmem.SaveToFile(dir+'\Hx.dat'); Hymem.SaveToFile(dir+'\Hy.dat'); Hzmem.SaveToFile(dir+'\Hz.dat'); Exmem.SaveToFile(dir+'\Ex.dat'); Eymem.SaveToFile(dir+'\Ey.dat'); Ezmem.SaveToFile(dir+'\Ez.dat'); ExBorderY.SaveToFile(dir+'\ExborderY.dat'); ExBorderZ.SaveToFile(dir+'\ExborderZ.dat'); EyBorderX.SaveToFile(dir+'\EyborderX.dat'); EyBorderZ.SaveToFile(dir+'\EyborderZ.dat'); EzBorderX.SaveToFile(dir+'\EzborderX.dat'); EzBorderY.SaveToFile(dir+'\EzborderY.dat'); AssignFile(inforFile,dir+'\infor.dat'); Reset(inforfile,4);// blockwrite(inforfile,StepN,1); blockwrite(inforfile,process,1); closefile(inforfile); calculation.Destroy; end; Close; end; procedure TDistribution.FileJudge(); //load the information before calculati on var i,j,k:integer; begin Assignfile(datafile,infornamer); reset(datafile,4); seek(datafile,0); blockread(datafile,StepN,1); //load the completed step 'StepN' blockread(datafile,process,1); //load the parm 'process' blockread(datafile,wavelength,1); //load the input wavelength blockread(datafile,precision,1); //load the precision of space grid blockread(datafile,I,1); //i blockread(datafile,J,1); //j blockread(datafile,k,1); //k blockread(datafile,mesg,20*sizeof(char)); closefile(datafile); if (i<>rangei)or(j<>rangej)or(k<>rangek) then begin //verify the data information fileready:=false; exit; end; //exhibit the loaded information Distribution.Caption :=' '+mesg; rangetxt.Caption :=inttostr(rangeI)+'X'+inttostr(rangeJ)+'X'+inttostr(rangeK); StepNtxt.Caption :='N='+inttostr(stepN); wavetxt.Caption :='Wave:'+floattostrF(wavelength,ffgeneral,4,5)+'nm'; precisiontxt.Caption :='Precision:'+floattostr(precision); processtxt.Caption :='Process:'+floattostr(process); end; procedure TDistribution.Loadfile(); begin mesgSb.SimpleText :='Loading File...........'; //load the data to the memorystream Hxmem.LoadFromFile(dir+'\Hx.dat'); Hymem.LoadFromFile(dir+'\Hy.dat'); Hzmem.LoadFromFile(dir+'\Hz.dat'); Exmem.LoadFromFile(dir+'\Ex.dat'); Eymem.LoadFromFile(dir+'\Ey.dat'); Ezmem.LoadFromFile(dir+'\Ez.dat'); //use the pointer direct to the memorystream //So the memorystream can be visited by Ex^[i,j,k] Ex:=Exmem.Memory; Ey:=Eymem.Memory; Ez:=Ezmem.Memory; Hx:=Hxmem.Memory; Hy:=Hymem.Memory; Hz:=Hzmem.Memory; //all the load process is completed Fileready:=true; end; procedure TDistribution.predraw(); //preparation for the color table var index:integer; begin //RGB table; for index:=1 to 765 do begin //You may change the index rgb table as you like if index <=255 then RGBtable[index]:=RGB(0,index,255); if (index >=256)and(index<=510) then RGBtable[index]:=RGB(index-255,255,255+25 5-index);// 3v if (index >=510)and(index<=765) then RGBtable[index]:=RGB(255,255-index+510,0) ; // 3v end; RGBtable[0]:=RGB(0,0,0); //RGBtable[1]:=RGB(0,0,0); end; procedure TDistribution.getFileReady(); begin fileJudge; //load information Loadfile; //load data predraw; //prapare color table end; procedure TDistribution.calculatebClick(Sender: TObject); begin if (fileready=false) then begin showmessage('You must select available FDTD infor file!'); exit; end; if newwork=true then begin calculation:=Tcalculatethread.Create(true); //create the calculation thread calculation.FreeOnTerminate:=True; end; if calculation.suspended=true then calculation.Resume; //if the thread already e xist calculating:=true; end; procedure TDistribution.pausebClick(Sender: TObject); begin calculating:=false; while not(savefree) do begin mesgSB.SimpleText :='Please waiting until calculation finished at 7. Process= '+inttostr(process); end; if calculation.suspended=false then calculation.suspend; end; procedure TDistribution.CreateFilebClick(Sender: TObject); begin fileready:=false; Application.CreateForm(TFileDefine, FileDefine); //create the form for file crea tion. filedefine.ShowModal; Filejudge; fileready:=true; end; procedure TDistribution.OpenFilebClick(Sender: TObject); begin fileready:=false; //file not ready yet if OpenDialog1.Execute then begin infornamer:=openDialog1.FileName; //get the infor filename end else infornamer:=''; if infornamer<>'' then begin getFileReady; if fileready=false then exit; end else showmessage('Please open correct FDTD file.'); end; procedure TDistribution.Timer1Timer(Sender: TObject); //dynamic keep watch on so me signal begin timer1.Enabled :=false; //show some information stepNtxt.Caption :='Step:'+inttostr(stepN); processtxt.caption:='Processing:'+inttostr(process); pagetxt.Caption :='Doing page:'+inttostr(page); if fileready=true then begin if calculating=false then mesgSB.SimpleText :=infornamer+' ready for calc ulation.'; //define which button should be enabled calculateb.Enabled :=true; xdrawb.Enabled :=True; ydrawb.Enabled :=True; zdrawb.Enabled :=True; xyzdrawb.Enabled :=True; drawallb.Enabled :=true; MovXB.Enabled :=true; MovYB.Enabled :=true; MovZB.Enabled :=true; Mov3dXb.Enabled :=true; Mov3dYb.Enabled :=true; Mov3dZb.Enabled :=true; Mov3dB.Enabled :=true; end else begin mesgSB.SimpleText :='Create File for calculation.'; pauseb.Enabled:=false; calculateb.Enabled :=false; xdrawb.Enabled :=false; ydrawb.Enabled :=false; zdrawb.Enabled :=false; xyzdrawb.Enabled :=false; drawallb.Enabled :=false; MovXB.Enabled :=false; MovYB.Enabled :=false; MovZB.Enabled :=false; Mov3dXb.Enabled :=false; Mov3dYb.Enabled :=false; Mov3dZb.Enabled :=false; mov3dB.Enabled :=false; end; if calculating=true then begin calculateb.Enabled :=false; createfileb.Enabled :=false; openfileb.Enabled :=false; pauseb.Enabled:=true; mesgSB.SimpleText :='Calculation is processing.......'; end else begin if fileready=true then calculateb.Enabled :=true; createfileb.Enabled :=true; openfileb.Enabled :=true; end; timer1.enabled:=true; end; procedure TDistribution.XYZdrawbClick(Sender: TObject); //draw 3 face of the cu be var rangeX,rangey,rangeZ:integer; Face1:array[1..4,1..2] of integer; face2:array[1..4,1..2] of integer; face3:array[1..4,1..2] of integer; max,min,maxmin:single; angle:single; x,y,colorindex:integer; i,j,k:integer; imagestream:TmemoryStream; image:PImageArray; begin rangex:=round(strtoint(xedit.Text)); rangeY:=strtoint(Yedit.text); rangez:=strtoint(zedit.text); if (rangex>rangeI-1)or(rangex=0) then begin showmessage('XPage number should be less than '+inttostr(rangeI)); exit; end; if (rangeY>rangej-1)or(rangey=0) then begin showmessage('YPage number should be less than '+inttostr(rangeI)); exit; end; if (rangez>rangeK-1)or(rangez=0) then begin showmessage('ZPage number should be less than '+inttostr(rangeI)); exit; end; max:=0;min:=0; imagestream:=TmemoryStream.Create; imagestream.SetSize((rangeI-1)*(rangeJ-1)*(rangek-1)*sizeof(single)); image:=imagestream.Memory; for k:=1 to rangek-1 do for i:=1 to rangeI-1 do for j:=1 to rangej-1 do begin case imageRgroup.ItemIndex of 0: image^[k,i,j]:=Ex^[k,i,j]; 1: image^[k,i,j]:=Ey^[k,i,j]; 2: image^[k,i,j]:=Ez^[k,i,j]; 3: image^[k,i,j]:=Hx^[k,i,j]; 4: image^[k,i,j]:=Hy^[k,i,j]; 5: image^[k,i,j]:=Hz^[k,i,j]; 6: image^[k,i,j]:=Ex^[k,i,j]; end; if maxImage^[k,i,j] then min:=Image^[k,i,j]; end; maxmin:=max-min; if maxmin<1e-10 then maxmin:=1e-10; pic.width:=0; pic.height:=0; pic.Width:=round(rangeJ+0.8*rangeI+0.1*rangeJ); pic.Height:=round(rangeK+0.8*rangeI+0.1*rangeK); angle:=Pi/4; face1[1,1]:=round(cos(angle)*(rangeI*0.8-rangex*0.8)+pic.Width/10); face1[1,2]:=round(sin(angle)*(-rangeI*0.8+rangex*0.8)+pic.Height-(pic.Height/10) ); face1[2,1]:=face1[1,1]+rangey;face1[2,2]:=face1[1,2]; face1[3,1]:=face1[1,1];face1[3,2]:=face1[1,2]-rangez; face1[4,1]:=face1[2,1];face1[4,2]:=face1[3,2]; face2[1,1]:=round(face1[2,1]+cos(angle)*rangex*0.8); face2[1,2]:=round(face1[2,2]-sin(angle)*rangex*0.8); face2[2,1]:=face1[2,1];face2[2,2]:=face1[2,2]; face2[3,1]:=face2[1,1];face2[3,2]:=face2[1,2]-rangez; face2[4,1]:=face1[4,1];face2[4,2]:=face1[4,2]; face3[1,1]:=face2[3,1]-rangey; face3[1,2]:=face2[3,2]; face3[2,1]:=face1[3,1];face3[2,2]:=face1[3,2]; face3[3,1]:=face2[3,1];face3[3,2]:=face2[3,2]; face3[4,1]:=face2[4,1];face3[4,2]:=face2[4,2]; pic.canvas.Pen.Color:=clgreen; pic.Canvas.Polyline([Point(face1[1,1],face1[1,2]), point(face1[2,1],face1[2,2]), Point(face1[4,1],face1[4,2]),Point(face1[3,1],face1[3,2]), point(face1[1,1],face1[1,2]),Point(face3[2,1],face3[2,2]), Point(face3[1,1],face3[1,2]),Point(face3[3,1],face3[3,2]), Point(face3[4,1],face3[4,2]),Point(face2[2,1],face1[2,2]), Point(face2[1,1],face2[1,2]),Point(face2[3,1],face2[3,2])]); pic.Canvas.Font.Color:=clwhite; pic.canvas.TextOut(face1[1,1]-10,face1[1,2]+5,'x'+inttostr(rangex)); pic.canvas.TextOut(face2[1,1]-8,face2[1,2]+10,'y'+inttostr(rangey)); pic.canvas.TextOut(face3[1,1]-25,face3[1,2]-15,'z'+inttostr(rangez)); for J:=1 to rangeY-1 do for k:=1 to rangez-1 do begin // colorindex:=round((768/maxmin)*abs(Image^[k,rangex,j]-min)); //2v colorindex:=round((768/maxmin)*abs(Image^[k,rangex,j])); //2v x:=face1[1,1]+j; y:=face1[1,2]-k; pic.canvas.pixels[x,y]:=RGBtable[colorindex]; end; for I:=1 to rangex-2 do for k:=1 to rangez-1 do begin // colorindex:=round((768/maxmin)*abs(Image^[k,I,rangey]-min)); //2v colorindex:=round((768/maxmin)*abs(Image^[k,I,rangey])); //2v x:=round(face2[1,1]-I*cos(angle)*0.8); y:=round(face2[1,2]-k+I*sin(angle)*0.8); pic.canvas.pixels[x,y]:=RGBtable[colorindex]; end; for J:=1 to rangeY-1 do for I:=1 to rangex-2 do begin // colorindex:=round((768/maxmin)*abs(Image^[rangez,I,j])); //2v x:=round(face3[1,1]+J-I*cos(angle)*0.8); y:=round(face3[1,2]+I*sin(angle)*0.8); pic.canvas.pixels[x,y]:=RGBtable[colorindex]; end; imageinfor.Picture.Bitmap:=pic; imageinfor.Refresh; imagestream.Destroy; image3dL.Caption :=Inttostr(imageRgroup.ItemIndex)+' 3D Image'; end; procedure TDistribution.XpageEKeyPress(Sender: TObject; var Key: Char); begin if not((ord('0')<=ord(key))and (ord('9')>=ord(key))) then key :=chr(0); end; procedure TDistribution.ZPageEKeyPress(Sender: TObject; var Key: Char); begin if not((ord('0')<=ord(key))and (ord('9')>=ord(key))) then key :=chr(0); end; procedure TDistribution.YPageeKeyPress(Sender: TObject; var Key: Char); begin if not((ord('0')<=ord(key))and (ord('9')>=ord(key))) then key :=chr(0); end; procedure TDistribution.XDrawbClick(Sender: TObject); var i,j,k:integer; max,min,maxmin:single; colorindex:integer; x,y:integer; imagestream:TmemoryStream; image:PImageArray; begin pagex:=StrtoInt(xpageE.Text); max:=0;min:=0; if (pagex>rangeI-1)or(pagex=0) then begin showmessage('Page number should be less than '+inttostr(rangeI)); exit; end; imagestream:=TmemoryStream.Create; imagestream.SetSize((rangeI-1)*(rangeJ-1)*(rangek-1)*sizeof(single)); image:=imagestream.Memory; for k:=1 to rangek-1 do for i:=1 to rangeI-1 do for j:=1 to rangej-1 do begin case imageRgroup.ItemIndex of 0: image^[k,i,j]:=Ex^[k,i,j]; 1: image^[k,i,j]:=Ey^[k,i,j]; 2: image^[k,i,j]:=Ez^[k,i,j]; 3: image^[k,i,j]:=Hx^[k,i,j]; 4: image^[k,i,j]:=Hy^[k,i,j]; 5: image^[k,i,j]:=Hz^[k,i,j]; 6: image^[k,i,j]:=Ex^[k,i,j]; end; if maxImage^[k,i,j] then min:=Image^[k,i,j]; end; maxmin:=max-min; if maxmin<1e-10 then maxmin:=1e-10; pic.Width:=rangeJ-1; pic.Height:=rangeK-1; for K:=1 to rangeK-1 do for j:=1 to rangeJ-1 do begin // colorindex:=round((768/maxmin)*abs(Image^[k,pagex,j]-min)); //2v colorindex:=round((768/maxmin)*abs(Image^[k,pagex,j])); //2v x:=j-1; y:=rangeK-1-k; pic.canvas.pixels[x,y]:=RGBtable[colorindex]; end; imagestream.Destroy; imageX.Picture.Bitmap:=pic; imageX.Refresh; end; procedure TDistribution.ZdrawbClick(Sender: TObject); var i,j,k:integer; max,min,maxmin:single; colorindex:integer; x,y:integer; imagestream:TmemoryStream; image:PImageArray; begin pagez:=StrtoInt(zpageE.Text); max:=0;min:=0; if (pagez>rangeK-1)or(pagez=0) then begin showmessage('Page number should be less than '+inttostr(rangeI)); exit; end; imagestream:=TmemoryStream.Create; imagestream.SetSize((rangeI-1)*(rangeJ-1)*(rangek-1)*sizeof(single)); image:=imagestream.Memory; for k:=1 to rangek-1 do for i:=1 to rangeI-1 do for j:=1 to rangej-1 do begin case imageRgroup.ItemIndex of 0: image^[k,i,j]:=Ex^[k,i,j]; 1: image^[k,i,j]:=Ey^[k,i,j]; 2: image^[k,i,j]:=Ez^[k,i,j]; 3: image^[k,i,j]:=Hx^[k,i,j]; 4: image^[k,i,j]:=Hy^[k,i,j]; 5: image^[k,i,j]:=Hz^[k,i,j]; 6: image^[k,i,j]:=Ex^[k,i,j]; end; if maxImage^[k,i,j] then min:=Image^[k,i,j]; end; maxmin:=max-min; if maxmin<1e-10 then maxmin:=1e-10; pic.Width:=rangeI-1; pic.Height:=rangeJ-1; for I:=1 to rangeI-1 do for j:=1 to rangeJ-1 do begin // colorindex:=round((768/maxmin)*abs(Image^[pagez,i,j]-min)); //2v colorindex:=round((768/maxmin)*abs(Image^[pagez,i,j])); //2v x:=I-1; y:=rangeJ-1-J; pic.canvas.pixels[x,y]:=RGBtable[colorindex]; end; imagestream.Destroy; imagez.Picture.Bitmap:=pic; imagez.Refresh; end; procedure TDistribution.ydrawbClick(Sender: TObject); var i,j,k:integer; max,min,maxmin:single; colorindex:integer; x,y:integer; imagestream:TmemoryStream; image:PImageArray; begin pagey:=StrtoInt(ypageE.Text); max:=0;min:=0; if (pagey>rangeJ-1)or(pagey=0) then begin showmessage('Page number should be less than '+inttostr(rangeJ)); exit; end; imagestream:=TmemoryStream.Create; imagestream.SetSize((rangeI-1)*(rangeJ-1)*(rangek-1)*sizeof(single)); image:=imagestream.Memory; for k:=1 to rangek-1 do for i:=1 to rangeI-1 do for j:=1 to rangej-1 do begin case imageRgroup.ItemIndex of 0: image^[k,i,j]:=Ex^[k,i,j]; 1: image^[k,i,j]:=Ey^[k,i,j]; 2: image^[k,i,j]:=Ez^[k,i,j]; 3: image^[k,i,j]:=Hx^[k,i,j]; 4: image^[k,i,j]:=Hy^[k,i,j]; 5: image^[k,i,j]:=Hz^[k,i,j]; 6: image^[k,i,j]:=Ex^[k,i,j]; end; if maxImage^[k,i,j] then min:=Image^[k,i,j]; end; maxmin:=max-min; if maxmin<1e-10 then maxmin:=1e-10; pic.Width:=rangeI-1; pic.Height:=rangeK-1; for I:=1 to rangeI-1 do for K:=1 to rangeK-1 do begin // colorindex:=round((768/maxmin)*abs(Image^[k,i,pagey]-min)); //2v colorindex:=round((768/maxmin)*abs(Image^[k,i,pagey])); //2v x:=I-1; y:=rangek-1-k; pic.canvas.pixels[x,y]:=RGBtable[colorindex]; end; imagestream.Destroy; imagey.Picture.Bitmap:=pic; imagey.Refresh; end; procedure TDistribution.DrawallBClick(Sender: TObject); var i,j,k:integer; max,min,maxmin:single; colorindex:integer; x,y:integer; imagestream:TmemoryStream; image:PImageArray; begin pagex:=StrtoInt(xpageE.Text); pagey:=StrtoInt(ypageE.Text); pagez:=StrtoInt(zpageE.Text); max:=0;min:=0; if (pagez>rangeK-1)or(pagez=0) then begin showmessage('Page number should be less than '+inttostr(rangeI)); exit; end; if (pagex>rangeI-1)or(pagex=0) then begin showmessage('Page number should be less than '+inttostr(rangeI)); exit; end; if (pagey>rangeJ-1)or(pagey=0) then begin showmessage('Page number should be less than '+inttostr(rangeJ)); exit; end; imagestream:=TmemoryStream.Create; imagestream.SetSize((rangeI-1)*(rangeJ-1)*(rangek-1)*sizeof(single)); image:=imagestream.Memory; for k:=1 to rangek-1 do for i:=1 to rangeI-1 do for j:=1 to rangej-1 do begin case imageRgroup.ItemIndex of 0: image^[k,i,j]:=Ex^[k,i,j]; 1: image^[k,i,j]:=Ey^[k,i,j]; 2: image^[k,i,j]:=Ez^[k,i,j]; 3: image^[k,i,j]:=Hx^[k,i,j]; 4: image^[k,i,j]:=Hy^[k,i,j]; 5: image^[k,i,j]:=Hz^[k,i,j]; 6: image^[k,i,j]:=Ex^[k,i,j]; end; if maxImage^[k,i,j] then min:=Image^[k,i,j]; end; maxmin:=max-min; if maxmin<1e-10 then maxmin:=1e-10; pic.Width:=rangeJ-1; pic.Height:=rangeK-1; for K:=1 to rangeK-1 do for j:=1 to rangeJ-1 do begin // colorindex:=round((768/maxmin)*abs(Image^[k,pagex,j]-min)); //2v colorindex:=round((768/maxmin)*abs(Image^[k,pagex,j])); //2v x:=j-1; y:=rangeK-1-k; pic.canvas.pixels[x,y]:=RGBtable[colorindex]; end; imageX.Picture.Bitmap:=pic; imageX.Refresh; pic.Width:=rangeI-1; pic.Height:=rangeK-1; for I:=1 to rangeI-1 do for K:=1 to rangeK-1 do begin // colorindex:=round((768/maxmin)*abs(Image^[k,i,pagey]-min)); //2v colorindex:=round((768/maxmin)*abs(Image^[k,i,pagey])); //2v x:=I-1; y:=rangek-1-k; pic.canvas.pixels[x,y]:=RGBtable[colorindex]; end; imagey.Picture.Bitmap:=pic; imagey.Refresh; pic.Width:=rangeI-1; pic.Height:=rangeJ-1; for I:=1 to rangeI-1 do for j:=1 to rangeJ-1 do begin // colorindex:=round((768/maxmin)*abs(Image^[pagez,i,j]-min)); //2v colorindex:=round((768/maxmin)*abs(Image^[pagez,i,j])); //2v x:=I-1; y:=rangeJ-1-J; pic.canvas.pixels[x,y]:=RGBtable[colorindex]; end; imagez.Picture.Bitmap:=pic; imagez.Refresh; imagestream.Destroy; end; procedure TDistribution.FormDestroy(Sender: TObject); begin Hxmem.Destroy; Hymem.Destroy; Hzmem.Destroy; Exmem.Destroy; Eymem.Destroy; Ezmem.Destroy; ExBorderY.Destroy; ExBorderZ.Destroy; EyBorderX.Destroy; EyBorderZ.Destroy; EzBorderX.Destroy; EzBorderY.Destroy; end; procedure TDistribution.MovXBClick(Sender: TObject); var i,j,k:integer; max,min,maxmin:single; colorindex:integer; x,y:integer; imagestream:TmemoryStream; image:PImageArray; begin max:=0;min:=0; imagestream:=TmemoryStream.Create; imagestream.SetSize((rangeI-1)*(rangeJ-1)*(rangek-1)*sizeof(single)); image:=imagestream.Memory; for k:=1 to rangek-1 do for i:=1 to rangeI-1 do for j:=1 to rangej-1 do begin case imageRgroup.ItemIndex of 0: image^[k,i,j]:=Ex^[k,i,j]; 1: image^[k,i,j]:=Ey^[k,i,j]; 2: image^[k,i,j]:=Ez^[k,i,j]; 3: image^[k,i,j]:=Hx^[k,i,j]; 4: image^[k,i,j]:=Hy^[k,i,j]; 5: image^[k,i,j]:=Hz^[k,i,j]; 6: image^[k,i,j]:=Ex^[k,i,j]; end; if maxImage^[k,i,j] then min:=Image^[k,i,j]; end; maxmin:=max-min; if maxmin<1e-10 then maxmin:=1e-10; pic.Width:=rangeJ-1; pic.Height:=rangeK-1; for i:=1 to rangeI-1 do begin for K:=1 to rangeK-1 do for j:=1 to rangeJ-1 do begin // colorindex:=round((768/maxmin)*abs(Image^[k,I,j]-min)); //2v colorindex:=round((768/maxmin)*abs(Image^[k,I,j])); //2v x:=j-1; y:=rangeK-1-k; pic.canvas.pixels[x,y]:=RGBtable[colorindex]; end; xpageE.Text:=inttostr(I); xpageE.Refresh; imageX.Picture.Bitmap:=pic; imageX.Refresh; end; imagestream.Destroy; end; procedure TDistribution.MovYbClick(Sender: TObject); var i,j,k:integer; max,min,maxmin:single; colorindex:integer; x,y:integer; imagestream:TmemoryStream; image:PImageArray; begin max:=0;min:=0; imagestream:=TmemoryStream.Create; imagestream.SetSize((rangeI-1)*(rangeJ-1)*(rangek-1)*sizeof(single)); image:=imagestream.Memory; for k:=1 to rangek-1 do for i:=1 to rangeI-1 do for j:=1 to rangej-1 do begin case imageRgroup.ItemIndex of 0: image^[k,i,j]:=Ex^[k,i,j]; 1: image^[k,i,j]:=Ey^[k,i,j]; 2: image^[k,i,j]:=Ez^[k,i,j]; 3: image^[k,i,j]:=Hx^[k,i,j]; 4: image^[k,i,j]:=Hy^[k,i,j]; 5: image^[k,i,j]:=Hz^[k,i,j]; 6: image^[k,i,j]:=Ex^[k,i,j]; end; if maxImage^[k,i,j] then min:=Image^[k,i,j]; end; maxmin:=max-min; if maxmin<1e-10 then maxmin:=1e-10; pic.Width:=rangeI-1; pic.Height:=rangeK-1; for j:=1 to rangeJ-1 do begin for I:=1 to rangeI-1 do for K:=1 to rangeK-1 do begin // colorindex:=round((768/maxmin)*abs(Image^[k,i,j]-min)); //2v colorindex:=round((768/maxmin)*abs(Image^[k,i,j])); //2v x:=I-1; y:=rangek-1-k; pic.canvas.pixels[x,y]:=RGBtable[colorindex]; end; ypageE.Text:=inttostr(j); ypageE.Refresh; imagey.Picture.Bitmap:=pic; imagey.Refresh; end; imagestream.Destroy; end; procedure TDistribution.MovZBClick(Sender: TObject); var i,j,k:integer; max,min,maxmin:single; colorindex:integer; x,y:integer; imagestream:TmemoryStream; image:PImageArray; begin max:=0;min:=0; imagestream:=TmemoryStream.Create; imagestream.SetSize((rangeI-1)*(rangeJ-1)*(rangek-1)*sizeof(single)); image:=imagestream.Memory; for k:=1 to rangek-1 do for i:=1 to rangeI-1 do for j:=1 to rangej-1 do begin case imageRgroup.ItemIndex of 0: image^[k,i,j]:=Ex^[k,i,j]; 1: image^[k,i,j]:=Ey^[k,i,j]; 2: image^[k,i,j]:=Ez^[k,i,j]; 3: image^[k,i,j]:=Hx^[k,i,j]; 4: image^[k,i,j]:=Hy^[k,i,j]; 5: image^[k,i,j]:=Hz^[k,i,j]; 6: image^[k,i,j]:=Ex^[k,i,j]; end; if maxImage^[k,i,j] then min:=Image^[k,i,j]; end; maxmin:=max-min; if maxmin<1e-10 then maxmin:=1e-10; pic.Width:=rangeI-1; pic.Height:=rangeJ-1; for K:=1 to rangeK-1 do begin for I:=1 to rangeI-1 do for j:=1 to rangeJ-1 do begin // colorindex:=round((768/maxmin)*abs(Image^[k,i,j]-min)); //2v colorindex:=round((768/maxmin)*abs(Image^[k,i,j])); //2v x:=I-1; y:=rangeJ-1-J; pic.canvas.pixels[x,y]:=RGBtable[colorindex]; end; zpageE.Text:=inttostr(k); zpageE.Refresh; imagez.Picture.Bitmap:=pic; imagez.Refresh; end; imagestream.Destroy; end; procedure TDistribution.StretchBClick(Sender: TObject); // Change the image size begin if Stretchb.Caption='Stretch' then begin imagex.Stretch :=false; imagey.Stretch :=false; imagez.Stretch :=false; imageinfor.Stretch :=false; Stretchb.Caption:='UnStretch'; end else begin imagex.Stretch :=True; imagey.Stretch :=True; imagez.Stretch :=True; imageinfor.stretch:=true; Stretchb.Caption:='Stretch'; end; end; procedure TDistribution.Mov3DBClick(Sender: TObject); var Face1:array[1..4,1..2] of integer; face2:array[1..4,1..2] of integer; face3:array[1..4,1..2] of integer; max,min,maxmin:single; angle:single; x,y,colorindex:integer; i,j,k,counter:integer; imagestream:TmemoryStream; image:PImageArray; begin max:=0;min:=0; image3dL.Caption :=Inttostr(imageRgroup.ItemIndex)+' 3D Image'; image3dL.Refresh; imagestream:=TmemoryStream.Create; imagestream.SetSize((rangeI-1)*(rangeJ-1)*(rangek-1)*sizeof(single)); image:=imagestream.Memory; for k:=1 to rangek-1 do for i:=1 to rangeI-1 do for j:=1 to rangej-1 do begin case imageRgroup.ItemIndex of 0: image^[k,i,j]:=Ex^[k,i,j]; 1: image^[k,i,j]:=Ey^[k,i,j]; 2: image^[k,i,j]:=Ez^[k,i,j]; 3: image^[k,i,j]:=Hx^[k,i,j]; 4: image^[k,i,j]:=Hy^[k,i,j]; 5: image^[k,i,j]:=Hz^[k,i,j]; 6: image^[k,i,j]:=Ex^[k,i,j]; end; if maxImage^[k,i,j] then min:=Image^[k,i,j]; end; maxmin:=max-min; if maxmin<1e-10 then maxmin:=1e-10; for counter:=1 to 1000 do begin if (counter>(rangeI-1))or(counter>(rangeJ-1))or(counter>(rangeK-1)) then exit; pic.width:=0; pic.height:=0; pic.Width:=round(rangeJ+0.8*rangeI+0.1*rangeJ); pic.Height:=round(rangeK+0.8*rangeI+0.1*rangeK); angle:=Pi/4; face1[1,1]:=round(cos(angle)*(rangeI*0.8-counter*0.8)+pic.Width/10); face1[1,2]:=round(sin(angle)*(-rangeI*0.8+counter*0.8)+pic.Height-(pic.Height/10 )); face1[2,1]:=face1[1,1]+counter;face1[2,2]:=face1[1,2]; face1[3,1]:=face1[1,1];face1[3,2]:=face1[1,2]-counter; face1[4,1]:=face1[2,1];face1[4,2]:=face1[3,2]; face2[1,1]:=round(face1[2,1]+cos(angle)*counter*0.8); face2[1,2]:=round(face1[2,2]-sin(angle)*counter*0.8); face2[2,1]:=face1[2,1];face2[2,2]:=face1[2,2]; face2[3,1]:=face2[1,1];face2[3,2]:=face2[1,2]-counter; face2[4,1]:=face1[4,1];face2[4,2]:=face1[4,2]; face3[1,1]:=face2[3,1]-counter; face3[1,2]:=face2[3,2]; face3[2,1]:=face1[3,1];face3[2,2]:=face1[3,2]; face3[3,1]:=face2[3,1];face3[3,2]:=face2[3,2]; face3[4,1]:=face2[4,1];face3[4,2]:=face2[4,2]; pic.canvas.Pen.Color:=clgreen; pic.Canvas.Polyline([Point(face1[1,1],face1[1,2]), point(face1[2,1],face1[2,2]), Point(face1[4,1],face1[4,2]),Point(face1[3,1],face1[3,2]), point(face1[1,1],face1[1,2]),Point(face3[2,1],face3[2,2]), Point(face3[1,1],face3[1,2]),Point(face3[3,1],face3[3,2]), Point(face3[4,1],face3[4,2]),Point(face2[2,1],face1[2,2]), Point(face2[1,1],face2[1,2]),Point(face2[3,1],face2[3,2])]); pic.Canvas.Font.Color:=clwhite; pic.canvas.TextOut(face1[1,1]-10,face1[1,2]+5,'x'+inttostr(counter)); pic.canvas.TextOut(face2[1,1]-8,face2[1,2]+10,'y'+inttostr(counter)); pic.canvas.TextOut(face3[1,1]-25,face3[1,2]-15,'z'+inttostr(counter)); for J:=1 to counter-1 do for k:=1 to counter-1 do begin // colorindex:=round((768/maxmin)*abs(Image^[k,counter,j]-min)); //2v colorindex:=round((768/maxmin)*abs(Image^[k,counter,j])); //2v x:=face1[1,1]+j; y:=face1[1,2]-k; pic.canvas.pixels[x,y]:=RGBtable[colorindex]; end; for I:=1 to counter-2 do for k:=1 to counter-1 do begin // colorindex:=round((768/maxmin)*abs(Image^[k,I,counter]-min)); //2v colorindex:=round((768/maxmin)*abs(Image^[k,I,counter])); //2v x:=round(face2[1,1]-I*cos(angle)*0.8); y:=round(face2[1,2]-k+I*sin(angle)*0.8); pic.canvas.pixels[x,y]:=RGBtable[colorindex]; end; for J:=1 to counter-1 do for I:=1 to counter-2 do begin // colorindex:=round((768/maxmin)*abs(Image^[counter,I,j]-min)); //2v colorindex:=round((768/maxmin)*abs(Image^[counter,I,j])); //2v x:=round(face3[1,1]+J-I*cos(angle)*0.8); y:=round(face3[1,2]+I*sin(angle)*0.8); pic.canvas.pixels[x,y]:=RGBtable[colorindex]; end; imageinfor.Picture.Bitmap:=pic; imageinfor.Refresh; end; imagestream.Destroy; end; procedure TDistribution.Mov3DxBClick(Sender: TObject); var Face1:array[1..4,1..2] of integer; face2:array[1..4,1..2] of integer; face3:array[1..4,1..2] of integer; max,min,maxmin:single; angle:single; rangeY,rangeZ:integer; x,y,colorindex:integer; i,j,k,counter:integer; imagestream:TmemoryStream; image:PImageArray; begin max:=0;min:=0; image3dL.Caption :=Inttostr(imageRgroup.ItemIndex)+' 3D Image'; image3dL.Refresh; rangeY:=strtoint(yedit.text); rangeZ:=strtoint(Zedit.text); imagestream:=TmemoryStream.Create; imagestream.SetSize((rangeI-1)*(rangeJ-1)*(rangek-1)*sizeof(single)); image:=imagestream.Memory; for k:=1 to rangek-1 do for i:=1 to rangeI-1 do for j:=1 to rangej-1 do begin case imageRgroup.ItemIndex of 0: image^[k,i,j]:=Ex^[k,i,j]; 1: image^[k,i,j]:=Ey^[k,i,j]; 2: image^[k,i,j]:=Ez^[k,i,j]; 3: image^[k,i,j]:=Hx^[k,i,j]; 4: image^[k,i,j]:=Hy^[k,i,j]; 5: image^[k,i,j]:=Hz^[k,i,j]; 6: image^[k,i,j]:=Ex^[k,i,j]; end; if maxImage^[k,i,j] then min:=Image^[k,i,j]; end; maxmin:=max-min; if maxmin<1e-10 then maxmin:=1e-10; for counter:=1 to 1000 do begin if (counter>(rangeI-1)) then exit; pic.width:=0; pic.height:=0; pic.Width:=round(rangeJ+0.8*rangeI+0.1*rangeJ); pic.Height:=round(rangeK+0.8*rangeI+0.1*rangeK); angle:=Pi/4; face1[1,1]:=round(cos(angle)*(rangeI*0.8-counter*0.8)+pic.Width/10); face1[1,2]:=round(sin(angle)*(-rangeI*0.8+counter*0.8)+pic.Height-(pic.Height/10 )); face1[2,1]:=face1[1,1]+rangey;face1[2,2]:=face1[1,2]; face1[3,1]:=face1[1,1];face1[3,2]:=face1[1,2]-rangez; face1[4,1]:=face1[2,1];face1[4,2]:=face1[3,2]; face2[1,1]:=round(face1[2,1]+cos(angle)*counter*0.8); face2[1,2]:=round(face1[2,2]-sin(angle)*counter*0.8); face2[2,1]:=face1[2,1];face2[2,2]:=face1[2,2]; face2[3,1]:=face2[1,1];face2[3,2]:=face2[1,2]-(rangez); face2[4,1]:=face1[4,1];face2[4,2]:=face1[4,2]; face3[1,1]:=face2[3,1]-(rangey); face3[1,2]:=face2[3,2]; face3[2,1]:=face1[3,1];face3[2,2]:=face1[3,2]; face3[3,1]:=face2[3,1];face3[3,2]:=face2[3,2]; face3[4,1]:=face2[4,1];face3[4,2]:=face2[4,2]; for J:=1 to rangey-1 do for k:=1 to rangez-1 do begin // colorindex:=round((768/maxmin)*abs(Image^[k,counter,j]-min)); //2v colorindex:=round((768/maxmin)*abs(Image^[k,counter,j])); //2v x:=face1[1,1]+j; y:=face1[1,2]-k; pic.canvas.pixels[x,y]:=RGBtable[colorindex]; end; for I:=1 to counter-2 do for k:=1 to rangez-1 do begin // colorindex:=round((768/maxmin)*abs(Image^[k,I,rangey]-min)); //2v colorindex:=round((768/maxmin)*abs(Image^[k,I,rangey])); //2v x:=round(face2[1,1]-I*cos(angle)*0.8); y:=round(face2[1,2]-k+I*sin(angle)*0.8); pic.canvas.pixels[x,y]:=RGBtable[colorindex]; end; for J:=1 to rangey-1 do for I:=1 to counter-2 do begin // colorindex:=round((768/maxmin)*abs(Image^[rangez,I,j]-min)); //2v colorindex:=round((768/maxmin)*abs(Image^[rangez,I,j])); //2v x:=round(face3[1,1]+J-I*cos(angle)*0.8); y:=round(face3[1,2]+I*sin(angle)*0.8); pic.canvas.pixels[x,y]:=RGBtable[colorindex]; end; pic.canvas.Pen.Color:=clgreen; pic.Canvas.Polyline([Point(face1[1,1],face1[1,2]), point(face1[2,1],face1[2,2]), Point(face1[4,1],face1[4,2]),Point(face1[3,1],face1[3,2]), point(face1[1,1],face1[1,2]),Point(face3[2,1],face3[2,2]), Point(face3[1,1],face3[1,2]),Point(face3[3,1],face3[3,2]), Point(face3[4,1],face3[4,2]),Point(face2[2,1],face1[2,2]), Point(face2[1,1],face2[1,2]),Point(face2[3,1],face2[3,2])]); pic.Canvas.Font.Color:=clwhite; pic.canvas.TextOut(face1[1,1]-10,face1[1,2]+5,'x'+inttostr(counter)); pic.canvas.TextOut(face2[1,1]-8,face2[1,2]+10,'y'+inttostr(rangey)); pic.canvas.TextOut(face3[1,1]-25,face3[1,2]-15,'z'+inttostr(rangez)); imageinfor.Picture.Bitmap:=pic; imageinfor.Refresh; end; imagestream.Destroy; end; procedure TDistribution.Mov3DYBClick(Sender: TObject); var Face1:array[1..4,1..2] of integer; face2:array[1..4,1..2] of integer; face3:array[1..4,1..2] of integer; max,min,maxmin:single; angle:single; rangex,rangez:integer; x,y,colorindex:integer; i,j,k,counter:integer; imagestream:TmemoryStream; image:PImageArray; begin max:=0;min:=0; image3dL.Caption :=Inttostr(imageRgroup.ItemIndex)+' 3D Image'; image3dL.Refresh; imagestream:=TmemoryStream.Create; imagestream.SetSize((rangeI-1)*(rangeJ-1)*(rangek-1)*sizeof(single)); image:=imagestream.Memory; rangex:=strtoint(xedit.text); rangez:=strtoint(zedit.text); for k:=1 to rangek-1 do for i:=1 to rangeI-1 do for j:=1 to rangej-1 do begin case imageRgroup.ItemIndex of 0: image^[k,i,j]:=Ex^[k,i,j]; 1: image^[k,i,j]:=Ey^[k,i,j]; 2: image^[k,i,j]:=Ez^[k,i,j]; 3: image^[k,i,j]:=Hx^[k,i,j]; 4: image^[k,i,j]:=Hy^[k,i,j]; 5: image^[k,i,j]:=Hz^[k,i,j]; 6: image^[k,i,j]:=Ex^[k,i,j]; end; if maxImage^[k,i,j] then min:=Image^[k,i,j]; end; maxmin:=max-min; if maxmin<1e-10 then maxmin:=1e-10; for counter:=1 to 1000 do begin if (counter>(rangeJ-1)) then exit; pic.width:=0; pic.height:=0; pic.Width:=round(rangeJ+0.8*rangeI+0.1*rangeJ); pic.Height:=round(rangeK+0.8*rangeI+0.1*rangeK); angle:=Pi/4; face1[1,1]:=round(cos(angle)*(rangeI*0.8-rangex*0.8)+pic.Width/10); face1[1,2]:=round(sin(angle)*(-rangeI*0.8+rangex*0.8)+pic.Height-(pic.Height/10) ); face1[2,1]:=face1[1,1]+counter;face1[2,2]:=face1[1,2]; face1[3,1]:=face1[1,1];face1[3,2]:=face1[1,2]-(rangez); face1[4,1]:=face1[2,1];face1[4,2]:=face1[3,2]; face2[1,1]:=round(face1[2,1]+cos(angle)*rangex*0.8); face2[1,2]:=round(face1[2,2]-sin(angle)*rangex*0.8); face2[2,1]:=face1[2,1];face2[2,2]:=face1[2,2]; face2[3,1]:=face2[1,1];face2[3,2]:=face2[1,2]-(rangez); face2[4,1]:=face1[4,1];face2[4,2]:=face1[4,2]; face3[1,1]:=face2[3,1]-counter; face3[1,2]:=face2[3,2]; face3[2,1]:=face1[3,1];face3[2,2]:=face1[3,2]; face3[3,1]:=face2[3,1];face3[3,2]:=face2[3,2]; face3[4,1]:=face2[4,1];face3[4,2]:=face2[4,2]; for J:=1 to counter-1 do for k:=1 to rangez-1 do begin // colorindex:=round((768/maxmin)*abs(Image^[k,rangex,j]-min)); //2v colorindex:=round((768/maxmin)*abs(Image^[k,rangex,j])); //2v x:=face1[1,1]+j; y:=face1[1,2]-k; pic.canvas.pixels[x,y]:=RGBtable[colorindex]; end; for I:=1 to rangex do for k:=1 to rangez-1 do begin // colorindex:=round((768/maxmin)*abs(Image^[k,I,counter]-min)); //2v colorindex:=round((768/maxmin)*abs(Image^[k,I,counter])); //2v x:=round(face2[1,1]-I*cos(angle)*0.8); y:=round(face2[1,2]-k+I*sin(angle)*0.8); pic.canvas.pixels[x,y]:=RGBtable[colorindex]; end; for J:=1 to counter-1 do for I:=1 to rangex do begin // colorindex:=round((768/maxmin)*abs(Image^[rangez,I,j]-min)); //2v colorindex:=round((768/maxmin)*abs(Image^[rangez,I,j])); //2v x:=round(face3[1,1]+J-I*cos(angle)*0.8); y:=round(face3[1,2]+I*sin(angle)*0.8); pic.canvas.pixels[x,y]:=RGBtable[colorindex]; end; pic.canvas.Pen.Color:=clgreen; pic.Canvas.Polyline([Point(face1[1,1],face1[1,2]), point(face1[2,1],face1[2,2]), Point(face1[4,1],face1[4,2]),Point(face1[3,1],face1[3,2]), point(face1[1,1],face1[1,2]),Point(face3[2,1],face3[2,2]), Point(face3[1,1],face3[1,2]),Point(face3[3,1],face3[3,2]), Point(face3[4,1],face3[4,2]),Point(face2[2,1],face1[2,2]), Point(face2[1,1],face2[1,2]),Point(face2[3,1],face2[3,2])]); pic.Canvas.Font.Color:=clwhite; pic.canvas.TextOut(face1[1,1]-10,face1[1,2]+5,'x'+inttostr(rangeI-1)); pic.canvas.TextOut(face2[1,1]-8,face2[1,2]+10,'y'+inttostr(counter)); pic.canvas.TextOut(face3[1,1]-25,face3[1,2]-15,'z'+inttostr(rangeK-1)); imageinfor.Picture.Bitmap:=pic; imageinfor.Refresh; end; imagestream.Destroy; end; procedure TDistribution.Mov3DzBClick(Sender: TObject); var Face1:array[1..4,1..2] of integer; face2:array[1..4,1..2] of integer; face3:array[1..4,1..2] of integer; max,min,maxmin:single; angle:single; rangex,rangey:integer; x,y,colorindex:integer; i,j,k,counter:integer; imagestream:TmemoryStream; image:PImageArray; begin max:=0;min:=0; image3dL.Caption :=Inttostr(imageRgroup.ItemIndex)+' 3D Image'; image3dL.Refresh; imagestream:=TmemoryStream.Create; imagestream.SetSize((rangeI-1)*(rangeJ-1)*(rangek-1)*sizeof(single)); image:=imagestream.Memory; rangex:=strtoint(xedit.text); rangeY:=strtoint(yedit.text); for k:=1 to rangek-1 do for i:=1 to rangeI-1 do for j:=1 to rangej-1 do begin case imageRgroup.ItemIndex of 0: image^[k,i,j]:=Ex^[k,i,j]; 1: image^[k,i,j]:=Ey^[k,i,j]; 2: image^[k,i,j]:=Ez^[k,i,j]; 3: image^[k,i,j]:=Hx^[k,i,j]; 4: image^[k,i,j]:=Hy^[k,i,j]; 5: image^[k,i,j]:=Hz^[k,i,j]; 6: image^[k,i,j]:=Ex^[k,i,j]; end; if maxImage^[k,i,j] then min:=Image^[k,i,j]; end; maxmin:=max-min; if maxmin<1e-10 then maxmin:=1e-10; for counter:=1 to 1000 do begin if (counter>(rangeK-1)) then exit; pic.width:=0; pic.height:=0; pic.Width:=round(rangeJ+0.8*rangeI+0.1*rangeJ); pic.Height:=round(rangeK+0.8*rangeI+0.1*rangeK); angle:=Pi/4; face1[1,1]:=round(cos(angle)*(rangeI*0.8-rangex*0.8)+pic.Width/10); face1[1,2]:=round(sin(angle)*(-rangeI*0.8+rangex*0.8)+pic.Height-(pic.Height/10) ); face1[2,1]:=face1[1,1]+rangey;face1[2,2]:=face1[1,2]; face1[3,1]:=face1[1,1];face1[3,2]:=face1[1,2]-counter; face1[4,1]:=face1[2,1];face1[4,2]:=face1[3,2]; face2[1,1]:=round(face1[2,1]+cos(angle)*rangex*0.8); face2[1,2]:=round(face1[2,2]-sin(angle)*rangex*0.8); face2[2,1]:=face1[2,1];face2[2,2]:=face1[2,2]; face2[3,1]:=face2[1,1];face2[3,2]:=face2[1,2]-counter; face2[4,1]:=face1[4,1];face2[4,2]:=face1[4,2]; face3[1,1]:=face2[3,1]-(rangey); face3[1,2]:=face2[3,2]; face3[2,1]:=face1[3,1];face3[2,2]:=face1[3,2]; face3[3,1]:=face2[3,1];face3[3,2]:=face2[3,2]; face3[4,1]:=face2[4,1];face3[4,2]:=face2[4,2]; for J:=1 to rangey-1 do for k:=1 to counter-1 do begin // colorindex:=round((768/maxmin)*abs(Image^[k,rangex,j]-min)); //2v colorindex:=round((768/maxmin)*abs(Image^[k,rangex,j])); //2v x:=face1[1,1]+j; y:=face1[1,2]-k; pic.canvas.pixels[x,y]:=RGBtable[colorindex]; end; for I:=1 to rangex do for k:=1 to counter-1 do begin // colorindex:=round((768/maxmin)*abs(Image^[k,I,rangey]-min)); //2v colorindex:=round((768/maxmin)*abs(Image^[k,I,rangey])); //2v x:=round(face2[1,1]-I*cos(angle)*0.8); y:=round(face2[1,2]-k+I*sin(angle)*0.8); pic.canvas.pixels[x,y]:=RGBtable[colorindex]; end; for J:=1 to rangey-1 do for I:=1 to rangex do begin // colorindex:=round((768/maxmin)*abs(Image^[counter,I,j]-min)); //2v colorindex:=round((768/maxmin)*abs(Image^[counter,I,j])); //2v x:=round(face3[1,1]+J-I*cos(angle)*0.8); y:=round(face3[1,2]+I*sin(angle)*0.8); pic.canvas.pixels[x,y]:=RGBtable[colorindex]; end; pic.canvas.Pen.Color:=clgreen; pic.Canvas.Polyline([Point(face1[1,1],face1[1,2]), point(face1[2,1],face1[2,2]), Point(face1[4,1],face1[4,2]),Point(face1[3,1],face1[3,2]), point(face1[1,1],face1[1,2]),Point(face3[2,1],face3[2,2]), Point(face3[1,1],face3[1,2]),Point(face3[3,1],face3[3,2]), Point(face3[4,1],face3[4,2]),Point(face2[2,1],face1[2,2]), Point(face2[1,1],face2[1,2]),Point(face2[3,1],face2[3,2])]); pic.Canvas.Font.Color:=clwhite; pic.canvas.TextOut(face1[1,1]-10,face1[1,2]+5,'x'+inttostr(rangeI-1)); pic.canvas.TextOut(face2[1,1]-8,face2[1,2]+10,'y'+inttostr(rangeJ-1)); pic.canvas.TextOut(face3[1,1]-25,face3[1,2]-15,'z'+inttostr(counter)); imageinfor.Picture.Bitmap:=pic; imageinfor.Refresh; end; imagestream.Destroy; end; end.