@niivue/niivue 0.12.2 → 0.13.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -2
- package/dist/assets/worker.9df7e894.js +1 -0
- package/dist/niivue.es.js +113 -5
- package/dist/niivue.umd.js +22 -22
- package/package.json +11 -11
- package/src/heap-verifier.js +51 -0
- package/src/index.html +3 -3
- package/src/linear-memory.js +33 -0
- package/src/niivue.js +107 -5
- package/src/nvimage.js +59 -0
- package/src/process-image.wasm +0 -0
- package/src/wasm/core.c +959 -0
- package/src/wasm/core.h +187 -0
- package/src/wasm/core32.c +3 -0
- package/src/wasm/core32.h +17 -0
- package/src/wasm/core64.c +3 -0
- package/src/wasm/core64.h +18 -0
- package/src/wasm/coreFLT.c +6285 -0
- package/src/wasm/nifti2_wasm.c +27 -0
- package/src/wasm/nifti2_wasm.h +76 -0
- package/src/wasm/walloc.c +466 -0
- package/src/worker.js +72 -0
package/src/wasm/core.h
ADDED
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
#ifndef CR_COREX_H
|
|
2
|
+
#define CR_COREX_H
|
|
3
|
+
|
|
4
|
+
#ifdef __cplusplus
|
|
5
|
+
extern "C" {
|
|
6
|
+
#endif
|
|
7
|
+
|
|
8
|
+
#include <stdio.h>
|
|
9
|
+
#include <stdlib.h>
|
|
10
|
+
#ifdef USING_WASM
|
|
11
|
+
#include <nifti2_wasm.h>
|
|
12
|
+
#else
|
|
13
|
+
#include <nifti2_io.h>
|
|
14
|
+
#endif
|
|
15
|
+
#include <float.h> //FLT_EPSILON
|
|
16
|
+
//#include <immintrin.h>
|
|
17
|
+
#include <limits.h>
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
#ifdef USING_WASM
|
|
21
|
+
void *xmalloc(size_t size);
|
|
22
|
+
void xfree(void *p);
|
|
23
|
+
#define _mm_malloc(size, alignment) xmalloc(size)
|
|
24
|
+
#define _mm_free(ptr) xfree(ptr)
|
|
25
|
+
#endif
|
|
26
|
+
|
|
27
|
+
//CORE32 and CORE64 handle Float32 and Float64 operations, CORE handles shared code
|
|
28
|
+
|
|
29
|
+
enum eOp { unknown,
|
|
30
|
+
add,
|
|
31
|
+
sub,
|
|
32
|
+
mul,
|
|
33
|
+
divX,
|
|
34
|
+
rem,
|
|
35
|
+
mod,
|
|
36
|
+
mas,
|
|
37
|
+
thr,
|
|
38
|
+
thrp,
|
|
39
|
+
thrP,
|
|
40
|
+
uthr,
|
|
41
|
+
uthrp,
|
|
42
|
+
uthrP,
|
|
43
|
+
clamp,
|
|
44
|
+
uclamp,
|
|
45
|
+
max,
|
|
46
|
+
min,
|
|
47
|
+
power,
|
|
48
|
+
seed,
|
|
49
|
+
inm,
|
|
50
|
+
ing,
|
|
51
|
+
smth,
|
|
52
|
+
exp1,
|
|
53
|
+
floor1,
|
|
54
|
+
round1,
|
|
55
|
+
trunc1,
|
|
56
|
+
ceil1,
|
|
57
|
+
log1,
|
|
58
|
+
sin1,
|
|
59
|
+
cos1,
|
|
60
|
+
tan1,
|
|
61
|
+
asin1,
|
|
62
|
+
acos1,
|
|
63
|
+
atan1,
|
|
64
|
+
sqr1,
|
|
65
|
+
sqrt1,
|
|
66
|
+
recip1,
|
|
67
|
+
abs1,
|
|
68
|
+
bin1,
|
|
69
|
+
binv1,
|
|
70
|
+
edge1,
|
|
71
|
+
index1,
|
|
72
|
+
nan1,
|
|
73
|
+
nanm1,
|
|
74
|
+
rand1,
|
|
75
|
+
randn1,
|
|
76
|
+
range1,
|
|
77
|
+
rank1,
|
|
78
|
+
ranknorm1,
|
|
79
|
+
pval1,
|
|
80
|
+
pval01,
|
|
81
|
+
cpval1,
|
|
82
|
+
ztop1,
|
|
83
|
+
ptoz1,
|
|
84
|
+
dilMk,
|
|
85
|
+
dilDk,
|
|
86
|
+
dilFk,
|
|
87
|
+
dilallk,
|
|
88
|
+
erok,
|
|
89
|
+
eroFk,
|
|
90
|
+
fmediank,
|
|
91
|
+
fmeank,
|
|
92
|
+
fmeanuk,
|
|
93
|
+
fmeanzerok,
|
|
94
|
+
subsamp2,
|
|
95
|
+
subsamp2offc
|
|
96
|
+
};
|
|
97
|
+
enum eDimReduceOp { Tmean,
|
|
98
|
+
Tstd,
|
|
99
|
+
Tmax,
|
|
100
|
+
Tmaxn,
|
|
101
|
+
Tmin,
|
|
102
|
+
Tmedian,
|
|
103
|
+
Tperc,
|
|
104
|
+
Tar1 };
|
|
105
|
+
|
|
106
|
+
//store inputs regarding input header
|
|
107
|
+
typedef struct {
|
|
108
|
+
int datatype;
|
|
109
|
+
float scl_slope, scl_inter;
|
|
110
|
+
} in_hdr;
|
|
111
|
+
//filter details for image resizing
|
|
112
|
+
//C Code From Graphics Gems III
|
|
113
|
+
//Dale Schumacher, "Optimization of Bitmap Scaling Operations"
|
|
114
|
+
//Dale Schumacher, "General Filtered Image Rescaling"
|
|
115
|
+
// https://github.com/erich666/GraphicsGems/tree/master/gemsiii
|
|
116
|
+
//see github for other filters
|
|
117
|
+
|
|
118
|
+
typedef struct {
|
|
119
|
+
int pixel;
|
|
120
|
+
double weight;
|
|
121
|
+
} CONTRIB;
|
|
122
|
+
typedef struct {
|
|
123
|
+
int n; /* number of contributors */
|
|
124
|
+
CONTRIB *p; /* pointer to list of contributions */
|
|
125
|
+
} CLIST;
|
|
126
|
+
|
|
127
|
+
typedef struct { /** x4 vector struct **/
|
|
128
|
+
float v[4] ;
|
|
129
|
+
} vec4 ;
|
|
130
|
+
|
|
131
|
+
#ifdef USING_WASM
|
|
132
|
+
void xmemcpy ( void * destination, const void * source, size_t num );
|
|
133
|
+
#else
|
|
134
|
+
int nifti_save(nifti_image * nim, const char *postfix);
|
|
135
|
+
nifti_image *nifti_image_read2( const char *hname , int read_data );
|
|
136
|
+
int * make_kernel_file(nifti_image * nim, int * nkernel, char * fin);
|
|
137
|
+
mat44 xform(nifti_image * nim);
|
|
138
|
+
int nifti_image_change_datatype ( nifti_image * nim, int dt , in_hdr * ihdr);
|
|
139
|
+
float max_displacement_mm( nifti_image * nim, nifti_image * nim2);
|
|
140
|
+
#endif
|
|
141
|
+
vec4 setVec4(float x, float y, float z);
|
|
142
|
+
vec4 nifti_vect44mat44_mul(vec4 v, mat44 m );
|
|
143
|
+
int neg_determ(nifti_image * nim);
|
|
144
|
+
int nii_otsu(int* H, int nBin, int mode);
|
|
145
|
+
float vertexDisplacement(float x, float y, float z, mat44 m, mat44 m2);
|
|
146
|
+
in_hdr set_input_hdr(nifti_image * nim);
|
|
147
|
+
int * make_kernel(nifti_image * nim, int * nkernel, int x, int y, int z);
|
|
148
|
+
int * make_kernel_sphere(nifti_image * nim, int * nkernel, double mm);
|
|
149
|
+
CLIST * createFilter(int srcXsize, int dstXsize, int filterMethod);
|
|
150
|
+
double qginv( double p );
|
|
151
|
+
double qg( double x );
|
|
152
|
+
|
|
153
|
+
#ifdef USING_WASM
|
|
154
|
+
//#define printfx(...) printf(__VA_ARGS__)
|
|
155
|
+
#define printfx(...)
|
|
156
|
+
#else
|
|
157
|
+
#define printfx(...) fprintf(stderr, __VA_ARGS__)
|
|
158
|
+
#endif
|
|
159
|
+
|
|
160
|
+
#ifndef MAX //from Christian Gaser's TFCE example
|
|
161
|
+
#define MAX(A,B) ((A) > (B) ? (A) : (B))
|
|
162
|
+
#endif
|
|
163
|
+
|
|
164
|
+
#ifndef MIN
|
|
165
|
+
#define MIN(A,B) ((A) > (B) ? (B) : (A))
|
|
166
|
+
#endif
|
|
167
|
+
|
|
168
|
+
#ifndef sqr
|
|
169
|
+
#define sqr(x) ((x)*(x))
|
|
170
|
+
#endif
|
|
171
|
+
|
|
172
|
+
#define LOAD_MAT44(AA,a11,a12,a13,a14,a21,a22,a23,a24,a31,a32,a33,a34) \
|
|
173
|
+
( AA.m[0][0]=a11 , AA.m[0][1]=a12 , AA.m[0][2]=a13 , AA.m[0][3]=a14 , \
|
|
174
|
+
AA.m[1][0]=a21 , AA.m[1][1]=a22 , AA.m[1][2]=a23 , AA.m[1][3]=a24 , \
|
|
175
|
+
AA.m[2][0]=a31 , AA.m[2][1]=a32 , AA.m[2][2]=a33 , AA.m[2][3]=a34 , \
|
|
176
|
+
AA.m[3][0]=AA.m[3][1]=AA.m[3][2]=0.0f , AA.m[3][3]=1.0f )
|
|
177
|
+
|
|
178
|
+
#define LOAD_MAT33(AA,a11,a12,a13 ,a21,a22,a23 ,a31,a32,a33) \
|
|
179
|
+
( AA.m[0][0]=a11 , AA.m[0][1]=a12 , AA.m[0][2]=a13 , \
|
|
180
|
+
AA.m[1][0]=a21 , AA.m[1][1]=a22 , AA.m[1][2]=a23 , \
|
|
181
|
+
AA.m[2][0]=a31 , AA.m[2][1]=a32 , AA.m[2][2]=a33 )
|
|
182
|
+
|
|
183
|
+
#ifdef __cplusplus
|
|
184
|
+
}
|
|
185
|
+
#endif
|
|
186
|
+
|
|
187
|
+
#endif // CR_COREX_H
|