///////////////////////////////////////////////////////////////////////////////// ein neues Objekt zum Baum hinzufügenbool CSpatialTreeNode::AddTile(CPgrTile *pTile, int nMaxDepth){// If there are subnodes, then consider wether this object// will fit in them. if (nMaxDepth > 1 && m_nSubNodes > 0) { for (int i = 0; i < m_nSubNodes; ++i) { _ASSERTE(NULL != m_apsSubNode[i]); if (m_apsSubNode[i] -> CheckObjectContained(pTile)) return m_apsSubNode[i] -> AddTile(pTile, nMaxDepth - 1); } } else if (nMaxDepth > 1 && 0 == m_nSubNodes) { // Otherwise, consider creating four subnodes if could fit into // them, and adding to the appropriate subnode. double adfBoundsMinH1[SPATIALTREE_DIMENSION], adfBoundsMaxH1[SPATIALTREE_DIMENSION]; double adfBoundsMinH2[SPATIALTREE_DIMENSION], adfBoundsMaxH2[SPATIALTREE_DIMENSION]; double adfBoundsMin1[SPATIALTREE_DIMENSION], adfBoundsMax1[SPATIALTREE_DIMENSION]; double adfBoundsMin2[SPATIALTREE_DIMENSION], adfBoundsMax2[SPATIALTREE_DIMENSION]; double adfBoundsMin3[SPATIALTREE_DIMENSION], adfBoundsMax3[SPATIALTREE_DIMENSION]; double adfBoundsMin4[SPATIALTREE_DIMENSION], adfBoundsMax4[SPATIALTREE_DIMENSION]; SplitBounds(m_dBoundsMin, m_dBoundsMax, adfBoundsMinH1, adfBoundsMaxH1, adfBoundsMinH2, adfBoundsMaxH2); SplitBounds(adfBoundsMinH1, adfBoundsMaxH1, adfBoundsMin1, adfBoundsMax1, adfBoundsMin2, adfBoundsMax2); SplitBounds(adfBoundsMinH2, adfBoundsMaxH2, adfBoundsMin3, adfBoundsMax3, adfBoundsMin4, adfBoundsMax4); if (CheckObjectContained(pTile, adfBoundsMin1, adfBoundsMax1) || CheckObjectContained(pTile, adfBoundsMin2, adfBoundsMax2) || CheckObjectContained(pTile, adfBoundsMin3, adfBoundsMax3) || CheckObjectContained(pTile, adfBoundsMin4, adfBoundsMax4)) { m_nSubNodes = 4; ATLTRY(( m_apsSubNode[0] = new CSpatialTreeNode(adfBoundsMin1, adfBoundsMax1), m_apsSubNode[1] = new CSpatialTreeNode(adfBoundsMin2, adfBoundsMax2), m_apsSubNode[2] = new CSpatialTreeNode(adfBoundsMin3, adfBoundsMax3), m_apsSubNode[3] = new CSpatialTreeNode(adfBoundsMin4, adfBoundsMax4) )); // recurse back on this node now that it has subnodes return AddTile(pTile, nMaxDepth); } }// If none of that worked, just add it to this nodes list. ++m_nFeatureCount;CPgrTile * *pFeatureIds = SfRealloc(m_pFeatureIds, sizeof(CPgrTile *) * m_nFeatureCount); if (NULL != pFeatureIds) { m_pFeatureIds = pFeatureIds; ATLTRY(m_pFeatureIds[m_nFeatureCount - 1] = new CPgrTile(*pTile)); return true; } return false;}