My Project
Functions
ecat7ml.c File Reference
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <ctype.h>
#include <string.h>
#include <unistd.h>
#include <time.h>
#include <swap.h>
#include "include/img.h"
#include "include/ecat7.h"
Include dependency graph for ecat7ml.c:

Go to the source code of this file.

Functions

void ecat7InitMatlist (ECAT7_MATRIXLIST *mlist)
 
void ecat7EmptyMatlist (ECAT7_MATRIXLIST *mlist)
 
int ecat7ReadMatlist (FILE *fp, ECAT7_MATRIXLIST *ml)
 
void ecat7PrintMatlist (ECAT7_MATRIXLIST *ml)
 
int ecat7EnterMatrix (FILE *fp, int matrix_id, int block_nr)
 
int ecat7_val_to_id (int frame, int plane, int gate, int data, int bed)
 
void ecat7_id_to_val (int matrix_id, ECAT7_Matval *matval)
 
void ecat7SortMatlistByPlane (ECAT7_MATRIXLIST *ml)
 
void ecat7SortMatlistByFrame (ECAT7_MATRIXLIST *ml)
 
int ecat7CheckMatlist (ECAT7_MATRIXLIST *ml)
 
int ecat7DeleteLateFrames (ECAT7_MATRIXLIST *ml, int frame_nr)
 
int ecat7GetPlaneAndFrameNr (ECAT7_MATRIXLIST *mlist, ECAT7_mainheader *h, int *plane_nr, int *frame_nr)
 
int ecat7GetMatrixBlockSize (ECAT7_MATRIXLIST *mlist, int *blk_nr)
 
int ecat7GetNums (ECAT7_MATRIXLIST *ml, ECAT7_mainheader *mh, FILE *fp, short int *num_planes, short int *num_frames, short int *num_gates, short int *num_bed_pos)
 
int ecat7GatherMatlist (ECAT7_MATRIXLIST *ml, short int do_planes, short int do_frames, short int do_gates, short int do_beds)
 

Function Documentation

◆ ecat7_id_to_val()

void ecat7_id_to_val ( int  matrix_id,
ECAT7_Matval matval 
)

Conversion of matrix identifier to numerical values

Parameters
matrix_idmatrix identifire coding
matvalmatrix values structure

Definition at line 299 of file ecat7ml.c.

References ECAT7_Matval::bed, ECAT7_Matval::data, ECAT7_Matval::frame, ECAT7_Matval::gate, and ECAT7_Matval::plane.

Referenced by ecat7DeleteLateFrames(), ecat7GatherMatlist(), ecat7GetNums(), ecat7GetPlaneAndFrameNr(), ecat7PrintMatlist(), ecat7PrintSubheader(), ecat7SortMatlistByFrame(), ecat7SortMatlistByPlane(), imgReadEcat7(), and imgReadEcat7Frame().

◆ ecat7_val_to_id()

int ecat7_val_to_id ( int  frame,
int  plane,
int  gate,
int  data,
int  bed 
)

Returns the matrix identifier.

Parameters
frameframe number [0..65536]
planeplane number [0..65536]
gategate number [0..64]
datadata [0..1]
bedbed position [0..16]
Returns
matrix identifier coding

Definition at line 282 of file ecat7ml.c.

Referenced by ecat7GatherMatlist(), imgWrite2DEcat7(), imgWriteEcat7(), imgWriteEcat7Frame(), and imgWritePolarmap().

◆ ecat7CheckMatlist()

int ecat7CheckMatlist ( ECAT7_MATRIXLIST ml)

Checks that all matrixlist entries have read/write status.

Parameters
mlchecked matrix list
Returns
0 if ok, or 1 if an entry is marked as deleted or unfinished

Definition at line 366 of file ecat7ml.c.

References ECAT7_MATRIXLIST::matdir, ECAT7_MATRIXLIST::matrixNr, and ECAT7_MatDir::status.

Referenced by imgReadEcat7(), imgReadEcat7Frame(), and imgReadEcat7Header().

◆ ecat7DeleteLateFrames()

int ecat7DeleteLateFrames ( ECAT7_MATRIXLIST ml,
int  frame_nr 
)

Mark deleted the frames after the specified frame number.

Parameters
mltarget matrix list
frame_nrfirst index to be marked as deleted [1..number of frames]
Returns
Returns the number of deleted matrices.

Definition at line 383 of file ecat7ml.c.

References ecat7_id_to_val(), ECAT7_Matval::frame, ECAT7_MatDir::id, ECAT7_MATRIXLIST::matdir, ECAT7_MATRIXLIST::matrixNr, and ECAT7_MatDir::status.

Here is the call graph for this function:

◆ ecat7EmptyMatlist()

void ecat7EmptyMatlist ( ECAT7_MATRIXLIST mlist)

Free memory allocated for ECAT matrix list.

Parameters
mlisttarget matrix list that has allocated memory

Definition at line 70 of file ecat7ml.c.

References ECAT7_MATRIXLIST::matdir, ECAT7_MATRIXLIST::matrixNr, and ECAT7_MATRIXLIST::matrixSpace.

