Xmipp  v3.23.11-Nereus
Macros | Functions
lib_vwk.cpp File Reference
#include "situs.h"
#include "lib_vwk.h"
#include "lib_vec.h"
#include "lib_err.h"
#include "lib_std.h"
Include dependency graph for lib_vwk.cpp:

Go to the source code of this file.

Macros

#define BARL   70 /* available space for histogram bars */
 

Functions

unsigned long gidz_cube (int k, int j, int i, unsigned ext)
 
unsigned long gidz_general (int k, int j, int i, unsigned ey, unsigned ex)
 
void create_padded_map (double **outmap, unsigned *out_extx, unsigned *out_exty, unsigned *out_extz, double *out_origx, double *out_origy, double *out_origz, unsigned long *out_nvox, double *inmap, unsigned in_extx, unsigned in_exty, unsigned in_extz, double in_origx, double in_origy, double in_origz, double widthx, double widthy, double widthz, unsigned margin[3])
 
void interpolate_map (double **outmap, unsigned *out_extx, unsigned *out_exty, unsigned *out_extz, double *out_origx, double *out_origy, double *out_origz, double out_widthx, double out_widthy, double out_widthz, double *inmap, unsigned in_extx, unsigned in_exty, unsigned in_extz, double in_origx, double in_origy, double in_origz, double in_widthx, double in_widthy, double in_widthz)
 
void project_map_lattice (double **outmap, unsigned ref_extx, unsigned ref_exty, unsigned ref_extz, double ref_origx, double ref_origy, double ref_origz, double ref_widthx, double ref_widthy, double ref_widthz, double *inmap, unsigned in_extx, unsigned in_exty, unsigned in_extz, double in_origx, double in_origy, double in_origz, double in_widthx, double in_widthy, double in_widthz)
 
void shrink_margin (double **outmap, unsigned *out_extx, unsigned *out_exty, unsigned *out_extz, double *out_origx, double *out_origy, double *out_origz, unsigned long *out_nvox, double *inmap, unsigned in_extx, unsigned in_exty, unsigned in_extz, double in_origx, double in_origy, double in_origz, double widthx, double widthy, double widthz)
 
double calc_total (double *phi, unsigned long nvox)
 
double calc_average (double *phi, unsigned long nvox)
 
double calc_sigma (double *phi, unsigned long nvox)
 
double calc_norm (double *phi, unsigned long nvox)
 
double calc_gz_average (double *phi, unsigned long nvox)
 
double calc_gz_sigma (double *phi, unsigned long nvox)
 
double calc_gz_norm (double *phi, unsigned long nvox)
 
double calc_max (double *phi, unsigned long nvox)
 
double calc_min (double *phi, unsigned long nvox)
 
void calc_map_info (double *phi, unsigned long nvox, double *maxdens, double *mindens, double *ave, double *sig)
 
void print_map_info (double *phi, unsigned long nvox)
 
void threshold (double *phi, unsigned long nvox, double limit)
 
void step_threshold (double *phi, unsigned long nvox, double limit)
 
void boost_factor_high (double *phi, unsigned long nvox, double limit, double scale)
 
void boost_power_high (double *phi, unsigned long nvox, double limit, double lexpo)
 
void normalize (double *phi, unsigned long nvox, double factor)
 
void floatshift (double *phi, unsigned long nvox, double dens)
 
int clipped (double *phi, unsigned long nvox, double max, double min)
 
void create_gaussian (double **phi, unsigned long *nvox, unsigned *ext, double sigmap, double sigma_factor)
 
void shrink_to_sigma_factor (double **outmap, unsigned *out_ext, double *inmap, unsigned in_ext, double sigmap, double sigma_factor)
 
void create_identity (double **phi, unsigned long *nvox, unsigned *ext)
 
void create_laplacian (double **phi, unsigned long *nvox, unsigned *ext)
 
void relax_laplacian (double **phi, unsigned extx, unsigned exty, unsigned extz, unsigned ignored[3], double radius)
 
void convolve_kernel_inside (double **outmap, double *inmap, unsigned in_extx, unsigned in_exty, unsigned in_extz, double *kernel, unsigned kernel_size)
 
void convolve_kernel_inside_fast (double **outmap, double *inmap, unsigned in_extx, unsigned in_exty, unsigned in_extz, double *kernel, unsigned kernel_size, double normfac, unsigned ignored[3])
 
void convolve_kernel_inside_erode (double **outmap, double *inmap, unsigned in_extx, unsigned in_exty, unsigned in_extz, double *kernel, unsigned kernel_size)
 
void convolve_kernel_outside (double **outmap, unsigned *out_extx, unsigned *out_exty, unsigned *out_extz, double *out_origx, double *out_origy, double *out_origz, double *inmap, unsigned in_extx, unsigned in_exty, unsigned in_extz, double in_origx, double in_origy, double in_origz, double widthx, double widthy, double widthz, double *kernel, unsigned kernel_size)
 
int print_histogram (unsigned *extx, unsigned *exty, unsigned *extz, double **phi, int nbins)
 
void print_diff_histogram (unsigned *extx, unsigned *exty, unsigned *extz, double **phi, int nbins)
 

Macro Definition Documentation

◆ BARL

#define BARL   70 /* available space for histogram bars */

Definition at line 20 of file lib_vwk.cpp.

Function Documentation

◆ boost_factor_high()

void boost_factor_high ( double *  phi,
unsigned long  nvox,
double  limit,
double  scale 
)

Definition at line 557 of file lib_vwk.cpp.

558 {
559  unsigned long m;
560 
561  for (m = 0; m < nvox; m++) if (*(phi + m) > limit) *(phi + m) *= scale;
562 }
int m

◆ boost_power_high()

void boost_power_high ( double *  phi,
unsigned long  nvox,
double  limit,
double  lexpo 
)

Definition at line 566 of file lib_vwk.cpp.

567 {
568  unsigned long m;
569  double lnorm, lconst;
570 
571  if (limit == 0) for (m = 0; m < nvox; m++) if (*(phi + m) > limit) *(phi + m) = pow(*(phi + m), lexpo);
572  else {
573  lnorm = 1.0 / (lexpo * pow(limit, (lexpo - 1.0)));
574  lconst = (1.0 - 1.0 / lexpo) * limit;
575  for (m = 0; m < nvox; m++) if (*(phi + m) > limit) *(phi + m) = lconst + pow(*(phi + m), lexpo) * lnorm;
576  }
577 }
int m

◆ calc_average()

double calc_average ( double *  phi,
unsigned long  nvox 
)

Definition at line 368 of file lib_vwk.cpp.

369 {
370  double total_density;
371  unsigned long m;
372  total_density = 0.0;
373  for (m = 0; m < nvox; m++) {
374  total_density += (*(phi + m));
375  }
376  return total_density / ((double)nvox);
377 }
int m

◆ calc_gz_average()

double calc_gz_average ( double *  phi,
unsigned long  nvox 
)

Definition at line 410 of file lib_vwk.cpp.

411 {
412  double total_density = 0.0;
413  unsigned long m = 0, t = 0;
414 
415  for (m = 0; m < nvox; m++) {
416  if (*(phi + m) > 0) {
417  total_density += (*(phi + m));
418  ++t;
419  }
420  }
421  if (t > 0) return total_density / ((double)t);
422  else return 0.0;
423 }
int m

◆ calc_gz_norm()

double calc_gz_norm ( double *  phi,
unsigned long  nvox 
)

Definition at line 446 of file lib_vwk.cpp.

447 {
448  unsigned long m = 0, t = 0;
449  double varsum = 0.0;
450 
451  for (m = 0; m < nvox; m++) {
452  if (*(phi + m) > 0) {
453  varsum += (*(phi + m)) * (*(phi + m));
454  ++t;
455  }
456  }
457  if (t > 0) return sqrt((varsum) / ((double)t));
458  else return 0.0;
459 }
void sqrt(Image< double > &op)
int m

◆ calc_gz_sigma()

double calc_gz_sigma ( double *  phi,
unsigned long  nvox 
)

Definition at line 427 of file lib_vwk.cpp.

428 {
429  unsigned long m = 0, t = 0;
430  double ave = 0.0, varsum = 0.0;
431 
432  ave = calc_gz_average(phi, nvox);
433 
434  for (m = 0; m < nvox; m++) {
435  if (*(phi + m) > 0) {
436  varsum += (*(phi + m) - ave) * (*(phi + m) - ave);
437  ++t;
438  }
439  }
440  if (t > 0) return sqrt((varsum) / ((double)t));
441  else return 0.0;
442 }
void sqrt(Image< double > &op)
double calc_gz_average(double *phi, unsigned long nvox)
Definition: lib_vwk.cpp:410
int m

