Changeset 18344
- Timestamp:
- Jun 27, 2008, 10:27:45 AM (18 years ago)
- File:
-
- 1 edited
-
trunk/psLib/src/types/psTree.c (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/types/psTree.c
r18335 r18344 368 368 PS_ASSERT_TREE_NON_NULL(tree, NULL); 369 369 PS_ASSERT_VECTOR_NON_NULL(coords, NULL); 370 PS_ASSERT_VECTOR_TYPE(coords, PS_TYPE_F64, NULL);371 370 PS_ASSERT_VECTOR_SIZE(coords, (long)tree->dim, NULL); 372 371 #endif 373 372 373 #define TREE_LEAF_CASE(TYPE) \ 374 case PS_TYPE_##TYPE: \ 375 for (; node->left; node = (coords->data.TYPE[node->divideDim] < tree->division[node->index]) ? \ 376 node->left : node->right); \ 377 break; 378 374 379 psTreeNode *node = tree->root; // Node of interest 375 for (; node->left; node = coords->data.F64[node->divideDim] < tree->division[node->index] ? 376 node->left : node->right); 380 switch (coords->type.type) { 381 TREE_LEAF_CASE(U8); 382 TREE_LEAF_CASE(U16); 383 TREE_LEAF_CASE(U32); 384 TREE_LEAF_CASE(U64); 385 TREE_LEAF_CASE(S8); 386 TREE_LEAF_CASE(S16); 387 TREE_LEAF_CASE(S32); 388 TREE_LEAF_CASE(S64); 389 TREE_LEAF_CASE(F32); 390 TREE_LEAF_CASE(F64); 391 default: 392 psError(PS_ERR_BAD_PARAMETER_TYPE, true, "Unsupported type: %x", coords->type.type); 393 return NULL; 394 } 377 395 return node; 378 396 } … … 464 482 // This is the engine for psTreeNearest() and psTreeNearestWithin() 465 483 static inline long treeNearestWithin(const psTree *tree, // Tree 466 const psVector *coord s, // Coordinates of interest484 const psVector *coordinates, // Coordinates of interest 467 485 double bestDistance // Distance (radius-squared) to best point 468 486 ) … … 470 488 #if 1 // Might be in a tight loop 471 489 PS_ASSERT_TREE_NON_NULL(tree, -1); 472 PS_ASSERT_VECTOR_NON_NULL(coords, -1); 473 PS_ASSERT_VECTOR_TYPE(coords, PS_TYPE_F64, -1); 474 PS_ASSERT_VECTOR_SIZE(coords, (long)tree->dim, -1); 490 PS_ASSERT_VECTOR_NON_NULL(coordinates, -1); 491 PS_ASSERT_VECTOR_SIZE(coordinates, (long)tree->dim, -1); 475 492 #endif 493 494 psVector *coords = (coordinates->type.type == PS_TYPE_F64 ? psMemIncrRefCounter((psVector*)coordinates) : 495 psVectorCopy(NULL, coordinates, PS_TYPE_F64)); // F64 version of coordinates 476 496 477 497 // Find the closest point in the leaf that contains the point of interest … … 513 533 } 514 534 psFree(work); 535 psFree(coords); 515 536 516 537 return bestIndex; … … 549 570 550 571 // Given an arbitrary point and a matching radius, return the number of points within that radius 551 long psTreeWithin(const psTree *tree, const psVector *coord s, double radius)572 long psTreeWithin(const psTree *tree, const psVector *coordinates, double radius) 552 573 { 553 574 #if 1 // Might be in a tight loop 554 575 PS_ASSERT_TREE_NON_NULL(tree, -1); 555 PS_ASSERT_VECTOR_NON_NULL(coords, -1); 556 PS_ASSERT_VECTOR_TYPE(coords, PS_TYPE_F64, -1); 557 PS_ASSERT_VECTOR_SIZE(coords, (long)tree->dim, -1); 576 PS_ASSERT_VECTOR_NON_NULL(coordinates, -1); 577 PS_ASSERT_VECTOR_SIZE(coordinates, (long)tree->dim, -1); 558 578 #endif 579 580 psVector *coords = (coordinates->type.type == PS_TYPE_F64 ? psMemIncrRefCounter((psVector*)coordinates) : 581 psVectorCopy(NULL, coordinates, PS_TYPE_F64)); // F64 version of coordinates 559 582 560 583 radius *= radius; // We work with the radius-squared … … 590 613 } 591 614 psFree(work); 615 psFree(coords); 592 616 593 617 return num; … … 612 636 613 637 // Given an arbitrary point and a matching radius, return whether there are any points within that radius 614 bool psTreeWithinAny(const psTree *tree, const psVector *coord s, double radius)638 bool psTreeWithinAny(const psTree *tree, const psVector *coordinates, double radius) 615 639 { 616 640 #if 1 // Might be in a tight loop 617 641 PS_ASSERT_TREE_NON_NULL(tree, false); 618 PS_ASSERT_VECTOR_NON_NULL(coords, false); 619 PS_ASSERT_VECTOR_TYPE(coords, PS_TYPE_F64, false); 620 PS_ASSERT_VECTOR_SIZE(coords, (long)tree->dim, false); 642 PS_ASSERT_VECTOR_NON_NULL(coordinates, false); 643 PS_ASSERT_VECTOR_SIZE(coordinates, (long)tree->dim, false); 621 644 #endif 645 646 psVector *coords = (coordinates->type.type == PS_TYPE_F64 ? psMemIncrRefCounter((psVector*)coordinates) : 647 psVectorCopy(NULL, coordinates, PS_TYPE_F64)); // F64 version of coordinates 622 648 623 649 radius *= radius; // We work with the radius-squared … … 628 654 psTreeNode *leaf = psTreeLeaf(tree, coords); // Leaf containing the point of interest 629 655 if (treeLeafSearchWithinAny(radius, tree, leaf, coords)) { 656 psFree(coords); 630 657 return true; 631 658 } … … 650 677 memset(work->data, 0, (workIndex + 1) * sizeof(void)); 651 678 psFree(work); 679 psFree(coords); 652 680 return true; 653 681 } … … 659 687 } 660 688 psFree(work); 689 psFree(coords); 661 690 662 691 return false;
Note:
See TracChangeset
for help on using the changeset viewer.