Referenced by ecat7PrintSubheader(), ecat7ReadMatlist(), imgReadEcat7(), imgReadEcat7Frame(), and imgReadEcat7Header().

◆ ecat7EnterMatrix()

int ecat7EnterMatrix ( FILE *  fp,
int  matrix_id,
int  block_nr 
)

Prepare matrix list for additional matrix data and return block number for matrix header. Directory records are written in big endian byte order. Set block_nr to the number of data blocks + (nr of header blocks - 1)

Parameters
fpfile pointer
matrix_idmatrix identifier coding
block_nrmatrix number [1..number of matrixes]
Returns
returns the block number for matrix header, -1 if invalid input, -2 if first directory block is not found, -3 if failed to read first block, -9 if other directory block is not found, -10 if failed to read other block, -11 if place for new directory block is not found, -12 if failed clear new block, -15 if place for new directory block is not found, -16 if failed to write into new block

Definition at line 184 of file ecat7ml.c.

References ECAT7_TEST, MatBLKSIZE, and MatFirstDirBlk.

Referenced by ecat7Write2DScanMatrix(), ecat7WriteImageMatrix(), ecat7WritePolarmapMatrix(), and ecat7WriteScanMatrix().

◆ ecat7GatherMatlist()

int ecat7GatherMatlist ( ECAT7_MATRIXLIST ml,
short int  do_planes,
short int  do_frames,
short int  do_gates,
short int  do_beds 
)

Matrix numbers in ECAT 7 matrix list are edited, when necessary, so that plane, frame, gate and/or bed numbers are continuous, starting from one (planes, frames and gates) or from zero (beds). List order is not changed.

Parameters
mlECAT 7 matrix list, where the matrix numbers will be edited
do_planesPlane numbers are gathered together (1) or not (0)
do_framesFrame numbers are gathered together (1) or not (0)
do_gatesGate numbers are gathered together (1) or not (0)
do_bedsBed numbers are gathered together (1) or not (0)
Returns
0 if successful, 1 if invalid input, 3 failed to allocate memory

Definition at line 572 of file ecat7ml.c.

References ECAT7_Matval::bed, ecat7_id_to_val(), ecat7_val_to_id(), ECAT7_Matval::frame, ECAT7_Matval::gate, ECAT7_MatDir::id, ECAT7_MATRIXLIST::matdir, ECAT7_MATRIXLIST::matrixNr, and ECAT7_Matval::plane.

Referenced by imgReadEcat7Frame(), and imgReadEcat7Header().

Here is the call graph for this function:

◆ ecat7GetMatrixBlockSize()

int ecat7GetMatrixBlockSize ( ECAT7_MATRIXLIST mlist,
int *  blk_nr 
)

Calculate the size of one data matrix in ECAT7 file matrix list, and check that the size is same in all matrices.

Parameters
mlistEcat7 matrix list; note that this list is here sorted by planes
blk_nrnumber of blocks will be put here; NULL if not needed
Returns
errstatus, which is STATUS_OK (0) when call was successful, and >0 in case of an error.

Definition at line 455 of file ecat7ml.c.

References ECAT7_MatDir::endblk, ECAT7_MATRIXLIST::matdir, ECAT7_MATRIXLIST::matrixNr, STATUS_FAULT, STATUS_OK, STATUS_VARMATSIZE, and ECAT7_MatDir::strtblk.

Referenced by imgReadEcat7Header().

◆ ecat7GetNums()

int ecat7GetNums ( ECAT7_MATRIXLIST ml,
ECAT7_mainheader mh,
FILE *  fp,
short int *  num_planes,
short int *  num_frames,
short int *  num_gates,
short int *  num_bed_pos 
)

Read the maximum plane, frame, gate and bed number from matrixlist. In case of 3D formats, num_planes is checked from the first subheader.

Parameters
mlPointer to matrixlist
mhPointer to mainheader
fpFile pointer to ECAT7 file opened in binary mode
num_planesnum_planes will be put here; NULL if not needed to be read
num_framesnum_planes will be put here; NULL if not needed to be read
num_gatesnum_planes will be put here; NULL if not needed to be read
num_bed_posnum_planes will be put here; NULL if not needed to be read
Returns
0 if successful, 1 if invalid input, 2 if no matrixes, 3 failed to allocate memory, 5 if failed to read image/scan header information

Definition at line 489 of file ecat7ml.c.

References ECAT7_Matval::bed, ECAT7_3DSCAN, ECAT7_3DSCAN8, ECAT7_3DSCANFIT, ecat7_id_to_val(), ECAT7_VOLUME16, ECAT7_VOLUME8, ecat7ReadImageheader(), ecat7ReadScanheader(), ecat7_mainheader::file_type, ECAT7_Matval::frame, ECAT7_Matval::gate, ECAT7_MatDir::id, ECAT7_MATRIXLIST::matdir, ECAT7_MATRIXLIST::matrixNr, ecat7_imageheader::num_dimensions, ecat7_scanheader::num_z_elements, ECAT7_Matval::plane, ECAT7_MatDir::strtblk, and ecat7_imageheader::z_dimension.

Here is the call graph for this function:

◆ ecat7GetPlaneAndFrameNr()

