Example #1
0
        void axRenderControl1_RcObjectEditFinish()
        {
            this.axRenderControl1.InteractMode = gviInteractMode.gviInteractNormal;
            polygonDraw = currentGeometry as IPolygon;
            //抬高一点
            for (int i = 0; i < polygonDraw.ExteriorRing.PointCount; i++)
            {
                IPoint pointOnExr = polygonDraw.ExteriorRing.GetPoint(i).Clone() as IPoint;
                pointOnExr.Z += 1;
                polygonDraw.ExteriorRing.UpdatePoint(i, pointOnExr);
            }

            renderpolygonDraw.SetFdeGeometry(polygonDraw);
            renderpolygonDraw.VisibleMask = gviViewportMask.gviViewNone;

            double height = 0.0;

            try
            {
                height = double.Parse(this.numHeight.Value.ToString());
            }
            catch (System.Exception ex)
            {
                MessageBox.Show("请检查挖洞高度");
                return;
            }

            //构造底面polygon
            IPolygon polygonBottom = geoFactory.CreateGeometry(gviGeometryType.gviGeometryPolygon, gviVertexAttribute.gviVertexAttributeZ) as IPolygon;

            for (int i = 0; i < polygonDraw.ExteriorRing.PointCount; i++)
            {
                IPoint pointOnExr = polygonDraw.ExteriorRing.GetPoint(i).Clone() as IPoint;
                maxZ          = pointOnExr.Z;
                pointOnExr.Z -= height;
                minZ          = pointOnExr.Z;
                polygonBottom.ExteriorRing.AppendPoint(pointOnExr);
            }
            polygonBottom.Close();
            PolygonList.Add(polygonBottom);
            //CreateRenderPolygon(polygonBottom);


            //构造侧面polygon
            for (int i = 0; i < polygonDraw.ExteriorRing.PointCount; i++)
            {
                IPoint pointOnExr = polygonDraw.ExteriorRing.GetPoint(i).Clone() as IPoint;
                pointOnExr.Z -= height;

                IPoint pointOnExr2 = null;
                if (i == polygonDraw.ExteriorRing.PointCount - 1)
                {
                    pointOnExr2 = polygonDraw.ExteriorRing.GetPoint(0).Clone() as IPoint;
                }
                else
                {
                    pointOnExr2 = polygonDraw.ExteriorRing.GetPoint(i + 1).Clone() as IPoint;
                }
                pointOnExr2.Z -= height;

                IPolygon polygonTemp = geoFactory.CreateGeometry(gviGeometryType.gviGeometryPolygon, gviVertexAttribute.gviVertexAttributeZ) as IPolygon;
                polygonTemp.ExteriorRing.AppendPoint(polygonDraw.ExteriorRing.GetPoint(i));
                polygonTemp.ExteriorRing.AppendPoint(pointOnExr);
                polygonTemp.ExteriorRing.AppendPoint(pointOnExr2);
                if (i == polygonDraw.ExteriorRing.PointCount - 1)
                {
                    polygonTemp.ExteriorRing.AppendPoint(polygonDraw.ExteriorRing.GetPoint(0));
                }
                else
                {
                    polygonTemp.ExteriorRing.AppendPoint(polygonDraw.ExteriorRing.GetPoint(i + 1));
                }
                polygonTemp.Close();
                PolygonList.Add(polygonTemp);
                //CreateRenderPolygon(polygonTemp);
            }


            List <IRowBuffer> list   = new List <IRowBuffer>();
            ISpatialFilter    filter = new SpatialFilter();

            filter.Geometry      = polygonDraw;
            filter.SpatialRel    = gviSpatialRel.gviSpatialRelEnvelope;
            filter.GeometryField = "Geometry";
            IRowBuffer row    = null;
            IFdeCursor cursor = __fc.Search(filter, false);

            while ((row = cursor.NextRow()) != null)
            {
                list.Add(row);
            }

            foreach (IRowBuffer r in list)
            {
                __fid = (Int32)r.GetValue(0);
                int geometryIndex = -1;
                geometryIndex = r.FieldIndex("Geometry");
                int nameIndex = -1;
                nameIndex = r.FieldIndex("Name");
                if (geometryIndex != -1)
                {
                    // 获取ModelPoint
                    IModelPoint mp = r.GetValue(geometryIndex) as IModelPoint;

                    // 获取Model
                    string modelName = mp.ModelName;
                    IModel m         = (__fc.FeatureDataSet as IResourceManager).GetModel(modelName);

                    Logger.WriteMsg(LogLevel.Message, "---------开始ModelPointToTriMesh----------", DateTime.Now);
                    // 获取MultiTriMesh
                    IMultiTriMesh multiTM = gc.ModelPointToTriMesh(m, mp, false);
                    Logger.WriteMsg(LogLevel.Message, string.Format("---------完成ModelPointToTriMesh:{0}----------", multiTM.GeometryCount), DateTime.Now);

                    // 获取Name
                    string strName = r.GetValue(nameIndex).ToString();
                    for (int i = 0; i < multiTM.GeometryCount; i++)
                    {
                        ITriMesh tm = multiTM.GetGeometry(i) as ITriMesh;
                        //if (!tm.IsClosed)
                        //    continue;

                        // 生成剖面
                        for (int p = 0; p < PolygonList.Count; p++)
                        {
                            IPolygon curPolygon = PolygonList[p];
                            Logger.WriteMsg(LogLevel.Message, string.Format("TM:{0} PG:{1}", i, p), DateTime.Now);
                            if (gc.GetSolidProfile(tm, curPolygon, out multiPolygon))
                            {
                                Logger.WriteMsg(LogLevel.Message, string.Format("TM:{0} PG:{1} TRUE", i, p), DateTime.Now);
                                if (multiPolygon != null && multiPolygon.GeometryCount > 0)
                                {
                                    for (int j = 0; j < multiPolygon.GeometryCount; j++)
                                    {
                                        IPolygon tm2 = multiPolygon.GetGeometry(j) as IPolygon;
                                        //RenderPolygonList.Add(CreateRenderPolygon(tm2));

                                        ICurveSymbol cs = new CurveSymbol();
                                        cs.Color = Color.FromArgb(0, Color.White);
                                        ISurfaceSymbol ss = new SurfaceSymbol();
                                        ss.BoundarySymbol = cs;
                                        ss.Color          = m.GetGroup(0).GetPrimitive(0).Material.DiffuseColor;
                                        IRenderPolygon tmPolygon = this.axRenderControl1.ObjectManager.CreateRenderPolygon(tm2, ss, rootId);
                                        tmPolygon.SetClientData("Name", strName);
                                        RenderPolygonList.Add(tmPolygon);

                                        #region 用当前选中的模型材质,生成截面模型

                                        /*
                                         * IModel outModel = null;
                                         * IModelPoint outMP = null;
                                         * gc.PolygonToModelPoint(tm2, out outModel, out outMP);
                                         *
                                         * if (outModel != null && outMP != null)
                                         * {
                                         *
                                         *  IDrawGroup dgroup = outModel.GetGroup(0);
                                         *  IDrawPrimitive dpri = dgroup.GetPrimitive(0);
                                         *  IDrawMaterial dmar = dpri.Material;
                                         *  dmar.CullMode = gviCullFaceMode.gviCullNone;
                                         *
                                         *  //处理贴图
                                         *  //IPropertySet psOut = new PropertySet();
                                         *  string imgName = m.GetGroup(0).GetPrimitive(0).Material.TextureName;
                                         *  if (imgName != "")
                                         *  {
                                         *      dmar.WrapModeS = gviTextureWrapMode.gviTextureWrapRepeat;
                                         *      dmar.WrapModeT = gviTextureWrapMode.gviTextureWrapRepeat;
                                         *
                                         *      //string tmpImgPath = (strMediaPath + @"\1\") + imgName + ".dds";
                                         *      //IImage imageOut = (__fc.FeatureDataSet as IResourceManager).GetImage(imgName);
                                         *      //imageOut.WriteFile(tmpImgPath);
                                         *      //psOut.SetProperty(imgName, imageOut);
                                         *      //dmar.TextureName = imgName;
                                         *
                                         *      IImage image = (__fc.FeatureDataSet as IResourceManager).GetImage(imgName);
                                         *      this.axRenderControl1.ObjectManager.AddImage(imgName, image);
                                         *      dmar.TextureName = imgName;
                                         *
                                         *      if (dpri.VertexArray.Length == 12)
                                         *      {
                                         *          IFloatArray texcoords = new FloatArray();
                                         *          texcoords.Append(0);
                                         *          texcoords.Append(0);
                                         *          texcoords.Append(1.0f);
                                         *          texcoords.Append(0);
                                         *          texcoords.Append(1.0f);
                                         *          texcoords.Append(1.0f);
                                         *          texcoords.Append(0);
                                         *          texcoords.Append(1.0f);
                                         *          dpri.TexcoordArray = texcoords;
                                         *      }
                                         *      else
                                         *      {
                                         *          IFloatArray texcoords = new FloatArray();
                                         *          texcoords.Append(0);
                                         *          texcoords.Append(0);
                                         *          for (int v = 3; v < dpri.VertexArray.Length - 2; )
                                         *          {
                                         *              texcoords.Append(Math.Abs(dpri.VertexArray.Get(v) - dpri.VertexArray.Get(0)));
                                         *              texcoords.Append(Math.Abs(dpri.VertexArray.Get(v+2) - dpri.VertexArray.Get(2)));
                                         *              v += 3;
                                         *          }
                                         *          dpri.TexcoordArray = texcoords;
                                         *      }
                                         *  }
                                         *  else
                                         *  {
                                         *      dmar.DepthBias = m.GetGroup(0).GetPrimitive(0).Material.DepthBias;
                                         *      dmar.DiffuseColor = m.GetGroup(0).GetPrimitive(0).Material.DiffuseColor;
                                         *      dmar.EnableBlend = m.GetGroup(0).GetPrimitive(0).Material.EnableBlend;
                                         *      dmar.EnableLight = m.GetGroup(0).GetPrimitive(0).Material.EnableLight;
                                         *      dmar.SpecularColor = m.GetGroup(0).GetPrimitive(0).Material.SpecularColor;
                                         *      dmar.WrapModeS = m.GetGroup(0).GetPrimitive(0).Material.WrapModeS;
                                         *      dmar.WrapModeT = m.GetGroup(0).GetPrimitive(0).Material.WrapModeT;
                                         *  }
                                         *
                                         *  dpri.Material = dmar;
                                         *  dgroup.SetPrimitive(0, dpri);
                                         *  outModel.SetGroup(0, dgroup);
                                         *
                                         *  //处理模型
                                         *  //string osgNameOut = __fid + "_" + p + "_" + j;
                                         *  //string tmpOSGPath = (strMediaPath + @"\1\" + osgNameOut + ".osg");
                                         *  //outModel.WriteFile(tmpOSGPath, psOut);
                                         *  //outMP.ModelName = tmpOSGPath;
                                         *
                                         *
                                         *  string osgName = __fid + "_" + p + "_" + j;
                                         *  this.axRenderControl1.ObjectManager.AddModel(osgName, outModel);
                                         *  outMP.ModelName = osgName;
                                         *
                                         *  //可视化
                                         *  outMP.ModelEnvelope = outModel.Envelope;
                                         *  IRenderModelPoint outRenderMP = this.axRenderControl1.ObjectManager.CreateRenderModelPoint(outMP, null, rootId);
                                         *  //this.axRenderControl1.RefreshModel(null, tmpOSGPath);
                                         *  outRenderMP.ShowOutline = true;
                                         *  //outRenderMP.VisibleMask = gviViewportMask.gviViewNone;
                                         *  RenderMPProfileList.Add(outRenderMP);
                                         * }
                                         */
                                        #endregion
                                    }
                                }
                            }
                        } //遍历PolygonList结束
                    }     //遍历multiTM结束



                    //去掉内环模型
                    __fl.VisibleMask = gviViewportMask.gviViewNone;
                    IModel            modelInterior = null;
                    IModelPoint       mpInterior    = null;
                    IRenderModelPoint rmpInterior   = null;
                    IModel            modelExterior = null;
                    IModelPoint       mpExterior    = null;
                    IRenderModelPoint rmpExterior   = null;
                    IMultiPolygon     mltiPolygon   = geoFactory.CreateGeometry(gviGeometryType.gviGeometryMultiPolygon, gviVertexAttribute.gviVertexAttributeZ) as IMultiPolygon;
                    mltiPolygon.AddGeometry(polygonDraw);
                    Logger.WriteMsg(LogLevel.Message, "---------开始SplitModelPointByPolygon2DWithZ----------", DateTime.Now);
                    if (gc.SplitModelPointByPolygon2DWithZ(mltiPolygon, m, mp, minZ, maxZ, out modelInterior, out mpInterior, out modelExterior, out mpExterior))
                    {
                        Logger.WriteMsg(LogLevel.Message, "SplitModelPointByPolygon2DWithZ返回值为TRUE", DateTime.Now);
                        if (modelExterior != null && mpExterior != null)
                        {
                            this.axRenderControl1.ObjectManager.AddModel(mpExterior.ModelName, modelExterior);
                            string[] imagenames = modelExterior.GetImageNames();
                            for (int q = 0; q < imagenames.Length; q++)
                            {
                                IImage image = (__fc.FeatureDataSet as IResourceManager).GetImage(imagenames[q]);
                                this.axRenderControl1.ObjectManager.AddImage(imagenames[q], image);
                            }
                            rmpExterior = this.axRenderControl1.ObjectManager.CreateRenderModelPoint(mpExterior, null, rootId);
                            RenderMPExteriorList.Add(rmpExterior);
                        }
                        if (modelInterior != null && mpInterior != null)
                        {
                            this.axRenderControl1.ObjectManager.AddModel(mpInterior.ModelName, modelInterior);
                            string[] imagenames = modelInterior.GetImageNames();
                            for (int q = 0; q < imagenames.Length; q++)
                            {
                                IImage image = (__fc.FeatureDataSet as IResourceManager).GetImage(imagenames[q]);
                                this.axRenderControl1.ObjectManager.AddImage(imagenames[q], image);
                            }
                            rmpInterior             = this.axRenderControl1.ObjectManager.CreateRenderModelPoint(mpInterior, null, rootId);
                            rmpInterior.VisibleMask = gviViewportMask.gviViewNone;
                            RenderMPInteriorList.Add(rmpInterior);
                        }
                    }
                }
            }//遍历RowBufferList结束
             //MessageBox.Show("执行成功");
        }
Example #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)
        }