Beispiel #1
0
        private void MainForm_Load(object sender, System.EventArgs e)
        {
            if (_geoFactory == null)
            {
                _geoFactory = new GeometryFactory();
            }
            if (_gc == null)
            {
                _gc = new GeometryConvertor();
            }

            // 初始化RenderControl控件
            IPropertySet ps = new PropertySet();

            ps.SetProperty("RenderSystem", gviRenderSystem.gviRenderOpenGL);
            this.axRenderControl1.Initialize(true, ps);
            this.axRenderControl1.Camera.FlyTime = 1;

            rootId = this.axRenderControl1.ObjectManager.GetProjectTree().RootID;

            // 设置天空盒

            if (System.IO.Directory.Exists(strMediaPath))
            {
                string  tmpSkyboxPath = strMediaPath + @"\skybox";
                ISkyBox skybox        = this.axRenderControl1.ObjectManager.GetSkyBox(0);
                skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageBack, tmpSkyboxPath + "\\1_BK.jpg");
                skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageBottom, tmpSkyboxPath + "\\1_DN.jpg");
                skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageFront, tmpSkyboxPath + "\\1_FR.jpg");
                skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageLeft, tmpSkyboxPath + "\\1_LF.jpg");
                skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageRight, tmpSkyboxPath + "\\1_RT.jpg");
                skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageTop, tmpSkyboxPath + "\\1_UP.jpg");
            }
            else
            {
                MessageBox.Show("请不要随意更改SDK目录名");
                return;
            }

            #region 创建地面模型
            Array imgNames = null;
            try
            {
                string           osgPath = (strMediaPath + @"\mdb+osg\Ground\00650100agc4001.osg");
                IResourceFactory resFac  = new ResourceFactory();
                IPropertySet     imgs    = new PropertySet();
                resFac.CreateModelAndImageFromFile(osgPath, out imgs, out ModelSrc, out MatrixSrc);
                this.axRenderControl1.ObjectManager.AddModel("test", ModelSrc);

                string[] keys = imgs.GetAllKeys();
                foreach (string imgName in keys)
                {
                    IImage img = imgs.GetProperty(imgName) as IImage;
                    this.axRenderControl1.ObjectManager.AddImage(imgName, img);
                }

                ModelPointSrc = _geoFactory.CreateGeometry(gviGeometryType.gviGeometryModelPoint, gviVertexAttribute.gviVertexAttributeZ) as IModelPoint;
                ModelPointSrc.ModelEnvelope = ModelSrc.Envelope;
                ModelPointSrc.FromMatrix(MatrixSrc);
                ModelPointSrc.ModelName = "test";

                RenderModelPointSrc = this.axRenderControl1.ObjectManager.CreateRenderModelPoint(ModelPointSrc, null, rootId);
                this.axRenderControl1.Camera.FlyToObject(RenderModelPointSrc.Guid, gviActionCode.gviActionFlyTo);
            }
            catch (COMException ex)
            {
                System.Diagnostics.Trace.WriteLine(ex.Message);
                return;
            }
            #endregion

            _geoEditor    = this.axRenderControl1.ObjectEditor;
            _multiPolygon = _geoFactory.CreateGeometry(gviGeometryType.gviGeometryMultiPolygon, gviVertexAttribute.gviVertexAttributeZ) as IMultiPolygon;

            {
                this.helpProvider1.SetShowHelp(this.axRenderControl1, true);
                this.helpProvider1.SetHelpString(this.axRenderControl1, "");
                this.helpProvider1.HelpNamespace = "GeometryConvert3.html";
            }
        }
Beispiel #2
0
        public void SearchModelPoint(IPolygon tarPolygon)
        {
            this.axRenderControl1.FeatureManager.UnhighlightAll();

            IRowBuffer row = null;

            foreach (IFeatureClass fc in fcMap.Keys)
            {
                if (!fc.Name.Equals("Building"))
                {
                    continue;
                }

                IFdeCursor cursor = null;
                try
                {
                    ISpatialFilter filter = new SpatialFilter();
                    filter.Geometry      = tarPolygon;
                    filter.SpatialRel    = gviSpatialRel.gviSpatialRelEnvelope; //用不相离查不出来
                    filter.GeometryField = "Geometry";
                    cursor = fc.Search(filter, false);
                    while ((row = cursor.NextRow()) != null)
                    {
                        int oid = (int)row.GetValue(0);
                        this.axRenderControl1.FeatureManager.SetFeatureVisibleMask(fc, oid, gviViewportMask.gviViewNone);

                        int         geoPos = row.FieldIndex("Geometry");
                        IModelPoint mp     = row.GetValue(geoPos) as IModelPoint;
                        if (geoConvertor == null)
                        {
                            geoConvertor = new GeometryConvertor();
                        }
                        if (mPolygon == null)
                        {
                            mPolygon = (new GeometryFactory()).CreateGeometry(gviGeometryType.gviGeometryMultiPolygon, gviVertexAttribute.gviVertexAttributeZ) as IMultiPolygon;
                        }
                        mPolygon.Clear();
                        mPolygon.AddGeometry(tarPolygon);

                        GetZToolStripTextBox();

                        IResourceManager rm            = fc.FeatureDataSet as IResourceManager;
                        IModel           model         = rm.GetModel(mp.ModelName);
                        IModel           modelInterior = null;
                        IModelPoint      mpInterior    = null;
                        IModel           modelExterior = null;
                        IModelPoint      mpExterior    = null;
                        if (minz == maxz)
                        {
                            geoConvertor.SplitModelPointByPolygon2D(mPolygon, model, mp, out modelInterior, out mpInterior, out modelExterior, out mpExterior);
                        }
                        else
                        {
                            geoConvertor.SplitModelPointByPolygon2DWithZ(mPolygon, model, mp, minz, maxz, out modelInterior, out mpInterior, out modelExterior, out mpExterior);
                        }

                        if (modelExterior != null)
                        {
                            this.axRenderControl1.ObjectManager.AddModel(fc.Name + oid + "Exterior", modelExterior);
                            mpExterior.ModelName = fc.Name + oid + "Exterior";

                            string[] imagenames = modelExterior.GetImageNames();
                            for (int j = 0; j < imagenames.Length; j++)
                            {
                                IImage image = rm.GetImage(imagenames[j]);
                                this.axRenderControl1.ObjectManager.AddImage(imagenames[j], image);
                            }
                            IRenderModelPoint rrrr = this.axRenderControl1.ObjectManager.CreateRenderModelPoint(mpExterior, null, rootId);
                            lll.Add(rrrr);
                        }
                    }
                }
                catch (COMException ex)
                {
                    System.Diagnostics.Trace.WriteLine(ex.Message);
                }
                finally
                {
                    if (cursor != null)
                    {
                        //Marshal.ReleaseComObject(cursor);
                        cursor = null;
                    }
                }
            } // end of foreach (IFeatureClass fc in fcMap.Keys)
        }