21 if ( hr[2] > 1 && d[1] < d[2] ) d[1] = d[2];
22 if ( hr[1] > 1 && d[0] < d[1] ) d[0] = d[1];
34 if ( ld < 1 )
return -100;
39 f = ld*(1.0 - 1.0/lde);
46 double f(0), ze(fabs(d[2])-hr[2]);
52 if ( ld < 1 )
return ze;
58 f = ld*(1.0 - 1.0/lde);
71 if ( mind < 0.001 && ld < 0.001 )
return 1;
76 if ( mind < maxd ) f = mind;
106 double width,
int fill_type,
double fill)
110 for ( nn=0; nn<n; nn++ )
111 shape(nn, type, rect, start, width, fill_type,
fill);
140 double width,
int fill_type,
double fill)
142 if ( fabs(width) < 0.001 ) {
143 if ( width < 0 ) width = -0.001;
150 if ( rect[0] < 1 ) rect[0] = x;
151 if ( rect[1] < 1 ) rect[1] = y;
152 if ( rect[2] < 1 ) rect[2] = z;
158 long i, xx, yy, zz, cc;
161 Vector3<double> cx(start[0] + (rect[0] - 1)/2.0, start[1] + (rect[1] - 1)/2.0, start[2] + (rect[2] - 1)/2.0);
167 if ( hi[0] >= x ) hi[0] = x - 1;
168 if ( hi[1] >= y ) hi[1] = y - 1;
169 if ( hi[2] >= z ) hi[2] = z - 1;
174 cout <<
"Filling a shape:" << endl;
175 cout <<
"Shape: " << type << endl;
176 cout <<
"Start: " << setprecision(3) << start << endl;
177 cout <<
"Size: " << rect << endl;
178 cout <<
"Width and fill value: " << width <<
" " <<
fill << endl << endl;
182 for ( zz=lo[2]; zz<=hi[2]; zz++ ) {
184 for ( yy=lo[1]; yy<=hi[1]; yy++ ) {
186 for ( xx=lo[0]; xx<=hi[0]; xx++ ) {
190 else if ( type == 1 )
192 else if ( type == 2 )
195 if ( f > 50 )
edge = 1e30;
198 cerr << xx <<
" " << yy <<
" " << zz <<
": Value too large or not finite!: " <<
edge << endl;
201 i =
index(xx, yy, zz, nn);
202 for ( cc=0; cc<c; cc++, i++ )
236 if ( fabs(width) < 0.001 ) {
237 if ( width < 0 ) width = -0.001;
241 if ( rect[0] < 1 ) rect[0] = x;
242 if ( rect[1] < 1 ) rect[1] = y;
243 if ( rect[2] < 1 ) rect[2] = z;
249 long i, xx, yy, zz, cc;
251 Vector3<double> cx(start[0] + (rect[0] - 1)/2.0, start[1] + (rect[1] - 1)/2.0, start[2] + (rect[2] - 1)/2.0);
259 cout <<
"Creating an edge mask:" << endl;
260 cout <<
"Shape: " << type << endl;
261 cout <<
"Start: " << setprecision(3) << start << endl;
262 cout <<
"Size: " << rect << endl;
263 cout <<
"Width: " << width << endl << endl;
268 for ( i=0, zz=0; zz<z; zz++ ) {
269 d[2] = (double)zz - cx[2];
270 for ( yy=0; yy<y; yy++ ) {
271 d[1] = (double)yy - cx[1];
272 for ( xx=0; xx<x; xx++ ) {
273 d[0] = (double)xx - cx[0];
276 else if ( type == 1 )
278 else if ( type == 2 )
281 if ( f > 50 )
edge = 1e30;
284 cerr << xx <<
" " << yy <<
" " << zz <<
": Value too large or not finite!: " <<
edge << endl;
287 for ( cc=0; cc<c; cc++, i++ )
322 double width,
int fill_type,
double fill)
327 dispatch_apply(n, dispatch_get_global_queue(0, 0), ^(
size_t nn){
331 #pragma omp parallel for
332 for (
long nn=0; nn<n; nn++ )
368 double width,
int fill_type,
double fill)
391 long i, nn, xx, yy, zz, cc;
395 cx[0] =
M_PI * 2.0L / ( x - 1);
396 cx[1] =
M_PI * 2.0L / ( y - 1);
397 cx[2] =
M_PI * 2.0L / ( z - 1);
400 cout <<
"Hann tapering window:" << endl;
401 cout <<
"Size: " <<
size() << endl;
402 cout <<
"Fill value: " <<
fill << endl << endl;
405 for ( i=nn=0; nn<n; nn++ ) {
406 for ( zz=0; zz<z; zz++ ) {
407 han[2] = 0.5 * (1. - cos(cx[2]*zz));
408 for ( yy=0; yy<y; yy++ ) {
409 han[1] = 0.5 * (1. - cos(cx[1]*yy));
410 for ( xx=0; xx<x; xx++ ) {
411 han[0] = 0.5 * (1. - cos(cx[0]*xx));
413 for ( cc=0; cc<c; cc++, i++ ) {
441 double width,
int fill_type,
double fill)
443 Vector3<long> rect((
long) (2*radius+0.5), (
long) (2*radius+0.5), (
long) (2*radius+0.5));
468 double height,
double width,
int fill_type,
double fill)
496 if ( sigma < 1 ) sigma = 1;
497 if ( amp == 0 ) amp = 1;
500 cout <<
"Calculating a Gaussian sphere:" << endl;
501 cout <<
"Center: " <<
center << endl;
502 cout <<
"Sigma: " << sigma << endl;
503 cout <<
"Amplitude: " << amp << endl << endl;
506 long i, xx, yy, zz, cc;
507 double x2, y2, z2, d2, v;
508 double fac(-0.5/(sigma*sigma));
510 for ( i=zz=0; zz<z; zz++ ) {
513 for ( yy=0; yy<y; yy++ ) {
516 for ( xx=0; xx<x; xx++ ) {
521 for ( cc=0; cc<c; cc++, i++ )
547 double maxrad,
double width,
int fill_type,
double fill)
551 for ( nn=0; nn<n; nn++ )
575 double maxrad,
double width,
int fill_type,
double fill)
577 if ( minrad > maxrad ) swap(minrad, maxrad);
578 if ( maxrad - minrad < 1 )
return 0;
580 if ( fabs(width) < 0.1 ) {
581 if ( width < 0 ) width = -0.1;
588 long i, xx, yy, zz, cc;
595 cout <<
"Filling shell:" << endl;
596 cout <<
"Center: " <<
center << endl;
597 cout <<
"Radii: " << minrad <<
" - " << maxrad << endl;
598 cout <<
"Gaussian width and fill value: " << width <<
" " <<
fill << endl << endl;
604 if ( hi[0] >= x ) hi[0] = x - 1;
605 if ( hi[1] >= y ) hi[1] = y - 1;
606 if ( hi[2] >= z ) hi[2] = z - 1;
619 for ( zz=lo[2]; zz<=hi[2]; zz++ ) {
621 for ( yy=lo[1]; yy<=hi[1]; yy++ ) {
623 for ( xx=lo[0]; xx<=hi[0]; xx++ ) {
627 if ( f > 40 )
edge = 1e30;
629 i =
index(0, xx, yy, zz, nn);
630 for ( cc=0; cc<c; cc++, i++ )
657 double maxrad,
double width,
int fill_type,
double fill)
659 if ( minrad > maxrad ) swap(minrad, maxrad);
660 if ( maxrad - minrad < 1 )
return 0;
662 if ( fabs(width) < 0.1 ) {
663 if ( width < 0 ) width = -0.1;
670 long i, xx, yy, zz, cc;
672 double f,
edge, mrw(maxrad + 3*width), a(
GOLDEN/fabs(width));
679 cout <<
"Filling shell with wrapping:" << endl;
680 cout <<
"Center: " <<
center << endl;
681 cout <<
"Radii: " << minrad <<
" - " << maxrad << endl;
682 cout <<
"Gaussian width and fill value: " << width <<
" " <<
fill << endl << endl;
688 for ( zz=lo[2]; zz<=hi[2]; zz++ ) {
690 if ( d[2] > sh[2] ) d[2] -= z;
691 if ( d[2] < -sh[2] ) d[2] += z;
692 iz = (zz<0)? zz + z: zz;
693 for ( yy=lo[1]; yy<=hi[1]; yy++ ) {
695 if ( d[1] > sh[1] ) d[1] -= y;
696 if ( d[1] < -sh[1] ) d[1] += y;
697 iy = (yy<0)? yy + y: yy;
698 for ( xx=lo[0]; xx<=hi[0]; xx++ ) {
700 if ( d[0] > sh[0] ) d[0] -= x;
701 if ( d[0] < -sh[0] ) d[0] += x;
702 ix = (xx<0)? xx + x: xx;
705 if ( f > 50 )
edge = 1e30;
707 i =
index(ix, iy, iz, nn);
708 for ( cc=0; cc<c; cc++, i++ )
732 double width,
double edge_width,
int fill_type,
double fill)
736 for ( nn=0; nn<n; nn++ )
737 bar(nn, start, end, width, edge_width, fill_type,
fill);
758 double width,
double edge_width,
int fill_type,
double fill)
760 if ( edge_width < 0.001 ) edge_width = 0.001;
766 cout <<
"Generating a bar" << endl;
767 cout <<
"Start: " << start << endl;
768 cout <<
"End: " << end << endl;
769 cout <<
"Fill value: " <<
fill << endl;
770 cout <<
"Width and edge width: " << width <<
" " << edge_width << endl << endl;
773 long i, xx, yy, zz, cc;
774 double t, d, half_width(width/2.0),
edge;
775 double a(
GOLDEN/fabs(edge_width));
779 double vlen(vec.
length());
780 double vpow(vlen*vlen);
788 if ( hi[0] >= x ) hi[0] = x - 1;
789 if ( hi[1] >= y ) hi[1] = y - 1;
790 if ( hi[2] >= z ) hi[2] = z - 1;
792 for ( zz=lo[2]; zz<=hi[2]; zz++ ) {
794 for ( yy=lo[1]; yy<=hi[1]; yy++ ) {
796 for ( xx=lo[0]; xx<=hi[0]; xx++, i++ ) {
800 if ( t >= 0 && t <= 1 ) {
802 edge = exp(a*(half_width - d));
804 i =
index(xx, yy, zz, nn);
805 for ( cc=0; cc<c; cc++, i++ )
823 long i, xx, yy, zz, nn;
824 double dx, dy, dz, v;
826 for ( i=nn=0; nn<n; nn++ ) {
827 for ( zz=0; zz<z; zz++ ) {
829 for ( yy=0; yy<y; yy++ ) {
831 for ( xx=0; xx<x; xx++, i++ ) {
833 v = param[0] + dx*param[1] + dy*param[2] + dz*param[3]
834 + dx*dx*param[4] + dy*dy*param[5] + dz*dz*param[6];
857 if ( compoundtype !=
TSimple ) {
858 cerr <<
"Error: The gap filter only operates on single value images!" << endl << endl;
862 long kernel_size(step);
864 if ( kernel_size%2 == 0 ) kernel_size += 1;
865 if ( kernel_size < 3 ) kernel_size = 3;
868 long i, j, nn, xx, yy, zz, kx, ky, kz;
869 Vector3<long> blocksize(kernel_size,kernel_size,kernel_size);
870 blocksize = blocksize.
min(
size());
871 long blocktotalsize(blocksize.
volume());
874 cout <<
"Filling the gaps:" << endl;
875 cout <<
"Block size: " << blocksize[0] <<
" x "
876 << blocksize[1] <<
" x " << blocksize[2] <<
" = " << blocktotalsize << endl;
882 long zlo, zhi, ylo, yhi, xlo, xhi;
883 for ( nn=0; nn<n; nn++ ) {
884 for ( zz=0; zz<z; zz+=step ) {
885 zlo = zz - blocksize[2]/2;
886 if ( zlo < 0 ) zlo = 0;
887 zhi = zz + blocksize[2]/2;
888 if ( zhi >= z ) zhi = z - 1;
889 for ( yy=0; yy<y; yy+=step ) {
890 ylo = yy - blocksize[1]/2;
891 if ( ylo < 0 ) ylo = 0;
892 yhi = yy + blocksize[1]/2;
893 if ( yhi >= y ) yhi = y - 1;
894 for ( xx=0; xx<x; xx+=step ) {
895 xlo = xx - blocksize[0]/2;
896 if ( xlo < 0 ) xlo = 0;
897 xhi = xx + blocksize[0]/2;
898 if ( xhi >= x ) xhi = x - 1;
899 i =
index(0, xx, yy, zz, nn);
902 for ( kz=zlo; kz<=zhi; kz++ ) {
903 for ( ky=ylo; ky<=yhi; ky++ ) {
904 for ( kx=xlo; kx<=xhi; kx++ ) {
905 j =
index(0, kx, ky, kz, nn);
917 cout <<
"DEBUG Bimage::fill_gaps: Done" << endl;
935 if ( compoundtype !=
TSimple ) {
936 cerr <<
"Error: The gap filter only operates on single value images!" << endl << endl;
941 long i, nn, xx, yy, zz;
942 long x1(0), x2(0), y1(0), y2(0), z1(0), z2(0);
943 double fx, fx1, fy, fy1, fz, fz1, v[8], vn;
944 for ( i=0; i<8; ++i ) v[i] = 0;
947 cout <<
"Interpolating the gaps:" << endl;
948 cout <<
"Step size: " << step << endl;
954 for ( i=nn=0; nn<n; nn++ ) {
955 for ( zz=0; zz<z; zz++ ) {
956 if ( zz%step == 0 ) {
960 fz = (zz - z1)*1.0/step;
962 for ( yy=0; yy<y; yy++ ) {
963 if ( yy%step == 0 ) {
967 fy = (yy - y1)*1.0/step;
969 for ( xx=0; xx<x; xx++, i++ ) {
970 if ( xx%step == 0 ) {
973 v[0] =
get(nn, x1, y1, z1);
974 v[1] =
get(nn, x2, y1, z1);
975 v[2] =
get(nn, x1, y2, z1);
976 v[3] =
get(nn, x2, y2, z1);
977 v[4] =
get(nn, x1, y1, z2);
978 v[5] =
get(nn, x2, y1, z2);
979 v[6] =
get(nn, x1, y2, z2);
980 v[7] =
get(nn, x2, y2, z2);
982 fx = (xx - x1)*1.0/step;
984 vn = fx1 * fy1 * fz1 * v[0];
985 vn += fx * fy1 * fz1 * v[1];
986 vn += fx1 * fy * fz1 * v[2];
987 vn += fx * fy * fz1 * v[3];
988 vn += fx1 * fy1 * fz * v[4];
989 vn += fx * fy1 * fz * v[5];
990 vn += fx1 * fy * fz * v[6];
991 vn += fx * fy * fz * v[7];
999 cout <<
"DEBUG Bimage::interpolate_gaps: Done" << endl;