Bsoft  2.1.0
Bernard's software package
Bimage_edit.cpp
Go to the documentation of this file.
1 
9 #include "Bimage.h"
10 #include "matrix_linear.h"
11 #include "utilities.h"
12 
13 // Declaration of global variables
14 extern int verbose; // Level of output to the screen
15 
16 
18 {
19  d = d.abs() - hr;
20 
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];
23 
24  return d[0];
25 }
26 
28 {
29  double f(0);
30 
31  Vector3<double> de(d/hr);
32  double ld(d.length());
33 
34  if ( ld < 1 ) return -100;
35 
36  double lde(de.length());
37 
38  if ( lde > 1e-20 )
39  f = ld*(1.0 - 1.0/lde);
40 
41  return f;
42 }
43 
45 {
46  double f(0), ze(fabs(d[2])-hr[2]);
47 
48  d[2] = 0;
49 
50  double ld(d.length());
51 
52  if ( ld < 1 ) return ze;
53 
54  Vector3<double> de(d/hr);
55  double lde(de.length());
56 
57  if ( lde > 1e-20 )
58  f = ld*(1.0 - 1.0/lde);
59 
60  if ( f < ze ) f = ze;
61 
62  return f;
63 }
64 
65 double shell_edge(Vector3<double> d, double mind, double maxd)
66 {
67  double f(0);
68 
69  double ld(d.length());
70 
71  if ( mind < 0.001 && ld < 0.001 ) return 1;
72 
73  mind = ld - mind ;
74  maxd -= ld;
75 
76  if ( mind < maxd ) f = mind;
77  else f = maxd;
78 
79  return f;
80 }
81 
82 
105 int Bimage::shape(int type, Vector3<long> rect, Vector3<double> start,
106  double width, int fill_type, double fill)
107 {
108  long nn;
109 
110  for ( nn=0; nn<n; nn++ )
111  shape(nn, type, rect, start, width, fill_type, fill);
112 
113  return 0;
114 }
115 
139 int Bimage::shape(long nn, int type, Vector3<long> rect, Vector3<double> start,
140  double width, int fill_type, double fill)
141 {
142  if ( fabs(width) < 0.001 ) {
143  if ( width < 0 ) width = -0.001;
144  else width = 0.001;
145  }
146 
147  if ( fill_type == FILL_AVERAGE ) fill = avg;
148  if ( fill_type == FILL_BACKGROUND ) fill = background(nn);
149 
150  if ( rect[0] < 1 ) rect[0] = x;
151  if ( rect[1] < 1 ) rect[1] = y;
152  if ( rect[2] < 1 ) rect[2] = z;
153  if ( z < 2 ) {
154  start[2] = 0;
155  rect[2] = z;
156  }
157 
158  long i, xx, yy, zz, cc;
159  double f(0), edge(3*width), a(-GOLDEN/width);
160  Vector3<double> d, hr(rect/2);
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);
162  Vector3<long> lo(start - edge);
163  Vector3<long> hi(start + rect + edge);
164 
165  hr = hr.max(1);
166  lo = lo.max(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;
170 
171 // cout << hr << endl;
172 
173  if ( verbose & VERB_PROCESS ) {
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;
179  }
180 
181 
182  for ( zz=lo[2]; zz<=hi[2]; zz++ ) {
183  d[2] = zz - cx[2];
184  for ( yy=lo[1]; yy<=hi[1]; yy++ ) {
185  d[1] = yy - cx[1];
186  for ( xx=lo[0]; xx<=hi[0]; xx++ ) {
187  d[0] = xx - cx[0];
188  if ( type == 0 )
189  f = rectangle_edge(d, hr);
190  else if ( type == 1 )
191  f = oval_edge(d, hr);
192  else if ( type == 2 )
193  f = cylinder_edge(d, hr);
194  f *= a;
195  if ( f > 50 ) edge = 1e30;
196  else edge = exp(f);
197  if ( !isfinite(edge) ) {
198  cerr << xx << " " << yy << " " << zz << ": Value too large or not finite!: " << edge << endl;
199  edge = 1e30;
200  }
201  i = index(xx, yy, zz, nn);
202  for ( cc=0; cc<c; cc++, i++ )
203  set(i, ((*this)[i] + fill*edge)/(1+edge));
204  }
205  }
206  }
207 
208  statistics();
209 
210  return 0;
211 }
212 
234  Vector3<double> start, double width)
235 {
236  if ( fabs(width) < 0.001 ) {
237  if ( width < 0 ) width = -0.001;
238  else width = 0.001;
239  }
240 
241  if ( rect[0] < 1 ) rect[0] = x;
242  if ( rect[1] < 1 ) rect[1] = y;
243  if ( rect[2] < 1 ) rect[2] = z;
244  if ( z < 2 ) {
245  start[2] = 0;
246  rect[2] = z;
247  }
248 
249  long i, xx, yy, zz, cc;
250  Vector3<double> d, hr(rect/2);
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);
252  double f(0), edge, a(GOLDEN/width);
253 
254  hr = hr.max(1);
255 
256 // cout << hr << endl;
257 
258  if ( verbose & VERB_PROCESS ) {
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;
264  }
265 
266  Bimage* pmask = new Bimage(Float, TSimple, size(), 1);
267 
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];
274  if ( type == 0 )
275  f = rectangle_edge(d, hr);
276  else if ( type == 1 )
277  f = oval_edge(d, hr);
278  else if ( type == 2 )
279  f = cylinder_edge(d, hr);
280  f *= a;
281  if ( f > 50 ) edge = 1e30;
282  else edge = exp(f);
283  if ( !isfinite(edge) ) {
284  cerr << xx << " " << yy << " " << zz << ": Value too large or not finite!: " << edge << endl;
285  edge = 1e30;
286  }
287  for ( cc=0; cc<c; cc++, i++ )
288  pmask->set(i, 1/(1+edge));
289  }
290  }
291  }
292 
293  pmask->statistics();
294 
295  return pmask;
296 }
297 
321 int Bimage::edge(int type, Vector3<long> rect, Vector3<double> start,
322  double width, int fill_type, double fill)
323 {
324  Bimage* pmask = edge_mask(type, rect, start, width);
325 
326 #ifdef HAVE_GCD
327  dispatch_apply(n, dispatch_get_global_queue(0, 0), ^(size_t nn){
328  apply_soft_mask(nn, pmask, fill_type, fill);
329  });
330 #else
331 #pragma omp parallel for
332  for ( long nn=0; nn<n; nn++ )
333  apply_soft_mask(nn, pmask, fill_type, fill);
334 #endif
335 
336  delete pmask;
337 
338  statistics();
339 
340  return 0;
341 }
342 
367 int Bimage::edge(long nn, int type, Vector3<long> rect, Vector3<double> start,
368  double width, int fill_type, double fill)
369 {
370  Bimage* pmask = edge_mask(type, rect, start, width);
371 
372  apply_soft_mask(nn, pmask, fill_type, fill);
373 
374  return 0;
375 }
376 
388 int Bimage::hanning_taper(double fill)
389 {
390 
391  long i, nn, xx, yy, zz, cc;
392  double vol, v;
393  Vector3<double> cx, han;
394 
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);
398 
399  if ( verbose & VERB_FULL ) {
400  cout << "Hann tapering window:" << endl;
401  cout << "Size: " << size() << endl;
402  cout << "Fill value: " << fill << endl << endl;
403  }
404 
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));
412  vol = han.volume();
413  for ( cc=0; cc<c; cc++, i++ ) {
414  v = ((*this)[i] - fill)*vol + fill;
415  set(i, v);
416  }
417  }
418  }
419  }
420  }
421 
422  return 0;
423 }
424 
440 int Bimage::sphere(Vector3<double> center, double radius,
441  double width, int fill_type, double fill)
442 {
443  Vector3<long> rect((long) (2*radius+0.5), (long) (2*radius+0.5), (long) (2*radius+0.5));
444  rect = rect.min(size());
445 
446  center -= rect/2;
447 
448  return shape(1, rect, center, width, fill_type, fill);
449 }
450 
467 int Bimage::cylinder(Vector3<double> center, double radius,
468  double height, double width, int fill_type, double fill)
469 {
470  Vector3<long> cyl(long(2*radius+0.5), long(2*radius+0.5), long(height+0.5));
471  cyl = cyl.min(size());
472 
473  center[0] -= radius;
474  center[1] -= radius;
475  center[2] -= height/2;
476 
477  return shape(2, cyl, center, width, fill_type, fill);
478 }
479 
494 int Bimage::gaussian_sphere(long nn, Vector3<double> center, double sigma, double amp)
495 {
496  if ( sigma < 1 ) sigma = 1;
497  if ( amp == 0 ) amp = 1;
498 
499  if ( verbose ) {
500  cout << "Calculating a Gaussian sphere:" << endl;
501  cout << "Center: " << center << endl;
502  cout << "Sigma: " << sigma << endl;
503  cout << "Amplitude: " << amp << endl << endl;
504  }
505 
506  long i, xx, yy, zz, cc;
507  double x2, y2, z2, d2, v;
508  double fac(-0.5/(sigma*sigma));
509 
510  for ( i=zz=0; zz<z; zz++ ) {
511  z2 = zz - center[2];
512  z2 *= z2;
513  for ( yy=0; yy<y; yy++ ) {
514  y2 = yy - center[1];
515  y2 *= y2;
516  for ( xx=0; xx<x; xx++ ) {
517  x2 = xx - center[0];
518  x2 *= x2;
519  d2 = x2 + y2 + z2;
520  v = amp*exp(fac*d2);
521  for ( cc=0; cc<c; cc++, i++ )
522  add(i, v);
523  }
524  }
525  }
526 
527  return 0;
528 }
529 
546 int Bimage::shell(Vector3<double> center, double minrad,
547  double maxrad, double width, int fill_type, double fill)
548 {
549  long nn;
550 
551  for ( nn=0; nn<n; nn++ )
552  shell(nn, center, minrad, maxrad, width, fill_type, fill);
553 
554  return 0;
555 }
556 
574 int Bimage::shell(long nn, Vector3<double> center, double minrad,
575  double maxrad, double width, int fill_type, double fill)
576 {
577  if ( minrad > maxrad ) swap(minrad, maxrad);
578  if ( maxrad - minrad < 1 ) return 0;
579 
580  if ( fabs(width) < 0.1 ) {
581  if ( width < 0 ) width = -0.1;
582  else width = 0.1;
583  }
584 
585  if ( fill_type == FILL_AVERAGE ) fill = avg;
586  if ( fill_type == FILL_BACKGROUND ) fill = background(nn);
587 
588  long i, xx, yy, zz, cc;
589  double f, edge, pad(5*width), mrp(maxrad + pad), a(GOLDEN/fabs(width));
590  Vector3<long> lo(center - mrp);
591  Vector3<long> hi(center + mrp);
592  Vector3<double> d;
593 
594  if ( verbose & VERB_PROCESS ) {
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;
599  }
600 
601 // lo = center - (maxrad + pad);
602  lo = lo.max(0);
603 // hi = center + (maxrad + pad);
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;
607 /*
608  cout << lo << tab << hi << endl;
609 
610  for ( xx=-2*maxrad; xx<2*maxrad; xx++ ) {
611  d[0] = xx;
612  f = shell_edge(d, minrad, maxrad);
613  f *= a;
614  if ( f > 40 ) edge = 1e30;
615  else edge = exp(f);
616  cout << xx << tab << f << tab << edge << endl;
617  }
618 */
619  for ( zz=lo[2]; zz<=hi[2]; zz++ ) {
620  d[2] = zz - center[2];
621  for ( yy=lo[1]; yy<=hi[1]; yy++ ) {
622  d[1] = yy - center[1];
623  for ( xx=lo[0]; xx<=hi[0]; xx++ ) {
624  d[0] = xx - center[0];
625  f = shell_edge(d, minrad, maxrad);
626  f *= a;
627  if ( f > 40 ) edge = 1e30;
628  else edge = exp(f);
629  i = index(0, xx, yy, zz, nn);
630  for ( cc=0; cc<c; cc++, i++ )
631  set(i, ((*this)[i] + fill*edge)/(1+edge));
632  }
633  }
634  }
635 
636  return 0;
637 }
638 
656 int Bimage::shell_wrap(long nn, Vector3<double> center, double minrad,
657  double maxrad, double width, int fill_type, double fill)
658 {
659  if ( minrad > maxrad ) swap(minrad, maxrad);
660  if ( maxrad - minrad < 1 ) return 0;
661 
662  if ( fabs(width) < 0.1 ) {
663  if ( width < 0 ) width = -0.1;
664  else width = 0.1;
665  }
666 
667  if ( fill_type == FILL_AVERAGE ) fill = avg;
668  if ( fill_type == FILL_BACKGROUND ) fill = background(nn);
669 
670  long i, xx, yy, zz, cc;
671  long ix, iy, iz;
672  double f, edge, mrw(maxrad + 3*width), a(GOLDEN/fabs(width));
673  Vector3<long> sh(size()/2);
674  Vector3<long> lo(center - mrw);
675  Vector3<long> hi(center + mrw);
676  Vector3<double> d;
677 
678  if ( verbose & VERB_PROCESS ) {
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;
683  }
684 
685 // lo = center - (maxrad + 3*width);
686 // hi = center + (maxrad + 3*width);
687 
688  for ( zz=lo[2]; zz<=hi[2]; zz++ ) {
689  d[2] = zz - center[2];
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++ ) {
694  d[1] = yy - center[1];
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++ ) {
699  d[0] = xx - center[0];
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;
703  f = shell_edge(d, minrad, maxrad);
704  f *= a;
705  if ( f > 50 ) edge = 1e30;
706  else edge = exp(f);
707  i = index(ix, iy, iz, nn);
708  for ( cc=0; cc<c; cc++, i++ )
709  set(i, ((*this)[i] + fill*edge)/(1+edge));
710  }
711  }
712  }
713 
714  return 0;
715 }
716 
732  double width, double edge_width, int fill_type, double fill)
733 {
734  long nn;
735 
736  for ( nn=0; nn<n; nn++ )
737  bar(nn, start, end, width, edge_width, fill_type, fill);
738 
739  return 0;
740 }
741 
758  double width, double edge_width, int fill_type, double fill)
759 {
760  if ( edge_width < 0.001 ) edge_width = 0.001;
761 
762  if ( fill_type == FILL_AVERAGE ) fill = avg;
763  if ( fill_type == FILL_BACKGROUND ) fill = background(nn);
764 
765  if ( verbose & VERB_PROCESS ) {
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;
771  }
772 
773  long i, xx, yy, zz, cc;
774  double t, d, half_width(width/2.0), edge;
775  double a(GOLDEN/fabs(edge_width));
776 
777  Vector3<double> vec(end - start);
778  Vector3<double> u, w;
779  double vlen(vec.length());
780  double vpow(vlen*vlen);
781  Vector3<double> lo, hi;
782 
783  lo = start.min(end);
784  lo -= 3*edge_width;
785  lo = lo.max(0);
786  hi = start.max(end);
787  hi += 3*edge_width;
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;
791 
792  for ( zz=lo[2]; zz<=hi[2]; zz++ ) {
793  u[2] = zz;
794  for ( yy=lo[1]; yy<=hi[1]; yy++ ) {
795  u[1] = yy;
796  for ( xx=lo[0]; xx<=hi[0]; xx++, i++ ) {
797  u[0] = xx;
798  w = start - u;
799  t = -w.scalar(vec)/vpow;
800  if ( t >= 0 && t <= 1 ) {
801  d = (vec.cross(w)).length()/vlen;
802  edge = exp(a*(half_width - d));
803  if ( !isfinite(edge) || edge > 1e30 ) edge = 1e30;
804  i = index(xx, yy, zz, nn);
805  for ( cc=0; cc<c; cc++, i++ )
806  set(i, ((*this)[i] + fill*edge)/(1+edge));
807  }
808  }
809  }
810  }
811 
812  return 0;
813 }
814 
821 int Bimage::quadric(double* param)
822 {
823  long i, xx, yy, zz, nn;
824  double dx, dy, dz, v;
825 
826  for ( i=nn=0; nn<n; nn++ ) {
827  for ( zz=0; zz<z; zz++ ) {
828  dz = -image[nn].origin()[2] + zz;
829  for ( yy=0; yy<y; yy++ ) {
830  dy = -image[nn].origin()[1] + yy;
831  for ( xx=0; xx<x; xx++, i++ ) {
832  dx = -image[nn].origin()[0] + xx;
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];
835  set(i, v);
836  }
837  }
838  }
839  }
840 
841  return 0;
842 }
843 
844 
855 int Bimage::fill_gaps(long step)
856 {
857  if ( compoundtype != TSimple ) {
858  cerr << "Error: The gap filter only operates on single value images!" << endl << endl;
859  return -1;
860  }
861 
862  long kernel_size(step);
863  double fill(200), v;
864  if ( kernel_size%2 == 0 ) kernel_size += 1;
865  if ( kernel_size < 3 ) kernel_size = 3;
866 
867  // Calculate the new size and set up
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());
872 
873  if ( verbose & VERB_PROCESS ) {
874  cout << "Filling the gaps:" << endl;
875  cout << "Block size: " << blocksize[0] << " x "
876  << blocksize[1] << " x " << blocksize[2] << " = " << blocktotalsize << endl;
877  }
878 
880 
881  // Do the fill filtering
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);
900  v = (*this)[i];
901  if ( v < fill ) {
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);
906  set(j, v);
907  }
908  }
909  }
910  }
911  }
912  }
913  }
914  }
915 
916  if ( verbose & VERB_DEBUG )
917  cout << "DEBUG Bimage::fill_gaps: Done" << endl;
918 
919  statistics();
920 
921  return 0;
922 }
923 
934 {
935  if ( compoundtype != TSimple ) {
936  cerr << "Error: The gap filter only operates on single value images!" << endl << endl;
937  return -1;
938  }
939 
940  // Calculate the new size and set up
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;
945 
946  if ( verbose & VERB_PROCESS ) {
947  cout << "Interpolating the gaps:" << endl;
948  cout << "Step size: " << step << endl;
949  }
950 
952 
953  // Do the fill filtering
954  for ( i=nn=0; nn<n; nn++ ) {
955  for ( zz=0; zz<z; zz++ ) {
956  if ( zz%step == 0 ) {
957  z1 = zz;
958  z2 = z1 + step;
959  }
960  fz = (zz - z1)*1.0/step;
961  fz1 = 1 - fz;
962  for ( yy=0; yy<y; yy++ ) {
963  if ( yy%step == 0 ) {
964  y1 = yy;
965  y2 = y1 + step;
966  }
967  fy = (yy - y1)*1.0/step;
968  fy1 = 1 - fy;
969  for ( xx=0; xx<x; xx++, i++ ) {
970  if ( xx%step == 0 ) {
971  x1 = xx;
972  x2 = x1 + step;
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);
981  }
982  fx = (xx - x1)*1.0/step;
983  fx1 = 1 - fx;
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];
992  set(i, vn);
993  }
994  }
995  }
996  }
997 
998  if ( verbose & VERB_DEBUG )
999  cout << "DEBUG Bimage::interpolate_gaps: Done" << endl;
1000 
1001  statistics();
1002 
1003  return 0;
1004 }
Bimage::height
Bimage * height(View *views, double threshold=0)
Calculates a set of height images from a 3D density map.
Definition: Bimage_topo.cpp:230
matrix_linear.h
Header file for matrix functions.
Bimage::edge_mask
Bimage * edge_mask(int type, Vector3< long > rect, Vector3< double > start, double width)
Creates a mask with the edge approaching zero.
Definition: Bimage_edit.cpp:233
VERB_DEBUG
#define VERB_DEBUG
Definition: utilities.h:116
Bimage::get
double get(long nn, long xx, long yy, long zz, long cc=0)
Returns the data value at the given coordinates.
Definition: Bimage.cpp:960
Bimage::fill_gaps
int fill_gaps(long step)
Fill the voxels that are not calculated.
Definition: Bimage_edit.cpp:855
Bimage::set
void set(long j, double v)
Sets a single value at the given index.
Definition: Bimage.cpp:1118
Bimage::shell
int shell(Vector3< double > center, double minrad, double maxrad, double width, int fill_type=0, double fill=0)
Fills a shell within an image with a uniform value.
Definition: Bimage_edit.cpp:546
Bimage::Bimage
Bimage()
Initializes an image.
Definition: Bimage.cpp:43
Bimage::center
int center(int fill_type=0, double fill=0)
Centers an image.
Definition: Bimage_transform.cpp:694
Vector3< double >
GOLDEN
#define GOLDEN
Definition: utilities.h:85
Bimage::background
double background(long nn)
Definition: Bimage.h:549
Bimage::size
Vector3< long > size() const
Definition: Bimage.h:386
FILL_AVERAGE
#define FILL_AVERAGE
Definition: utilities.h:177
oval_edge
double oval_edge(Vector3< double > d, Vector3< double > hr)
Definition: Bimage_edit.cpp:27
rectangle_edge
double rectangle_edge(Vector3< double > d, Vector3< double > hr)
Definition: Bimage_edit.cpp:17
Vector3::scalar
double scalar(const Vector3 &v) const
Definition: Vector3.h:249
length
double length(vector< T > v)
Definition: Vector3.h:530
Bimage::image
Bsub_image * image
Definition: Bimage.h:202
VERB_PROCESS
#define VERB_PROCESS
Definition: utilities.h:111
Bimage::shell_wrap
int shell_wrap(long nn, Vector3< double > center, double minrad, double maxrad, double width, int fill_type=0, double fill=0)
Fills a shell within an image with a uniform value with wrapping.
Definition: Bimage_edit.cpp:656
Bsub_image::origin
void origin(double x, double y, double z)
Definition: Bimage.h:136
TSimple
@ TSimple
Definition: Bimage.h:59
Bimage::add
void add(long j, double v)
Definition: Bimage.h:321
Bimage::interpolate_gaps
int interpolate_gaps(long step)
Interpolate the voxels that are not calculated.
Definition: Bimage_edit.cpp:933
Bimage::hanning_taper
int hanning_taper(double fill=0)
Apply Hanning taper window to the image.
Definition: Bimage_edit.cpp:388
Bimage::cylinder
int cylinder(Vector3< double > center, double radius, double height, double width, int fill_type=0, double fill=0)
Fills a cylinder within an image with a uniform value.
Definition: Bimage_edit.cpp:467
Bimage
General image parameter class.
Definition: Bimage.h:177
Bimage::shape
int shape(int type, Vector3< long > rect, Vector3< double > start, double width, int fill_type=0, double fill=0)
Creates a shape in an image and fills it with a constant value.
Definition: Bimage_edit.cpp:105
Bimage.h
Header file for image class.
Bimage::apply_soft_mask
long apply_soft_mask(long nn, Bimage *pmask, int fill_type, double fill)
Applies a soft mask to a sub-image.
Definition: Bimage_mask.cpp:2516
M_PI
#define M_PI
Definition: utilities.h:63
utilities.h
Header file for general utilities.
isfinite
bool isfinite(complex< T > &value)
verbose
int verbose
Bimage::change_type
void change_type(char letter)
Get the data type indicated by a single letter code.
Definition: Bimage.cpp:1765
Bimage::index
long index(long nx, long ny) const
Definition: Bimage.h:396
Vector3::volume
double volume()
Definition: Vector3.h:237
Bimage::fill
void fill(double v)
Definition: Bimage.h:706
cylinder_edge
double cylinder_edge(Vector3< double > d, Vector3< double > hr)
Definition: Bimage_edit.cpp:44
VERB_FULL
#define VERB_FULL
Definition: utilities.h:113
FILL_BACKGROUND
#define FILL_BACKGROUND
Definition: utilities.h:178
Vector3::min
Type min()
Definition: Vector3.h:169
Bimage::pad
int pad(long sz, int fill_type=0, double fill=0)
Pads an image to a new size with a given fill value.
Definition: Bimage_resize.cpp:347
Bimage::bar
int bar(Vector3< double > start, Vector3< double > end, double width, double edge_width, int fill_type=0, double fill=0)
Generates a bar between start and end points.
Definition: Bimage_edit.cpp:731
Vector3::length
double length()
Definition: Vector3.h:222
Bimage::edge
int edge(int type, Vector3< long > rect, Vector3< double > start, double width, int fill_type=0, double fill=0)
Smooths the image edge with a soft rectangular function.
Definition: Bimage_edit.cpp:321
Float
@ Float
Definition: utilities.h:161
Bimage::quadric
int quadric(double *param)
Generates a quadric surface over the whole image.
Definition: Bimage_edit.cpp:821
Bimage::statistics
long statistics()
Calculates the statistics for an image.
Definition: Bimage_stats.cpp:22
Vector3::cross
Vector3 cross(const Vector3 &v)
Definition: Vector3.h:252
Bimage::sphere
int sphere(Vector3< double > center, double radius, double width=0, int fill_type=0, double fill=0)
Fills a sphere within an image with a uniform value.
Definition: Bimage_edit.cpp:440
shell_edge
double shell_edge(Vector3< double > d, double mind, double maxd)
Definition: Bimage_edit.cpp:65
Bimage::gaussian_sphere
int gaussian_sphere(long nn, Vector3< double > center, double sigma, double amp)
Fills a gaussian sphere within an image with a uniform value.
Definition: Bimage_edit.cpp:494
Vector3::abs
Vector3 abs()
Definition: Vector3.h:201
Vector3::max
Type max()
Definition: Vector3.h:175