◆ calc_map_info()

void calc_map_info ( double *  phi,
unsigned long  nvox,
double *  maxdens,
double *  mindens,
double *  ave,
double *  sig 
)

Definition at line 491 of file lib_vwk.cpp.

492 {
493  unsigned long m;
494 
495  *maxdens = -1e20;
496  *mindens = 1e20;
497  *ave = 0.0;
498  for (m = 0; m < nvox; m++) {
499  if (*(phi + m) > *maxdens) *maxdens = *(phi + m);
500  if (*(phi + m) < *mindens) *mindens = *(phi + m);
501  *ave += *(phi + m);
502  }
503  *ave /= (double)nvox;
504  *sig = 0.0;
505  for (m = 0; m < nvox; m++) if (*(phi + m) > 0) *sig += (*(phi + m) - *ave) * (*(phi + m) - *ave);
506  *sig /= (double)nvox;
507  *sig = sqrt(*sig);
508 }
void sqrt(Image< double > &op)
int m

◆ calc_max()

double calc_max ( double *  phi,
unsigned long  nvox 
)

Definition at line 463 of file lib_vwk.cpp.

464 {
465  unsigned long m;
466  double maxdens;
467 
468  maxdens = -1e20;
469  for (m = 0; m < nvox; m++) {
470  if (*(phi + m) > maxdens) maxdens = *(phi + m);
471  }
472  return maxdens;
473 }
int m

◆ calc_min()

double calc_min ( double *  phi,
unsigned long  nvox 
)

Definition at line 477 of file lib_vwk.cpp.

478 {
479  unsigned long m;
480  double mindens;
481 
482  mindens = 1e20;
483  for (m = 0; m < nvox; m++) {
484  if (*(phi + m) < mindens) mindens = *(phi + m);
485  }
486  return mindens;
487 }
int m

◆ calc_norm()

double calc_norm ( double *  phi,
unsigned long  nvox 
)

Definition at line 396 of file lib_vwk.cpp.

397 {
398  unsigned long m;
399  double varsum;
400 
401  varsum = 0.0;
402  for (m = 0; m < nvox; m++) {
403  varsum += (*(phi + m)) * (*(phi + m));
404  }
405  return sqrt((varsum) / ((double)nvox));
406 }
void sqrt(Image< double > &op)
int m

◆ calc_sigma()

double calc_sigma ( double *  phi,
unsigned long  nvox 
)

Definition at line 381 of file lib_vwk.cpp.

382 {
383  unsigned long m;
384  double ave, varsum;
385 
386  ave = calc_average(phi, nvox);
387  varsum = 0.0;
388  for (m = 0; m < nvox; m++) {
389  varsum += (*(phi + m) - ave) * (*(phi + m) - ave);
390  }
391  return sqrt((varsum) / ((double)nvox));
392 }
void sqrt(Image< double > &op)
double calc_average(double *phi, unsigned long nvox)
Definition: lib_vwk.cpp:368
int m

◆ calc_total()

double calc_total ( double *  phi,
unsigned long  nvox 
)

Definition at line 357 of file lib_vwk.cpp.

358 {
359  unsigned long m;
360  double total_density;
361  total_density = 0.0;
362  for (m = 0; m < nvox; m++) total_density += (*(phi + m));
363  return total_density;
364 }
int m

◆ clipped()

int clipped ( double *  phi,
unsigned long  nvox,
double  max,
double  min 
)

Definition at line 603 of file lib_vwk.cpp.

604 {
605  unsigned i;
606  int clipping = 0;
607 
608  for (i = 0; i < nvox; i++) {
609  if (*(phi + i) < min) {
610  *(phi + i) = min;
611  clipping = 1;
612  } else if (*(phi + i) > max) {
613  *(phi + i) = max;
614  clipping = 1;
615  }
616  }
617  return clipping;
618 }
void min(Image< double > &op1, const Image< double > &op2)
#define i
void max(Image< double > &op1, const Image< double > &op2)

◆ convolve_kernel_inside()

void convolve_kernel_inside ( double **  outmap,
double *  inmap,
unsigned  in_extx,
unsigned  in_exty,
unsigned  in_extz,
double *  kernel,
unsigned  kernel_size 
)

Definition at line 819 of file lib_vwk.cpp.

822 {
823  double dval;
824  unsigned long out_nvox;
825  unsigned indx, indy, indz;
826  int indx2, indy2, indz2, margin;
827  double *tmpmap;
828  const char *program = "lib_vwk";
829 
830  if (kernel_size < 1 || 2 * ((kernel_size + 1) / 2) - kernel_size - 1 != 0) {
831  error_kernel_size(17140, program, kernel_size);
832  }
833 
834  margin = (kernel_size - 1) / 2;
835  out_nvox = in_extx * in_exty * in_extz;
836 
837  do_vect(&tmpmap, out_nvox);
838  cp_vect(&tmpmap, &inmap, out_nvox); /* save inmap in case it gets overwritten */
839  zero_vect(*outmap, out_nvox);
840 
841  for (indz = margin; indz < in_extz - margin; indz++)
842  for (indy = margin; indy < in_exty - margin; indy++)
843  for (indx = margin; indx < in_extx - margin; indx++) {
844  dval = *(tmpmap + gidz_general(indz, indy, indx, in_exty, in_extx));
845  if (dval != 0.0) for (indz2 = -margin; indz2 <= margin; indz2++)
846  for (indy2 = -margin; indy2 <= margin; indy2++)
847  for (indx2 = -margin; indx2 <= margin; indx2++) {
848  *(*outmap + gidz_general(indz + indz2, indy + indy2, indx + indx2, in_exty, in_extx))
849  += *(kernel + gidz_cube(indz2 + margin, indy2 + margin, indx2 + margin, kernel_size)) * dval;
850  }
851  }
852  free_vect_and_zero_ptr((void**)&tmpmap);
853 }
void free_vect_and_zero_ptr(void **pvect)
Definition: lib_vec.cpp:83
unsigned long gidz_general(int k, int j, int i, unsigned ey, unsigned ex)
Definition: lib_vwk.cpp:32
unsigned long gidz_cube(int k, int j, int i, unsigned ext)
Definition: lib_vwk.cpp:25
void error_kernel_size(int error_number, const char *program, unsigned kernal_size)
Definition: lib_err.cpp:283
void do_vect(double **pvect, unsigned long len)
Definition: lib_vec.cpp:32
void cp_vect(double **vect1, double **vect2, unsigned long len)
Definition: lib_vec.cpp:44
void zero_vect(double *vect, unsigned long len)
Definition: lib_vec.cpp:26

◆ convolve_kernel_inside_erode()

void convolve_kernel_inside_erode ( double **  outmap,
double *  inmap,
unsigned  in_extx,
unsigned  in_exty,
unsigned  in_extz,
double *  kernel,
unsigned  kernel_size 
)

Definition at line 896 of file lib_vwk.cpp.

