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