Beispiel #1
0
        OctreeCheck findDescendantLeafNodesInDict(CellID64 cellid, out List <UInt64> outIDs)
        {
            outIDs = new List <UInt64>();

            if (cellid.Level >= MaxDepth)
            {
                return(OctreeCheck.NOTFOUND);
            }

            for (int i = 0; i < 8; ++i)
            {
                CellID64 childID = CellID64.newChildCellId(cellid, i);
                CellData cData;
                int      dictIdx;
                bool     found = masterDictClass.TryGetValue(childID.iCellID, out dictIdx, out cData);
                if (found)
                {
                    if (cData.nodeType == (int)OctreeCellType.LEAF)
                    {
                        outIDs.Add(childID.iCellID);
                    }
                    else if (cData.nodeType == (byte)OctreeCellType.NODE)
                    {
                        List <UInt64> outList;
                        OctreeCheck   ret = findDescendantLeafNodesInDict(childID, out outList);
                        if (outList.Count > 0)
                        {
                            outIDs.AddRange(outList);
                        }
                    }
                }
            }
            if (outIDs.Count > 0)
            {
                return(OctreeCheck.FOUNDDESCENDANT);
            }
            else
            {
                return(OctreeCheck.NOTFOUND);
            }
        }
Beispiel #2
0
        OctreeCheck findDescendants(CellID64 cellid, out List <UInt64> IDsFound)
        {
            OctreeCheck ret = getCellDescendants(cellid, _ID, out IDsFound);

            return(ret);
        }
Beispiel #3
0
        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);
            }
        }