899 {
900  unsigned long out_nvox;
901  unsigned indx, indy, indz;
902  int indx2, indy2, indz2, margin;
903  double *tmpmap;
904  double dval, dval2;
905  unsigned skip;
906  const char *program = "lib_vwk";
907 
908  if (kernel_size < 1 || 2 * ((kernel_size + 1) / 2) - kernel_size - 1 != 0) {
909  error_kernel_size(17150, program, kernel_size);
910  }
911 
912  margin = (kernel_size - 1) / 2;
913  out_nvox = in_extx * in_exty * in_extz;
914 
915  do_vect(&tmpmap, out_nvox);
916  cp_vect(&tmpmap, &inmap, out_nvox); /* save inmap in case it gets overwritten */
917  zero_vect(*outmap, out_nvox);
918 
919  for (indz = margin; indz < in_extz - margin; indz++)
920  for (indy = margin; indy < in_exty - margin; indy++)
921  for (indx = margin; indx < in_extx - margin; indx++) {
922  skip = 0;
923  for (indz2 = -margin; skip == 0 && indz2 <= margin; indz2++)
924  for (indy2 = -margin; skip == 0 && indy2 <= margin; indy2++)
925  for (indx2 = -margin; skip == 0 && indx2 <= margin; indx2++) { /* check if kernel hits zero density */
926  dval = *(tmpmap + gidz_general(indz + indz2, indy + indy2, indx + indx2, in_exty, in_extx));
927  dval2 = *(kernel + gidz_cube(margin - indz2, margin - indy2, margin - indx2, kernel_size));
928  if (dval == 0.0 && dval2 != 0.0) skip = 1;
929  }
930  if (skip == 0) {
931  for (indz2 = -margin; indz2 <= margin; indz2++)
932  for (indy2 = -margin; indy2 <= margin; indy2++)
933  for (indx2 = -margin; indx2 <= margin; indx2++) {
934  dval = *(tmpmap + gidz_general(indz + indz2, indy + indy2, indx + indx2, in_exty, in_extx));
935  dval2 = *(kernel + gidz_cube(margin - indz2, margin - indy2, margin - indx2, kernel_size));
936  *(*outmap + gidz_general(indz, indy, indx, in_exty, in_extx)) += dval * dval2;
937  }
938  }
939  }
940  free_vect_and_zero_ptr((void**)&tmpmap);
941 }
void free_vect_and_zero_ptr(void **pvect)
Definition: lib_vec.cpp:83
unsigned long gidz_general(int k, int j, int i, unsigned ey, unsigned ex)
Definition: lib_vwk.cpp:32
unsigned long gidz_cube(int k, int j, int i, unsigned ext)
Definition: lib_vwk.cpp:25
void error_kernel_size(int error_number, const char *program, unsigned kernal_size)
Definition: lib_err.cpp:283
void do_vect(double **pvect, unsigned long len)
Definition: lib_vec.cpp:32
void cp_vect(double **vect1, double **vect2, unsigned long len)
Definition: lib_vec.cpp:44
void zero_vect(double *vect, unsigned long len)
Definition: lib_vec.cpp:26

◆ convolve_kernel_inside_fast()

void convolve_kernel_inside_fast ( double **  outmap,
double *  inmap,
unsigned  in_extx,
unsigned  in_exty,
unsigned  in_extz,
double *  kernel,
unsigned  kernel_size,
double  normfac,
unsigned  ignored[3] 
)

Definition at line 859 of file lib_vwk.cpp.

862 {
863  double dval, inv_normfac;
864  unsigned long out_nvox;
865  unsigned indx, indy, indz;
866  int indx2, indy2, indz2, margin, marginx, marginy, marginz;
867 
868  margin = (kernel_size - 1) / 2;
869  marginx = margin + ignored[0];
870  marginy = margin + ignored[1];
871  marginz = margin + ignored[2];
872  out_nvox = in_extx * in_exty * in_extz;
873  inv_normfac = 1.0 / normfac;
874 
875  zero_vect(*outmap, out_nvox);
876 
877  for (indz = marginz; indz < in_extz - marginz; indz++)
878  for (indy = marginy; indy < in_exty - marginy; indy++)
879  for (indx = marginx; indx < in_extx - marginx; indx++) {
880  dval = (*(inmap + gidz_general(indz, indy, indx, in_exty, in_extx))) * inv_normfac;
881  if (dval != 0.0) for (indz2 = -margin; indz2 <= margin; indz2++)
882  for (indy2 = -margin; indy2 <= margin; indy2++)
883  for (indx2 = -margin; indx2 <= margin; indx2++) {
884  *(*outmap + gidz_general(indz + indz2, indy + indy2, indx + indx2, in_exty, in_extx))
885  += *(kernel + gidz_cube(indz2 + margin, indy2 + margin, indx2 + margin, kernel_size)) * dval;
886  }
887  }
888 }
unsigned long gidz_general(int k, int j, int i, unsigned ey, unsigned ex)
Definition: lib_vwk.cpp:32
unsigned long gidz_cube(int k, int j, int i, unsigned ext)
Definition: lib_vwk.cpp:25
void zero_vect(double *vect, unsigned long len)
Definition: lib_vec.cpp:26

◆ convolve_kernel_outside()

void convolve_kernel_outside ( double **  outmap,
unsigned *  out_extx,
unsigned *  out_exty,
unsigned *  out_extz,
double *  out_origx,
double *  out_origy,
double *  out_origz,
double *  inmap,
unsigned  in_extx,
unsigned  in_exty,
unsigned  in_extz,
double  in_origx,
double  in_origy,
double  in_origz,
double  widthx,
double  widthy,
double  widthz,
double *  kernel,
unsigned  kernel_size 
)

Definition at line 947 of file lib_vwk.cpp.

953 {
954  double dval;
955  unsigned long out_nvox;
956  unsigned long in_nvox;
957  unsigned indx, indy, indz, tmp_extx, tmp_exty;
958  int indx2, indy2, indz2, margin;
959  double *tmpmap;
960  const char *program = "lib_vwk";
961 
962  if (kernel_size < 1 || 2 * ((kernel_size + 1) / 2) - kernel_size - 1 != 0) {
963  error_kernel_size(17160, program, kernel_size);
964  }
965 
966  margin = (kernel_size - 1) / 2;
967  tmp_extx = in_extx;
968  tmp_exty = in_exty;
969  *out_extx = kernel_size - 1 + in_extx; /* may overwrite in_extx */
970  *out_exty = kernel_size - 1 + in_exty; /* may overwrite in_exty */
971  *out_extz = kernel_size - 1 + in_extz; /* may overwrite in_extz */
972 
973  in_nvox = in_extx * in_exty * in_extz;
974  out_nvox = (*out_extx) * (*out_exty) * (*out_extz);
975 
976  do_vect(&tmpmap, in_nvox);
977  cp_vect(&tmpmap, &inmap, in_nvox); /* save inmap in case it gets overwritten */
978  zero_vect(*outmap, out_nvox);
979 
980  for (indz = margin; indz < (*out_extz) - margin; indz++)
981  for (indy = margin; indy < (*out_exty) - margin; indy++)
982  for (indx = margin; indx < (*out_extx) - margin; indx++) {
983  dval = *(tmpmap + gidz_general(indz - margin, indy - margin, indx - margin, tmp_exty, tmp_extx));
984  if (dval != 0.0) for (indz2 = -margin; indz2 <= margin; indz2++)
985  for (indy2 = -margin; indy2 <= margin; indy2++)
986  for (indx2 = -margin; indx2 <= margin; indx2++) {
987  *(*outmap + gidz_general(indz + indz2, indy + indy2, indx + indx2, (*out_exty), (*out_extx)))
988  += *(kernel + gidz_cube(indz2 + margin, indy2 + margin, indx2 + margin, kernel_size)) * dval;
989  }
990  }
991  free_vect_and_zero_ptr((void**)&tmpmap);
992  *out_origx = in_origx - widthx * margin;
993  *out_origy = in_origy - widthy * margin;
994  *out_origz = in_origz - widthz * margin;
995 }
void free_vect_and_zero_ptr(void **pvect)
Definition: lib_vec.cpp:83
unsigned long gidz_general(int k, int j, int i, unsigned ey, unsigned ex)
Definition: lib_vwk.cpp:32
unsigned long gidz_cube(int k, int j, int i, unsigned ext)
Definition: lib_vwk.cpp:25
void error_kernel_size(int error_number, const char *program, unsigned kernal_size)
Definition: lib_err.cpp:283
void do_vect(double **pvect, unsigned long len)
Definition: lib_vec.cpp:32
void cp_vect(double **vect1, double **vect2, unsigned long len)
Definition: lib_vec.cpp:44
void zero_vect(double *vect, unsigned long len)
Definition: lib_vec.cpp:26

◆ create_gaussian()

void create_gaussian ( double **  phi,
unsigned long *  nvox,
unsigned *  ext,
double  sigmap,
double  sigma_factor 
)

Definition at line 625 of file lib_vwk.cpp.

