TPCCLIB
Toggle main menu visibility
Loading...
Searching...
No Matches
libtpctacimg
x.c
Go to the documentation of this file.
1
4
/*****************************************************************************/
5
#include "tpcclibConfig.h"
6
/*****************************************************************************/
7
#include "
tpctacimg.h
"
8
/*****************************************************************************/
9
10
/*****************************************************************************/
17
int
tacimgXMatch
(
19
TAC
*tac,
21
IMG
*img
22
) {
23
if
(img==NULL || tac==NULL)
return
(-1);
24
25
double
acceptedDif=2.2;
// sec
26
27
/* Get the last common sample nr */
28
int
sNr=tac->
sampleNr
;
if
(img->
dimt
<sNr) sNr=img->
dimt
;
29
if
(sNr==0)
return
(0);
30
31
/* Get the x of the last common sample */
32
double
tLastImg=0.5*(img->
x1
[sNr-1]+img->
x2
[sNr-1]);
33
double
tLastTac=tac->
x
[sNr-1];
if
(tac->
isframe
) tLastTac=0.5*(tac->
x1
[sNr-1]+tac->
x2
[sNr-1]);
34
if
(acceptedDif>tLastImg) acceptedDif=0.1*tLastImg;
35
36
/* Need to convert x unit? */
37
double
tscale=nan(
""
);
38
if
(tac->
tunit
==
UNIT_SEC
&& img->
tunit
==
UNIT_SEC
) tscale=1.;
39
else
if
(tac->
tunit
==
UNIT_SEC
&& img->
tunit
==
UNIT_MIN
) tscale=1.0/60;
40
else
if
(tac->
tunit
==
UNIT_MIN
&& img->
tunit
==
UNIT_SEC
) tscale=60.;
41
else
if
(tac->
tunit
==
UNIT_MIN
&& img->
tunit
==
UNIT_MIN
) tscale=1.;
42
else
{
43
if
(tLastImg>30.*tLastTac) tscale=60.;
44
else
if
(fabs(tLastImg-tLastTac)<30.) tscale=1.;
45
}
46
if
(!isfinite(tscale))
return
(0);
47
48
/* Compare sample times frame-by-frame */
49
int
n=0;
50
if
(tac->
isframe
==0) {
// check frame mid times
51
for
(
int
i=0; i<sNr; i++) {
52
double
f=fabs(tac->
x
[i]*tscale - 0.5*(img->
x1
[i]+img->
x2
[i]));
53
if
(f>acceptedDif) n++;
54
}
55
}
else
{
56
for
(
int
i=0; i<sNr; i++) {
57
double
f=fabs(tac->
x1
[i]*tscale - img->
x1
[i]);
58
if
(f>acceptedDif) {n++;
continue
;}
59
f=fabs(tac->
x2
[i]*tscale - img->
x2
[i]);
60
if
(f>acceptedDif) n++;
61
}
62
}
63
if
(n==0)
return
(1);
else
return
(0);
64
}
65
/*****************************************************************************/
66
67
/*****************************************************************************/
74
int
tacimgXCopy
(
76
TAC
*tac,
78
IMG
*img
79
) {
80
if
(img==NULL || tac==NULL)
return
(
TPCERROR_NO_DATA
);
81
if
(tac->
sampleNr
>img->
dimt
|| img->
dimt
<1)
return
(
TPCERROR_INCOMPATIBLE_DATA
);
82
83
int
sNr=tac->
_sampleNr
;
if
(img->
dimt
<sNr) sNr=img->
dimt
;
84
85
for
(
int
i=0; i<sNr; i++) {
86
tac->
x1
[i]=img->
x1
[i];
87
tac->
x2
[i]=img->
x2
[i];
88
tac->
x
[i]=0.5*(tac->
x1
[i]+tac->
x2
[i]);
89
}
90
tac->
isframe
=1;
91
tac->
tunit
=img->
tunit
;
92
return
(
TPCERROR_OK
);
93
}
94
/*****************************************************************************/
95
96
/*****************************************************************************/
IMG
Definition
tpcimage.h:82
IMG::x1
float * x1
Definition
tpcimage.h:180
IMG::x2
float * x2
Definition
tpcimage.h:182
IMG::dimt
unsigned short int dimt
Definition
tpcimage.h:110
IMG::tunit
unit tunit
Definition
tpcimage.h:205
TAC
Definition
tpctac.h:87
TAC::x
double * x
Definition
tpctac.h:97
TAC::_sampleNr
int _sampleNr
Definition
tpctac.h:121
TAC::sampleNr
int sampleNr
Definition
tpctac.h:89
TAC::isframe
int isframe
Definition
tpctac.h:95
TAC::x2
double * x2
Definition
tpctac.h:101
TAC::tunit
unit tunit
Definition
tpctac.h:109
TAC::x1
double * x1
Definition
tpctac.h:99
UNIT_MIN
@ UNIT_MIN
minutes
Definition
tpcextensions.h:90
UNIT_SEC
@ UNIT_SEC
seconds
Definition
tpcextensions.h:89
TPCERROR_OK
@ TPCERROR_OK
No error.
Definition
tpcextensions.h:191
TPCERROR_NO_DATA
@ TPCERROR_NO_DATA
File contains no data.
Definition
tpcextensions.h:203
TPCERROR_INCOMPATIBLE_DATA
@ TPCERROR_INCOMPATIBLE_DATA
Incompatible data.
Definition
tpcextensions.h:216
tpctacimg.h
Header file for libtpctacimg.
tacimgXMatch
int tacimgXMatch(TAC *tac, IMG *img)
Definition
x.c:17
tacimgXCopy
int tacimgXCopy(TAC *tac, IMG *img)
Definition
x.c:74
Generated on
for TPCCLIB by
1.17.0