Esempio n. 1
0
        void insertDataToDict(Tuple <UInt64, UInt64> elementID, CellID64 cellID)
        {
            CellData cellData;
            int      dictIdx;

            if (!masterDictClass.TryGetValue(cellID.iCellID, out dictIdx, out cellData))
            {
                // no entry yet for this cell
                createCellInDict(elementID, cellID);
                masterDictClass.TryGetValue(cellID.iCellID, out dictIdx, out cellData);
            }

            if (cellData.nodeType == 1)      //it's leaf, add the elementID
            {
                if (cellData.data == null)
                {
                    cellData.data = new SortedSet <int>();
                }

                cellData.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
            {
                insertDataToDict(elementID, CellID64.newChildCellId(cellID, 0));
                insertDataToDict(elementID, CellID64.newChildCellId(cellID, 1));
                insertDataToDict(elementID, CellID64.newChildCellId(cellID, 2));
                insertDataToDict(elementID, CellID64.newChildCellId(cellID, 3));
                insertDataToDict(elementID, CellID64.newChildCellId(cellID, 4));
                insertDataToDict(elementID, CellID64.newChildCellId(cellID, 5));
                insertDataToDict(elementID, CellID64.newChildCellId(cellID, 6));
                insertDataToDict(elementID, CellID64.newChildCellId(cellID, 7));
            }
        }
Esempio n. 2
0
        public static Octree.OctreeCheck getCellDescendants(CellID64 cellid, int fedID, out List <UInt64> IDsFound)
        {
            IDsFound = new List <UInt64>();
            Octree.OctreeCheck ret;

            string            whereCond = Octree.childrenCellCondition(cellid);
            string            sqlStmt   = "SELECT UNIQUE CELLID FROM " + DBOperation.formatTabName("BIMRL_SPATIALINDEX", fedID) + " WHERE " + whereCond;
            DataTable         dt        = new DataTable();
            OracleCommand     command   = new OracleCommand(sqlStmt, DBOperation.DBConn);
            OracleDataAdapter dtAdapter = new OracleDataAdapter(command);

            dtAdapter.Fill(dt);
            if (dt.Rows.Count > 0)
            {
                ret = Octree.OctreeCheck.FOUNDDESCENDANT;
            }
            else
            {
                ret = Octree.OctreeCheck.NOTFOUND;
            }

            foreach (DataRow dtRow in dt.Rows)
            {
                CellID64 cell = new CellID64(dtRow["CELLID"].ToString());
                IDsFound.Add(cell.iCellID);
            }

            return(ret);
        }
Esempio n. 3
0
        public static void getCellIDComponents(CellID64 cell, out int XMinComp, out int YMinComp, out int ZMinComp, out int XMaxComp, out int YMaxComp, out int ZMaxComp)
        {
            XMinComp = 0;
            YMinComp = 0;
            ZMinComp = 0;
            XMaxComp = 0;
            YMaxComp = 0;
            ZMaxComp = 0;
            int depth    = CellID64.getLevel(cell);
            int maxDepth = 19;

            for (int i = 0; i < maxDepth; i++)
            {
                int tmpOffset = (int)((cell.iCellID & (UInt64)0x1 << (61 - i * 3)) >> (61 - i * 3 - (maxDepth - 1 - i)));
                XMinComp |= tmpOffset;
                tmpOffset = (int)((cell.iCellID & (UInt64)0x1 << (62 - i * 3)) >> (62 - i * 3 - (maxDepth - 1 - i)));
                YMinComp |= tmpOffset;
                tmpOffset = (int)((cell.iCellID & (UInt64)0x1 << (63 - i * 3)) >> (63 - i * 3 - (maxDepth - 1 - i)));
                ZMinComp |= tmpOffset;
            }
            // Get the max index by adding 1 (at depth) to get the next neighbor cell
            XMaxComp = XMinComp + (0x1 << (19 - depth));
            YMaxComp = YMinComp + (0x1 << (19 - depth));
            ZMaxComp = ZMinComp + (0x1 << (19 - depth));
        }
Esempio n. 4
0
        public static string childrenCellCondition(CellID64 cellID)
        {
            string cellIDStr   = cellID.ToString();
            int    usedCharIdx = (int)Math.Ceiling((double)(CellID64.getLevel(cellID) / 2));
            string tmpStr      = "(CELLID LIKE '" + cellIDStr.Substring(0, usedCharIdx) + "%' AND CELLID > '" + cellIDStr + "')";

            return(tmpStr);
        }
Esempio n. 5
0
        public static CellID64 getSmallestContainingCell(LineSegment3D line)
        {
            CellID64 llbSmallestCell = CellID64.cellAtMaxDepth(line.startPoint);
            CellID64 urtSmallestCell = CellID64.cellAtMaxDepth(line.endPoint);
            CellID64 theCell         = getCombinedSmallestContainingCell(llbSmallestCell, urtSmallestCell);

            return(theCell);
        }
Esempio n. 6
0
 ///
 /// Creates a new octree.
 ///
 public OctreeNode(OctreeNode parentID, int depth, int leafNo)
 {
     this._depth  = depth;
     this._parent = parentID;
     nodeCellID   = CellID64.newChildCellId(parentID.nodeCellID, leafNo);
     _children    = new List <OctreeNode>();
     _flag        = PolyhedronIntersectEnum.Intersect;
 }
Esempio n. 7
0
        public static CellID64 getSmallestContainingCell(BoundingBox3D BBox)
        {
            // 1st step. Get the minimum Octree Cell containing the polyH bounding box

            CellID64 llbSmallestCell = CellID64.cellAtMaxDepth(BBox.LLB);
            CellID64 urtSmallestCell = CellID64.cellAtMaxDepth(BBox.URT);
            CellID64 theCell         = getCombinedSmallestContainingCell(llbSmallestCell, urtSmallestCell);

            return(theCell);
        }
Esempio n. 8
0
        public static CellID64 cellAtDepth(Point3D point, int depth)
        {
            Vector3D relPos = new Vector3D();

            // adjust point not to exceed the World BB boundaries. Note that the position MUST be a little inside the box
            if (point.X <= Octree.WorldBB.LLB.X)
            {
                point.X = Octree.WorldBB.LLB.X + 0.000001;
            }
            else if (point.X >= Octree.WorldBB.URT.X)
            {
                point.X = Octree.WorldBB.URT.X - 0.000001;
            }

            if (point.Y <= Octree.WorldBB.LLB.Y)
            {
                point.Y = Octree.WorldBB.LLB.Y + 0.000001;
            }
            else if (point.Y >= Octree.WorldBB.URT.Y)
            {
                point.Y = Octree.WorldBB.URT.Y - 0.000001;
            }

            if (point.Z <= Octree.WorldBB.LLB.Z)
            {
                point.Z = Octree.WorldBB.LLB.Z + 0.000001;
            }
            else if (point.Z >= Octree.WorldBB.URT.Z)
            {
                point.Z = Octree.WorldBB.URT.Z - 0.000001;
            }
            //

            relPos = point - Octree.WorldBB.LLB;
            Vector3D cellSizeAtDepth = cellSize(depth);
            int      cellIdX         = (int)Math.Floor(relPos.X / cellSizeAtDepth.X);
            int      cellIdY         = (int)Math.Floor(relPos.Y / cellSizeAtDepth.Y);
            int      cellIdZ         = (int)Math.Floor(relPos.Z / cellSizeAtDepth.Z);
            UInt64   iCellID         = 0;

            for (int i = depth - 1; i >= 0; i--)
            {
                UInt64 z   = (UInt64)(cellIdZ & (1 << i)) << (63 - (depth - 1 - i) * 3 - i);
                UInt64 y   = (UInt64)(cellIdY & (1 << i)) << (62 - (depth - 1 - i) * 3 - i);
                UInt64 x   = (UInt64)(cellIdX & (1 << i)) << (61 - (depth - 1 - i) * 3 - i);
                UInt64 tmp = z | y | x;
                iCellID |= tmp;
            }
            iCellID |= (UInt64)depth << 1;

            CellID64 cellID = new CellID64(iCellID);

            return(cellID);
        }
Esempio n. 9
0
        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);
        }