627 {
628  int exth, indx, indy, indz;
629  double dsqu;
630  double mscale;
631  unsigned long count;
632  double bvalue, cvalue;
633 
634  /* truncate at sigma_factor * sigma1D */
635  exth = (int) ceil(sigma_factor * sigmap);
636  *ext = 2 * exth - 1;
637  *nvox = *ext * *ext * *ext;
638 
639  printf("lib_vwk> Generating Gaussian kernel with %d^3 = %lu voxels.\n", *ext, *nvox);
640  do_vect(phi, *nvox);
641 
642  /* write Gaussian within sigma_factor * sigma-1D to map */
643  bvalue = -1.0 / (2.0 * sigmap * sigmap);
644  cvalue = sigma_factor * sigma_factor * sigmap * sigmap;
645 
646  mscale = 0.0;
647  for (indz = 0; indz < (int)*ext; indz++)
648  for (indy = 0; indy < (int)*ext; indy++)
649  for (indx = 0; indx < (int)*ext; indx++) {
650  dsqu = (indx - exth + 1) * (indx - exth + 1) +
651  (indy - exth + 1) * (indy - exth + 1) +
652  (indz - exth + 1) * (indz - exth + 1);
653  if (dsqu <= cvalue)
654  *(*phi + gidz_cube(indz, indy, indx, *ext)) = exp(dsqu * bvalue);
655  mscale += *(*phi + gidz_cube(indz, indy, indx, *ext));
656  }
657  for (count = 0; count < *nvox; count++) *(*phi + count) /= mscale;
658 }
unsigned long gidz_cube(int k, int j, int i, unsigned ext)
Definition: lib_vwk.cpp:25
void do_vect(double **pvect, unsigned long len)
Definition: lib_vec.cpp:32

◆ create_identity()

void create_identity ( double **  phi,
unsigned long *  nvox,
unsigned *  ext 
)

Definition at line 707 of file lib_vwk.cpp.

708 {
709  *ext = 1;
710  *nvox = 1;
711  do_vect(phi, *nvox);
712  *(*phi + 0) = 1.0;
713 }
void do_vect(double **pvect, unsigned long len)
Definition: lib_vec.cpp:32

◆ create_laplacian()

void create_laplacian ( double **  phi,
unsigned long *  nvox,
unsigned *  ext 
)

Definition at line 717 of file lib_vwk.cpp.

718 {
719  int indx, indy, indz;
720  double lap_discrete[3][3][3] = {
721  { {0.0, 0.0, 0.0}, {0.0, 1. / 12.0, 0.0}, {0.0, 0.0, 0.0} },
722  { {0.0, 1.0 / 12.0, 0.0}, {1.0 / 12.0, -6.0 / 12.0, 1.0 / 12.0}, {0.0, 1.0 / 12.0, 0.0} },
723  { {0.0, 0.0, 0.0}, {0.0, 1.0 / 12.0, 0.0}, {0.0, 0.0, 0.0} }
724  };
725 
726  *ext = 3;
727  *nvox = *ext * *ext * *ext;
728 
729  printf("lib_vwk> Generating Laplacian kernel with %d^3 = %lu voxels.\n", *ext, *nvox);
730  do_vect(phi, *nvox);
731 
732  for (indz = 0; indz < (int)*ext; indz++)
733  for (indy = 0; indy < (int)*ext; indy++)
734  for (indx = 0; indx < (int)*ext; indx++)
735  *(*phi + gidz_cube(indz, indy, indx, *ext)) = lap_discrete[indx][indy][indz];
736 }
unsigned long gidz_cube(int k, int j, int i, unsigned ext)
Definition: lib_vwk.cpp:25
void do_vect(double **pvect, unsigned long len)
Definition: lib_vec.cpp:32

◆ create_padded_map()

void create_padded_map ( double **  outmap,
unsigned *  out_extx,
unsigned *  out_exty,
unsigned *  out_extz,
double *  out_origx,
double *  out_origy,
double *  out_origz,
unsigned long *  out_nvox,
double *  inmap,
unsigned  in_extx,
unsigned  in_exty,
unsigned  in_extz,
double  in_origx,
double  in_origy,
double  in_origz,
double  widthx,
double  widthy,
double  widthz,
unsigned  margin[3] 
)

Definition at line 40 of file lib_vwk.cpp.

46 {
47  unsigned indz, indx, indy;
48  unsigned long index_old, index_new;
49 
50  *out_nvox = (in_extx + margin[0] * 2) * (in_exty + margin[1] * 2) * (in_extz + margin[2] * 2);
51  do_vect(outmap, *out_nvox);
52 
53  for (indz = 0; indz < in_extz; indz++)
54  for (indy = 0; indy < in_exty; indy++)
55  for (indx = 0; indx < in_extx; indx++) {
56  index_old = in_extx * in_exty * indz + in_extx * indy + indx;
57  index_new = ((in_extx + 2 * margin[0]) * (in_exty + 2 * margin[1]) *
58  (indz + margin[2]) + (in_extx + 2 * margin[0]) *
59  (indy + margin[1]) + (indx + margin[0]));
60  *(*outmap + index_new) = *(inmap + index_old);
61  }
62 
63  *out_extx = in_extx + margin[0] * 2; /* may destroy in_extx if out_extx points to it */
64  *out_exty = in_exty + margin[1] * 2; /* may destroy in_exty if out_exty points to it */
65  *out_extz = in_extz + margin[2] * 2; /* may destroy in_extz if out_extz points to it */
66  *out_origx = in_origx - margin[0] * widthx; /* may destroy in_origx if out_origx points to it */
67  *out_origy = in_origy - margin[1] * widthy; /* may destroy in_origy if out_origy points to it */
68  *out_origz = in_origz - margin[2] * widthz; /* may destroy in_origz if out_origz points to it */
69 
70  /* input variables are no longer used since they may have been overwritten */
71  printf("lib_vwk> Map size expanded from %d x %d x %d to %d x %d x %d by zero-padding.\n",
72  *out_extx - margin[0] * 2, *out_exty - margin[1] * 2, *out_extz - margin[2] * 2,
73  *out_extx, *out_exty, *out_extz);
74  printf("lib_vwk> New map origin (coord of first voxel): (%.3f,%.3f,%.3f)\n", *out_origx, *out_origy, *out_origz);
75 }
void do_vect(double **pvect, unsigned long len)
Definition: lib_vec.cpp:32

◆ floatshift()

void floatshift ( double *  phi,
unsigned long  nvox,
double  dens 
)

Definition at line 594 of file lib_vwk.cpp.

595 {
596  unsigned i;
597 
598  for (i = 0; i < nvox; i++) *(phi + i) -= dens;
599 }
#define i

◆ gidz_cube()

unsigned long gidz_cube ( int  k,
int  j,
int  i,
unsigned  ext 
)

Definition at line 25 of file lib_vwk.cpp.

26 {
27  return ext * ext * k + ext * j + i;
28 }
#define i
ql0001_ & k(htemp+1),(cvec+1),(atemp+1),(bj+1),(bl+1),(bu+1),(x+1),(clamda+1), &iout, infoqp, &zero,(w+1), &lenw,(iw+1), &leniw, &glob_grd.epsmac
#define j

◆ gidz_general()

unsigned long gidz_general ( int  k,
int  j,
int  i,
unsigned  ey,
unsigned  ex 
)

Definition at line 32 of file lib_vwk.cpp.

33 {
34  return ex * ey * k + ex * j + i;
35 }
#define i
ql0001_ & k(htemp+1),(cvec+1),(atemp+1),(bj+1),(bl+1),(bu+1),(x+1),(clamda+1), &iout, infoqp, &zero,(w+1), &lenw,(iw+1), &leniw, &glob_grd.epsmac
#define j

◆ interpolate_map()

void interpolate_map ( double **  outmap,
unsigned *  out_extx,
unsigned *  out_exty,
unsigned *  out_extz,
double *  out_origx,
double *  out_origy,
double *  out_origz,
double  out_widthx,
double  out_widthy,
double  out_widthz,
double *  inmap,
unsigned  in_extx,
unsigned  in_exty,
unsigned  in_extz,
double  in_origx,
double  in_origy,
double  in_origz,
double  in_widthx,
double  in_widthy,
double  in_widthz 
)

Definition at line 82 of file lib_vwk.cpp.

