Esempio n. 1
0
        public void createFacesFromBIMRLElement(int federatedId, string whereCond)
        {
            DBOperation.beginTransaction();
            string           currStep = string.Empty;
            OracleCommand    command  = new OracleCommand(" ", DBOperation.DBConn);
            OracleDataReader reader;

            try
            {
                SdoGeometry sdoGeomData = new SdoGeometry();

                string sqlStmt = "select elementid, geometrybody from " + DBOperation.formatTabName("BIMRL_ELEMENT", federatedId) + " where geometrybody is not null ";
                if (!string.IsNullOrEmpty(whereCond))
                {
                    sqlStmt += " and " + whereCond;
                }
                currStep = sqlStmt;

                command.CommandText = sqlStmt;
                command.FetchSize   = 20;

                reader = command.ExecuteReader();

                while (reader.Read())
                {
                    string elemID = reader.GetString(0);
                    sdoGeomData = reader.GetValue(1) as SdoGeometry;

                    Polyhedron geom;
                    if (!SDOGeomUtils.generate_Polyhedron(sdoGeomData, out geom))
                    {
                        continue;                                       // if there is something not right, skip the geometry
                    }
                    // - Process face information and create consolidated faces and store them into BIMRL_TOPO_FACE table
                    BIMRLGeometryPostProcess processFaces = new BIMRLGeometryPostProcess(elemID, geom, _refBIMRLCommon, federatedId, null);
                    processFaces.simplifyAndMergeFaces();
                    processFaces.insertIntoDB(false);
                }
                reader.Dispose();
            }
            catch (OracleException e)
            {
                string excStr = "%%Read Error - " + e.Message + "\n\t" + currStep;
                _refBIMRLCommon.StackPushError(excStr);
            }
            catch (SystemException e)
            {
                string excStr = "%%Read Error - " + e.Message + "\n\t" + currStep;
                _refBIMRLCommon.StackPushError(excStr);
                throw;
            }

            command.Dispose();
        }
Esempio n. 2
0
        /// <summary>
        /// This function is to patch data, updating element's major axes and their OBB at the same time
        /// </summary>
        /// <param name="fedID"></param>
        /// <param name="whereCond"></param>
        public static void updateMajorAxesAndOBB(int fedID, string whereCond)
        {
            BIMRLCommon bimrlCommon = new BIMRLCommon();

            string sqlStmt = "SELECT ELEMENTID, GEOMETRYBODY FROM " + DBOperation.formatTabName("BIMRL_ELEMENT", fedID) + " WHERE GEOMETRYBODY IS NOT NULL";

            if (!string.IsNullOrEmpty(whereCond))
            {
                sqlStmt += " AND " + whereCond;
            }

            OracleCommand    cmd    = new OracleCommand(sqlStmt, DBOperation.DBConn);
            OracleDataReader reader = cmd.ExecuteReader();

            while (reader.Read())
            {
                string      elementid = reader.GetString(0);
                SdoGeometry geom      = reader.GetValue(1) as SdoGeometry;

                Polyhedron polyH;
                if (!SDOGeomUtils.generate_Polyhedron(geom, out polyH))
                {
                    continue;  // something wrong, unable to get the polyhedron, skip
                }
                BIMRLGeometryPostProcess postProc = new BIMRLGeometryPostProcess(elementid, polyH, bimrlCommon, fedID, null);
                postProc.deriveMajorAxes();
                postProc.trueOBBFaces();
                postProc.projectedFaces();

                //// create OBB topo face information
                //if (postProc.OBB != null)
                //{
                //    Polyhedron obbGeom;
                //    if (SDOGeomUtils.generate_Polyhedron(postProc.OBB, out obbGeom))
                //    {
                //        BIMRLGeometryPostProcess processFaces = new BIMRLGeometryPostProcess(elementid, obbGeom, bimrlCommon, fedID, "OBB");
                //        processFaces.simplifyAndMergeFaces();
                //        processFaces.insertIntoDB(false);
                //    }
                //}
            }
            reader.Close();
        }