Esempio n. 10
0
        public static CellID64 parentCell(CellID64 cell)
        {
            UInt64 a = 0;

            for (int i = 0; i < CellID64.getLevel(cell) - 1; i++)
            {
                a |= cell.iCellID & (UInt64)7 << (61 - i * 3);
            }
            a |= (UInt64)(CellID64.getLevel(cell) - 1) << 1;
            CellID64 pCell = new CellID64(a);

            return(pCell);
        }
Esempio n. 11
0
        static CellID64 getCombinedSmallestContainingCell(params CellID64[] inputCells)
        {
            UInt64 cellidMask = 0xFFFFFFFFFFFFFF80;
            int    startLevel = 0;
            int    level      = 0;

            UInt64[] cellCode = new UInt64[inputCells.Count()];
            int      inputCnt = 0;

            foreach (CellID64 inp in inputCells)
            {
                if (startLevel < inp.Level)
                {
                    startLevel = inp.Level;                    // get the largest level
                }
                cellCode[inputCnt] = inp.iCellID & cellidMask; // remove the level
                inputCnt++;
            }

            bool   same      = false;
            UInt64 shiftMask = 0xffffffffffffffff << ((19 - startLevel) * 3 + 7);

            for (int i = startLevel; i >= 0; --i)
            {
                for (int ccount = 1; ccount < inputCells.Count(); ++ccount)
                {
                    cellCode[0]      = cellCode[0] & shiftMask;
                    cellCode[ccount] = cellCode[ccount] & shiftMask;
                    shiftMask        = shiftMask << 3;
                    if (cellCode[0] == cellCode[ccount])
                    {
                        same = true;
                    }
                    else
                    {
                        break;
                    }
                }
                if (same)
                {
                    level = i;
                    break;
                }
            }
            UInt64   iSmallestCell             = cellCode[0] | (uint)level << 1;
            CellID64 theSmallestContainingCell = new CellID64(iSmallestCell);

            return(theSmallestContainingCell);
        }
