示例#1
0
文件: Test.cpp 项目: larcohex/random
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

    // Output:
    //
    // nrects = 4
    // Hit data rect 1
    // Hit data rect 2
    // Search resulted in 2 hits
    // it[0] 0 = (0,0,2,2)
    // it[1] 1 = (5,5,7,7)
    // it[2] 2 = (8,5,9,6)
    // it[3] 3 = (7,1,9,2)
    // it[0] 0
    // it[1] 1
    // it[2] 2
    // it[3] 3
}
示例#2
0
int main()
{
	RTree tree;
	
	for(int i = 0;i < DATA_NUMBER; ++i)
	{
		double min[2],max[2];
		min[0] = rand() % MAP_SIZE;
		max[0] = min[0];
		min[1] = rand() % MAP_SIZE;
		max[1] = min[1];
		tree.Insert(min, max, i);  //Insert (x,y,id)
	}
	outFileData(&tree);
	//tree.fileInsert("data.txt");
	//tree.printRec(tree.getMBR(tree.getRoot()));

	RTree::Iterator it;
	for( tree.GetFirst(it); 
       !tree.IsNull(it);
       tree.GetNext(it) )
	{
		int value = tree.GetAt(it);
    
		double x,y;
		it.GetCard(&x,&y);
		cout << "ID " << value << " : " << "(" << x << "," << y << ")" << endl;
	}

	Table1 table1;
	Table2 table2;
	Table3 table3;
	generateTable(&tree,&table1,&table2,&table3);
	printTable(&table1,&table2,&table3);
	outFileTable(&table1,&table2,&table3);

	TimeCounter tc;
	double CreateTime = 0.0;
	tc.StartTime();
	cout << QueryPlan(&tree,K_NEAREST) << endl;
	CreateTime = tc.EndTime();
	cout << "QueryPlan Time: " << CreateTime << " ms" << endl;

//	outFileRect(&tree);

	system("pause");
	return 0;
}