88 {
89 
90  int isx_out, isy_out, isz_out;
91  int iex_out, iey_out, iez_out;
92  double deltax, deltay, deltaz;
93  unsigned long out_nvox;
94  unsigned indx, indy, indz;
95  unsigned sx, sy, sz;
96  double xpos, ypos, zpos, gx, gy, gz, a, b, c;
97  int x0, y0, z0, x1, y1, z1;
98 
99  /* output start index rel. to coordinate system origin, asserting that outmap is fully embedded in inmap */
100  isx_out = (int)ceil(in_origx / out_widthx);
101  isy_out = (int)ceil(in_origy / out_widthy);
102  isz_out = (int)ceil(in_origz / out_widthz);
103 
104  /* output end index rel. to coordinate system origin, asserting that outmap is fully embedded in inmap */
105  iex_out = (int)floor((in_origx + in_widthx * (in_extx - 1)) / out_widthx);
106  iey_out = (int)floor((in_origy + in_widthy * (in_exty - 1)) / out_widthy);
107  iez_out = (int)floor((in_origz + in_widthz * (in_extz - 1)) / out_widthz);
108 
109  /* assign output grid size */
110  sx = in_extx;
111  sy = in_exty;
112  sz = in_extz; /* save input size parameters in case they get over written */
113  *out_extx = iex_out - isx_out + 1; /* may destroy in_extx if out_extx points to it */
114  *out_exty = iey_out - isy_out + 1; /* may destroy in_exty if out_exty points to it */
115  *out_extz = iez_out - isz_out + 1; /* may destroy in_extz if out_extz points to it */
116  if (*out_extx < 2 || *out_exty < 2 || *out_extz < 2) {
117  error_underflow(17005, "lib_vwk");
118  }
119 
120  /* save origin shift */
121  deltax = isx_out * out_widthx - in_origx;
122  deltay = isy_out * out_widthy - in_origy;
123  deltaz = isz_out * out_widthz - in_origz;
124 
125  /* now allocate outmap */
126  out_nvox = (*out_extx) * (*out_exty) * (*out_extz);
127  do_vect(outmap, out_nvox);
128 
129  /* loop through outmap */
130  for (indz = 0; indz < *out_extz; indz++)
131  for (indy = 0; indy < *out_exty; indy++)
132  for (indx = 0; indx < *out_extx; indx++) {
133 
134  /* determine position of outmap voxel relative to start of inmap */
135  xpos = deltax + indx * out_widthx;
136  ypos = deltay + indy * out_widthy;
137  zpos = deltaz + indz * out_widthz;
138 
139  /* compute position in inmap voxel units */
140  gx = (xpos / in_widthx);
141  gy = (ypos / in_widthy);
142  gz = (zpos / in_widthz);
143 
144  /* compute bounding box voxel indices and linear distances */
145  x0 = (int) floor(gx);
146  y0 = (int) floor(gy);
147  z0 = (int) floor(gz);
148  x1 = (int) ceil(gx);
149  y1 = (int) ceil(gy);
150  z1 = (int) ceil(gz);
151  a = gx - x0;
152  b = gy - y0;
153  c = gz - z0;
154 
155  /* interpolate */
156  *(*outmap + gidz_general(indz, indy, indx, *out_exty, *out_extx)) =
157  a * b * c * *(inmap + gidz_general(z1, y1, x1, sy, sx)) +
158  (1 - a) * b * c * *(inmap + gidz_general(z1, y1, x0, sy, sx)) +
159  a * (1 - b) * c * *(inmap + gidz_general(z1, y0, x1, sy, sx)) +
160  a * b * (1 - c) * *(inmap + gidz_general(z0, y1, x1, sy, sx)) +
161  a * (1 - b) * (1 - c) * *(inmap + gidz_general(z0, y0, x1, sy, sx)) +
162  (1 - a) * b * (1 - c) * *(inmap + gidz_general(z0, y1, x0, sy, sx)) +
163  (1 - a) * (1 - b) * c * *(inmap + gidz_general(z1, y0, x0, sy, sx)) +
164  (1 - a) * (1 - b) * (1 - c) * *(inmap + gidz_general(z0, y0, x0, sy, sx));
165  }
166 
167  *out_origx = in_origx + deltax; /* may destroy in_origx if out_origx points to it */
168  *out_origy = in_origy + deltay; /* may destroy in_origy if out_origy points to it */
169  *out_origz = in_origz + deltaz; /* may destroy in_origz if out_origz points to it */
170 
171  /* don't use in_origx, in_origy, in_origz below this line since they may have been overwritten */
172  if (sx != *out_extx || sy != *out_exty || sz != *out_extz)
173  printf("lib_vwk> Map interpolated from %d x %d x %d to %d x %d x %d.\n",
174  sx, sy, sz, *out_extx, *out_exty, *out_extz);
175  if (in_widthx != out_widthx || in_widthy != out_widthy || in_widthz != out_widthz)
176  printf("lib_vwk> Voxel spacings interpolated from (%.3f,%.3f,%.3f) to (%.3f,%.3f,%.3f).\n",
177  in_widthx, in_widthy, in_widthz, out_widthx, out_widthy, out_widthz);
178  if (deltax != 0.0 || deltay != 0.0 || deltaz != 0.0)
179  printf("lib_vwk> New map origin (coord of first voxel), in register with coordinate system origin: (%.3f,%.3f,%.3f)\n", *out_origx, *out_origy, *out_origz);
180 }
__host__ __device__ float2 floor(const float2 v)
doublereal * c
unsigned long gidz_general(int k, int j, int i, unsigned ey, unsigned ex)
Definition: lib_vwk.cpp:32
#define z0
doublereal * b
#define y0
#define x0
void do_vect(double **pvect, unsigned long len)
Definition: lib_vec.cpp:32
void error_underflow(int error_number, const char *program)
Definition: lib_err.cpp:263
doublereal * a

◆ normalize()

void normalize ( double *  phi,
unsigned long  nvox,
double  factor 
)

Definition at line 581 of file lib_vwk.cpp.

582 {
583  unsigned i;
584  const char *program = "lib_vwk";
585 
586  if (factor == 0.0) {
587  error_normalize(17130, program);
588  }
589  for (i = 0; i < nvox; i++) *(phi + i) /= factor;
590 }
void error_normalize(int error_number, const char *program)
Definition: lib_err.cpp:273
#define i

◆ print_diff_histogram()

void print_diff_histogram ( unsigned *  extx,
unsigned *  exty,
unsigned *  extz,
double **  phi,
int  nbins 
)

Definition at line 1114 of file lib_vwk.cpp.

1116 {
1117 
1118 
1119  unsigned long nvox, count;
1120  double maxdensity, mindensity, scale;
1121  int *his, *phis;
1122  int currp, current;
1123  int peak, i, j;
1124  double *pphi;
1125 
1126  nvox = *extx * *exty * *extz;
1127  pphi = *phi;
1128 
1129  /* make nbins odd */
1130  nbins = (1 + 2 * (nbins / 2));
1131  printf("lib_vwk> Printing centered difference histogram (%d histogram bins used):\n", nbins);
1132 
1133 
1134  mindensity = calc_min(pphi, nvox);
1135  maxdensity = calc_max(pphi, nvox);
1136  printf("lib_vwk> Difference density range: %f to %f, ", mindensity, maxdensity);
1137  if (maxdensity > -mindensity) {
1138  maxdensity = -mindensity;
1139  printf("upper tail clipped, ");
1140  } else {
1141  mindensity = -maxdensity;
1142  printf("lower tail clipped, ");
1143  }
1144  printf("showing %d histogram bins about center:\n", nbins);
1145 
1146  if (maxdensity > mindensity) {
1147 
1148  his = (int *) alloc_vect(nbins, sizeof(int));
1149  phis = (int *) alloc_vect(nbins, sizeof(int));
1150 
1151 
1152  /* set up histogram, ignoring zero values */
1153  for (j = 0; j < nbins; j++) his[j] = 0;
1154  scale = ((nbins - 1) / (maxdensity - mindensity));
1155  for (count = 0; count < nvox; count++) {
1156  if (*(pphi + count) != 0) {
1157  current = (int) floor(0.5 + (*(pphi + count) - mindensity) * scale);
1158  ++his[current];
1159  }
1160  }
1161 
1162  /* determine fullest bin for normalization */
1163  currp = 0;
1164  peak = 0;
1165  for (j = 0; j < nbins; j++) {
1166  if (his[j] >= currp) {
1167  currp = his[j];
1168  peak = j;
1169  }
1170  }
1171  if (his[peak] > 0) {
1172  for (j = 0; j < nbins; j++) {
1173  phis[j] = (int) floor((BARL * his[j] / his[peak]) + 0.5);
1174  }
1175  }
1176 
1177  /* print histogram */
1178  for (j = 0; j < nbins; j++) {
1179  printf("%8.3f |", mindensity + (j / (nbins - 1.0)) * (maxdensity - mindensity));
1180  for (i = 0; i < phis[j]; ++i) printf("=");
1181  printf(" %d ", his[j]);
1182  if (his[peak] > 0) {
1183  if (his[j] > 0) {
1184  if (phis[j] <= BARL) for (i = (int)(floor(log10(his[j])) - floor(log10(his[peak])) - BARL - 3 + phis[j]); i <= 0; ++i) {
1185  if (j == (nbins - 1) / 2) printf(".");
1186  else {
1187  if ((j % 2) || (i % 4)) printf(" ");
1188  else printf(".");
1189  }
1190  }
1191  } else {
1192  for (i = -(int)floor(log10(his[peak])) - BARL - 3 + phis[j]; i <= 0; ++i) {
1193  if (j == (nbins - 1) / 2) printf(".");
1194  else {
1195  if ((j % 2) || (i % 4)) printf(" ");
1196  else printf(".");
1197  }
1198  }
1199  }
1200  }
1201  printf("\n");
1202  }
1203  }
1204  return;
1205 }
__host__ __device__ float2 floor(const float2 v)
#define BARL
Definition: lib_vwk.cpp:20
#define i
double calc_min(double *phi, unsigned long nvox)
Definition: lib_vwk.cpp:477
double calc_max(double *phi, unsigned long nvox)
Definition: lib_vwk.cpp:463
void log10(Image< double > &op)
#define j
struct Convex_T peak(struct stack_T *stack)
Definition: stack.cpp:33
void * alloc_vect(unsigned int n, size_t elem_size)
Definition: lib_vec.cpp:71