Esempio n. 12
0
        public static List <Point3D> getCellIdxCorner(CellID64 cell)
        {
            List <Point3D> cornerLoc = new List <Point3D>();
            Point3D        pos       = new Point3D();
            int            depth     = CellID64.getLevel(cell);
            Vector3D       tileSize  = cellSize(depth);

            pos = getCellIdxLoc(cell);
            cornerLoc.Add(pos);
            Point3D pos2 = new Point3D(pos.X + tileSize.X, pos.Y + tileSize.Y, pos.Z + tileSize.Z);

            cornerLoc.Add(pos2);

            return(cornerLoc);
        }
Esempio n. 13
0
        public static CellID64 newChildCellId(CellID64 seed, int nodeId)
        {
            UInt64 cellidMask = 0xFFFFFFFFFFFFFF80;

            int    level     = getLevel(seed) + 1;
            UInt64 tmpCellid = seed.iCellID;

            // reset level and flag from the original/seed data
            tmpCellid  = tmpCellid & cellidMask;
            tmpCellid  = tmpCellid | ((UInt64)nodeId << (64 - level * 3));
            tmpCellid |= (UInt64)level << 1;
            CellID64 tmpCell = new CellID64(tmpCellid);

            return(tmpCell);
        }
Esempio n. 14
0
        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);
        }
