QuadTree.h 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /*************************************************************************
  2. * Copyright (c) 2011 AT&T Intellectual Property
  3. * All rights reserved. This program and the accompanying materials
  4. * are made available under the terms of the Eclipse Public License v1.0
  5. * which accompanies this distribution, and is available at
  6. * https://www.eclipse.org/legal/epl-v10.html
  7. *
  8. * Contributors: Details at https://graphviz.org
  9. *************************************************************************/
  10. #pragma once
  11. #include <stdio.h>
  12. #ifdef __cplusplus
  13. extern "C" {
  14. #endif
  15. typedef struct node_data_struct *node_data;
  16. struct node_data_struct {
  17. double node_weight;
  18. double *coord;
  19. int id;
  20. void *data;
  21. node_data next;
  22. };
  23. typedef struct QuadTree_struct *QuadTree;
  24. struct QuadTree_struct {
  25. /* a data structure containing coordinates of n items, their average is in "average".
  26. The current level is a square or cube of width "width", which is subdivided into
  27. 2^dim QuadTrees qts. At the last level, all coordinates are stored in a single linked list l.
  28. total_weight is the combined weights of the nodes */
  29. int n;/* number of items */
  30. double total_weight;
  31. int dim;
  32. double *center;/* center of the bounding box, array of dimension dim. Allocated inside */
  33. double width;/* center +/- width gives the lower/upper bound, so really width is the
  34. "radius" */
  35. double *average;/* the average coordinates. Array of length dim. Allocated inside */
  36. QuadTree *qts;/* subtree . If dim = 2, there are 4, dim = 3 gives 8 */
  37. node_data l;
  38. int max_level;
  39. void *data;
  40. };
  41. QuadTree QuadTree_new(int dim, double *center, double width, int max_level);
  42. void QuadTree_delete(QuadTree q);
  43. QuadTree QuadTree_add(QuadTree q, double *coord, double weight, int id);/* coord is copied in */
  44. void QuadTree_print(FILE *fp, QuadTree q);
  45. QuadTree QuadTree_new_from_point_list(int dim, int n, int max_level, double *coord);
  46. double point_distance(double *p1, double *p2, int dim);
  47. void QuadTree_get_supernodes(QuadTree qt, double bh, double *pt, int nodeid, int *nsuper,
  48. int *nsupermax, double **center, double **supernode_wgts, double **distances, double *counts);
  49. void QuadTree_get_repulsive_force(QuadTree qt, double *force, double *x, double bh, double p, double KP, double *counts);
  50. /* find the nearest point and put in ymin, index in imin and distance in min */
  51. void QuadTree_get_nearest(QuadTree qt, double *x, double *ymin, int *imin, double *min);
  52. QuadTree QuadTree_new_in_quadrant(int dim, double *center, double width, int max_level, int i);
  53. #ifdef __cplusplus
  54. }
  55. #endif