◆ print_histogram()

int print_histogram ( unsigned *  extx,
unsigned *  exty,
unsigned *  extz,
double **  phi,
int  nbins 
)

Definition at line 1001 of file lib_vwk.cpp.

1003 {
1004 
1005 
1006  unsigned long nvox, count;
1007  double maxdensity, mindensity, scale;
1008  int *his, *phis;
1009  int currp, currnp, current;
1010  int peak, nextpeak, i, j;
1011  double histotal;
1012  double *hisc;
1013  double *pphi;
1014 
1015  nvox = *extx * *exty * *extz;
1016  pphi = *phi;
1017 
1018  mindensity = calc_min(pphi, nvox);
1019  maxdensity = calc_max(pphi, nvox);
1020  printf("lib_vwk> Density information. min: %f max: %f ave: %f sig: %f norm: %f \n", mindensity, maxdensity, calc_average(pphi, nvox), calc_sigma(pphi, nvox), calc_norm(pphi, nvox));
1021  printf("lib_vwk> Above zero density information. ave: %f sig: %f norm: %f \n", calc_gz_average(pphi, nvox), calc_gz_sigma(pphi, nvox), calc_gz_norm(pphi, nvox));
1022 
1023  if (maxdensity > mindensity) {
1024 
1025  if (nbins <= 0) {
1026  printf("lib_vwk> Please enter the of number histogram bins: ");
1027  nbins = readln_int();
1028  }
1029 
1030  his = (int *) alloc_vect(nbins, sizeof(int));
1031  phis = (int *) alloc_vect(nbins, sizeof(int));
1032  hisc = (double *) alloc_vect(nbins, sizeof(double));
1033 
1034  printf("lib_vwk> Printing voxel histogram, %d histogram bins\n", nbins);
1035  printf("lib_vwk> (density value; voxel count; top-down cumulative volume fraction):\n");
1036 
1037  for (j = 0; j < nbins; j++) {
1038  his[j] = 0;
1039  hisc[j] = 0.0;
1040  }
1041  scale = ((nbins - 1) / (maxdensity - mindensity));
1042  for (count = 0; count < nvox; count++) {
1043  current = (int) floor(0.5 + (*(pphi + count) - mindensity) * scale);
1044  ++his[current];
1045  }
1046 
1047  /* determine two fullest bins for normalization */
1048  currp = 0;
1049  currnp = 0;
1050  nextpeak = 0;
1051  peak = 0;
1052  for (j = 0; j < nbins; j++) {
1053  if (his[j] >= currp) {
1054  currnp = currp;
1055  nextpeak = peak;
1056  currp = his[j];
1057  peak = j;
1058  } else if (his[j] >= currnp) {
1059  currnp = his[j];
1060  nextpeak = j;
1061  }
1062  }
1063 
1064  histotal = 0.0;
1065  for (j = 0; j < nbins; j++) histotal += his[j];
1066  hisc[0] = 1.0;
1067 
1068  if (histotal > 0) for (j = 1; j < nbins; j++) hisc[j] = hisc [j - 1] - (his[j - 1] / histotal);
1069  else for (j = 1; j < nbins; j++) hisc[j] = 0;
1070 
1071  if (his[nextpeak] > 0) {
1072  for (j = 0; j < nbins; j++) {
1073  phis[j] = (int) floor((BARL * his[j] / his[nextpeak]) + 0.5);
1074  if (phis[j] > BARL) phis[j] = BARL + 1;
1075  }
1076  } else {
1077  if (his[peak] > 0) {
1078  for (j = 0; j < nbins; j++) {
1079  phis[j] = (int)floor((BARL * his[j] / his[peak]) + 0.5);
1080  if (phis[j] > BARL) phis[j] = BARL + 1;
1081  }
1082  } else for (j = 0; j < nbins; j++) phis[j] = 0;
1083  }
1084 
1085  /* print histogram */
1086  for (j = 0; j < nbins; j++) {
1087  printf("%8.3f |", mindensity + (j / (nbins - 1.0)) * (maxdensity - mindensity));
1088  for (i = 0; i < phis[j]; ++i) printf("=");
1089  if (phis[j] > BARL) printf("->");
1090  printf(" %d ", his[j]);
1091  if (his[peak] > 0) {
1092  if (his[j] > 0) {
1093  if (phis[j] <= BARL) for (i = (int)(floor(log10(his[j])) - floor(log10(his[peak])) - BARL - 3 + phis[j]); i < 0; ++i) {
1094  if ((j % 2) || (i % 4)) printf(" ");
1095  else printf(".");
1096  }
1097  } else {
1098  for (i = -(int)floor(log10(his[peak])) - BARL - 3 + phis[j]; i < 0; ++i) {
1099  if ((j % 2) || (i % 4)) printf(" ");
1100  else printf(".");
1101  }
1102  }
1103  }
1104  printf("| %5.3e\n", hisc[j]);
1105  }
1106  printf("lib_vwk> Maximum at density value %5.3f\n", mindensity + (peak / (nbins - 1.0)) * (maxdensity - mindensity));
1107  }
1108  return nbins;
1109 }
__host__ __device__ float2 floor(const float2 v)
#define BARL
Definition: lib_vwk.cpp:20
double calc_gz_average(double *phi, unsigned long nvox)
Definition: lib_vwk.cpp:410
double calc_average(double *phi, unsigned long nvox)
Definition: lib_vwk.cpp:368
#define i
int readln_int()
Definition: lib_std.cpp:19
double calc_sigma(double *phi, unsigned long nvox)
Definition: lib_vwk.cpp:381
double calc_gz_norm(double *phi, unsigned long nvox)
Definition: lib_vwk.cpp:446
double calc_norm(double *phi, unsigned long nvox)
Definition: lib_vwk.cpp:396
double calc_gz_sigma(double *phi, unsigned long nvox)
Definition: lib_vwk.cpp:427
double calc_min(double *phi, unsigned long nvox)
Definition: lib_vwk.cpp:477
double calc_max(double *phi, unsigned long nvox)
Definition: lib_vwk.cpp:463
void log10(Image< double > &op)
#define j
struct Convex_T peak(struct stack_T *stack)
Definition: stack.cpp:33
void * alloc_vect(unsigned int n, size_t elem_size)
Definition: lib_vec.cpp:71

◆ print_map_info()

void print_map_info ( double *  phi,
unsigned long  nvox 
)

Definition at line 513 of file lib_vwk.cpp.

514 {
515  double maxdens, mindens, sig, ave;
516 
517  calc_map_info(phi, nvox, &maxdens, &mindens, &ave, &sig);
518  printf("lib_vwk> Map density info: max %f, min %f, ave %f, sig %f.\n", maxdens, mindens, ave, sig);
519 }
void calc_map_info(double *phi, unsigned long nvox, double *maxdens, double *mindens, double *ave, double *sig)
Definition: lib_vwk.cpp:491

◆ project_map_lattice()

void project_map_lattice ( double **  outmap,
unsigned  ref_extx,
unsigned  ref_exty,
unsigned  ref_extz,
double  ref_origx,
double  ref_origy,
double  ref_origz,
double  ref_widthx,
double  ref_widthy,
double  ref_widthz,
double *  inmap,
unsigned  in_extx,
unsigned  in_exty,
unsigned  in_extz,
double  in_origx,
double  in_origy,
double  in_origz,
double  in_widthx,
double  in_widthy,
double  in_widthz 
)

Definition at line 185 of file lib_vwk.cpp.

