Example #1
0
void cOctree<_DataType>::ComputeOctree()
{
	if (Width_mi<0 || Height_mi<0 || Depth_mi<0) printf ("ComputeOctree: Error!\n");

	
#ifdef	DEBUG_OCTREE	
	printf ("Computing Octree ... ");
	printf ("\n"); fflush (stdout);
#endif

	CellID_mi = 0;

	Root_m = new cOctreeCell;
	Root_m->setStartCoord(0, 0, 0);
	Root_m->setEndCoord(Width_mi, Height_mi, Depth_mi);
	Root_m->CellID_mi = CellID_mi;
	CountClasses(&(Root_m->Class_mi[0]), &(Root_m->StartCoord_mi[0]), &(Root_m->EndCoord_mi[0]));
	CellID_mi++;
	
	int		MaxLevel = 10;
	GenerateOctree(Root_m, MaxLevel);
	
	
}
//
// Wrapper Functions
// - you should probably only have to deal
// with these functions unless you want more 
// trees
void pheromoneBuild(void)
{
	pheromone_tree = GenerateOctree();
} // end of the function
Example #3
0
void cOctree<_DataType>::GenerateOctree(cOctreeCell *CurrCell, int CurrLevel)
{
	if (CurrLevel<0) return;
	if (CurrCell==NULL) return;

	int				i, j, CurrStart[3], CurrEnd[3], CurrMid[3];
	cOctreeCell		*Children[8];


	for (i=0; i<3; i++) {
		CurrStart[i] = CurrCell->StartCoord_mi[i];
		CurrEnd[i] = CurrCell->EndCoord_mi[i];
		CurrMid[i] = (CurrStart[i]+CurrEnd[i])/2;
		if (CurrStart[i]==CurrEnd[i]) return;
	}

#ifdef	DEBUG_OCTREE
		printf ("Id = %3d, ", CurrCell->CellID_mi);
		printf ("L = %3d, ", CurrLevel);
		printf ("Start = %3d %3d %3d, ", CurrStart[0], CurrStart[1], CurrStart[2]);
		printf ("End = %3d %3d %3d ", CurrEnd[0], CurrEnd[1], CurrEnd[2]);
//		printf ("Mid = %3d %3d %3d ", CurrMid[0], CurrMid[1], CurrMid[2]);
#endif


	for (i=0; i<8; i++) {
		Children[i] = new cOctreeCell;
		CurrCell->Children_m[i] = Children[i];
		Children[i]->Parent_m = CurrCell;
	}
	
	Children[0]->setStartCoord(CurrStart[0], CurrStart[1], CurrStart[2]);
	Children[0]->setEndCoord(CurrMid[0], CurrMid[1], CurrMid[2]);
	Children[1]->setStartCoord(CurrMid[0], CurrStart[1], CurrStart[2]);
	Children[1]->setEndCoord(CurrEnd[0], CurrMid[1], CurrMid[2]);
	Children[2]->setStartCoord(CurrMid[0], CurrMid[1], CurrStart[2]);
	Children[2]->setEndCoord(CurrEnd[0], CurrEnd[1], CurrMid[2]);
	Children[3]->setStartCoord(CurrStart[0], CurrMid[1], CurrStart[2]);
	Children[3]->setEndCoord(CurrMid[0], CurrEnd[1], CurrMid[2]);
	
	Children[4]->setStartCoord(CurrStart[0], CurrStart[1], CurrMid[2]);
	Children[4]->setEndCoord(CurrMid[0], CurrMid[1], CurrEnd[2]);
	Children[5]->setStartCoord(CurrMid[0], CurrStart[1], CurrMid[2]);
	Children[5]->setEndCoord(CurrEnd[0], CurrMid[1], CurrEnd[2]);
	Children[6]->setStartCoord(CurrMid[0], CurrMid[1], CurrMid[2]);
	Children[6]->setEndCoord(CurrEnd[0], CurrEnd[1], CurrEnd[2]);
	Children[7]->setStartCoord(CurrStart[0], CurrMid[1], CurrMid[2]);
	Children[7]->setEndCoord(CurrMid[0], CurrEnd[1], CurrEnd[2]);
	for (i=0; i<8; i++) {
		Children[i]->CellID_mi = CellID_mi++;
		CountClasses(&(Children[i]->Class_mi[0]), &(Children[i]->StartCoord_mi[0]), &(Children[i]->EndCoord_mi[0]));
	}

#ifdef	DEBUG_OCTREE
	printf ("Classes = ");
	for (i=1; i<NUM_CLASSES; i++) {
		printf ("%6d ", CurrCell->Class_mi[i]);
	}
	printf ("\n"); fflush (stdout);
#endif

	
	int		NumClasses;
	for (i=0; i<8; i++) {
		NumClasses = 0;
		for (j=1; j<NUM_CLASSES; j++) {
			if (Children[i]->Class_mi[j]>0) NumClasses++;
		}
		if (NumClasses>=2) GenerateOctree(CurrCell->Children_m[i], CurrLevel-1);
	}
	
}