Beispiel #4
0
        //void insertDataToDictDB(string elementID, CellID64 cellID)
        //{
        //    CellData cellData;
        //    cellData.nodeType = 1;
        //    string sqlStmt = null;

        //    short cellType;
        //    try
        //    {
        //        if (!masterDictDB.TryGetValue(cellID.ToString(), out cellType))
        //        {
        //            // no entry yet for this cell
        //            createCellInDictDB(elementID, cellID);
        //            masterDictDB.TryGetValue(cellID.ToString(), out cellType);
        //        }

        //        if (cellType == 1)         //it's leaf, add the elementID
        //        {
        //            DBOperation.executeSingleStmt("INSERT INTO CELLTREEDETTMP (CELLID,ELEMENTID) VALUES ('" + cellID.ToString() + "','" + elementID.ToString() + "')" );
        //        }
        //        else   // it's a node, we must traverse down and add elementID to all the leaves. Not ideal to pass the same flag, but better than none
        //        {
        //            insertDataToDictDB(elementID, CellID64.newChildCellId(cellID, 0));
        //            insertDataToDictDB(elementID, CellID64.newChildCellId(cellID, 1));
        //            insertDataToDictDB(elementID, CellID64.newChildCellId(cellID, 2));
        //            insertDataToDictDB(elementID, CellID64.newChildCellId(cellID, 3));
        //            insertDataToDictDB(elementID, CellID64.newChildCellId(cellID, 4));
        //            insertDataToDictDB(elementID, CellID64.newChildCellId(cellID, 5));
        //            insertDataToDictDB(elementID, CellID64.newChildCellId(cellID, 6));
        //            insertDataToDictDB(elementID, CellID64.newChildCellId(cellID, 7));
        //        }
        //    }
        //    catch (OracleException e)
        //    {
        //        string excStr = "%%Read Error - " + e.Message + "\n\t" + sqlStmt;
        //        refCellBIMRLCommon.StackPushError(excStr);
        //    }
        //}

        //void createCellInDictDB(string elementID, CellID64 cellID)
        //{
        //    CellID64 parentID = CellID64.parentCell(cellID);
        //    string sqlStmt = null;

        //    try
        //    {
        //        short cellType;
        //        if (!masterDictDB.TryGetValue(parentID.ToString(), out cellType))
        //        {
        //            createCellInDictDB(elementID, parentID);
        //            masterDictDB.TryGetValue(parentID.ToString(), out cellType);
        //        }

        //        // 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
        //        DBOperation.executeSingleStmt("DELETE FROM CELLTREEDETTMP WHERE CELLID='" + parentID.ToString() + "' AND ELEMENTID='" + elementID.ToString() + "'");
        //        for (int i = 0; i < 8; ++i)
        //        {
        //            //findCellPar.Value = cellIDIns;
        //            //sqlStmt = findCellSQL;
        //            //celltypeObj = findCellCmd.ExecuteScalar();
        //            //if (celltypeObj == null)

        //            string childID = CellID64.newChildCellId(parentID, i).ToString();
        //            if (!masterDictDB.ContainsKey(childID))
        //                masterDictDB.Add(childID, 1);

        //            DBOperation.executeSingleStmt("INSERT INTO CELLTREEDETTMP (CELLID,ELEMENTID) SELECT '" + childID
        //                + "',ELEMENTID FROM CELLTREEDETTMP WHERE CELLID='" + parentID.ToString() +"'");
        //        }
        //        // reset cellData and set the nodeType to "node"
        //        //cellData.nodeType = 0;
        //        masterDictDB[parentID.ToString()] = 0;
        //        DBOperation.executeSingleStmt("DELETE FROM CELLTREEDETTMP WHERE CELLID='" + parentID.ToString() + "'");
        //    }
        //    catch (OracleException e)
        //    {
        //        string excStr = "%%Read Error - " + e.Message + "\n\t" + sqlStmt;
        //        refCellBIMRLCommon.StackPushError(excStr);
        //    }
        //}

        void insertDataToUserDict(Tuple <UInt64, UInt64> elementID, CellID64 cellID, int borderFlag, bool traverseDepth)
        {
            CellData      cellData;
            int           dictIdx;
            List <UInt64> foundID;
            OctreeCheck   retEnum = findNodeInDict(cellID.iCellID, traverseDepth, out foundID);

            if (retEnum == OctreeCheck.NOTFOUND)
            {
                // no entry yet for this cell
                SortedSet <int> data     = new SortedSet <int>();
                byte            cellType = (byte)OctreeCellType.LEAF;
                data.Add(getIndexForElementID(elementID)); // borderflag is not used anymore
                cellData = new CellData {
                    nodeType = cellType, data = data
                };
                userDict.Add(cellID.iCellID, cellData);
            }
            else if (retEnum == OctreeCheck.NODEFOUND)
            {
                masterDictClass.TryGetValue(cellID.iCellID, out dictIdx, out cellData);
                if (cellData.nodeType == 1)     //it's leaf, add the elementID
                {
                    SortedSet <int> iData    = new SortedSet <int>();
                    byte            cellType = (byte)OctreeCellType.LEAF;
                    //iData.Add(elementID, borderFlag);
                    iData.Add(getIndexForElementID(elementID));
                    CellData cdata;
                    if (!userDict.TryGetValue(cellID.iCellID, out cdata))
                    {
                        // entry is not found in the userdict yet
                        cdata          = new CellData();
                        cdata.nodeType = cellType;
                        cdata.data     = iData;
                        userDict.Add(cellID.iCellID, cdata);
                    }
                    else
                    {
                        if (cdata.data == null)
                        {
                            cdata.data = new SortedSet <int>();
                        }
                        cdata.data.Add(getIndexForElementID(elementID));
                    }
                }
                else // it's a node, we must traverse down and add elementID to all the leaves. Not ideal to pass the same flag, but better than none
                {
                    insertDataToUserDict(elementID, CellID64.newChildCellId(cellID, 0), borderFlag, true);
                    insertDataToUserDict(elementID, CellID64.newChildCellId(cellID, 1), borderFlag, true);
                    insertDataToUserDict(elementID, CellID64.newChildCellId(cellID, 2), borderFlag, true);
                    insertDataToUserDict(elementID, CellID64.newChildCellId(cellID, 3), borderFlag, true);
                    insertDataToUserDict(elementID, CellID64.newChildCellId(cellID, 4), borderFlag, true);
                    insertDataToUserDict(elementID, CellID64.newChildCellId(cellID, 5), borderFlag, true);
                    insertDataToUserDict(elementID, CellID64.newChildCellId(cellID, 6), borderFlag, true);
                    insertDataToUserDict(elementID, CellID64.newChildCellId(cellID, 7), borderFlag, true);
                }
            }
            else if (retEnum == OctreeCheck.FOUNDANCESTOR || retEnum == OctreeCheck.FOUNDDESCENDANT)
            {
                SortedSet <int> data = new SortedSet <int>();

                byte cellType = (byte)OctreeCellType.LEAF;
                if (retEnum == OctreeCheck.FOUNDANCESTOR)
                {
                    cellType = (int)OctreeCellType.LEAFWITHANCESTOR;
                }
                if (retEnum == OctreeCheck.FOUNDDESCENDANT)
                {
                    cellType = (int)OctreeCellType.LEAFWITHDESCENDANT;
                }

                if (userDictKeepOriginalCell)
                {
                    data.Add(getIndexForElementID(elementID));
                    cellData = new CellData {
                        nodeType = cellType, data = data
                    };
                    userDict.Add(cellID.iCellID, cellData);
                }
                // Now loop through the Ancestor ID(s) found and create new entry(ies) in the userDict
                foreach (UInt64 id in foundID)
                {
                    CellData cData;
                    if (!userDict.TryGetValue(id, out cData))
                    {
                        SortedSet <int> iData = new SortedSet <int>();
                        iData.Add(getIndexForElementID(elementID));
                        cData = new CellData {
                            nodeType = (int)OctreeCellType.LEAF, data = iData
                        };
                        userDict.Add(id, cData);
                    }
                    else
                    {
                        if (cData.data == null)
                        {
                            cData.data = new SortedSet <int>();
                        }
                        cData.data.Add(getIndexForElementID(elementID));
                    }
                }
            }
        }