Esempio n. 15
0
        void init(int ID, int initDictNo, int maxDepth, bool forUserDict, bool skipRegenDict)
        {
            if (_ID != ID)
            {
                _ID = ID;
                // If not empty, claer first before reallocating a new ones
                masterDictClass.Reset();
                if (elemIDDict != null)
                {
                    elemIDDict.Clear();
                }
                if (elemIDList != null)
                {
                    elemIDList.Clear();
                }

                elemIDDict = new Dictionary <Tuple <UInt64, UInt64>, int>(initDictNo);
                elemIDList = new List <Tuple <UInt64, UInt64> >(initDictNo);

                CellID64 cell = new CellID64("000000000000");
                masterDictClass.AddOrUpdate(cell.iCellID, new CellData {
                    nodeType = 0, data = new SortedSet <int>()
                });
                if (!skipRegenDict)
                {
                    regenSpatialIndexDict(ID, masterDictClass);
                    //_regen = true;
                }
                _maxDepth  = maxDepth;
                candidates = new List <string>();
            }
            if (forUserDict)
            {
                if (userDict != null)
                {
                    userDict.Clear();
                }

                userDict = new Dictionary <UInt64, CellData>(1000);
                userDictKeepOriginalCell = false;
            }
        }
Esempio n. 16
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);
            }
        }
Esempio n. 17
0
        public static void regenSpatialIndexDict(int fedID, OctreeDict regenSpIndexTree)
        {
            BIMRLCommon refBIMRLCommon = new BIMRLCommon();
            string      sqlStmt        = "SELECT ELEMENTID, CELLID FROM " + DBOperation.formatTabName("BIMRL_SPATIALINDEX", fedID);

            try
            {
                OracleCommand cmd = new OracleCommand(sqlStmt, DBOperation.DBConn);
                cmd.FetchSize = 100000;
                OracleDataReader reader = cmd.ExecuteReader();
                while (reader.Read())
                {
                    string    elementid = reader.GetString(0);
                    ElementID eID       = new ElementID(elementid);
                    string    cellid    = reader.GetString(1);
                    CellID64  cell      = new CellID64(cellid);

                    SortedSet <int> cData = new SortedSet <int>();
                    cData.Add(getIndexForElementID(eID.ElementIDNo)); // the flag is no longer used, any value doesn't matter
                    CellData data = new CellData {
                        nodeType = 1, data = cData
                    };
                    regenSpIndexTree.AddOrUpdate(cell.iCellID, data);
                }
                reader.Dispose();
                cmd.Dispose();
            }
            catch (OracleException e)
            {
                string excStr = "%%Read Error - " + e.Message + "\n\t" + sqlStmt;
                refBIMRLCommon.StackPushError(excStr);
            }
            catch (SystemException e)
            {
                string excStr = "%%Read Error - " + e.Message + "\n\t" + sqlStmt;
                refBIMRLCommon.StackPushError(excStr);
                throw;
            }
        }
Esempio n. 18
0
        public static Point3D getCellIdxLoc(CellID64 cell)
        {
            Point3D pos     = new Point3D();
            int     XOffset = 0;
            int     YOffset = 0;
            int     ZOffset = 0;
            int     depth   = CellID64.getLevel(cell);

            for (int i = 0; i < depth; i++)
            {
                int tmpOffset = (int)((cell.iCellID & (UInt64)0x1 << (61 - i * 3)) >> (61 - i * 3 - (depth - 1 - i)));
                XOffset  |= tmpOffset;
                tmpOffset = (int)((cell.iCellID & (UInt64)0x1 << (62 - i * 3)) >> (62 - i * 3 - (depth - 1 - i)));
                YOffset  |= tmpOffset;
                tmpOffset = (int)((cell.iCellID & (UInt64)0x1 << (63 - i * 3)) >> (63 - i * 3 - (depth - 1 - i)));
                ZOffset  |= tmpOffset;
            }
            Vector3D tileSize = cellSize(depth);

            pos.X = XOffset * tileSize.X + Octree.WorldBB.LLB.X;
            pos.Y = YOffset * tileSize.Y + Octree.WorldBB.LLB.Y;
            pos.Z = ZOffset * tileSize.Z + Octree.WorldBB.LLB.Z;
            return(pos);
        }
