TPCCLIB
Loading...
Searching...
No Matches
imageheader.c
Go to the documentation of this file.
1
6/*****************************************************************************/
7#include "tpcclibConfig.h"
8/*****************************************************************************/
9#include "tpcimage.h"
10/*****************************************************************************/
11
12/*****************************************************************************/
20 IMG *img1,
22 IMG *img2
23) {
24 if(img1==NULL || img2==NULL) return(TPCERROR_FAIL);
25 if(!imgHasData(img1) || !imgHasData(img2)) return(TPCERROR_FAIL);
26
27 strlcpy(img2->studyNr, img1->studyNr, MAX_STUDYNR_LEN+1);
28 img2->isot=img1->isot;
30 strlcpy(img2->scanStart, img1->scanStart, 20);
31 img2->content=img1->content;
32 img2->modality=img1->modality;
33 img2->format=img1->format;
34 img2->oformat=img1->oformat;
35 img2->sizex=img1->sizex;
36 img2->sizey=img1->sizey;
37 img2->sizez=img1->sizez;
38 img2->gapx=img1->gapx;
39 img2->gapy=img1->gapy;
40 img2->gapz=img1->gapz;
41 img2->xform[0]=img1->xform[0];
42 img2->xform[1]=img1->xform[1];
43 for(int i=0; i<6; i++) img2->quatern[i]=img1->quatern[i];
44 for(int i=0; i<12; i++) img2->srow[i]=img1->srow[i];
45 for(int i=0; i<6; i++) img2->iop[i]=img1->iop[i];
46 for(int i=0; i<3; i++) img2->ipp[i]=img1->ipp[i];
47 for(int i=0; i<12; i++) img2->mt[i]=img1->mt[i];
48 img2->cunit=img1->cunit;
49 img2->tunit=img1->tunit;
50
51 return(TPCERROR_OK);
52}
53/*****************************************************************************/
54
55/*****************************************************************************/
63 IMG *img,
65 TPCSTATUS *status
66) {
67 int verbose=0; if(status!=NULL) verbose=status->verbose;
68 if(verbose>0) {printf("%s(img)\n", __func__); fflush(stdout);}
69
70 if(img==NULL || !imgHasData(img)) {
71 statusSet(status, __func__, __FILE__, __LINE__, TPCERROR_NO_DATA);
72 return(TPCERROR_NO_DATA);
73 }
74
75 /* If output header is empty then copy input header;
76 if file formats match, copy directly, otherwise convert contents */
77 if(img->oh.keyNr==0 && img->ih.keyNr>0) {
78 if(img->format==img->oformat) {
79 if(verbose>1) printf("copying header\n");
80 if(iftDuplicate(&img->ih, &img->oh)!=TPCERROR_OK) {
81 statusSet(status, __func__, __FILE__, __LINE__, TPCERROR_INVALID_HEADER);
83 }
84 } else {
85 if(verbose>1) printf("converting header\n");
86
87 }
88 }
89
90 /* Set fields from IMG structure */
91
92 iftDeleteKey(&img->oh, "dimx");
93 if(iftPutUInt(&img->oh, "dimx", img->dimz, 0, NULL)!=0) return(TPCERROR_INVALID_HEADER);
94 iftDeleteKey(&img->oh, "dimy");
95 if(iftPutUInt(&img->oh, "dimy", img->dimz, 0, NULL)!=0) return(TPCERROR_INVALID_HEADER);
96 iftDeleteKey(&img->oh, "dimz");
97 if(iftPutUInt(&img->oh, "dimz", img->dimz, 0, NULL)!=0) return(TPCERROR_INVALID_HEADER);
98 iftDeleteKey(&img->oh, "dimt");
99 if(iftPutUInt(&img->oh, "dimt", img->dimz, 0, NULL)!=0) return(TPCERROR_INVALID_HEADER);
100
102 iftDeleteKey(&img->oh, "modality");
103 if(iftPut(&img->oh, "modality", imgModalityDescr(img->modality), 0, NULL)!=0)
105 }
106 if(img->content!=IMG_CONTENT_UNKNOWN) {
107 iftDeleteKey(&img->oh, "content");
108 if(iftPut(&img->oh, "content", imgContentDescr(img->content), 0, NULL)!=0)
110 }
111 if(img->format!=IMG_FORMAT_UNKNOWN) {
112 iftDeleteKey(&img->oh, "format");
113 if(iftPut(&img->oh, "format", imgFormatDescr(img->format), 0, NULL)!=0)
115 }
116 if(img->isot!=ISOTOPE_UNKNOWN) {
117 iftDeleteKey(&img->oh, "isotope");
118 if(iftPut(&img->oh, "isotope", isotopeName(img->isot), 0, NULL)!=0)
120 }
122 iftDeleteKey(&img->oh, "decay_correction");
123 char buf[8];
124 if(img->decayCorrection==DECAY_CORRECTED) strcpy(buf, "y"); else strcpy(buf, "n");
125 if(iftPut(&img->oh, "decay_correction", buf, 0, NULL)!=0)
127 }
128 if(img->cunit!=UNIT_UNKNOWN) {
129 iftDeleteKey(&img->oh, "pixel_unit");
130 if(iftPut(&img->oh, "pixel_unit", unitName(img->cunit), 0, NULL)!=0)
132 }
133 if(img->tunit!=UNIT_UNKNOWN) {
134 iftDeleteKey(&img->oh, "time_unit");
135 if(iftPut(&img->oh, "time_unit", unitName(img->tunit), 0, NULL)!=0)
137 }
138
139 statusSet(status, __func__, __FILE__, __LINE__, TPCERROR_OK);
140 return(TPCERROR_OK);
141}
142/*****************************************************************************/
143
144/*****************************************************************************/
145
146/*****************************************************************************/
147
148/*****************************************************************************/
int iftPutUInt(IFT *ift, const char *key, const unsigned int value, char comment, TPCSTATUS *status)
Definition ift.c:180
int iftPut(IFT *ift, const char *key, const char *value, char comment, TPCSTATUS *status)
Definition ift.c:63
int iftDuplicate(IFT *ift1, IFT *ift2)
Definition ift.c:236
void iftDeleteKey(IFT *ift, const char *key)
Definition iftfind.c:169
int imgHasData(IMG *img)
Definition image.c:218
char * imgModalityDescr(imgmodality c)
Definition image.c:27
char * imgContentDescr(imgcontent c)
Definition image.c:51
int imgFillOHeader(IMG *img, TPCSTATUS *status)
Definition imageheader.c:61
int imgCopyHeader(IMG *img1, IMG *img2)
Definition imageheader.c:18
char * imgFormatDescr(imgformat c)
Definition imageio.c:36
char * isotopeName(int isotope_code)
Definition isotope.c:101
void statusSet(TPCSTATUS *s, const char *func, const char *srcfile, int srcline, tpcerror error)
Definition statusmsg.c:142
size_t strlcpy(char *dst, const char *src, size_t dstsize)
Definition stringext.c:632
int keyNr
Definition tpcift.h:47
Definition tpcimage.h:82
float sizex
Definition tpcimage.h:119
imgmodality modality
Definition tpcimage.h:100
unit cunit
Definition tpcimage.h:203
float gapx
Definition tpcimage.h:126
imgformat format
Definition tpcimage.h:103
float ipp[3]
Definition tpcimage.h:141
short int xform[2]
Definition tpcimage.h:133
float quatern[6]
Definition tpcimage.h:135
float iop[6]
Definition tpcimage.h:139
float srow[12]
Definition tpcimage.h:137
float sizey
Definition tpcimage.h:121
IFT ih
Definition tpcimage.h:208
imgcontent content
Definition tpcimage.h:97
char scanStart[20]
Definition tpcimage.h:94
unsigned short int dimz
Definition tpcimage.h:116
float mt[12]
Definition tpcimage.h:144
decaycorrection decayCorrection
Definition tpcimage.h:91
IFT oh
Definition tpcimage.h:210
char studyNr[MAX_STUDYNR_LEN+1]
Definition tpcimage.h:85
float gapy
Definition tpcimage.h:128
isotope isot
Definition tpcimage.h:88
float gapz
Definition tpcimage.h:130
imgformat oformat
Definition tpcimage.h:105
float sizez
Definition tpcimage.h:123
unit tunit
Definition tpcimage.h:205
int verbose
Verbose level, used by statusPrint() etc.
@ UNIT_UNKNOWN
Unknown unit.
@ TPCERROR_FAIL
General error.
@ TPCERROR_INVALID_HEADER
Invalid header contents.
@ TPCERROR_OK
No error.
@ TPCERROR_NO_DATA
File contains no data.
char * unitName(int unit_code)
Definition units.c:143
#define MAX_STUDYNR_LEN
Define max study number length.
Header file for libtpcimage.
@ IMG_MODALITY_UNKNOWN
Unknown modality.
Definition tpcimage.h:57
@ IMG_FORMAT_UNKNOWN
Unknown format.
Definition tpcimage.h:33
@ IMG_CONTENT_UNKNOWN
Unknown data content.
Definition tpcimage.h:71
@ DECAY_UNKNOWN
Not known; usually assumed that data is corrected.
Definition tpcisotope.h:79
@ DECAY_CORRECTED
Data is corrected for physical decay.
Definition tpcisotope.h:81
@ ISOTOPE_UNKNOWN
Unknown.
Definition tpcisotope.h:51