Beispiel #1
0
int main()
{
	fp = fopen("1.txt", "w");
	struct Node* root = RTreeNewIndex();
	int nhits;
	printf("nrects = %d\n", nrects);
	/*
	 * Insert all the data rects.
	 * Notes about the arguments:
	 * parameter 1 is the rect being inserted,
	 * parameter 2 is its ID. NOTE: *** ID MUST NEVER BE ZERO ***, hence the +1,
	 * parameter 3 is the root of the tree. Note: its address is passed
	 * because it can change as a result of this call, therefore no other parts
	 * of this code should stash its address since it could change undernieth.
	 * parameter 4 is always zero which means to add from the root.
	 */
	//读入文件
	char filename[] = "input.txt";
	FILE *fin;
	char StrLine[1024];             //每行最大读取的字符数
	if ((fin = fopen(filename, "r")) == NULL) //判断文件是否存在及可读
	{
		printf("error!");
		return -1;
	}
	int num = 0;
	int num2 = 0;
	struct Rect file_rect[6000];
	while (!feof(fin))
	{

		fscanf(fin, "%f", &file_rect[num].boundary[num2]);
		num2++;
		char c;
		fscanf(fin, "%c", &c);
		if (c == '\n')
		{
			num++;
			num2 = 0;
		}
		//fgets(StrLine, 1024, fin);  //读取一行
		// printf("%s", StrLine); //输出
	}
	fclose(fin);                     //关闭文件

	for(int i=0; i<=num; i++)
		RTreeInsertRect(&file_rect[i], i+1, &root, 0); // i+1 is rect ID. Note: root can change
	//nhits = RTreeSearch(root, &search_rect, MySearchCallback, 0);
	//printf("Search resulted in %d hits\n", nhits);

	//float d=RTreeDistance(rects[0], rects[4]);
	//printf("dmin:%f\n", d);
	//RTreePrintNode(root, 0);
	if (root->branch[0].child&&root->branch[1].child)
		RTreeSearch1(&root->branch[0], &root->branch[1],3);

	fclose(fp);
	return 0;
}
Beispiel #2
0
RTree_t *RTreeOpen()
{
    RTree_t *rtp;

    if ((rtp = NEW(RTree_t)))
	rtp->root = RTreeNewIndex(rtp);
    return rtp;
}