Esempio n. 19
0
        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;
            }
        }
Esempio n. 20
0
 /// Creates a new octree.
 ///
 public OctreeNode()
 {
     nodeCellID = new CellID64((UInt64)0);  // root/level-0 tile
     _children  = new List <OctreeNode>();
     _flag      = PolyhedronIntersectEnum.FullyContains;
 }
Esempio n. 21
0
        public static int getLevel(string cellIdStr)
        {
            CellID64 cellId = new CellID64(cellIdStr);

            return((int)(cellId.iCellID & levelMask) >> 1);
        }
Esempio n. 22
0
        OctreeCheck findDescendants(CellID64 cellid, out List <UInt64> IDsFound)
        {
            OctreeCheck ret = getCellDescendants(cellid, _ID, out IDsFound);

            return(ret);
        }
Esempio n. 23
0
        /// <summary>
        /// Collect ALL the cellids from userDict for populating transient geometry(ies)
        /// </summary>
        /// <param name="elementIDList"></param>
        /// <param name="cellIDStrList"></param>
        /// <param name="borderFlagList"></param>
        public void collectSpatialIndexUserDict(out List <string> elementIDList, out List <string> cellIDStrList, out List <int> XMinB, out List <int> YMinB, out List <int> ZMinB,
                                                out List <int> XMaxB, out List <int> YMaxB, out List <int> ZMaxB, out List <int> depthList, out List <int> cellType)
        {
            int initArraySize = 50000;

            elementIDList = new List <string>(initArraySize);
            cellIDStrList = new List <string>(initArraySize);
            cellType      = new List <int>(initArraySize);
            XMinB         = new List <int>(initArraySize);
            YMinB         = new List <int>(initArraySize);
            ZMinB         = new List <int>(initArraySize);
            XMaxB         = new List <int>(initArraySize);
            YMaxB         = new List <int>(initArraySize);
            ZMaxB         = new List <int>(initArraySize);
            depthList     = new List <int>(initArraySize);

            int XMin;
            int YMin;
            int ZMin;
            int XMax;
            int YMax;
            int ZMax;

            foreach (KeyValuePair <UInt64, CellData> dictEntry in userDict)
            {
                CellID64 cellID = new CellID64(dictEntry.Key);
                if (dictEntry.Value.data != null)
                {
                    foreach (int tupEID in dictEntry.Value.data)
                    {
                        ElementID eID = new ElementID(getElementIDByIndex(tupEID));

                        // For UserGeom, the ID i s generated from string of a simple number padded left with '0'. Now we need to remove them
                        int end0Pos = 0;
                        for (int i = 0; i < eID.ElementIDString.Length; ++i)
                        {
                            if (eID.ElementIDString[i] != '0')
                            {
                                end0Pos = i;
                                break;
                            }
                        }
                        string userGeomID = eID.ElementIDString.Remove(0, end0Pos);

                        elementIDList.Add(userGeomID);
                        cellIDStrList.Add(cellID.ToString());
                        // cellType.Add(eID.Value);
                        cellType.Add(dictEntry.Value.nodeType);

                        CellID64.getCellIDComponents(cellID, out XMin, out YMin, out ZMin, out XMax, out YMax, out ZMax);
                        XMinB.Add(XMin);
                        YMinB.Add(YMin);
                        ZMinB.Add(ZMin);
                        XMaxB.Add(XMax);
                        YMaxB.Add(YMax);
                        ZMaxB.Add(ZMax);
                        depthList.Add(CellID64.getLevel(cellID));
                    }
                }
            }
        }
Esempio n. 24
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);
            }
        }
Esempio n. 25
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));
                    }
                }
            }
        }
Esempio n. 26
0
 public static int getLevel(CellID64 cell)
 {
     return((int)(cell.iCellID & levelMask) >> 1);
 }