public static List <string> parentCellList(CellID64 cellID) { List <string> cidList = new List <string>(); CellID64 pCell = cellID; for (int i = CellID64.getLevel(pCell); i > 0; i--) { pCell = CellID64.parentCell(pCell); cidList.Add(pCell.ToString()); } return(cidList); }
public static string parentsCellCondition(CellID64 cellID) { string tmpStr = ""; CellID64 pCell = cellID; for (int i = CellID64.getLevel(cellID); i > 0; i--) { if (i < CellID64.getLevel(cellID)) { tmpStr += " OR "; } pCell = CellID64.parentCell(pCell); tmpStr += "(CELLID = '" + pCell.ToString() + "' OR CELLID = '"; pCell.setBorderCell(); tmpStr += pCell.ToString() + "')"; } return(tmpStr); }
OctreeCheck findNodeInDict(UInt64 nodeID, bool depthOnly, out List <UInt64> IDsFound) { IDsFound = new List <UInt64>(); CellID64 cellid = new CellID64(nodeID); if (cellid.Level > MaxDepth) { return(OctreeCheck.NOTFOUND); } CellData outData; int dictIdx; if (masterDictClass.TryGetValue(nodeID, out dictIdx, out outData)) { IDsFound.Add(nodeID); return(OctreeCheck.NODEFOUND); } // No node found at the exact location // 1. try to find ancestor (it is easier to get) bool found = false; if (!depthOnly) { while (!found) { CellID64 parentcell = CellID64.parentCell(cellid); if (parentcell.iCellID == 0) { break; // reached root cell, it means not found } found = masterDictClass.TryGetValue(parentcell.iCellID, out dictIdx, out outData); if (found) { IDsFound.Add(parentcell.iCellID); } else { cellid = parentcell; } } } // if still not found, search for the children if (found) { return(OctreeCheck.FOUNDANCESTOR); } else { // Reset the cellid to the original cellid and not the overwritten one by "found ancestor" logic cellid = new CellID64(nodeID); if (cellid.Level >= Octree.MaxDepth) { return(OctreeCheck.NOTFOUND); } // We will only search for descendants if it is not at the max depth since node at max depth definitely does not have any descendants List <UInt64> outID; // OctreeCheck ret = findDescendants(cellid, out outID); // This version uses DB query OctreeCheck ret = findDescendantLeafNodesInDict(cellid, out outID); // This version uses Dict search if (ret == OctreeCheck.FOUNDDESCENDANT) { IDsFound.AddRange(outID); } return(ret); } }
void createCellInDict(Tuple <UInt64, UInt64> elementID, CellID64 cellID) { CellID64 parentID = CellID64.parentCell(cellID); CellData cellData; int dictIdx; if (!masterDictClass.TryGetValue(parentID.iCellID, out dictIdx, out cellData)) { if (parentID.Level <= 0) { masterDictClass.AddOrUpdate(parentID.iCellID, new CellData { nodeType = 0, data = new SortedSet <int>() }); } else { createCellInDict(elementID, parentID); } masterDictClass.TryGetValue(parentID.iCellID, out dictIdx, out cellData); } try { // entry found, need to create all the entries for the children and transfer all the data into the new cells // remove the current elementid in the data first if present. It will be added later on if (cellData.data != null) { cellData.data.Remove(getIndexForElementID(elementID)); masterDictClass.AddOrUpdate(CellID64.newChildCellId(parentID, 0).iCellID, new CellData { nodeType = 1, data = new SortedSet <int>(cellData.data) }); masterDictClass.AddOrUpdate(CellID64.newChildCellId(parentID, 1).iCellID, new CellData { nodeType = 1, data = new SortedSet <int>(cellData.data) }); masterDictClass.AddOrUpdate(CellID64.newChildCellId(parentID, 2).iCellID, new CellData { nodeType = 1, data = new SortedSet <int>(cellData.data) }); masterDictClass.AddOrUpdate(CellID64.newChildCellId(parentID, 3).iCellID, new CellData { nodeType = 1, data = new SortedSet <int>(cellData.data) }); masterDictClass.AddOrUpdate(CellID64.newChildCellId(parentID, 4).iCellID, new CellData { nodeType = 1, data = new SortedSet <int>(cellData.data) }); masterDictClass.AddOrUpdate(CellID64.newChildCellId(parentID, 5).iCellID, new CellData { nodeType = 1, data = new SortedSet <int>(cellData.data) }); masterDictClass.AddOrUpdate(CellID64.newChildCellId(parentID, 6).iCellID, new CellData { nodeType = 1, data = new SortedSet <int>(cellData.data) }); masterDictClass.AddOrUpdate(CellID64.newChildCellId(parentID, 7).iCellID, new CellData { nodeType = 1, data = new SortedSet <int>(cellData.data) }); // reset cellData and set the nodeType to "node" cellData.data.Clear(); } else { masterDictClass.AddOrUpdate(CellID64.newChildCellId(parentID, 0).iCellID, new CellData { nodeType = 1, data = new SortedSet <int>() }); masterDictClass.AddOrUpdate(CellID64.newChildCellId(parentID, 1).iCellID, new CellData { nodeType = 1, data = new SortedSet <int>() }); masterDictClass.AddOrUpdate(CellID64.newChildCellId(parentID, 2).iCellID, new CellData { nodeType = 1, data = new SortedSet <int>() }); masterDictClass.AddOrUpdate(CellID64.newChildCellId(parentID, 3).iCellID, new CellData { nodeType = 1, data = new SortedSet <int>() }); masterDictClass.AddOrUpdate(CellID64.newChildCellId(parentID, 4).iCellID, new CellData { nodeType = 1, data = new SortedSet <int>() }); masterDictClass.AddOrUpdate(CellID64.newChildCellId(parentID, 5).iCellID, new CellData { nodeType = 1, data = new SortedSet <int>() }); masterDictClass.AddOrUpdate(CellID64.newChildCellId(parentID, 6).iCellID, new CellData { nodeType = 1, data = new SortedSet <int>() }); masterDictClass.AddOrUpdate(CellID64.newChildCellId(parentID, 7).iCellID, new CellData { nodeType = 1, data = new SortedSet <int>() }); } cellData.nodeType = 0; masterDictClass.Replace(parentID.iCellID, cellData, dictIdx); } catch (Exception ex) { refCellBIMRLCommon.StackPushError(ex.Message); throw; } }