TPCCLIB
Toggle main menu visibility
Loading...
Searching...
No Matches
libtpcimage
imageheader.c
Go to the documentation of this file.
1
6
/*****************************************************************************/
7
#include "tpcclibConfig.h"
8
/*****************************************************************************/
9
#include "
tpcimage.h
"
10
/*****************************************************************************/
11
12
/*****************************************************************************/
18
int
imgCopyHeader
(
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
;
29
img2->
decayCorrection
=img1->
decayCorrection
;
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
/*****************************************************************************/
61
int
imgFillOHeader
(
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
);
82
return
(
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
101
if
(img->
modality
!=
IMG_MODALITY_UNKNOWN
) {
102
iftDeleteKey
(&img->
oh
,
"modality"
);
103
if
(
iftPut
(&img->
oh
,
"modality"
,
imgModalityDescr
(img->
modality
), 0, NULL)!=0)
104
return
(
TPCERROR_INVALID_HEADER
);
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)
109
return
(
TPCERROR_INVALID_HEADER
);
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)
114
return
(
TPCERROR_INVALID_HEADER
);
115
}
116
if
(img->
isot
!=
ISOTOPE_UNKNOWN
) {
117
iftDeleteKey
(&img->
oh
,
"isotope"
);
118
if
(
iftPut
(&img->
oh
,
"isotope"
,
isotopeName
(img->
isot
), 0, NULL)!=0)
119
return
(
TPCERROR_INVALID_HEADER
);
120
}
121
if
(img->
decayCorrection
!=
DECAY_UNKNOWN
) {
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)
126
return
(
TPCERROR_INVALID_HEADER
);
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)
131
return
(
TPCERROR_INVALID_HEADER
);
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)
136
return
(
TPCERROR_INVALID_HEADER
);
137
}
138
139
statusSet
(status, __func__, __FILE__, __LINE__,
TPCERROR_OK
);
140
return
(
TPCERROR_OK
);
141
}
142
/*****************************************************************************/
143
144
/*****************************************************************************/
145
146
/*****************************************************************************/
147
148
/*****************************************************************************/
iftPutUInt
int iftPutUInt(IFT *ift, const char *key, const unsigned int value, char comment, TPCSTATUS *status)
Definition
ift.c:180
iftPut
int iftPut(IFT *ift, const char *key, const char *value, char comment, TPCSTATUS *status)
Definition
ift.c:63
iftDuplicate
int iftDuplicate(IFT *ift1, IFT *ift2)
Definition
ift.c:236
iftDeleteKey
void iftDeleteKey(IFT *ift, const char *key)
Definition
iftfind.c:169
imgHasData
int imgHasData(IMG *img)
Definition
image.c:218
imgModalityDescr
char * imgModalityDescr(imgmodality c)
Definition
image.c:27
imgContentDescr
char * imgContentDescr(imgcontent c)
Definition
image.c:51
imgFillOHeader
int imgFillOHeader(IMG *img, TPCSTATUS *status)
Definition
imageheader.c:61
imgCopyHeader
int imgCopyHeader(IMG *img1, IMG *img2)
Definition
imageheader.c:18
imgFormatDescr
char * imgFormatDescr(imgformat c)
Definition
imageio.c:36
isotopeName
char * isotopeName(int isotope_code)
Definition
isotope.c:101
statusSet
void statusSet(TPCSTATUS *s, const char *func, const char *srcfile, int srcline, tpcerror error)
Definition
statusmsg.c:142
strlcpy
size_t strlcpy(char *dst, const char *src, size_t dstsize)
Definition
stringext.c:630
IFT::keyNr
int keyNr
Definition
tpcift.h:47
IMG
Definition
tpcimage.h:82
IMG::sizex
float sizex
Definition
tpcimage.h:119
IMG::modality
imgmodality modality
Definition
tpcimage.h:100
IMG::cunit
unit cunit
Definition
tpcimage.h:203
IMG::gapx
float gapx
Definition
tpcimage.h:126
IMG::format
imgformat format
Definition
tpcimage.h:103
IMG::ipp
float ipp[3]
Definition
tpcimage.h:141
IMG::xform
short int xform[2]
Definition
tpcimage.h:133
IMG::quatern
float quatern[6]
Definition
tpcimage.h:135
IMG::iop
float iop[6]
Definition
tpcimage.h:139
IMG::srow
float srow[12]
Definition
tpcimage.h:137
IMG::sizey
float sizey
Definition
tpcimage.h:121
IMG::ih
IFT ih
Definition
tpcimage.h:208
IMG::content
imgcontent content
Definition
tpcimage.h:97
IMG::scanStart
char scanStart[20]
Definition
tpcimage.h:94
IMG::dimz
unsigned short int dimz
Definition
tpcimage.h:116
IMG::mt
float mt[12]
Definition
tpcimage.h:144
IMG::decayCorrection
decaycorrection decayCorrection
Definition
tpcimage.h:91
IMG::oh
IFT oh
Definition
tpcimage.h:210
IMG::studyNr
char studyNr[MAX_STUDYNR_LEN+1]
Definition
tpcimage.h:85
IMG::gapy
float gapy
Definition
tpcimage.h:128
IMG::isot
isotope isot
Definition
tpcimage.h:88
IMG::gapz
float gapz
Definition
tpcimage.h:130
IMG::oformat
imgformat oformat
Definition
tpcimage.h:105
IMG::sizez
float sizez
Definition
tpcimage.h:123
IMG::tunit
unit tunit
Definition
tpcimage.h:205
TPCSTATUS
Definition
tpcextensions.h:241
TPCSTATUS::verbose
int verbose
Verbose level, used by statusPrint() etc.
Definition
tpcextensions.h:242
UNIT_UNKNOWN
@ UNIT_UNKNOWN
Unknown unit.
Definition
tpcextensions.h:85
TPCERROR_FAIL
@ TPCERROR_FAIL
General error.
Definition
tpcextensions.h:192
TPCERROR_INVALID_HEADER
@ TPCERROR_INVALID_HEADER
Invalid header contents.
Definition
tpcextensions.h:223
TPCERROR_OK
@ TPCERROR_OK
No error.
Definition
tpcextensions.h:191
TPCERROR_NO_DATA
@ TPCERROR_NO_DATA
File contains no data.
Definition
tpcextensions.h:203
unitName
char * unitName(int unit_code)
Definition
units.c:143
MAX_STUDYNR_LEN
#define MAX_STUDYNR_LEN
Define max study number length.
Definition
tpcextensions.h:46
tpcimage.h
Header file for libtpcimage.
IMG_MODALITY_UNKNOWN
@ IMG_MODALITY_UNKNOWN
Unknown modality.
Definition
tpcimage.h:57
IMG_FORMAT_UNKNOWN
@ IMG_FORMAT_UNKNOWN
Unknown format.
Definition
tpcimage.h:33
IMG_CONTENT_UNKNOWN
@ IMG_CONTENT_UNKNOWN
Unknown data content.
Definition
tpcimage.h:71
DECAY_UNKNOWN
@ DECAY_UNKNOWN
Not known; usually assumed that data is corrected.
Definition
tpcisotope.h:79
DECAY_CORRECTED
@ DECAY_CORRECTED
Data is corrected for physical decay.
Definition
tpcisotope.h:81
ISOTOPE_UNKNOWN
@ ISOTOPE_UNKNOWN
Unknown.
Definition
tpcisotope.h:51
Generated on
for TPCCLIB by
1.17.0