STIR 6.4.0
ecat6_utils.h
Go to the documentation of this file.
1//
2//
3/*
4 Copyright (C) 2000 PARAPET partners
5 Copyright (C) 2000- 2008, Hammersmith Imanet Ltd
6 This file is part of STIR.
7
8 SPDX-License-Identifier: Apache-2.0 AND License-ref-PARAPET-license
9
10 See STIR/LICENSE.txt for details
11*/
12
21/* History:
22 KT 18/08/2000 added file_data_to_host, get_attnheaders
23 KT 11/01/2002 added normalisation file things, removed get_attndata
24 KT 13/01/2008 replace original CTI code with calls to LLN matrix library:
25 introduced mhead_ptr in various functions
26 have #define STIR_ORIGINAL_ECAT6 to be able to switch between old and new version
27*/
28
29#ifndef __stir_IO_ecat6_utils_h
30#define __stir_IO_ecat6_utils_h
31
32#include "stir/IO/ecat6_types.h"
33
34#include <stdlib.h>
35
36START_NAMESPACE_STIR
37START_NAMESPACE_ECAT
38START_NAMESPACE_ECAT6
39
40// CTI UTILITIES
41
45long cti_numcod(int frame, int plane, int gate, int data, int bed);
53void cti_numdoc(long matnum, Matval* matval);
61int cti_rings2plane(short nrings, short ring0, short ring1);
62
63// FILE ACCESS
64
72FILE* cti_create(const char* fname, const ECAT6_Main_header* mhead);
73
82int cti_rblk(FILE* fptr, int blkno, void* bufr, int nblks);
91int cti_wblk(FILE* fptr, int blkno, void* bufr, int nblks);
99int cti_read_ECAT6_Main_header(FILE* fptr, ECAT6_Main_header* h);
109int cti_read_scan_subheader(FILE* fptr, const ECAT6_Main_header*, int blknum, Scan_subheader*);
110
120int cti_read_attn_subheader(FILE* fptr, const ECAT6_Main_header* h, int blknum, Attn_subheader* header_ptr);
121
131int cti_read_norm_subheader(FILE* fptr, const ECAT6_Main_header* h, int blknum, Norm_subheader* header_ptr);
132
142int cti_read_image_subheader(FILE* fptr, const ECAT6_Main_header* h, int blknum, Image_subheader* header_ptr);
143
154int cti_enter(FILE* fptr, const ECAT6_Main_header* mhead_ptr, long matnum, int nblks);
165int cti_lookup(FILE* fptr, const ECAT6_Main_header* mhead_ptr, long matnum, MatDir* entry);
175int cti_write_idata(FILE* fptr, int blk, const short* data, int isize);
184int cti_write_image_subheader(FILE* fptr, const ECAT6_Main_header* h, int blknum, const Image_subheader* header_ptr);
192int cti_write_ECAT6_Main_header(FILE* fptr, const ECAT6_Main_header* header_ptr);
201int cti_write_scan_subheader(FILE* fptr, const ECAT6_Main_header* h, int blknum, const Scan_subheader* header_ptr);
202
219int cti_write_image(FILE* fptr,
220 long matnum,
221 const ECAT6_Main_header* mhead_ptr,
222 const Image_subheader* header_ptr,
223 const short* data,
224 int data_size);
241int cti_write_scan(FILE* fptr,
242 long matnum,
243 const ECAT6_Main_header* mhead_ptr,
244 const Scan_subheader* header_ptr,
245 const short* data,
246 int data_size);
257int get_scanheaders(FILE* fptr, long matnum, ECAT6_Main_header* mhead, Scan_subheader* shead, ScanInfoRec* scanParams);
272// KT 18/05/2000 changed type from short to char
273
274int get_scandata(FILE* fptr, char* scan, ScanInfoRec* scanParams);
275
286int get_attnheaders(FILE* fptr, long matnum, ECAT6_Main_header* mhead, Attn_subheader* shead, ScanInfoRec* attnParams);
287
298int get_normheaders(FILE* fptr, long matnum, ECAT6_Main_header* mhead, Norm_subheader* shead, ScanInfoRec* nrmParams);
299
300// OTHER UTILITIES
301
303int file_data_to_host(char* dptr, int nblks, int dtype);
304
305#ifdef STIR_ORIGINAL_ECAT6
306
307/*
308 \brief Find minimum and maximum values in a buffer of floats
309 \ingroup ECAT
310
311 \param buf array of count floats
312 \param min will be set to the smallest positive float in buf
313 \param max will be set to the largest float contained in buf
314 \param count number of elements in buf
315*/
316void ffind_minmax(float* buf, float* min, float* max, int bufsize);
317/*
318 \brief Find minimum and maximum values in a buffer of shorts
319
320 \param buf array of bufsize shorts
321 \param min will be set to the smallest positive short in buf
322 \param max will be set to the largest short contained in buf
323 \param bufsize number of elements in array
324*/
325void sfind_minmax(short* buf, short* min, short* max, int bufsize);
326/*
327 \brief Copy array, swapping bytes as we go
328
329 \param from input array
330 \param to output array (may be same as input array)ibytes
331 \param length total number of bytes to copy
332*/
333void swab(char* from, char* to, int length);
334/*
335 \brief Copy array, swapping 16-bit words as we go.
336
337 \param from data buffer to copy.
338 \param to where to copy the data. may be same as (or overlap) from.
339 \param length number of 16-bit words to swap
340*/
341void swaw(short* from, short* to, int length);
342/*
343 \brief Get indexed value from buffer, a vax float, and return it as an IEEE float.
344 (a swab has to be performed first on bigendian machines)
345
346 \param bufr input data buffer.
347 \param off offset into buffer of first 16-bit half of the 32-bit value to convert.
348*/
349float get_vax_float(const unsigned short* bufr, int off);
350/*
351 \brief Get the indexed value from a buffer, a 32-bit vax long, and convert it by swapping the words.
352 (a swab has to be performed first on bigendian machines)
353
354 \param bufr input data buffer.
355 \param off index into buffer of first 16-bit word of the 32-bit value to convert.
356*/
357long get_vax_long(const unsigned short* bufr, int off);
364void dump_ECAT6_Main_header(FILE* fptr, const ECAT6_Main_header* mhead);
365/*
366 \brief Convert a sun long int to a vax long int, i.e. swap the 16-bit words of the 32-bit long.
367 (sun long = sun int = 32 bits)
368 (a swab has to be performed afterwards on bigendian machines)
369
370 \param in value to convert.
371 \param out result.
372*/
373void hostltovaxl(const long in, unsigned short out[2]);
374/*
375 \brief Convert a host float to a vax float
376 (a swab has to be performed afterwards on bigendian machines)
377
378 \param in value to convert.
379 \param out result.
380*/
381void hostftovaxf(const float in, unsigned short out[2]);
382
384ECAT6_Main_header main_zero_fill();
385#endif // STIR_ORIGINAL_ECAT6
387Scan_subheader scan_zero_fill();
389Image_subheader img_zero_fill();
390
391END_NAMESPACE_ECAT6
392END_NAMESPACE_ECAT
393END_NAMESPACE_STIR
394#endif
ECAT 6 CTI matrix parameters.
int cti_lookup(FILE *fptr, const ECAT6_Main_header *mhead_ptr, long matnum, MatDir *entry)
Look up a "matrix number" in the file and return the MatDir entry for it. Returns 0 if the lookup was...
Definition ecat6_utils.cxx:329
int cti_read_ECAT6_Main_header(FILE *fptr, ECAT6_Main_header *h)
Read header data from a file and place it into a ECAT6_Main_header struct. Returns EXIT_SUCCESS if no...
Definition ecat6_utils.cxx:290
int get_scandata(FILE *fptr, char *scan, ScanInfoRec *scanParams)
Read scan data from file. Returns EXIT_FAILURE if the data could not be read.
Definition ecat6_utils.cxx:148
int get_normheaders(FILE *fptr, long matnum, ECAT6_Main_header *mhead, Norm_subheader *shead, ScanInfoRec *nrmParams)
Read main header and subheader from normalisation file. Returns EXIT_SUCCESS if no error.
Definition ecat6_utils.cxx:223
int cti_write_image_subheader(FILE *fptr, const ECAT6_Main_header *h, int blknum, const Image_subheader *header_ptr)
Write an image subheader into a matrix file. Returns 0 if successful.
Definition ecat6_utils.cxx:363
int cti_read_attn_subheader(FILE *fptr, const ECAT6_Main_header *h, int blknum, Attn_subheader *header_ptr)
Read header data from a file and place it into a Attn_subheader struct. Returns EXIT_SUCCESS if no er...
Definition ecat6_utils.cxx:349
int cti_write_idata(FILE *fptr, int blk, const short *data, int isize)
Write data in blocks from buffer into file.
Definition ecat6_utils.cxx:404
int get_attnheaders(FILE *fptr, long matnum, ECAT6_Main_header *mhead, Attn_subheader *shead, ScanInfoRec *attnParams)
Read main header and subheader from attn file. Returns EXIT_SUCCESS if no error.
Definition ecat6_utils.cxx:163
int cti_read_scan_subheader(FILE *fptr, const ECAT6_Main_header *, int blknum, Scan_subheader *)
Read header data from a file and place it into a Scan_subheader struct. Returns EXIT_SUCCESS if no er...
Definition ecat6_utils.cxx:342
void cti_numdoc(long matnum, Matval *matval)
Unpack encoded data into a nice struct. Reverse of cti_numcod ().
Definition ecat6_utils.cxx:303
FILE * cti_create(const char *fname, const ECAT6_Main_header *mhead)
Open a file and write main header to it. Returns a pointer to the file, or 0 if unsuccessful.
Definition ecat6_utils.cxx:284
int cti_write_scan(FILE *fptr, long matnum, const ECAT6_Main_header *mhead_ptr, const Scan_subheader *header_ptr, const short *data, int data_size)
Write a scan, including headers, into a matrix file.
Definition ecat6_utils.cxx:472
int cti_write_ECAT6_Main_header(FILE *fptr, const ECAT6_Main_header *header_ptr)
Write an image main header into a matrix file. Returns 0 if successful.
int cti_rblk(FILE *fptr, int blkno, void *bufr, int nblks)
Read from a matrix file starting at the given block. Returns EXIT_SUCCESS if all went well.
Definition ecat6_utils.cxx:309
int cti_enter(FILE *fptr, const ECAT6_Main_header *mhead_ptr, long matnum, int nblks)
Create entry in file corresponding to matnum, and return offset of next block. Or some such....
Definition ecat6_utils.cxx:323
int cti_wblk(FILE *fptr, int blkno, void *bufr, int nblks)
Write blocks from buffer into file. Returns EXIT_SUCCESS if successful.
Definition ecat6_utils.cxx:316
int cti_rings2plane(short nrings, short ring0, short ring1)
Get sinogram plane from ring pair.
Definition ecat6_utils.cxx:392
int get_scanheaders(FILE *fptr, long matnum, ECAT6_Main_header *mhead, Scan_subheader *shead, ScanInfoRec *scanParams)
Read main header and subheader from scan file. Returns EXIT_SUCCESS if no error.
Definition ecat6_utils.cxx:88
int cti_write_image(FILE *fptr, long matnum, const ECAT6_Main_header *mhead_ptr, const Image_subheader *header_ptr, const short *data, int data_size)
Write an image, including headers, into a matrix file.
Definition ecat6_utils.cxx:452
long cti_numcod(int frame, int plane, int gate, int data, int bed)
Encode scan information into a single, incomprehensible number.
Definition ecat6_utils.cxx:297
int cti_write_scan_subheader(FILE *fptr, const ECAT6_Main_header *h, int blknum, const Scan_subheader *header_ptr)
Write a scan subheader into a matrix file.
Definition ecat6_utils.cxx:371
int cti_read_norm_subheader(FILE *fptr, const ECAT6_Main_header *h, int blknum, Norm_subheader *header_ptr)
Read header data from a file and place it into a Norm_subheader struct. Returns EXIT_SUCCESS if no er...
Definition ecat6_utils.cxx:356
int cti_read_image_subheader(FILE *fptr, const ECAT6_Main_header *h, int blknum, Image_subheader *header_ptr)
Read header data from a file and place it into an Image_subheader struct. Returns EXIT_SUCCESS if no ...
Definition ecat6_utils.cxx:335
Image_subheader img_zero_fill()
Fill image subheader with negative or default values.
Definition ecat6_utils.cxx:553
int file_data_to_host(char *dptr, int nblks, int dtype)
Convert data in buffer dptr to native host format.
Definition ecat6_utils.cxx:379
Scan_subheader scan_zero_fill()
Fill scan subheader with negative or default values.
Definition ecat6_utils.cxx:506
ECAT 6 CTI scanner parameters.
Definition ecat6_types.h:82