191 {
192 
193  double deltax, deltay, deltaz;
194  unsigned long out_nvox;
195  unsigned indx, indy, indz;
196  double xpos, ypos, zpos, gx, gy, gz, a, b, c;
197  int x0, y0, z0, x1, y1, z1;
198 
199  if (ref_extx < 2 || ref_exty < 2 || ref_extz < 2) {
200  error_underflow(17010, "lib_vwk");
201  }
202  /* save origin shift */
203  deltax = ref_origx - in_origx;
204  deltay = ref_origy - in_origy;
205  deltaz = ref_origz - in_origz;
206 
207  /* now allocate outmap */
208  out_nvox = (ref_extx) * (ref_exty) * (ref_extz);
209  do_vect(outmap, out_nvox);
210 
211  /* loop through outmap */
212  for (indz = 0; indz < ref_extz; indz++)
213  for (indy = 0; indy < ref_exty; indy++)
214  for (indx = 0; indx < ref_extx; indx++) {
215 
216  /* determine position of outmap voxel relative to start of inmap */
217  xpos = deltax + indx * ref_widthx;
218  ypos = deltay + indy * ref_widthy;
219  zpos = deltaz + indz * ref_widthz;
220 
221  /* compute position in inmap index units */
222  gx = (xpos / in_widthx);
223  gy = (ypos / in_widthy);
224  gz = (zpos / in_widthz);
225 
226  /* compute probe box voxel indices and linear distances */
227  x0 = (int) floor(gx);
228  y0 = (int) floor(gy);
229  z0 = (int) floor(gz);
230  x1 = (int) ceil(gx);
231  y1 = (int) ceil(gy);
232  z1 = (int) ceil(gz);
233 
234  /* if probe box inside inmap interpolate */
235  if (x0 >= 0 && x1 < (int)in_extx && y0 >= 0 && y1 < (int)in_exty && z0 >= 0 && z1 < (int)in_extz) {
236  a = gx - x0;
237  b = gy - y0;
238  c = gz - z0;
239  *(*outmap + gidz_general(indz, indy, indx, ref_exty, ref_extx)) =
240  a * b * c * *(inmap + gidz_general(z1, y1, x1, in_exty, in_extx)) +
241  (1 - a) * b * c * *(inmap + gidz_general(z1, y1, x0, in_exty, in_extx)) +
242  a * (1 - b) * c * *(inmap + gidz_general(z1, y0, x1, in_exty, in_extx)) +
243  a * b * (1 - c) * *(inmap + gidz_general(z0, y1, x1, in_exty, in_extx)) +
244  a * (1 - b) * (1 - c) * *(inmap + gidz_general(z0, y0, x1, in_exty, in_extx)) +
245  (1 - a) * b * (1 - c) * *(inmap + gidz_general(z0, y1, x0, in_exty, in_extx)) +
246  (1 - a) * (1 - b) * c * *(inmap + gidz_general(z1, y0, x0, in_exty, in_extx)) +
247  (1 - a) * (1 - b) * (1 - c) * *(inmap + gidz_general(z0, y0, x0, in_exty, in_extx));
248  }
249  }
250 
251  /* print some info */
252  if (in_extx != ref_extx || in_exty != ref_exty || in_extz != ref_extz)
253  printf("lib_vwk> %d x %d x %d map projected to %d x %d x %d lattice.\n",
254  in_extx, in_exty, in_extz, ref_extx, ref_exty, ref_extz);
255  if (in_widthx != ref_widthx || in_widthy != ref_widthy || in_widthz != ref_widthz)
256  printf("lib_vwk> Voxel spacings interpolated from (%.3f,%.3f,%.3f) to (%.3f,%.3f,%.3f).\n",
257  in_widthx, in_widthy, in_widthz, ref_widthx, ref_widthy, ref_widthz);
258  if (deltax != 0.0 || deltay != 0.0 || deltaz != 0.0)
259  printf("lib_vwk> New map origin (coord of first voxel): (%.3f,%.3f,%.3f)\n", ref_origx, ref_origy, ref_origz);
260 }
__host__ __device__ float2 floor(const float2 v)
doublereal * c
unsigned long gidz_general(int k, int j, int i, unsigned ey, unsigned ex)
Definition: lib_vwk.cpp:32
#define z0
doublereal * b
#define y0
#define x0
void do_vect(double **pvect, unsigned long len)
Definition: lib_vec.cpp:32
void error_underflow(int error_number, const char *program)
Definition: lib_err.cpp:263
doublereal * a

◆ relax_laplacian()

void relax_laplacian ( double **  phi,
unsigned  extx,
unsigned  exty,
unsigned  extz,
unsigned  ignored[3],
double  radius 
)

Definition at line 742 of file lib_vwk.cpp.

744 {
745  double average[27] = {0.0, 0.0, 0.0, 0.0, 1.0 / 6.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0 / 6.0, 0.0, 1.0 / 6.0, 0.0, 1.0 / 6.0, 0.0, 1.0 / 6.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0 / 6.0, 0.0, 0.0, 0.0, 0.0};
746  double *nextphi, diff, norm;
747  unsigned long nvox, indv, indw, threscount, maskcount;
748  char *mask;
749  unsigned indx, indy, indz;
750  int indx2, indy2, indz2;
751  int margx, margy, margz, margin;
752  const char *program = "lib_vwk";
753 
754  margx = (int)(ignored[0] + radius);
755  margy = (int)(ignored[1] + radius);
756  margz = (int)(ignored[2] + radius);
757  margin = (int) ceil(radius);
758  printf("lib_vwk> Relaxing %d voxel thick shell about thresholded density... \n", margin);
759 
760  /* allocate phi mask */
761  nvox = extx * exty * extz;
762  mask = (char *) alloc_vect(nvox, sizeof(char));
763  for (indv = 0; indv < nvox; indv++)
764  *(mask + indv) = 1;
765 
766  /* assign phi mask value based on distance to thresholded map */
767  for (indz = margz; indz < extz - margz; indz++)
768  for (indy = margy; indy < exty - margy; indy++)
769  for (indx = margx; indx < extx - margx; indx++) {
770  indv = gidz_general(indz, indy, indx, exty, extx);
771  if (*(*phi + indv) != 0)
772  for (indz2 = -margin; indz2 <= margin; indz2++)
773  for (indy2 = -margin; indy2 <= margin; indy2++)
774  for (indx2 = -margin; indx2 <= margin; indx2++) {
775  indw = gidz_general(indz + indz2, indy + indy2, indx + indx2, exty, extx);
776  if (*(*phi + indw) == 0.0 && indz2 * indz2 + indy2 * indy2 + indx2 * indx2 < radius * radius) *(mask + indw) = 0;
777  }
778  }
779  /* compute norm */
780  maskcount = 0;
781  threscount = 0;
782  norm = 0.0;
783  for (indv = 0; indv < nvox; indv++) {
784  if (*(*phi + indv) != 0.0) {
785  ++threscount;
786  norm += *(*phi + indv);
787  } else if (*(mask + indv) == 0) ++maskcount;
788  }
789  if (0 == threscount) {
790  printf("threscount was 0 (zero)\n");
791  exit(-1);
792  }
793  norm /= (double)threscount; /* average density for thresholded volume, assuming threscount>0 */
794  norm *= maskcount;/* density total one would get if mask=0 was filled with average */
795 
796  /* iterate on original lattice, no focusing */
797  do_vect(&nextphi, nvox);
798  do {
799  convolve_kernel_inside_fast(&nextphi, *phi, extx, exty, extz, average, 3, 1.0, ignored);
800  diff = 0.0;
801  for (indz = ignored[2]; indz < extz - ignored[2]; indz++)
802  for (indy = ignored[1]; indy < exty - ignored[1]; indy++)
803  for (indx = ignored[0]; indx < extx - ignored[0]; indx++) {
804  indv = gidz_general(indz, indy, indx, exty, extx);
805  if (*(mask + indv) == 0) {
806  diff += fabs(*(nextphi + indv) - * (*phi + indv));
807  *(*phi + indv) = *(nextphi + indv);
808  }
809  }
810  } while (diff > 1E-8 * norm);
811  free_vect_and_zero_ptr((void**)&nextphi);
812  free_vect_and_zero_ptr((void**)&mask);
813 }
void free_vect_and_zero_ptr(void **pvect)
Definition: lib_vec.cpp:83
unsigned long gidz_general(int k, int j, int i, unsigned ey, unsigned ex)
Definition: lib_vwk.cpp:32
T norm(const std::vector< T > &v)
Definition: vector_ops.h:399
void convolve_kernel_inside_fast(double **outmap, double *inmap, unsigned in_extx, unsigned in_exty, unsigned in_extz, double *kernel, unsigned kernel_size, double normfac, unsigned ignored[3])
Definition: lib_vwk.cpp:859
void do_vect(double **pvect, unsigned long len)
Definition: lib_vec.cpp:32
void * alloc_vect(unsigned int n, size_t elem_size)
Definition: lib_vec.cpp:71

