DESCRIPTION.TREE 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /* updated by Mitasova Nov. 96, no changes necessary */
  2. DATa STRUCTURES:
  3. ----------------
  4. #define VOID_T char
  5. struct multfunc {
  6. int (*compare) ();
  7. VOID_T **(*divide_data) ();
  8. int (*add_data) ();
  9. int (*intersect) ();
  10. int (*division_check) ();
  11. int (*get_points) ();
  12. };
  13. struct tree_info {
  14. struct multfunc *functions;
  15. double dmin;
  16. int kmax;
  17. struct multtree *root;
  18. };
  19. struct multtree {
  20. VOID_T *data;
  21. struct multtree **leafs;
  22. struct multtree *parent;
  23. int multant;
  24. };
  25. FUNCTIONS:
  26. ----------
  27. struct multfunc * MT_functions_new(compare,divide_data,add_data,
  28. intersect,division_check,get_points)
  29. int (*compare) ();
  30. VOID_T **(*divide_data) ();
  31. int (*add_data) ();
  32. int (*intersect) ();
  33. int (*division_check) ();
  34. int (*get_points) ();
  35. /* Initializes FUNCTIONS structure with given arguments*/
  36. struct tree_info * MT_tree_info_new (root,functions,dmin,kmax)
  37. struct multtree *root;
  38. struct multfunc *functions;
  39. double dmin;
  40. int kmax;
  41. /*Initializes TREE_INFO using given arguments*/
  42. struct multtree * MT_tree_new (data, leafs, parent, multant)
  43. VOID_T *data;
  44. struct multtree **leafs;
  45. struct multtree *parent;
  46. int multant;
  47. /*Initializes TREE using given arguments*/
  48. int
  49. MT_insert (point,info,tree,n_leafs)
  50. VOID_T *point;
  51. struct tree_info *info;
  52. struct multtree *tree;
  53. int n_leafs;
  54. /*First checks for dividing cond. (if n_points>=KMAX) and TREE is a leaf
  55. by calling one of tree's functions (division_check()).
  56. If TREE is not a leaf (is a node) uses function compare to determine
  57. into which "son" we need to insert the point and calls MT_insert()
  58. with this son as a n argument.
  59. If TREE is a leaf but we don't need to divide it (n_points<KMAX) then
  60. calls function add_data(POINT) to add POINT to the data of TREE and
  61. returns the result of add_data() (which returns 1 if the point is
  62. inserted and 0 if its ignored (when its too dense)).
  63. If Division_check returns true, calls MT_divide(TREE) and then calls
  64. insert_quad() to insert the POINT into divided TREE and returns the
  65. result of MT_divide(). */
  66. int
  67. MT_divide (info,tree,n_leafs)
  68. struct tree_info *info;
  69. struct multtree *tree;
  70. int n_leafs;
  71. /* Divides the tree by calling one of tree's functions (divide_data())
  72. and returns the result of divide_data() */
  73. int
  74. MT_region_data (info, tree, data, MAX, n_leafs)
  75. struct tree_info *info;
  76. struct multtree *tree;
  77. VOID_T *data;
  78. int MAX; /* max number of points we can add (KMAX2) */
  79. int n_leafs;
  80. /* Gets points inside the region defined by DATA from TREE and
  81. adds them to DATA. If the number of eligible
  82. point is more than MAX returns MAX+1 othervise returns number of points added
  83. to DATA.
  84. Uses tree's functions intersect() to find leafs that intersect given region
  85. and get_points() to get points from such leafs. */