Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/160.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ C++;R-树库-我必须计算束盒吗?_C++_R Tree - Fatal编程技术网

C++ C++;R-树库-我必须计算束盒吗?

C++ C++;R-树库-我必须计算束盒吗?,c++,r-tree,C++,R Tree,我试图使用以下库,但在库中显示的示例中,用户定义了边界框。在我的问题中,我每次都有未知维度的数据,所以我不知道如何使用它。除此之外,R-树是否应该能够在每次插入时计算边界框 这是库的示例代码,您可以看到用户每次都定义边界框: #include <stdio.h> #include "RTree.h" struct Rect { Rect() {} Rect(int a_minX, int a_minY, int a_maxX, int a_maxY) { m

我试图使用以下库,但在库中显示的示例中,用户定义了边界框。在我的问题中,我每次都有未知维度的数据,所以我不知道如何使用它。除此之外,R-树是否应该能够在每次插入时计算边界框

这是库的示例代码,您可以看到用户每次都定义边界框:

#include <stdio.h>
#include "RTree.h"

struct Rect
{
  Rect()  {}

  Rect(int a_minX, int a_minY, int a_maxX, int a_maxY)
  {
    min[0] = a_minX;
    min[1] = a_minY;

    max[0] = a_maxX;
    max[1] = a_maxY;
  }


  int min[2];
  int max[2];
};

struct Rect rects[] = 
{
  Rect(0, 0, 2, 2), // xmin, ymin, xmax, ymax (for 2 dimensional RTree)
  Rect(5, 5, 7, 7),
  Rect(8, 5, 9, 6),
  Rect(7, 1, 9, 2),
};

int nrects = sizeof(rects) / sizeof(rects[0]);

Rect search_rect(6, 4, 10, 6); // search will find above rects that this one overlaps


bool MySearchCallback(int id, void* arg) 
{
  printf("Hit data rect %d\n", id);
  return true; // keep going
}


void main()
{
  RTree<int, int, 2, float> tree;

  int i, nhits;
  printf("nrects = %d\n", nrects);

  for(i=0; i<nrects; i++)
  {
    tree.Insert(rects[i].min, rects[i].max, i); // Note, all values including zero are fine in this version
  }

  nhits = tree.Search(search_rect.min, search_rect.max, MySearchCallback, NULL);

  printf("Search resulted in %d hits\n", nhits);

  // Iterator test 
  int itIndex = 0;
  RTree<int, int, 2, float>::Iterator it;
  for( tree.GetFirst(it); 
       !tree.IsNull(it);
       tree.GetNext(it) )
  {
    int value = tree.GetAt(it);

    int boundsMin[2] = {0,0};
    int boundsMax[2] = {0,0};
    it.GetBounds(boundsMin, boundsMax);
    printf("it[%d] %d = (%d,%d,%d,%d)\n", itIndex++, value, boundsMin[0], boundsMin[1], boundsMax[0], boundsMax[1]);
  }

  // Iterator test, alternate syntax
  itIndex = 0;
  tree.GetFirst(it);
  while( !it.IsNull() )
  {
    int value = *it;
    ++it;
    printf("it[%d] %d\n", itIndex++, value);
  }

  getchar(); // Wait for keypress on exit so we can read console output
}
维度 您对维度的要求会有一些限制。这是因为计算机只有无限的存储空间,所以不能存储无限多的维度。实际上,这是一个由你决定你希望支持多少维度的决定。最常见的数字当然是2和3。你真的需要支持11人吗?你打算什么时候用

您可以通过始终使用支持的最大数量的R树,并将零作为其他坐标传递,或者最好创建多个代码路径,每个支持的维度数量对应一个代码路径。也就是说,您将有一组用于二维数据的例程和另一组用于三维数据的例程,依此类推

计算边界框 边界框是与轴对齐的矩形或长方体,完全包围要添加的对象

  • 因此,如果要插入与轴对齐的矩形/长方体等,则形状就是边界框
  • 如果要插入点,则每个标注的最小值和最大值就是该标注的点值
  • 任何其他形状,都必须计算边界框。例如,如果要插入三角形,则需要计算完全围绕三角形的矩形作为边界框

库无法为您执行此操作,因为它不知道您正在插入什么。您可能正在插入存储为“中心+半径”或复杂三角形网格形状的球体。R-树可以提供空间索引,但需要您提供一点点信息来填补空白。

所谓“未知维度”,您的意思是:可能是3d、4d、5d???或者你的意思是“未知尺寸限制”是的。维度将取决于每次的数据文件(2d、3d、4d等)。此外,数据将从文件中加载(因此我知道大小)。但将来可能会有一个流媒体功能。所以我不知道该怎么办。我是否创建边界框?是自动创建的吗?我很困惑。数据项只是点(一组坐标),还是像直线、三角形、立方体等形状?我在我的例子中插入点,所以如果我在树中插入点,我必须像一个盒子一样插入。然后库将其索引到更大的框中。我很抱歉,对吗?示例的要点必须是框的重叠。这就是它创建矩形而不是点的原因。你怎么认为?提前谢谢!是的,没错。对于你的例子,一个点的边界框是一个边长为零的框。现在我有一个新问题,在我把数据放入R树之后,我无法以DFS方式遍历它。你知道如何获取每个节点的数据直到找到一片叶子吗?只需调用
Search
并传递正负无穷大作为边界。这将为您提供所有节点。我的意思是只获取特定节点的数据,然后是子树。我曾想过使用搜索函数来实现它,但它不会返回指向节点的指针或我可以使用的东西。
-------------------------------
| ID | dimension1 | dimension2|
-------------------------------
| 1  |    8       |     9     |
| 2  |    3       |     5     |
| 3  |    2       |     1     |
| 4  |    6       |     7     |
-------------------------------