| 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 |
|
| 11 |
#pragma once |
| 12 |
|
| 13 |
#include <stdio.h> |
| 14 |
|
| 15 |
#ifdef __cplusplus |
| 16 |
extern "C" { |
| 17 |
#endif |
| 18 |
|
| 19 |
typedef struct node_data_struct *node_data; |
| 20 |
|
| 21 |
struct node_data_struct { |
| 22 |
double node_weight; |
| 23 |
double *coord; |
| 24 |
int id; |
| 25 |
void *data; |
| 26 |
node_data next; |
| 27 |
}; |
| 28 |
|
| 29 |
typedef struct QuadTree_struct *QuadTree; |
| 30 |
|
| 31 |
struct QuadTree_struct { |
| 32 |
/* a data structure containing coordinates of n items, their average is in "average". |
| 33 |
The current level is a square or cube of width "width", which is subdivided into |
| 34 |
2^dim QuadTrees qts. At the last level, all coordinates are stored in a single linked list l. |
| 35 |
total_weight is the combined weights of the nodes */ |
| 36 |
int n;/* number of items */ |
| 37 |
double total_weight; |
| 38 |
int dim; |
| 39 |
double *center;/* center of the bounding box, array of dimension dim. Allocated inside */ |
| 40 |
double width;/* center +/- width gives the lower/upper bound, so really width is the |
| 41 |
"radius" */ |
| 42 |
double *average;/* the average coordinates. Array of length dim. Allocated inside */ |
| 43 |
QuadTree *qts;/* subtree . If dim = 2, there are 4, dim = 3 gives 8 */ |
| 44 |
node_data l; |
| 45 |
int max_level; |
| 46 |
void *data; |
| 47 |
}; |
| 48 |
|
| 49 |
|
| 50 |
QuadTree QuadTree_new(int dim, double *center, double width, int max_level); |
| 51 |
|
| 52 |
void QuadTree_delete(QuadTree q); |
| 53 |
|
| 54 |
QuadTree QuadTree_add(QuadTree q, double *coord, double weight, int id);/* coord is copied in */ |
| 55 |
|
| 56 |
void QuadTree_print(FILE *fp, QuadTree q); |
| 57 |
|
| 58 |
QuadTree QuadTree_new_from_point_list(int dim, int n, int max_level, double *coord); |
| 59 |
|
| 60 |
double point_distance(double *p1, double *p2, int dim); |
| 61 |
|
| 62 |
void QuadTree_get_supernodes(QuadTree qt, double bh, double *pt, int nodeid, int *nsuper, |
| 63 |
int *nsupermax, double **center, double **supernode_wgts, double **distances, double *counts); |
| 64 |
|
| 65 |
void QuadTree_get_repulsive_force(QuadTree qt, double *force, double *x, double bh, double p, double KP, double *counts); |
| 66 |
|
| 67 |
/* find the nearest point and put in ymin, index in imin and distance in min */ |
| 68 |
void QuadTree_get_nearest(QuadTree qt, double *x, double *ymin, int *imin, double *min); |
| 69 |
|
| 70 |
QuadTree QuadTree_new_in_quadrant(int dim, double *center, double width, int max_level, int i); |
| 71 |
|
| 72 |
#ifdef __cplusplus |
| 73 |
} |
| 74 |
#endif |