Esempio n. 3
0
        public void createSpatialIndexFromBIMRLElement(int federatedId, string whereCond, bool createFaces = true, bool createSpIdx = true)
        {
            DBOperation.beginTransaction();
            string           currStep = string.Empty;
            OracleCommand    command  = new OracleCommand(" ", DBOperation.DBConn);
            OracleDataReader reader;
            bool             selectedRegen = false;

            Point3D llb;
            Point3D urt;

            DBOperation.getWorldBB(federatedId, out llb, out urt);
            Octree.WorldBB  = new BoundingBox3D(llb, urt);
            Octree.MaxDepth = DBOperation.OctreeSubdivLevel;

            try
            {
                command.CommandText = "SELECT COUNT(*) FROM " + DBOperation.formatTabName("BIMRL_ELEMENT", federatedId) + " where geometrybody is not null ";
                object rC            = command.ExecuteScalar();
                int    totalRowCount = Convert.ToInt32(rC.ToString()) * (int)Math.Pow(8, 2);

                string sqlStmt = "select elementid, elementtype, geometrybody from " + DBOperation.formatTabName("BIMRL_ELEMENT", federatedId) + " where geometrybody is not null ";
                if (!string.IsNullOrEmpty(whereCond))
                {
                    sqlStmt      += " and " + whereCond;
                    selectedRegen = true;
                }
                currStep = sqlStmt;

                command.CommandText = sqlStmt;
                command.FetchSize   = 20;

                // The following is needed to update the element table with Bbox information
                string sqlStmt3 = "UPDATE " + DBOperation.formatTabName("BIMRL_ELEMENT", federatedId) + " SET GeometryBody_BBOX = :bbox, "
                                  + "GeometryBody_BBOX_CENTROID = :cent WHERE ELEMENTID = :eid";
                OracleCommand commandUpdBbox = new OracleCommand(" ", DBOperation.DBConn);
                commandUpdBbox.CommandText = sqlStmt3;
                commandUpdBbox.Parameters.Clear();

                OracleParameter[] Bbox = new OracleParameter[3];
                Bbox[0]             = commandUpdBbox.Parameters.Add("bbox", OracleDbType.Object);
                Bbox[0].Direction   = ParameterDirection.Input;
                Bbox[0].UdtTypeName = "MDSYS.SDO_GEOMETRY";
                List <List <SdoGeometry> > bboxListList = new List <List <SdoGeometry> >();
                List <SdoGeometry>         bboxList     = new List <SdoGeometry>();

                Bbox[1]             = commandUpdBbox.Parameters.Add("cent", OracleDbType.Object);
                Bbox[1].Direction   = ParameterDirection.Input;
                Bbox[1].UdtTypeName = "MDSYS.SDO_GEOMETRY";
                List <List <SdoGeometry> > centListList = new List <List <SdoGeometry> >();
                List <SdoGeometry>         centList     = new List <SdoGeometry>();

                Bbox[2]           = commandUpdBbox.Parameters.Add("eid", OracleDbType.Varchar2);
                Bbox[2].Direction = ParameterDirection.Input;
                List <List <string> > eidUpdListList = new List <List <string> >();
                List <string>         eidUpdList     = new List <string>();
                int sublistCnt = 0;

                // end for Bbox

                Octree octreeInstance = null;
                if (selectedRegen)
                {
                    octreeInstance = new Octree(federatedId, totalRowCount, DBOperation.OctreeSubdivLevel);
                }
                else
                {
                    octreeInstance = new Octree(federatedId, totalRowCount, DBOperation.OctreeSubdivLevel, false, true);      // Since it is not selectedRegen, we will rebuild the entire tree, skip Dict regen for this case
                }
                reader = command.ExecuteReader();

                while (reader.Read())
                {
                    string elemID  = reader.GetString(0);
                    string elemTyp = reader.GetString(1);

                    SdoGeometry sdoGeomData = reader.GetValue(2) as SdoGeometry;

                    Polyhedron geom;
                    if (!SDOGeomUtils.generate_Polyhedron(sdoGeomData, out geom))
                    {
                        continue;                                       // if there is something not right, skip the geometry
                    }
                    // - Update geometry info with BBox information
                    SdoGeometry bbox = new SdoGeometry();
                    bbox.Dimensionality = 3;
                    bbox.LRS            = 0;
                    bbox.GeometryType   = (int)SdoGeometryTypes.GTYPE.POLYGON;
                    int gType = bbox.PropertiesToGTYPE();

                    double[] arrCoord    = new double[6];
                    int[]    elemInfoArr = { 1, (int)SdoGeometryTypes.ETYPE_SIMPLE.POLYGON_EXTERIOR, 1 };
                    arrCoord[0] = geom.boundingBox.LLB.X;
                    arrCoord[1] = geom.boundingBox.LLB.Y;
                    arrCoord[2] = geom.boundingBox.LLB.Z;
                    arrCoord[3] = geom.boundingBox.URT.X;
                    arrCoord[4] = geom.boundingBox.URT.Y;
                    arrCoord[5] = geom.boundingBox.URT.Z;

                    bbox.ElemArrayOfInts         = elemInfoArr;
                    bbox.OrdinatesArrayOfDoubles = arrCoord;
                    bboxList.Add(bbox);

                    SdoGeometry centroid = new SdoGeometry();
                    centroid.Dimensionality = 3;
                    centroid.LRS            = 0;
                    centroid.GeometryType   = (int)SdoGeometryTypes.GTYPE.POINT;
                    gType = centroid.PropertiesToGTYPE();
                    SdoPoint cent = new SdoPoint();
                    cent.XD           = geom.boundingBox.Center.X;
                    cent.YD           = geom.boundingBox.Center.Y;
                    cent.ZD           = geom.boundingBox.Center.Z;
                    centroid.SdoPoint = cent;
                    centList.Add(centroid);

                    eidUpdList.Add(elemID);

                    sublistCnt++;

                    // Set 1000 records as a threshold for interval commit later on
                    if (sublistCnt >= 500)
                    {
                        bboxListList.Add(bboxList);
                        centListList.Add(centList);
                        eidUpdListList.Add(eidUpdList);

                        sublistCnt = 0;
                        bboxList   = new List <SdoGeometry>();
                        centList   = new List <SdoGeometry>();
                        eidUpdList = new List <string>();
                    }

                    // We will skip large buildinglementproxy that has more than 5000 vertices
                    bool largeMesh = (string.Compare(elemTyp, "IFCBUILDINGELEMENTPROXY", true) == 0) && geom.Vertices.Count > 5000;
                    if ((createFaces && !largeMesh) || (createFaces && selectedRegen))
                    {
                        // - Process face information and create consolidated faces and store them into BIMRL_TOPO_FACE table
                        BIMRLGeometryPostProcess processFaces = new BIMRLGeometryPostProcess(elemID, geom, _refBIMRLCommon, federatedId, null);
                        processFaces.simplifyAndMergeFaces();
                        processFaces.insertIntoDB(false);
                    }

                    if (createSpIdx)
                    {
                        octreeInstance.ComputeOctree(elemID, geom);
                    }
                }

                reader.Dispose();


                if (createSpIdx)
                {
                    // Truncate the table first before reinserting the records
                    FederatedModelInfo fedModel = DBOperation.getFederatedModelByID(federatedId);
                    if (DBOperation.DBUserID.Equals(fedModel.FederatedID))
                    {
                        DBOperation.executeSingleStmt("TRUNCATE TABLE " + DBOperation.formatTabName("BIMRL_SPATIALINDEX", federatedId));
                    }
                    else
                    {
                        DBOperation.executeSingleStmt("DELETE FROM " + DBOperation.formatTabName("BIMRL_SPATIALINDEX"));
                    }

                    collectSpatialIndexAndInsert(octreeInstance, federatedId);
                }

                if (sublistCnt > 0)
                {
                    bboxListList.Add(bboxList);
                    centListList.Add(centList);
                    eidUpdListList.Add(eidUpdList);
                }

                for (int i = 0; i < eidUpdListList.Count; i++)
                {
                    Bbox[0].Value = bboxListList[i].ToArray();
                    Bbox[0].Size  = bboxListList[i].Count;
                    Bbox[1].Value = centListList[i].ToArray();
                    Bbox[1].Size  = centListList[i].Count;
                    Bbox[2].Value = eidUpdListList[i].ToArray();
                    Bbox[2].Size  = eidUpdListList[i].Count;

                    commandUpdBbox.ArrayBindCount = eidUpdListList[i].Count;    // No of values in the array to be inserted
                    int commandStatus = commandUpdBbox.ExecuteNonQuery();
                    DBOperation.commitTransaction();
                }

                if (!string.IsNullOrEmpty(whereCond) && createSpIdx)
                {
                    command.CommandText = "UPDATE BIMRL_FEDERATEDMODEL SET MAXOCTREELEVEL=" + Octree.MaxDepth.ToString() + " WHERE FEDERATEDID=" + federatedId.ToString();
                    command.ExecuteNonQuery();
                    DBOperation.commitTransaction();
                }
            }
            catch (OracleException e)
            {
                string excStr = "%%Read Error - " + e.Message + "\n\t" + currStep;
                _refBIMRLCommon.StackPushError(excStr);
            }
            catch (SystemException e)
            {
                string excStr = "%%Read Error - " + e.Message + "\n\t" + currStep;
                _refBIMRLCommon.StackPushError(excStr);
                throw;
            }

            command.Dispose();
        }