PostGIS  2.5.7dev-r@@SVN_REVISION@@

◆ gserialized_spgist_inner_consistent_3d()

PGDLLEXPORT Datum gserialized_spgist_inner_consistent_3d ( PG_FUNCTION_ARGS  )

Definition at line 505 of file gserialized_spgist_3d.c.

506 {
507  spgInnerConsistentIn *in = (spgInnerConsistentIn *)PG_GETARG_POINTER(0);
508  spgInnerConsistentOut *out = (spgInnerConsistentOut *)PG_GETARG_POINTER(1);
509  int i;
510  MemoryContext old_ctx;
511  CubeBox3D *cube_box;
512  uint8 octant;
513  BOX3D *centroid;
514  int *nodeNumbers;
515  void **traversalValues;
516 
517  if (in->allTheSame)
518  {
519  /* Report that all nodes should be visited */
520  out->nNodes = in->nNodes;
521  out->nodeNumbers = (int *)palloc(sizeof(int) * in->nNodes);
522  for (i = 0; i < in->nNodes; i++)
523  out->nodeNumbers[i] = i;
524 
525  PG_RETURN_VOID();
526  }
527 
528  /*
529  * We are saving the traversal value or initialize it an unbounded one, if
530  * we have just begun to walk the tree.
531  */
532  if (in->traversalValue)
533  cube_box = in->traversalValue;
534  else
535  cube_box = initCubeBox();
536 
537  centroid = DatumGetBox3DP(in->prefixDatum);
538 
539  /* Allocate enough memory for nodes */
540  out->nNodes = 0;
541  nodeNumbers = (int *)palloc(sizeof(int) * in->nNodes);
542  traversalValues = (void **)palloc(sizeof(void *) * in->nNodes);
543 
544  /*
545  * We switch memory context, because we want to allocate memory for new
546  * traversal values (next_cube_box) and pass these pieces of memory to
547  * further call of this function.
548  */
549  old_ctx = MemoryContextSwitchTo(in->traversalMemoryContext);
550 
551  for (octant = 0; octant < in->nNodes; octant++)
552  {
553  CubeBox3D *next_cube_box = nextCubeBox3D(cube_box, centroid, octant);
554  bool flag = true;
555 
556  for (i = 0; i < in->nkeys; i++)
557  {
558  StrategyNumber strategy = in->scankeys[i].sk_strategy;
559  Datum query = in->scankeys[i].sk_argument;
560  BOX3D *box = DatumGetBox3DP(DirectFunctionCall1(LWGEOM_to_BOX3D, query));
561 
562  switch (strategy)
563  {
566  flag = overlap6D(next_cube_box, box);
567  break;
568 
571  flag = contain6D(next_cube_box, box);
572  break;
573 
575  flag = !overRight6D(next_cube_box, box);
576  break;
577 
579  flag = !right6D(next_cube_box, box);
580  break;
581 
583  flag = !overLeft6D(next_cube_box, box);
584  break;
585 
587  flag = !left6D(next_cube_box, box);
588  break;
589 
591  flag = !overBelow6D(next_cube_box, box);
592  break;
593 
595  flag = !below6D(next_cube_box, box);
596  break;
597 
599  flag = !overAbove6D(next_cube_box, box);
600  break;
601 
603  flag = !above6D(next_cube_box, box);
604  break;
605 
607  flag = !overFront6D(next_cube_box, box);
608  break;
609 
611  flag = !front6D(next_cube_box, box);
612  break;
613 
615  flag = !overBack6D(next_cube_box, box);
616  break;
617 
619  flag = !back6D(next_cube_box, box);
620  break;
621 
622  default:
623  elog(ERROR, "unrecognized strategy: %d", strategy);
624  }
625 
626  /* If any check is failed, we have found our answer. */
627  if (!flag)
628  break;
629  }
630 
631  if (flag)
632  {
633  traversalValues[out->nNodes] = next_cube_box;
634  nodeNumbers[out->nNodes] = octant;
635  out->nNodes++;
636  }
637  else
638  {
639  /*
640  * If this node is not selected, we don't need to keep the next
641  * traversal value in the memory context.
642  */
643  pfree(next_cube_box);
644  }
645  }
646 
647  /* Pass to the next level only the values that need to be traversed */
648  out->nodeNumbers = (int *)palloc(sizeof(int) * out->nNodes);
649  out->traversalValues = (void **)palloc(sizeof(void *) * out->nNodes);
650  for (i = 0; i < out->nNodes; i++)
651  {
652  out->nodeNumbers[i] = nodeNumbers[i];
653  out->traversalValues[i] = traversalValues[i];
654  }
655  pfree(nodeNumbers);
656  pfree(traversalValues);
657 
658  /* Switch after */
659  MemoryContextSwitchTo(old_ctx);
660 
661  PG_RETURN_VOID();
662 }
static bool front6D(CubeBox3D *cube_box, BOX3D *query)
static bool back6D(CubeBox3D *cube_box, BOX3D *query)
static bool right6D(CubeBox3D *cube_box, BOX3D *query)
static bool overBack6D(CubeBox3D *cube_box, BOX3D *query)
static bool overAbove6D(CubeBox3D *cube_box, BOX3D *query)
static bool overlap6D(CubeBox3D *cube_box, BOX3D *query)
static CubeBox3D * nextCubeBox3D(CubeBox3D *cube_box, BOX3D *centroid, uint8 octant)
static bool overRight6D(CubeBox3D *cube_box, BOX3D *query)
static bool overFront6D(CubeBox3D *cube_box, BOX3D *query)
static CubeBox3D * initCubeBox(void)
static bool contain6D(CubeBox3D *cube_box, BOX3D *query)
static bool overBelow6D(CubeBox3D *cube_box, BOX3D *query)
static bool above6D(CubeBox3D *cube_box, BOX3D *query)
static bool below6D(CubeBox3D *cube_box, BOX3D *query)
static bool overLeft6D(CubeBox3D *cube_box, BOX3D *query)
static bool left6D(CubeBox3D *cube_box, BOX3D *query)
#define SPGOverlapStrategyNumber
#define SPGOverLeftStrategyNumber
#define SPGLeftStrategyNumber
#define SPGAboveStrategyNumber
#define SPGSameStrategyNumber
#define SPGOverBackStrategyNumber
#define SPGContainedByStrategyNumber
#define SPGOverRightStrategyNumber
#define SPGFrontStrategyNumber
#define SPGBelowStrategyNumber
#define SPGRightStrategyNumber
#define SPGOverFrontStrategyNumber
#define SPGContainsStrategyNumber
#define SPGOverBelowStrategyNumber
#define SPGBackStrategyNumber
#define SPGOverAboveStrategyNumber
Datum LWGEOM_to_BOX3D(PG_FUNCTION_ARGS)
Definition: lwgeom_box3d.c:390
Datum centroid(PG_FUNCTION_ARGS)

References above6D(), back6D(), below6D(), centroid(), contain6D(), front6D(), initCubeBox(), left6D(), LWGEOM_to_BOX3D(), nextCubeBox3D(), overAbove6D(), overBack6D(), overBelow6D(), overFront6D(), overlap6D(), overLeft6D(), overRight6D(), right6D(), SPGAboveStrategyNumber, SPGBackStrategyNumber, SPGBelowStrategyNumber, SPGContainedByStrategyNumber, SPGContainsStrategyNumber, SPGFrontStrategyNumber, SPGLeftStrategyNumber, SPGOverAboveStrategyNumber, SPGOverBackStrategyNumber, SPGOverBelowStrategyNumber, SPGOverFrontStrategyNumber, SPGOverlapStrategyNumber, SPGOverLeftStrategyNumber, SPGOverRightStrategyNumber, SPGRightStrategyNumber, and SPGSameStrategyNumber.

Here is the call graph for this function: