📄 analyze.pas
字号:
unit analyze;
{$A-} {turn off byte alignment!!!}
interface
{$IFDEF Linux}
uses
SysUtils,QDialogs,QControls,dicom,define_types;
{$ELSE}
uses
Windows, Messages,SysUtils,dicom,Dialogs,define_types;
{$ENDIF}
type
AHdr = packed record
HdrSz : longint;
Data_Type: array [1..10] of char;
db_name: array [1..18] of char;
extents: longint; (* 32 + 4 *)
session_error: smallint; (* 36 + 2 *)
regular: char; (* 38 + 1 *)
hkey_un0: char; (* 39 + 1 *)
dim: array[0..7] of smallint; (* 0 + 16 *)
vox_units: array[1..4] of char; (* 16 + 4 *)
(* up to 3 characters for the voxels units label; i.e. mm., um., cm.*)
cal_units: array [1..8] of char; (* 20 + 4 *)
(* up to 7 characters for the calibration units label; i.e. HU *)
unused1: smallint; (* 24 + 2 *)
datatype: smallint ; (* 30 + 2 *)
bitpix: smallint; (* 32 + 2 *)
dim_un0: smallint ; (* 34 + 2 *)
pixdim: array[1..8]of single; (* 36 + 32 *)
(*
pixdim[] specifies the voxel dimensions:
pixdim[1] - voxel width {in SPM [2]}
pixdim[2] - voxel height {in SPM [3]}
pixdim[3] - interslice distance {in SPM [4]}
..etc
*)
vox_offset: single; (* 68 + 4 *)
roi_scale: single; (* 72 + 4 *)
funused1: single; (* 76 + 4 *)
funused2: single; (* 80 + 4 *)
cal_max: single; (* 84 + 4 *)
cal_min: single; (* 88 + 4 *)
compressed: longint; (* 92 + 4 *)
verified: longint; (* 96 + 4 *)
glmax, glmin: longint; (* 100 + 8 *)
descrip: array[1..80] of char; (* 0 + 80 *)
aux_file: array[1..24] of char; (* 80 + 24 *)
orient: char; (* 104 + 1 *)
(*originator: array [1..10] of char; (* 105 + 10 *)
originator: array [1..5] of smallint; (* 105 + 10 *)
generated: array[1..10]of char; (* 115 + 10 *)
scannum: array[1..10]of char;{array [1..10] of char {extended??} (* 125 + 10 *)
patient_id: array [1..10] of char; (* 135 + 10 *)
exp_date: array [1..10] of char; (* 145 + 10 *)
exp_time: array[1..10] of char; (* 155 + 10 *)
hist_un0: array [1..3] of char; (* 165 + 3 *)
views: longint; (* 168 + 4 *)
vols_added: longint; (* 172 + 4 *)
start_field: longint; (* 176 + 4 *)
field_skip: longint; (* 180 + 4 *)
omax,omin: longint; (* 184 + 8 *)
smax,smin:longint; (* 192 + 8 *)
{} end;
function OpenAnalyze (var lHdrOK,lImgOK : boolean; var lDynStr, lFileName: string; var lDicomData: DicomData): boolean;
function SaveAnalyzeHdr (lHdrName: string; lDicomData: DicomData): boolean;
implementation
procedure Swap2 (var lInt: SmallInt);
begin
lInt := swap(lInt);
end;
function swap64r(s : double):double;
type
swaptype = packed record
case byte of
0:(Word1,Word2,Word3,Word4 : word); //word is 16 bit
1:(float:double);
end;
swaptypep = ^swaptype;
var
inguy:swaptypep;
outguy:swaptype;
begin
inguy := @s; //assign address of s to inguy
outguy.Word1 := swap(inguy^.Word4);
outguy.Word2 := swap(inguy^.Word3);
outguy.Word3 := swap(inguy^.Word2);
outguy.Word4 := swap(inguy^.Word1);
try
swap64r:=outguy.float;
except
swap64r := 0;
exit;
end;{}
end;
function swap32i(var s : LongInt): Longint;
type
swaptype = packed record
case byte of
0:(Word1,Word2 : word); //word is 16 bit
1:(Long:LongInt);
end;
swaptypep = ^swaptype;
var
inguy:swaptypep;
outguy:swaptype;
begin
inguy := @s; //assign address of s to inguy
outguy.Word1 := swap(inguy^.Word2);
outguy.Word2 := swap(inguy^.Word1);
swap32i:=outguy.Long;
end;
procedure swap4r(var s : single);
type
swaptype = packed record
case byte of
0:(Word1,Word2 : word); //word is 16 bit
1:(sing:single);
end;
swaptypep = ^swaptype;
var
inguy:swaptypep;
outguy:swaptype;
begin
inguy := @s; //assign address of s to inguy
outguy.Word1 := swap(inguy^.Word2);
outguy.Word2 := swap(inguy^.Word1);
s:=outguy.sing;
end;
function fswap4r (s:single): single;
type
swaptype = packed record
case byte of
0:(Word1,Word2 : word); //word is 16 bit
1:(float:single);
end;
swaptypep = ^swaptype;
var
inguy:swaptypep;
outguy:swaptype;
begin
inguy := @s; //assign address of s to inguy
outguy.Word1 := swap(inguy^.Word2);
outguy.Word2 := swap(inguy^.Word1);
fswap4r:=outguy.float;
end;
{procedure Swap4r (var lR: single);
begin
lR := fswap4r(lR)
end; }
procedure swap4(var s : LongInt);
type
swaptype = packed record
case byte of
0:(Word1,Word2 : word); //word is 16 bit
1:(Long:LongInt);
end;
swaptypep = ^swaptype;
var
inguy:swaptypep;
outguy:swaptype;
begin
inguy := @s; //assign address of s to inguy
outguy.Word1 := swap(inguy^.Word2);
outguy.Word2 := swap(inguy^.Word1);
s:=outguy.Long;
end;
function fswap4 (s:longint): longint;
var l: longint;
begin
l := s;
swap4(l);
fswap4 := l;
end;
function fswap8 (s:double): double;
type
swaptype8 = packed record
case byte of
0:(Word1,Word2,Word3,Word4 : word); //word is 16 bit
1:(Dbl:Double);
end;
swaptype8p = ^swaptype8;
var
inguy:swaptype8p;
outguy:swaptype8;
begin
inguy := @s; //assign address of s to inguy
outguy.Word1 := swap(inguy^.Word4);
outguy.Word2 := swap(inguy^.Word3);
outguy.Word3 := swap(inguy^.Word2);
outguy.Word4 := swap(inguy^.Word1);
fswap8:=outguy.Dbl;
end;
procedure SwapBytes (var lAHdr: AHdr);
var
// l10 : array [1..10] of byte;
lInc: integer;
begin
with lAHdr do begin
swap4(hdrsz);
{for lInc := 1 to 10 do
Data_Type[lInc] := chr(0); for chars: no need to swap 1 byte
for lInc := 1 to 18 do
db_name[lInc] := chr(0);}
swap4(extents); (* 32 + 4 *)
swap2(session_error); (* 36 + 2 *)
{regular:=chr(0); (* 38 + 1 *)
hkey_un0:=chr(0);} (* 39 + 1 *)
for lInc := 0 to 7 do
swap2(dim[lInc]); (* 0 + 16 *)
{for lInc := 1 to 4 do
vox_units[lInc] := chr(0); (* 16 + 4 *)
for lInc := 1 to 4 do
cal_units[lInc] := chr(0);} (* 20 + 4 *)
swap2(unused1); (* 24 + 2 *)
swap2(datatype); (* 30 + 2 *)
swap2(bitpix); (* 32 + 2 *)
swap2(dim_un0); (* 34 + 2 *)
for lInc := 1 to 4 do
swap4r(pixdim[linc]); (* 36 + 32 *)
swap4r(vox_offset);
{roi scale = 1}
swap4r(roi_scale);
swap4r(funused1); (* 76 + 4 *)
swap4r(funused2); (* 80 + 4 *)
swap4r(cal_max); (* 84 + 4 *)
swap4r(cal_min); (* 88 + 4 *)
swap4(compressed); (* 92 + 4 *)
swap4(verified); (* 96 + 4 *)
swap4(glmax);
swap4(glmin); (* 100 + 8 *)
{for lInc := 1 to 80 do
gAHdr.descrip[lInc] := chr(0);{80 spaces}
{for lInc := 1 to 24 do
gAHdr.aux_file[lInc] := chr(0);{24 spaces}
orient:= chr(0); (* 104 + 1 *)
(*originator: array [1..10] of char; (* 105 + 10 *)
for lInc := 1 to 5 do
swap2(originator[lInc]); (* 105 + 10 *)
{for lInc := 1 to 10 do
generated[lInc] := chr(0); (* 115 + 10 *)
for lInc := 1 to 10 do
scannum[lInc] := chr(0);{}
// scannum := 0{fswap10(scannum)};
(* 125 + 10 *)
{for lInc := 1 to 10 do
patient_id[lInc] := chr(0); (* 135 + 10 *)
for lInc := 1 to 10 do
exp_date[lInc] := chr(0); (* 135 + 10 *)
for lInc := 1 to 10 do
exp_time[lInc] := chr(0); (* 135 + 10 *)
for lInc := 1 to 3 do
hist_un0[lInc] := chr(0); (* 135 + 10 *)
{}
swap4(views); (* 168 + 4 *)
swap4(vols_added); (* 172 + 4 *)
swap4(start_field); (* 176 + 4 *)
swap4(field_skip); (* 180 + 4 *)
swap4(omax);
swap4(omin); (* 184 + 8 *)
swap4(smax);
swap4(smin); (* 192 + 8 *)
end; {with}
end;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -