main.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679
  1. /****************************************************************************
  2. *
  3. * MODULE: v.kernel
  4. *
  5. * AUTHOR(S): Stefano Menegon, ITC-irst, Trento, Italy
  6. * PURPOSE: Generates a raster density map from vector points data using
  7. * a moving 2D isotropic Gaussian kernel or
  8. * optionally generates a vector density map on vector network
  9. * with a 1D kernel
  10. * COPYRIGHT: (C) 2004 by the GRASS Development Team
  11. *
  12. * This program is free software under the GNU General Public
  13. * License (>=v2). Read the file COPYING that comes with GRASS
  14. * for details.
  15. *
  16. *****************************************************************************/
  17. #include <math.h>
  18. #include <stdio.h>
  19. #include <stdlib.h>
  20. #include <float.h>
  21. #include <grass/gis.h>
  22. #include <grass/glocale.h>
  23. #include <grass/gmath.h>
  24. #include <grass/Vect.h>
  25. #include "global.h"
  26. static int ndists; /* number of distances in dists */
  27. static double *dists; /* array of all distances < dmax */
  28. static int npoints;
  29. int net = 0;
  30. static double dimension = 2.;
  31. /* define score function L(window size) */
  32. double L(double smooth)
  33. {
  34. int ii;
  35. double resL, n, term;
  36. n = npoints;
  37. resL = 0.;
  38. term = 1. / pow((2. * M_PI), dimension / 2.);
  39. for (ii = 0; ii < ndists; ii++) {
  40. /* resL+= gaussianFunction(dists[ii]/smooth,2.,dimension) - 2. * gaussianKernel(dists[ii]/smooth,term); */
  41. resL +=
  42. gaussianFunction(dists[ii] / smooth, 2.,
  43. dimension) -
  44. 2. * gaussianFunction(dists[ii] / smooth, 1., dimension);
  45. }
  46. if (!net)
  47. resL *= 2.;
  48. resL =
  49. (1. / (pow(n, 2.) * pow(smooth, dimension))) * (resL +
  50. n *
  51. (gaussianFunction
  52. (0., 2.,
  53. dimension) -
  54. 2. *
  55. gaussianFunction(0.,
  56. 1.,
  57. dimension)))
  58. + (2. / (n * pow(smooth, dimension))) * gaussianFunction(0., 1.,
  59. dimension);
  60. /* resL = (1./(pow(n,2.)*pow(smooth,dimension))) * (resL + n*( gaussianFunction(0.,2.,dimension) - 2. * gaussianKernel(0.,term)) ) + (2./(n*pow(smooth,dimension)))*gaussianKernel(0.,term); */
  61. G_debug(3, "smooth = %e resL = %e", smooth, resL);
  62. G_message(_("\tScore Value=%f\tsmoothing parameter (standard deviation)=%f"),
  63. resL, smooth);
  64. return (resL);
  65. }
  66. int main(int argc, char **argv)
  67. {
  68. struct Option *in_opt, *net_opt, *out_opt;
  69. struct Option *stddev_opt, *dsize_opt, *segmax_opt, *netmax_opt,
  70. *multip_opt;
  71. struct Flag *flag_o, *flag_q;
  72. struct Map_info In, Net, Out;
  73. int fdout = 0, maskfd = 0;
  74. int row, col;
  75. struct Cell_head window;
  76. double gaussian;
  77. double N, E;
  78. CELL *mask = NULL;
  79. DCELL *output_cell = NULL;
  80. double sigma, dmax, segmax, netmax, multip;
  81. double **coordinate;
  82. double sigmaOptimal;
  83. struct GModule *module;
  84. double dsize;
  85. double term;
  86. double gausmax = 0;
  87. /* Initialize the GIS calls */
  88. G_gisinit(argv[0]);
  89. module = G_define_module();
  90. module->keywords = _("vector, kernel density");
  91. module->description =
  92. _("Generates a raster density map from vector points data using a moving 2D isotropic Gaussian kernel or "
  93. "optionally generates a vector density map on vector network with a 1D kernel.");
  94. in_opt = G_define_standard_option(G_OPT_V_INPUT);
  95. in_opt->description = _("Input vector with training points");
  96. net_opt = G_define_standard_option(G_OPT_V_INPUT);
  97. net_opt->key = "net";
  98. net_opt->description = _("Input network vector map");
  99. net_opt->required = NO;
  100. out_opt = G_define_option();
  101. out_opt->key = "output";
  102. out_opt->type = TYPE_STRING;
  103. out_opt->key_desc = "name";
  104. out_opt->required = YES;
  105. out_opt->description = _("Output raster/vector map");
  106. stddev_opt = G_define_option();
  107. stddev_opt->key = "stddeviation";
  108. stddev_opt->type = TYPE_DOUBLE;
  109. stddev_opt->required = YES;
  110. stddev_opt->description = _("Standard deviation in map units");
  111. dsize_opt = G_define_option();
  112. dsize_opt->key = "dsize";
  113. dsize_opt->type = TYPE_DOUBLE;
  114. dsize_opt->required = NO;
  115. dsize_opt->description = _("Discretization error in map units");
  116. dsize_opt->answer = "0.";
  117. segmax_opt = G_define_option();
  118. segmax_opt->key = "segmax";
  119. segmax_opt->type = TYPE_DOUBLE;
  120. segmax_opt->required = NO;
  121. segmax_opt->description = _("Maximum length of segment on network");
  122. segmax_opt->answer = "100.";
  123. netmax_opt = G_define_option();
  124. netmax_opt->key = "distmax";
  125. netmax_opt->type = TYPE_DOUBLE;
  126. netmax_opt->required = NO;
  127. netmax_opt->description = _("Maximum distance from point to network");
  128. netmax_opt->answer = "100.";
  129. multip_opt = G_define_option();
  130. multip_opt->key = "mult";
  131. multip_opt->type = TYPE_DOUBLE;
  132. multip_opt->required = NO;
  133. multip_opt->description = _("Multiply the density result by this number");
  134. multip_opt->answer = "1.";
  135. flag_o = G_define_flag();
  136. flag_o->key = 'o';
  137. flag_o->description =
  138. _("Try to calculate an optimal standard deviation with 'stddeviation' taken as maximum (experimental)");
  139. flag_q = G_define_flag();
  140. flag_q->key = 'q';
  141. flag_q->description =
  142. _("Only calculate optimal standard deviation and exit (no map is written)");
  143. if (G_parser(argc, argv))
  144. exit(EXIT_FAILURE);
  145. /*read options */
  146. sigma = atof(stddev_opt->answer);
  147. dsize = atof(dsize_opt->answer);
  148. segmax = atof(segmax_opt->answer);
  149. netmax = atof(netmax_opt->answer);
  150. multip = atof(multip_opt->answer);
  151. if (flag_q->answer) {
  152. flag_o->answer = 1;
  153. }
  154. if (net_opt->answer) {
  155. Vect_check_input_output_name(in_opt->answer, out_opt->answer,
  156. GV_FATAL_EXIT);
  157. Vect_check_input_output_name(net_opt->answer, out_opt->answer,
  158. GV_FATAL_EXIT);
  159. }
  160. G_get_window(&window);
  161. G_message("STDDEV: %f\nRES: %f\tROWS: %d\tCOLS: %d",
  162. sigma, window.ew_res, window.rows, window.cols);
  163. /* Open input vector */
  164. Vect_set_open_level(2);
  165. Vect_open_old(&In, in_opt->answer, "");
  166. if (net_opt->answer) {
  167. int nlines, line;
  168. int notreachable = 0;
  169. struct line_pnts *Points;
  170. Points = Vect_new_line_struct();
  171. net = 1;
  172. dimension = 1.;
  173. /* Open input network */
  174. Vect_set_open_level(2);
  175. Vect_open_old(&Net, net_opt->answer, "");
  176. Vect_net_build_graph(&Net, GV_LINES, 0, 0, NULL, NULL, NULL, 0, 0);
  177. if (!flag_q->answer) {
  178. Vect_open_new(&Out, out_opt->answer, 0);
  179. Vect_hist_command(&Out);
  180. }
  181. /* verify not reachable points */
  182. nlines = Vect_get_num_lines(&In);
  183. for (line = 1; line <= nlines; line++) {
  184. int ltype;
  185. ltype = Vect_read_line(&In, Points, NULL, line);
  186. if (!(ltype & GV_POINTS))
  187. continue;
  188. if (Vect_find_line
  189. (&Net, Points->x[0], Points->y[0], 0.0, GV_LINES, netmax, 0,
  190. 0) == 0)
  191. notreachable++;
  192. }
  193. if (notreachable > 0)
  194. G_warning(_("%d points outside threshold"), notreachable);
  195. }
  196. else {
  197. /* check and open the name of output map */
  198. if (!flag_q->answer) {
  199. G_set_fp_type(DCELL_TYPE);
  200. if ((fdout = G_open_raster_new(out_opt->answer, DCELL_TYPE)) < 0)
  201. G_fatal_error(_("Unable to create raster map <%s>"),
  202. out_opt->answer);
  203. /* open mask file */
  204. if ((maskfd = G_maskfd()) >= 0)
  205. mask = G_allocate_cell_buf();
  206. else
  207. mask = NULL;
  208. /* allocate output raster */
  209. output_cell = G_allocate_raster_buf(DCELL_TYPE);
  210. }
  211. }
  212. /* valutazione distanza ottimale */
  213. if (flag_o->answer) {
  214. /* Note: sigmaOptimal calculates using ALL points (also those outside the region) */
  215. G_message(_("Automatic choose of smoothing parameter (standard deviation), maximum possible "
  216. "value of standard deviation is was set to %f"), sigma);
  217. /* maximum distance 4*sigma (3.9*sigma ~ 1.0000), keep it small, otherwise it takes
  218. * too much points and calculation on network becomes slow */
  219. dmax = 4 * sigma; /* used as maximum value */
  220. G_message(_("Using maximum distance between points: %f"), dmax);
  221. if (net_opt->answer) {
  222. npoints = Vect_get_num_primitives(&In, GV_POINTS);
  223. /* Warning: each distance is registered twice (both directions) */
  224. ndists =
  225. compute_all_net_distances(&In, &Net, netmax, &dists, dmax);
  226. }
  227. else {
  228. /* Read points */
  229. npoints = read_points(&In, &coordinate, dsize);
  230. ndists = compute_all_distances(coordinate, &dists, npoints, dmax);
  231. }
  232. G_message(_("Number of input points: %d."), npoints);
  233. G_message(_("%d distances read from the map."), ndists);
  234. if (ndists == 0)
  235. G_fatal_error(_("Distances between all points are beyond %e (4 * "
  236. "standard deviation), unable to calculate optimal value."),
  237. dmax);
  238. /* double iii;
  239. for ( iii = 1.; iii <= 10000; iii++){
  240. fprintf(stderr,"i=%f v=%.16f \n",iii,R(iii));
  241. } */
  242. /* sigma is used in brent as maximum possible value for sigmaOptimal */
  243. sigmaOptimal = brent_iterate(L, 0.0, sigma, 1000);
  244. G_message(_("Optimal smoothing parameter (standard deviation): %f."),
  245. sigmaOptimal);
  246. /* Reset sigma to calculated optimal value */
  247. sigma = sigmaOptimal;
  248. if (flag_q->answer) {
  249. Vect_close(&In);
  250. if (net_opt->answer)
  251. Vect_close(&Net);
  252. exit(EXIT_SUCCESS);
  253. }
  254. }
  255. term = 1. / (pow(sigma, dimension) * pow((2. * M_PI), dimension / 2.));
  256. dmax = sigma * 4.;
  257. if (net) {
  258. int line, nlines;
  259. struct line_pnts *Points, *SPoints;
  260. struct line_cats *SCats;
  261. G_message(_("\nWriting output vector map using smooth parameter=%f."),
  262. sigma);
  263. G_message(_("\nNormalising factor=%f."),
  264. 1. / gaussianFunction(sigma / 4., sigma, dimension));
  265. /* Divide lines to segments and calculate gaussian for center of each segment */
  266. Points = Vect_new_line_struct();
  267. SPoints = Vect_new_line_struct();
  268. SCats = Vect_new_cats_struct();
  269. nlines = Vect_get_num_lines(&Net);
  270. G_debug(3, "net nlines = %d", nlines);
  271. for (line = 1; line <= nlines; line++) {
  272. int seg, nseg, ltype;
  273. double llength, length, x, y;
  274. ltype = Vect_read_line(&Net, Points, NULL, line);
  275. if (!(ltype & GV_LINES))
  276. continue;
  277. llength = Vect_line_length(Points);
  278. nseg = (int)(1 + llength / segmax);
  279. length = llength / nseg;
  280. G_debug(3, "net line = %d, nseg = %d, seg length = %f", line,
  281. nseg, length);
  282. for (seg = 0; seg < nseg; seg++) {
  283. double offset1, offset2;
  284. offset1 = (seg + 0.5) * length;
  285. Vect_point_on_line(Points, offset1, &x, &y, NULL, NULL, NULL);
  286. G_debug(3, " segment = %d, offset = %f, xy = %f %f", seg,
  287. offset1, x, y);
  288. compute_net_distance(x, y, &In, &Net, netmax, sigma, term,
  289. &gaussian, dmax);
  290. gaussian *= multip;
  291. if (gaussian > gausmax)
  292. gausmax = gaussian;
  293. G_debug(3, " gaussian = %f", gaussian);
  294. /* Write segment */
  295. if (gaussian > 0) {
  296. offset1 = seg * length;
  297. offset2 = (seg + 1) * length;
  298. if (offset2 > llength)
  299. offset2 = llength;
  300. Vect_line_segment(Points, offset1, offset2, SPoints);
  301. /* TODO!!! remove later
  302. if ( SPoints->n_points > 0 )
  303. Vect_append_point( SPoints, SPoints->x[SPoints->n_points-1],
  304. SPoints->y[SPoints->n_points-1], 0 );
  305. */
  306. Vect_reset_cats(SCats);
  307. Vect_cat_set(SCats, 1, (int)gaussian);
  308. Vect_write_line(&Out, GV_LINE, SPoints, SCats);
  309. }
  310. }
  311. G_percent(line, nlines, 1);
  312. }
  313. Vect_close(&Net);
  314. Vect_build(&Out);
  315. Vect_close(&Out);
  316. }
  317. else {
  318. G_message(_("\nWriting output raster map using smooth parameter=%f."),
  319. sigma);
  320. G_message(_("\nNormalising factor=%f."),
  321. 1. / gaussianFunction(sigma / 4., sigma, dimension));
  322. for (row = 0; row < window.rows; row++) {
  323. G_percent(row, window.rows, 2);
  324. if (mask) {
  325. if (G_get_map_row(maskfd, mask, row) < 0)
  326. G_fatal_error(_("Unable to read MASK"));
  327. }
  328. for (col = 0; col < window.cols; col++) {
  329. /* don't interpolate outside of the mask */
  330. if (mask && mask[col] == 0) {
  331. G_set_d_null_value(&output_cell[col], 1);
  332. continue;
  333. }
  334. N = G_row_to_northing(row + 0.5, &window);
  335. E = G_col_to_easting(col + 0.5, &window);
  336. compute_distance(N, E, &In, sigma, term, &gaussian, dmax);
  337. output_cell[col] = multip * gaussian;
  338. if (gaussian > gausmax)
  339. gausmax = gaussian;
  340. }
  341. G_put_raster_row(fdout, output_cell, DCELL_TYPE);
  342. }
  343. G_close_cell(fdout);
  344. }
  345. G_message(_("Maximum value in output: %e."), gausmax);
  346. Vect_close(&In);
  347. exit(EXIT_SUCCESS);
  348. }
  349. /* Read points to array return number of points */
  350. int read_points(struct Map_info *In, double ***coordinate, double dsize)
  351. {
  352. int line, nlines, npoints, ltype, i = 0;
  353. double **xySites;
  354. static struct line_pnts *Points = NULL;
  355. if (!Points)
  356. Points = Vect_new_line_struct();
  357. /* Allocate array of pointers */
  358. npoints = Vect_get_num_primitives(In, GV_POINT);
  359. xySites = (double **)G_calloc(npoints, sizeof(double *));
  360. nlines = Vect_get_num_lines(In);
  361. for (line = 1; line <= nlines; line++) {
  362. ltype = Vect_read_line(In, Points, NULL, line);
  363. if (!(ltype & GV_POINT))
  364. continue;
  365. xySites[i] = (double *)G_calloc((size_t) 2, sizeof(double));
  366. xySites[i][0] = Points->x[0];
  367. xySites[i][1] = Points->y[0];
  368. i++;
  369. }
  370. *coordinate = xySites;
  371. return (npoints);
  372. }
  373. /* Calculate distances < dmax between all sites in coordinate
  374. * Return: number of distances in dists */
  375. double compute_all_distances(double **coordinate, double **dists, int n,
  376. double dmax)
  377. {
  378. int ii, jj, kk;
  379. size_t nn;
  380. nn = n * (n - 1) / 2;
  381. *dists = (double *)G_calloc(nn, sizeof(double));
  382. kk = 0;
  383. for (ii = 0; ii < n - 1; ii++) {
  384. for (jj = ii + 1; jj < n; jj++) {
  385. double dist;
  386. dist = euclidean_distance(coordinate[ii], coordinate[jj], 2);
  387. G_debug(3, "dist = %f", dist);
  388. if (dist <= dmax) {
  389. (*dists)[kk] = dist;
  390. kk++;
  391. }
  392. }
  393. }
  394. return (kk);
  395. }
  396. /* Calculate distances < dmax between all sites in coordinate
  397. * Return: number of distances in dists */
  398. double compute_all_net_distances(struct Map_info *In, struct Map_info *Net,
  399. double netmax, double **dists, double dmax)
  400. {
  401. int nn, kk, nalines, aline;
  402. double dist;
  403. struct line_pnts *APoints, *BPoints;
  404. BOUND_BOX box;
  405. struct ilist *List;
  406. APoints = Vect_new_line_struct();
  407. BPoints = Vect_new_line_struct();
  408. List = Vect_new_list();
  409. nn = Vect_get_num_primitives(In, GV_POINTS);
  410. nn = nn * (nn - 1);
  411. *dists = (double *)G_calloc(nn, sizeof(double));
  412. kk = 0;
  413. nalines = Vect_get_num_lines(In);
  414. for (aline = 1; aline <= nalines; aline++) {
  415. int i, altype;
  416. G_debug(3, " aline = %d", aline);
  417. altype = Vect_read_line(In, APoints, NULL, aline);
  418. if (!(altype & GV_POINTS))
  419. continue;
  420. box.E = APoints->x[0] + dmax;
  421. box.W = APoints->x[0] - dmax;
  422. box.N = APoints->y[0] + dmax;
  423. box.S = APoints->y[0] - dmax;
  424. box.T = PORT_DOUBLE_MAX;
  425. box.B = -PORT_DOUBLE_MAX;
  426. Vect_select_lines_by_box(In, &box, GV_POINT, List);
  427. G_debug(3, " %d points in box", List->n_values);
  428. for (i = 0; i < List->n_values; i++) {
  429. int bline, ret;
  430. bline = List->value[i];
  431. if (bline == aline)
  432. continue;
  433. G_debug(3, " bline = %d", bline);
  434. Vect_read_line(In, BPoints, NULL, bline);
  435. ret =
  436. Vect_net_shortest_path_coor(Net, APoints->x[0], APoints->y[0],
  437. 0.0, BPoints->x[0], BPoints->y[0],
  438. 0.0, netmax, netmax, &dist, NULL,
  439. NULL, NULL, NULL, NULL, NULL);
  440. G_debug(3, " SP: %f %f -> %f %f", APoints->x[0], APoints->y[0],
  441. BPoints->x[0], BPoints->y[0]);
  442. if (ret == 0) {
  443. G_debug(3, "not reachable");
  444. continue; /* Not reachable */
  445. }
  446. G_debug(3, " dist = %f", dist);
  447. if (dist <= dmax) {
  448. (*dists)[kk] = dist;
  449. kk++;
  450. }
  451. G_debug(3, " kk = %d", kk);
  452. }
  453. }
  454. return (kk);
  455. }
  456. /* Compute gausian for x, y along Net, using all points in In */
  457. void compute_net_distance(double x, double y, struct Map_info *In,
  458. struct Map_info *Net, double netmax, double sigma,
  459. double term, double *gaussian, double dmax)
  460. {
  461. int i;
  462. double dist;
  463. static struct line_pnts *Points = NULL;
  464. BOUND_BOX box;
  465. static struct ilist *List = NULL;
  466. if (!Points)
  467. Points = Vect_new_line_struct();
  468. if (!List)
  469. List = Vect_new_list();
  470. *gaussian = .0;
  471. /* The network is usually much bigger than dmax and to calculate shortest path is slow
  472. * -> use spatial index to select points */
  473. box.E = x + dmax;
  474. box.W = x - dmax;
  475. box.N = y + dmax;
  476. box.S = y - dmax;
  477. box.T = PORT_DOUBLE_MAX;
  478. box.B = -PORT_DOUBLE_MAX;
  479. Vect_select_lines_by_box(In, &box, GV_POINT, List);
  480. G_debug(3, " %d points in box", List->n_values);
  481. for (i = 0; i < List->n_values; i++) {
  482. int line, ret;
  483. line = List->value[i];
  484. Vect_read_line(In, Points, NULL, line);
  485. G_debug(3, " SP: %f %f -> %f %f", x, y, Points->x[0], Points->y[0]);
  486. ret =
  487. Vect_net_shortest_path_coor(Net, x, y, 0.0, Points->x[0],
  488. Points->y[0], 0.0, netmax, netmax,
  489. &dist, NULL, NULL, NULL, NULL, NULL,
  490. NULL);
  491. if (ret == 0) {
  492. G_debug(3, "not reachable");
  493. continue; /* Not reachable */
  494. }
  495. if (dist <= dmax)
  496. *gaussian += gaussianKernel(dist / sigma, term);
  497. G_debug(3, " dist = %f gaussian = %f", dist, *gaussian);
  498. }
  499. }
  500. void compute_distance(double N, double E, struct Map_info *In,
  501. double sigma, double term, double *gaussian,
  502. double dmax)
  503. {
  504. int line, nlines;
  505. double a[2], b[2];
  506. double dist;
  507. /* spatial index handling, borrowed from lib/vector/Vlib/find.c */
  508. BOUND_BOX box;
  509. static struct ilist *NList = NULL;
  510. static struct line_pnts *Points = NULL;
  511. a[0] = E;
  512. a[1] = N;
  513. if (!NList)
  514. NList = Vect_new_list();
  515. if (!Points)
  516. Points = Vect_new_line_struct();
  517. /* create bounding box 2x2*dmax size from the current cell center */
  518. box.N = N + dmax;
  519. box.S = N - dmax;
  520. box.E = E + dmax;
  521. box.W = E - dmax;
  522. box.T = HUGE_VAL;
  523. box.B = -HUGE_VAL;
  524. /* number of lines within dmax box */
  525. nlines = Vect_select_lines_by_box(In, &box, GV_POINT, NList);
  526. *gaussian = .0;
  527. for (line = 0; line < nlines; line++) {
  528. Vect_read_line(In, Points, NULL, NList->value[line]);
  529. b[0] = Points->x[0];
  530. b[1] = Points->y[0];
  531. dist = euclidean_distance(a, b, 2);
  532. if (dist <= dmax)
  533. *gaussian += gaussianKernel(dist / sigma, term);
  534. }
  535. }