◆ shrink_margin()

void shrink_margin ( double **  outmap,
unsigned *  out_extx,
unsigned *  out_exty,
unsigned *  out_extz,
double *  out_origx,
double *  out_origy,
double *  out_origz,
unsigned long *  out_nvox,
double *  inmap,
unsigned  in_extx,
unsigned  in_exty,
unsigned  in_extz,
double  in_origx,
double  in_origy,
double  in_origz,
double  widthx,
double  widthy,
double  widthz 
)

Definition at line 266 of file lib_vwk.cpp.

271 {
272  unsigned m, p, q, sx, sy, sz;
273  unsigned minx, miny, minz, maxx, maxy, maxz;
274  int margin[6];
275  unsigned indz, indx, indy;
276  unsigned long index_old, index_new;
277  const char *program = "lib_vwk";
278 
279  maxx = 0;
280  maxy = 0;
281  maxz = 0;
282  minx = in_extx - 1;
283  miny = in_exty - 1;
284  minz = in_extz - 1;
285 
286  for (q = 0; q < in_extz; q++)
287  for (m = 0; m < in_exty; m++)
288  for (p = 0; p < in_extx; p++)
289  if (*(inmap + gidz_general(q, m, p, in_exty, in_extx)) > 0) {
290  if (p <= minx) minx = p;
291  if (p >= maxx) maxx = p;
292  if (m <= miny) miny = m;
293  if (m >= maxy) maxy = m;
294  if (q <= minz) minz = q;
295  if (q >= maxz) maxz = q;
296  }
297 
298  if (maxx < minx) {
299  error_density(17020, program);
300  }
301 
302  margin[1] = in_extx - maxx - 1;
303  margin[3] = in_exty - maxy - 1;
304  margin[5] = in_extz - maxz - 1;
305  margin[0] = minx;
306  margin[2] = miny;
307  margin[4] = minz;
308 
309  /* compute new grid size */
310  p = in_extx - (margin[0] + margin[1]);
311  m = in_exty - (margin[2] + margin[3]);
312  q = in_extz - (margin[4] + margin[5]);
313 
314  /* number of map intervals to be odd, if necessary they are increase */
315  if (2 * (p / 2) == p) {
316  p++;
317  if (margin[0] > 0)margin[0]--;
318  }
319  if (2 * (m / 2) == m) {
320  m++;
321  if (margin[2] > 0)margin[2]--;
322  }
323  if (2 * (q / 2) == q) {
324  q++;
325  if (margin[4] > 0)margin[4]--;
326  }
327 
328 
329  *out_nvox = p * m * q;
330  do_vect(outmap, *out_nvox);
331 
332  for (indz = margin[4]; indz < in_extz - margin[5]; indz++)
333  for (indy = margin[2]; indy < in_exty - margin[3]; indy++)
334  for (indx = margin[0]; indx < in_extx - margin[1]; indx++) {
335  index_new = p * m * (indz - margin[4]) + p * (indy - margin[2]) + (indx - margin[0]);
336  index_old = in_extx * in_exty * indz + in_extx * indy + indx;
337  *(*outmap + index_new) = *(inmap + index_old);
338  }
339  sx = in_extx;
340  sy = in_exty;
341  sz = in_extz;
342  *out_extx = p;/* may destroy in_extx if out_extx points to it */
343  *out_exty = m;/* may destroy in_exty if out_exty points to it */
344  *out_extz = q;/* may destroy in_extz if out_extz points to it */
345  *out_origx = in_origx + margin[0] * widthx; /* may destroy in_origx if out_origx points to it */
346  *out_origy = in_origy + margin[2] * widthy; /* may destroy in_origy if out_origy points to it */
347  *out_origz = in_origz + margin[4] * widthz; /* may destroy in_origz if out_origz points to it */
348 
349  /* input variables are no longer used since they may have been overwritten */
350  printf("lib_vwk> Map size changed from %d x %d x %d to %d x %d x %d.\n", sx, sy, sz, *out_extx, *out_exty, *out_extz);
351  printf("lib_vwk> New map origin (coord of first voxel): (%.3f,%.3f,%.3f)\n", *out_origx, *out_origy, *out_origz);
352 }
unsigned long gidz_general(int k, int j, int i, unsigned ey, unsigned ex)
Definition: lib_vwk.cpp:32
int m
void error_density(int error_number, const char *program)
Definition: lib_err.cpp:79
void do_vect(double **pvect, unsigned long len)
Definition: lib_vec.cpp:32

◆ shrink_to_sigma_factor()

void shrink_to_sigma_factor ( double **  outmap,
unsigned *  out_ext,
double *  inmap,
unsigned  in_ext,
double  sigmap,
double  sigma_factor 
)

Definition at line 663 of file lib_vwk.cpp.

665 {
666  int exth, indx, indy, indz;
667  unsigned long nvox, index_old, index_new;
668  unsigned margin;
669  double cvalue, dsqu;
670  const char *program = "lib_vwk";
671 
672  /* truncate at sigma_factor * sigma1D */
673  exth = (int) ceil(sigma_factor * sigmap);
674  *out_ext = 2 * exth - 1;
675  if (*out_ext > in_ext || 2 * (in_ext / 2) == in_ext) {
676  error_kernels(17030, program);
677  }
678  nvox = *out_ext * *out_ext * *out_ext;
679  cvalue = sigma_factor * sigma_factor * sigmap * sigmap;
680 
681  printf("lib_vwk> Generating kernel with %d^3 = %lu voxels.\n", *out_ext, nvox);
682  do_vect(outmap, nvox);
683 
684  margin = (in_ext - *out_ext) / 2;
685  for (indz = margin; indz < (int)(in_ext - margin); indz++)
686  for (indy = margin; indy < (int)(in_ext - margin); indy++)
687  for (indx = margin; indx < (int)(in_ext - margin); indx++) {
688  index_new = *out_ext * *out_ext * (indz - margin) + *out_ext * (indy - margin) + (indx - margin);
689  index_old = in_ext * in_ext * indz + in_ext * indy + indx;
690  *(*outmap + index_new) = *(inmap + index_old);
691  }
692 
693  /* make the kernel spherical */
694  for (indz = 0; indz < (int)*out_ext; indz++)
695  for (indy = 0; indy < (int)*out_ext; indy++)
696  for (indx = 0; indx < (int)*out_ext; indx++) {
697  index_new = (*out_ext) * (*out_ext) * indz + (*out_ext) * indy + indx;
698  dsqu = (indx - exth + 1) * (indx - exth + 1) +
699  (indy - exth + 1) * (indy - exth + 1) +
700  (indz - exth + 1) * (indz - exth + 1);
701  if (dsqu > cvalue) *(*outmap + index_new) = 0.0;
702  }
703 }
void error_kernels(int error_number, const char *program)
Definition: lib_err.cpp:278
void do_vect(double **pvect, unsigned long len)
Definition: lib_vec.cpp:32

◆ step_threshold()

void step_threshold ( double *  phi,
unsigned long  nvox,
double  limit 
)

Definition at line 540 of file lib_vwk.cpp.

541 {
542  unsigned long m, v;
543 
544  v = nvox;
545  for (m = 0; m < nvox; m++) {
546  if (*(phi + m) < limit) {
547  *(phi + m) = 0.0;
548  --v;
549  } else *(phi + m) = 1.0;
550  }
551  printf("lib_vwk> Setting density values below %f to zero and equal or above to one.\n", limit);
552  printf("lib_vwk> Remaining occupied volume: %lu voxels.\n", v);
553 }
int m

◆ threshold()

void threshold ( double *  phi,
unsigned long  nvox,
double  limit 
)

Definition at line 524 of file lib_vwk.cpp.

525 {
526  unsigned long m, v;
527 
528  v = nvox;
529  for (m = 0; m < nvox; m++) if (*(phi + m) < limit) {
530  *(phi + m) = 0.0;
531  --v;
532  }
533  printf("lib_vwk> Setting density values below %f to zero.\n", limit);
534  printf("lib_vwk> Remaining occupied volume: %lu voxels.\n", v);
535 }
int m