int ecat7GetPlaneAndFrameNr ( ECAT7_MATRIXLIST mlist,
ECAT7_mainheader h,
int *  plane_nr,
int *  frame_nr 
)

Calculate the number of planes and frames/gates from ECAT7 matrix list. Check that all planes have equal nr of frames/gates, that frames/gates are sequentally numbered.

Parameters
mlistEcat7 matrix list; note that this list is here sorted by planes
hEcat7 main header structure
plane_nrNumber of planes will be put here; NULL if not needed [1..number of planes, or NULL]
frame_nrNumber of frames/gates will be put here; NULL if not needed [1..number of frames, or NULL]
Returns
errstatus, which is STATUS_OK (0) when call was successful, and >0 in case of an error. Note that if this is 3D image volume or sinogram, then the returned plane_nr will be one, and the actual Z dim must be read from subheader.

Definition at line 409 of file ecat7ml.c.

References ecat7_id_to_val(), ecat7SortMatlistByPlane(), ECAT7_Matval::frame, ECAT7_Matval::gate, ECAT7_MatDir::id, ECAT7_MATRIXLIST::matdir, ECAT7_MATRIXLIST::matrixNr, ecat7_mainheader::num_frames, ecat7_mainheader::num_gates, ECAT7_Matval::plane, STATUS_FAULT, STATUS_MISSINGMATRIX, and STATUS_OK.

Referenced by imgReadEcat7Header().

Here is the call graph for this function:

◆ ecat7InitMatlist()

void ecat7InitMatlist ( ECAT7_MATRIXLIST mlist)

Initiate ECAT matrix list. Call this once before first use.

Parameters
mlisttarget matrix list

Definition at line 59 of file ecat7ml.c.

References ECAT7_MATRIXLIST::matdir, ECAT7_MATRIXLIST::matrixNr, and ECAT7_MATRIXLIST::matrixSpace.

Referenced by ecat7PrintSubheader(), imgReadEcat7(), imgReadEcat7Frame(), and imgReadEcat7Header().

◆ ecat7PrintMatlist()

void ecat7PrintMatlist ( ECAT7_MATRIXLIST ml)

Print ECAT matrix list on stdout.

Parameters
mlmatrix list for Ecat7 file

Definition at line 149 of file ecat7ml.c.

References ECAT7_Matval::bed, ecat7_id_to_val(), ECAT7_MatDir::endblk, ECAT7_Matval::frame, ECAT7_Matval::gate, ECAT7_MatDir::id, ECAT7_MATRIXLIST::matdir, ECAT7_MATRIXLIST::matrixNr, ECAT7_Matval::plane, ECAT7_MatDir::status, and ECAT7_MatDir::strtblk.

Referenced by ecat7PrintSubheader(), and imgReadEcat7().

Here is the call graph for this function:

◆ ecat7ReadMatlist()

int ecat7ReadMatlist ( FILE *  fp,
ECAT7_MATRIXLIST ml 
)

Read ECAT matrix list. Matrix list must be initiated (once) before calling this.

Parameters
fpfile pointer
mlmatrix list structure for Ecat7
Returns
returns 0 if ok, 1 if invalid input, 2 if first matrix is not found, 3 if failed to read matrix, 4 if data allocation failed for matrix, 5 if other error occurred.

Definition at line 86 of file ecat7ml.c.

References ECAT7_TEST, ecat7EmptyMatlist(), ECAT7_MatDir::endblk, ECAT7_MatDir::id, MatBLKSIZE, ECAT7_MATRIXLIST::matdir, MatFirstDirBlk, ECAT7_MATRIXLIST::matrixNr, ECAT7_MATRIXLIST::matrixSpace, ECAT7_MatDir::status, and ECAT7_MatDir::strtblk.

Referenced by ecat7PrintSubheader(), imgReadEcat7(), imgReadEcat7Frame(), and imgReadEcat7Header().

Here is the call graph for this function:

◆ ecat7SortMatlistByFrame()

void ecat7SortMatlistByFrame ( ECAT7_MATRIXLIST ml)

Sort matrixlist by frame and plane. Bubble sorting algorithm.

Parameters
mltarget matrix list

Definition at line 340 of file ecat7ml.c.

References ecat7_id_to_val(), ECAT7_Matval::frame, ECAT7_MatDir::id, ECAT7_MATRIXLIST::matdir, ECAT7_MATRIXLIST::matrixNr, and ECAT7_Matval::plane.

Referenced by imgReadEcat7Frame().

Here is the call graph for this function:

◆ ecat7SortMatlistByPlane()

void ecat7SortMatlistByPlane ( ECAT7_MATRIXLIST ml)

Sort matrixlist by plane and frame. Bubble sorting algorithm.

Parameters
mltarget matrix list

Definition at line 314 of file ecat7ml.c.

References ecat7_id_to_val(), ECAT7_Matval::frame, ECAT7_MatDir::id, ECAT7_MATRIXLIST::matdir, ECAT7_MATRIXLIST::matrixNr, and ECAT7_Matval::plane.

Referenced by ecat7GetPlaneAndFrameNr(), and imgReadEcat7().

Here is the call graph for this function: