예제 #1
0
        public void TestDeepCopy()
        {
            var g  = (Point)Read("POINT ( 10 10) ");
            var g2 = Factory.CreateGeometry(g);

            g.CoordinateSequence.SetOrdinate(0, 0, 99);
            Assert.IsTrue(!g.EqualsExact(g2));
        }
예제 #2
0
        /// <summary>
        /// 加载直升机骨骼动画
        /// </summary>
        private void LoadXFilePlane()
        {
            string fileName = (strMediaPath + @"\x\Vehicles\wrj.X");

            if (skinMeshPlane == null)
            {
                // 构造ModelPoint
                IGeometryFactory gf = new GeometryFactory();
                IModelPoint      mp = gf.CreateGeometry(gviGeometryType.gviGeometryModelPoint, gviVertexAttribute.gviVertexAttributeZ) as IModelPoint;
                mp.ModelName  = fileName;
                mp.SpatialCRS = datasetCRS;
                // 设置位置
                IMatrix matrix = new Matrix();
                matrix.MakeIdentity();
                v3.Set(planeX, planeY, planeZ);
                matrix.SetTranslate(v3);
                mp.FromMatrix(matrix);
                // 创建骨骼动画
                skinMeshPlane = CommonUnity.RenderHelper.ObjectManager.CreateSkinnedMesh(mp, rootId);
                if (skinMeshPlane == null)
                {
                    MessageBox.Show("骨骼动画创建失败!");
                    return;
                }
                skinMeshPlane.Loop = true;
                skinMeshPlane.Play();
                skinMeshPlane.MaxVisibleDistance = 1000;
            }
        }
예제 #3
0
        /// <summary>
        /// 加载人物骨骼动画
        /// </summary>
        private void LoadXFileCharacter()
        {
            string fileName = (strMediaPath + @"\x\Character\QiYeYuanGong.X");

            if (skinMeshCharacter == null)
            {
                // 构造ModelPoint
                IGeometryFactory gf = new GeometryFactory();
                IModelPoint      mp = gf.CreateGeometry(gviGeometryType.gviGeometryModelPoint, gviVertexAttribute.gviVertexAttributeZ) as IModelPoint;
                mp.ModelName  = fileName;
                mp.SpatialCRS = datasetCRS;
                // 设置位置
                IMatrix matrix = new Matrix();
                matrix.MakeIdentity();
                v3.Set(gugeX, gugeY, gugeZ);
                matrix.SetTranslate(v3);
                mp.FromMatrix(matrix);
                // 创建骨骼动画
                skinMeshCharacter = CommonUnity.RenderHelper.ObjectManager.CreateSkinnedMesh(mp, rootId);
                if (skinMeshCharacter == null)
                {
                    MessageBox.Show("骨骼动画创建失败!");
                    return;
                }
                skinMeshCharacter.Duration = 1;  //人物的那个骨骼动画播放速度调快一倍
                skinMeshCharacter.Loop     = true;
                skinMeshCharacter.Play();
                skinMeshCharacter.MaxVisibleDistance = 1000;
            }
        }
예제 #4
0
        private void LoadPlane()
        {
            // 加载直升飞机
            string fileName = (strMediaPath + @"\x\Vehicles\wrj.X");

            if (skinMeshPlane == null)
            {
                // 构造ModelPoint
                IGeometryFactory gf = new GeometryFactory();
                IModelPoint      mp = gf.CreateGeometry(gviGeometryType.gviGeometryModelPoint, gviVertexAttribute.gviVertexAttributeZ) as IModelPoint;
                mp.ModelName  = fileName;
                mp.SpatialCRS = new CRSFactory().CreateFromWKT(wkt) as ISpatialCRS;
                // 设置位置
                IMatrix matrix = new Matrix();
                matrix.MakeIdentity();
                matrix.SetTranslate(line.GetPoint(0).Position);
                mp.FromMatrix(matrix);
                // 创建骨骼动画
                skinMeshPlane = this.axRenderControl1.ObjectManager.CreateSkinnedMesh(mp, rootId);
                if (skinMeshPlane == null)
                {
                    MessageBox.Show("骨骼动画创建失败!");
                    return;
                }
                skinMeshPlane.Loop = true;
                skinMeshPlane.Play();
                skinMeshPlane.MaxVisibleDistance = 1000;
                skinMeshPlane.ViewingDistance    = 100;

                // 绑定到运动路径
                IMotionable m = skinMeshPlane as IMotionable;
                position.Set(0, 0, 0);
                m.Bind2(dynamicObject, position, 0, 0, 0);
            }
        }
예제 #5
0
        /// <summary>
        /// 加载模型
        /// </summary>
        private void LoadModel()
        {
            string           modelName  = (strMediaPath + @"\osg\Vehicles\XiaoFangChe\xiaoFangChe3.OSG");
            IGeometryFactory geoFactory = new GeometryFactory();
            IModelPoint      modelPoint = (IModelPoint)geoFactory.CreateGeometry(gviGeometryType.gviGeometryModelPoint, gviVertexAttribute.gviVertexAttributeZ);

            modelPoint.ModelName = modelName;
            modelPoint.SetCoords(firstX, firstY, firstZ, 0, 0);
            modelPoint.SpatialCRS        = datasetCRS;
            renderModelPoint             = CommonUnity.RenderHelper.ObjectManager.CreateRenderModelPoint(modelPoint, null, rootId);
            renderModelPoint.VisibleMask = gviViewportMask.gviViewAllNormalView;
        }
예제 #6
0
        private void LoadSkinMeshAndViewshed()
        {
            string fileName = (strMediaPath + @"\x\Character\QiYeYuanGong.X");

            if (skinMesh == null)
            {
                // 构造ModelPoint
                IGeometryFactory gf = new GeometryFactory();
                IModelPoint      mp = gf.CreateGeometry(gviGeometryType.gviGeometryModelPoint, gviVertexAttribute.gviVertexAttributeZ) as IModelPoint;
                mp.ModelName  = fileName;
                mp.SpatialCRS = new CRSFactory().CreateFromWKT(wkt) as ISpatialCRS;
                // 设置位置
                IMatrix matrix = new Matrix();
                matrix.MakeIdentity();
                matrix.SetTranslate(line.GetPoint(0).Position);
                mp.FromMatrix(matrix);
                // 创建骨骼动画
                skinMesh = this.axRenderControl1.ObjectManager.CreateSkinnedMesh(mp, rootId);
                if (skinMesh == null)
                {
                    MessageBox.Show("骨骼动画创建失败!");
                    return;
                }
                skinMesh.Loop = true;
                skinMesh.Play();
                skinMesh.MaxVisibleDistance = 1000;
                skinMesh.ViewingDistance    = 50;

                // 绑定到运动路径
                IMotionable m = skinMesh as IMotionable;
                position.Set(0, 0, 0);
                m.Bind2(dynamicObject, position, 0, 0, 0);
                this.axRenderControl1.Camera.FlyToObject(skinMesh.Guid, gviActionCode.gviActionFollowBehind);
            }

            if (tv == null)
            {
                tv = this.axRenderControl1.ObjectManager.CreateViewshed(line.GetPoint(0), rootId);
                IMotionable tvm = tv as IMotionable;
                position.Set(0, 0, 0);
                tvm.Bind2(dynamicObject, position, 0, 0, 0);
            }
        }
예제 #7
0
        /// <summary>
        /// 绘制区域多边形
        /// </summary>
        private void StartDraw()
        {
            Clear();
            IGeometryFactory geometryFactory = new GeometryFactory();
            IPolygon         polygon         = (IPolygon)geometryFactory.CreateGeometry(gviGeometryType.gviGeometryPolygon, gviVertexAttribute.gviVertexAttributeNone);

            ISurfaceSymbol surfaceSymbol = new SurfaceSymbol()
            {
                Color = System.Drawing.Color.Yellow
            };

            IObjectManager objectManager = _AxRenderControl.ObjectManager;

            _RenderPolygon                    = objectManager.CreateRenderPolygon(polygon, surfaceSymbol, rootId);
            _RenderPolygon.HeightStyle        = gviHeightStyle.gviHeightOnTerrain;
            _RenderPolygon.MaxVisibleDistance = double.MaxValue;
            _RenderPolygon.MinVisiblePixels   = 3;

            _AxRenderControl.ObjectEditor.StartEditRenderGeometry(_RenderPolygon, gviGeoEditType.gviGeoEditCreator);
        }
예제 #8
0
파일: MainForm.cs 프로젝트: batuZ/Samples
        private void toolStripButton_CreateRenderModelPoint_Click(object sender, EventArgs e)
        {
            IModel model = CreateModel(1, 1, 1, 0xffffffff);

            RenderControl.ObjectManager.AddModel("model", model);
            t.Stop();
            foreach (IRenderModelPoint m in list)
            {
                RenderControl.ObjectManager.DeleteObject(m.Guid);
            }
            list.Clear();
            MatrixList.Clear();
            int              x = Convert.ToInt32(toolStripTextBox_x.Text.Trim());
            int              y = Convert.ToInt32(toolStripTextBox_y.Text.Trim());
            int              n = Convert.ToInt32(toolStripTextBox_n.Text.Trim());
            double           x1, y1;
            IGeometryFactory gf = new GeometryFactory();

            for (int j = 0; j < x; j++)
            {
                for (int k = 0; k < y; k++)
                {
                    IModelPoint mp = gf.CreateGeometry(gviGeometryType.gviGeometryModelPoint, gviVertexAttribute.gviVertexAttributeZ) as IModelPoint;

                    x1               = n * j;
                    y1               = n * k;
                    mp.X             = x1;
                    mp.Y             = y1;
                    mp.Z             = 0;
                    mp.ModelName     = "model";
                    mp.ModelEnvelope = model.Envelope;
                    IRenderModelPoint rmp = RenderControl.ObjectManager.CreateRenderModelPoint(mp, null, RenderControl.ProjectTree.RootID);
                    rmp.MaxVisibleDistance = 99999999999999;
                    rmp.MinVisiblePixels   = 0;
                    list.Add(rmp);
                    MatrixList.Add(mp.AsMatrix());
                }
            }
        }
예제 #9
0
        /// <summary>
        /// 加载动态树骨骼动画
        /// </summary>
        private void LoadXFileTrees()
        {
            {
                string fileName = (strMediaPath + @"\x\Trees\tree.X");
                if (skinMeshTree == null)
                {
                    // 构造ModelPoint
                    IGeometryFactory gf = new GeometryFactory();
                    IModelPoint      mp = gf.CreateGeometry(gviGeometryType.gviGeometryModelPoint, gviVertexAttribute.gviVertexAttributeZ) as IModelPoint;
                    mp.ModelName  = fileName;
                    mp.SpatialCRS = datasetCRS;
                    // 设置位置
                    IMatrix matrix = new Matrix();
                    matrix.MakeIdentity();
                    v3.Set(treeX, treeY, treeZ);
                    matrix.SetTranslate(v3);
                    mp.FromMatrix(matrix);
                    mp.SelfScale(0.75, 0.75, 0.75);
                    // 创建骨骼动画
                    skinMeshTree = CommonUnity.RenderHelper.ObjectManager.CreateSkinnedMesh(mp, rootId);
                    if (skinMeshTree == null)
                    {
                        MessageBox.Show("骨骼动画创建失败!");
                        return;
                    }
                    skinMeshTree.Duration = 4;
                    skinMeshTree.Loop     = true;
                    skinMeshTree.Play();
                    skinMeshTree.MaxVisibleDistance = 1000;
                }
            }

            {
                string fileName = (strMediaPath + @"\x\Trees\tree1.X");
                if (skinMeshTree1 == null)
                {
                    // 构造ModelPoint
                    IGeometryFactory gf = new GeometryFactory();
                    IModelPoint      mp = gf.CreateGeometry(gviGeometryType.gviGeometryModelPoint, gviVertexAttribute.gviVertexAttributeZ) as IModelPoint;
                    mp.ModelName  = fileName;
                    mp.SpatialCRS = datasetCRS;
                    // 设置位置
                    IMatrix matrix = new Matrix();
                    matrix.MakeIdentity();
                    v3.Set(tree1X, tree1Y, tree1Z);
                    matrix.SetTranslate(v3);
                    mp.FromMatrix(matrix);
                    mp.SelfScale(0.5, 0.5, 0.5);
                    // 创建骨骼动画
                    skinMeshTree1 = CommonUnity.RenderHelper.ObjectManager.CreateSkinnedMesh(mp, rootId);
                    if (skinMeshTree == null)
                    {
                        MessageBox.Show("骨骼动画创建失败!");
                        return;
                    }
                    skinMeshTree1.Duration = 3;
                    skinMeshTree1.Loop     = true;
                    skinMeshTree1.Play();
                    skinMeshTree1.MaxVisibleDistance = 1000;
                }
            }

            {
                string fileName = (strMediaPath + @"\x\Trees\tree2.X");
                if (skinMeshTree2 == null)
                {
                    // 构造ModelPoint
                    IGeometryFactory gf = new GeometryFactory();
                    IModelPoint      mp = gf.CreateGeometry(gviGeometryType.gviGeometryModelPoint, gviVertexAttribute.gviVertexAttributeZ) as IModelPoint;
                    mp.ModelName  = fileName;
                    mp.SpatialCRS = datasetCRS;
                    // 设置位置
                    IMatrix matrix = new Matrix();
                    matrix.MakeIdentity();
                    v3.Set(tree2X, tree2Y, tree2Z);
                    matrix.SetTranslate(v3);
                    mp.FromMatrix(matrix);
                    mp.SelfScale(0.25, 0.25, 0.25);
                    // 创建骨骼动画
                    skinMeshTree2 = CommonUnity.RenderHelper.ObjectManager.CreateSkinnedMesh(mp, rootId);
                    if (skinMeshTree2 == null)
                    {
                        MessageBox.Show("骨骼动画创建失败!");
                        return;
                    }
                    skinMeshTree2.Loop = true;
                    skinMeshTree2.Play();
                    skinMeshTree2.MaxVisibleDistance = 1000;
                }
            }
        }
예제 #10
0
        private void LoadDynamicTableLabel()
        {
            #region 加载一个标签
            dynamicTableLabel = axRenderControl1.ObjectManager.CreateTableLabel(2, 2, rootId);

            dynamicTableLabel.TitleText = "消防车当前位置";
            dynamicTableLabel.SetRecord(0, 0, "X:");
            dynamicTableLabel.SetRecord(0, 1, firstX.ToString());
            dynamicTableLabel.SetRecord(1, 0, "Y:");
            dynamicTableLabel.SetRecord(1, 1, firstY.ToString());

            position.Set(firstX, firstY, firstZ + 2.4);
            if (fde_point == null)
            {
                fde_point = (new GeometryFactory()).CreatePoint(gviVertexAttribute.gviVertexAttributeZ);
            }
            fde_point.Position         = position;
            dynamicTableLabel.Position = fde_point;

            dynamicTableLabel.BorderColor          = System.Drawing.Color.White;
            dynamicTableLabel.BorderWidth          = 2;
            dynamicTableLabel.TableBackgroundColor = System.Drawing.Color.Gray;
            dynamicTableLabel.TitleBackgroundColor = System.Drawing.Color.Red;

            // 表头样式
            TextAttribute headerTextAttribute = new TextAttribute();
            headerTextAttribute.TextColor              = System.Drawing.Color.Black;
            headerTextAttribute.OutlineColor           = System.Drawing.Color.Red;
            headerTextAttribute.Font                   = "黑体";
            headerTextAttribute.Bold                   = true;
            headerTextAttribute.MultilineJustification = gviMultilineJustification.gviMultilineLeft;
            dynamicTableLabel.SetColumnTextAttribute(0, headerTextAttribute);

            // 内容样式
            TextAttribute contentTextAttribute = new TextAttribute();
            contentTextAttribute.TextColor              = System.Drawing.Color.Black;
            contentTextAttribute.OutlineColor           = System.Drawing.Color.Red;
            contentTextAttribute.Font                   = "黑体";
            contentTextAttribute.Bold                   = false;
            contentTextAttribute.MultilineJustification = gviMultilineJustification.gviMultilineLeft;
            dynamicTableLabel.SetColumnTextAttribute(1, contentTextAttribute);

            // 标题样式
            TextAttribute capitalTextAttribute = new TextAttribute();
            capitalTextAttribute.TextColor              = System.Drawing.Color.White;
            capitalTextAttribute.OutlineColor           = System.Drawing.Color.Gray;
            capitalTextAttribute.Font                   = "华文新魏";
            capitalTextAttribute.TextSize               = 14;
            capitalTextAttribute.MultilineJustification = gviMultilineJustification.gviMultilineCenter;
            capitalTextAttribute.Bold                   = true;
            dynamicTableLabel.TitleTextAttribute        = capitalTextAttribute;

            angle.Set(0, -20, 0);
            axRenderControl1.Camera.LookAt(position, 30, angle);
            #endregion

            #region 加载一个模型
            if (renderModelPoint == null)
            {
                string           modelName  = (strMediaPath + @"\osg\Vehicles\XiaoFangChe\xiaoFangChe3.OSG");
                IGeometryFactory geoFactory = new GeometryFactory();
                IModelPoint      modePoint  = (IModelPoint)geoFactory.CreateGeometry(gviGeometryType.gviGeometryModelPoint, gviVertexAttribute.gviVertexAttributeZ);
                modePoint.ModelName = modelName;
                modePoint.SetCoords(firstX, firstY, firstZ, 0, 0);
                renderModelPoint = axRenderControl1.ObjectManager.CreateRenderModelPoint(modePoint, null, rootId);
            }
            #endregion

            #region 加载一个运动路径
            if (motionPath == null)
            {
                motionPath = axRenderControl1.ObjectManager.CreateMotionPath(rootId);
                // 为MotionPath添加第一个点
                position.Set(firstX, firstY, firstZ);
                angle.Set(firstH, firstP, firstR);
                scale.Set(firstSX, firstSY, firstSZ);
                motionPath.AddWaypoint(position, angle, scale, firtWhen);
                //为MotionPath添加第二个点
                position.Set(secondX, secondY, secondZ);
                angle.Set(secondH, secondP, secondR);
                scale.Set(secondSX, secondSY, secondSZ);
                motionPath.AddWaypoint(position, angle, scale, secondWhen);
                //为MotionPath添加第三个点
                position.Set(thirdX, thirdY, thirdZ);
                angle.Set(thirdH, thirdP, thirdR);
                scale.Set(thirdSX, thirdSY, thirdSZ);
                motionPath.AddWaypoint(position, angle, scale, thirdWhen);
                //为MotionPath添加第四个点
                position.Set(fourthX, fourthY, fourthZ);
                angle.Set(fourthH, fourthP, fourthR);
                scale.Set(fourthSX, fourthSY, fourthSZ);
                motionPath.AddWaypoint(position, angle, scale, fourthWhen);
            }
            #endregion

            #region 将模型和标牌同时绑定在路径上
            m = renderModelPoint as IMotionable;
            //将模型绑定到路径上

            v3.Set(0, 0, 0);
            m.Bind(motionPath, v3, 0, 0, 0);

            // 将标牌绑定到路径上
            if (dynamicTableLabel != null && motionPath != null)
            {
                m = dynamicTableLabel as IMotionable;
                v3.Set(0, 0, 6);
                m.Bind(motionPath, v3, 0, 0, 0);
            }
            #endregion
        }
예제 #11
0
        public void ImportModelMdb(IFeatureClass fc, string mdbFile, int groupId)
        {
            try
            {
                //2、获取基本信息
                FileInfo fInfo       = new FileInfo(mdbFile);
                string   strFilePath = fInfo.DirectoryName;

                Gvitech.CityMaker.Resource.IResourceFactory rf = new Gvitech.CityMaker.Resource.ResourceFactory();
                IResourceManager rm = fc.FeatureDataSet as IResourceManager;
                Dictionary <string, IEnvelope> cacheModeInfos = new Dictionary <string, IEnvelope>();
                List <string> cacheImageNames = new List <string>();

                IGeometryFactory geoFactory = new GeometryFactory();
                IResourceFactory symbolFac  = new ResourceFactory();

                IRowBufferCollection fcRows = new RowBufferCollection();
                IRowBuffer           fcRow  = null;

                //4、解析mdb
                string strConn    = _ConnStr + mdbFile + "\'";
                int    index      = 0;
                int    totalCount = 0;
                using (OleDbConnection oleConn = new OleDbConnection(strConn))
                {
                    oleConn.Open();
                    string          strSql      = "select count(*)  from Attribute_Table_CityManager";
                    OleDbCommand    countCmd    = new OleDbCommand(strSql, oleConn);
                    OleDbDataReader countReader = countCmd.ExecuteReader();
                    countReader.Read();
                    totalCount = countReader.GetInt32(0);
                    countReader.Close();

                    OleDbCommand    command   = new OleDbCommand(_QueryModelStr, oleConn);
                    OleDbDataReader reader    = command.ExecuteReader();
                    IModelPoint     modePoint = null;
                    while (reader.Read())
                    {
                        int    percent = ++index * 100 / totalCount;
                        string toolTip = string.Format("已完成{0}条/总共{1}条 {2}%", index, totalCount, percent);
                        CommonEntity.FormEntity.Text = toolTip;

                        double dScaleX = 0.0;
                        double dScaleY = 0.0;
                        double dScaleZ = 0.0;

                        double.TryParse(reader.GetString(9), out dScaleX);
                        double.TryParse(reader.GetString(10), out dScaleY);
                        double.TryParse(reader.GetString(11), out dScaleZ);

                        //if (dScaleX < 0 || dScaleY < 0 || dScaleZ < 0)
                        //    continue;

                        //fc
                        fcRow = fc.CreateRowBuffer();
                        int nPose = fcRow.FieldIndex("name");
                        if (nPose == -1)
                        {
                            continue;
                        }
                        string modelName = reader.GetString(0);
                        fcRow.SetValue(nPose, modelName);

                        nPose = fcRow.FieldIndex("groupId");
                        if (nPose == -1)
                        {
                            continue;
                        }
                        fcRow.SetValue(nPose, groupId);

                        modePoint = (IModelPoint)geoFactory.CreateGeometry(
                            gviGeometryType.gviGeometryModelPoint,
                            gviVertexAttribute.gviVertexAttributeZ);
                        modePoint.ModelName = modelName;

                        double dModePointX = double.Parse(reader.GetString(2)) + 0;  // CoorX = 0
                        double dModePointY = double.Parse(reader.GetString(3)) + 0;  // CoorY = 0
                        double dModePointZ = double.Parse(reader.GetString(4)) + 0;  // CoorZ = 0

                        double dRotationAngle = double.Parse(reader.GetString(5));
                        double dAxisX         = double.Parse(reader.GetString(6));
                        double dAxisY         = double.Parse(reader.GetString(7));
                        double dAxisZ         = double.Parse(reader.GetString(8));

                        double dUTransAngel = double.Parse(reader.GetString(12));
                        double dUTransX     = double.Parse(reader.GetString(13));
                        double dUTransY     = double.Parse(reader.GetString(14));
                        double dUTransZ     = double.Parse(reader.GetString(15));

                        modePoint.X = dModePointX;
                        modePoint.Y = dModePointY;
                        modePoint.Z = dModePointZ;

                        IMatrix matrix = new Matrix();

                        IVector3 pointVec = new Vector3();
                        pointVec.X = dModePointX;
                        pointVec.Y = dModePointY;
                        pointVec.Z = dModePointZ;

                        IVector3 Scale = new Vector3();
                        Scale.X = dScaleX;
                        Scale.Y = dScaleY;
                        Scale.Z = dScaleZ;

                        IVector3 Rotation = new Vector3();
                        Rotation.X = dAxisX;
                        Rotation.Y = dAxisY;
                        Rotation.Z = dAxisZ;

                        IVector3 Shear = new Vector3();
                        Shear.X = dUTransX;
                        Shear.Y = dUTransY;
                        Shear.Z = dUTransZ;

                        matrix.Compose2(pointVec, Scale, dRotationAngle, Rotation, dUTransAngel, Shear);
                        modePoint.FromMatrix(matrix);

                        //mc
                        IPropertySet Images = null;

                        //如果内存中不包含
                        if (!cacheModeInfos.Keys.Contains(modelName))
                        {
                            //数据库中包含
                            if (rm.ModelExist(modelName))
                            {
                                //重名即跳过
                                IEnvelope ev = rm.GetModel(modelName).Envelope;
                                modePoint.ModelEnvelope = ev;
                            }
                            else
                            {
                                IModel  simpleModel = null;
                                string  osgFilePath = strFilePath + "\\" + modelName + ".osg";
                                IModel  fineModel   = null;
                                IMatrix m           = null;
                                symbolFac.CreateModelAndImageFromFileEx(osgFilePath,
                                                                        out Images, out simpleModel, out fineModel, out m);
                                if (fineModel == null || fineModel.GroupCount == 0)
                                {
                                    continue;
                                }

                                cacheModeInfos[modelName] = modePoint.ModelEnvelope = Clone(fineModel.Envelope);

                                rm.AddModel(modelName, fineModel, simpleModel);
                            }
                        }
                        else
                        {
                            modePoint.ModelEnvelope = cacheModeInfos[modelName];
                        }

                        nPose = fcRow.FieldIndex("Geometry");
                        fcRow.SetValue(nPose, modePoint);
                        fcRows.Add(fcRow);

                        //tc
                        if (Images != null)
                        {
                            int nCount = Images.Count;
                            if (nCount > 0)
                            {
                                Hashtable htImages = Images.AsHashtable();
                                foreach (DictionaryEntry item in htImages)
                                {
                                    string imgName = item.Key.ToString();
                                    IImage img     = item.Value as IImage;
                                    if (img == null)
                                    {
                                        continue;
                                    }
                                    if (string.IsNullOrEmpty(imgName))
                                    {
                                        continue;
                                    }

                                    //如果内存中不包含
                                    if (!cacheImageNames.Contains(imgName))
                                    {
                                        //数据库中包含
                                        if (rm.ImageExist(imgName))
                                        {
                                            //重名即跳过
                                        }
                                    }

                                    //如果内存中不包含,数据库中也不包含
                                    if (!rm.ImageExist(imgName) &&
                                        !cacheImageNames.Contains(imgName))
                                    {
                                        cacheImageNames.Add(imgName);
                                        rm.AddImage(imgName, img);
                                    }
                                }
                            }
                        }
                        //end

                        if (fcRows.Count >= 10)
                        {
                            InsertFeatures(fc as IObjectClass, fcRows);
                            fcRows.Clear();
                        }
                    }
                    reader.Close();
                    oleConn.Close();
                }

                if (fcRows.Count > 0)
                {
                    InsertFeatures(fc as IObjectClass, fcRows);
                    fcRows.Clear();
                }
            }
            catch (System.Exception ex)
            {
                if (ex.GetType().Name.Equals("UnauthorizedAccessException"))
                {
                    MessageBox.Show("需要标准runtime授权");
                }
                else
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }
예제 #12
0
        public void ImportModelXml(IFeatureClass fc, string mdbFile, int groupId, int _nCount)
        {
            try
            {
                //2、获取基本信息
                FileInfo         fInfo       = new FileInfo(mdbFile);
                string           strFilePath = fInfo.DirectoryName;
                IResourceManager rm          = fc.FeatureDataSet as IResourceManager;
                Dictionary <string, IEnvelope> cacheModeInfos = new Dictionary <string, IEnvelope>();
                List <string> cacheImageNames = new List <string>();

                IGeometryFactory geoFactory = new GeometryFactory();
                IResourceFactory symbolFac  = new ResourceFactory();

                IRowBufferCollection fcRows = new RowBufferCollection();
                IRowBuffer           fcRow  = null;

                //4、解析xml
                string      strConn    = "" + mdbFile + "\'";
                int         index      = 0;
                int         totalCount = _nCount;
                IModelPoint modePoint  = null;
                for (int i = 0; i < _nCount; ++i)
                {
                    int    percent = ++index * 100 / totalCount;
                    string toolTip = string.Format("已完成{0}条/总共{1}条 {2}%", index, totalCount, percent);
                    CommonEntity.FormEntity.Text = toolTip;

                    //fc
                    fcRow = fc.CreateRowBuffer();
                    int nPose = fcRow.FieldIndex("name");
                    if (nPose == -1)
                    {
                        continue;
                    }
                    string modelName = _dataTable.Rows[i]["ModelName"].ToString();
                    fcRow.SetValue(nPose, modelName);

                    nPose = fcRow.FieldIndex("groupId");
                    if (nPose == -1)
                    {
                        continue;
                    }
                    fcRow.SetValue(nPose, groupId);

                    modePoint = (IModelPoint)geoFactory.CreateGeometry(
                        gviGeometryType.gviGeometryModelPoint,
                        gviVertexAttribute.gviVertexAttributeZ);
                    modePoint.ModelName = modelName;

                    double dModePointX = double.Parse(_dataTable.Rows[i]["LocationX"].ToString()) + 0;  // CoorX = 0
                    double dModePointY = double.Parse(_dataTable.Rows[i]["LocationY"].ToString()) + 0;  // CoorY = 0
                    double dModePointZ = double.Parse(_dataTable.Rows[i]["LocationZ"].ToString()) + 0;  // CoorZ = 0

                    string  strMatrix = _dataTable.Rows[i]["Matrix3"].ToString();
                    float[] Matrix    = null;
                    if (!string.IsNullOrEmpty(strMatrix))
                    {
                        string[] strArray = strMatrix.Split(',');
                        if (strArray.Length == 9)
                        {
                            Matrix    = new float[9];
                            Matrix[0] = float.Parse(strArray[0]);
                            Matrix[1] = float.Parse(strArray[1]);
                            Matrix[2] = float.Parse(strArray[2]);
                            Matrix[3] = float.Parse(strArray[3]);
                            Matrix[4] = float.Parse(strArray[4]);
                            Matrix[5] = float.Parse(strArray[5]);
                            Matrix[6] = float.Parse(strArray[6]);
                            Matrix[7] = float.Parse(strArray[7]);
                            Matrix[8] = float.Parse(strArray[8]);
                        }
                    }
                    modePoint.X        = dModePointX;
                    modePoint.Y        = dModePointY;
                    modePoint.Z        = dModePointZ;
                    modePoint.Matrix33 = Matrix;


                    //mc
                    IPropertySet Images = null;

                    //如果内存中不包含
                    if (!cacheModeInfos.Keys.Contains(modelName))
                    {
                        //数据库中包含
                        if (rm.ModelExist(modelName))
                        {
                            //重名即跳过
                            IEnvelope ev = rm.GetModel(modelName).Envelope;
                            modePoint.ModelEnvelope = ev;
                        }
                        else
                        {
                            IModel  simpleModel = null;
                            string  osgFilePath = strFilePath + "\\" + modelName + ".osg";
                            IModel  fineModel   = null;
                            IMatrix matrix      = null;
                            symbolFac.CreateModelAndImageFromFileEx(osgFilePath,
                                                                    out Images, out simpleModel, out fineModel, out matrix);
                            if (fineModel == null || fineModel.GroupCount == 0)
                            {
                                continue;
                            }

                            cacheModeInfos[modelName] = modePoint.ModelEnvelope = Clone(fineModel.Envelope);

                            rm.AddModel(modelName, fineModel, simpleModel);
                            //Marshal.ReleaseComObject(simpleModel);
                            //Marshal.ReleaseComObject(fineModel);
                        }
                    }
                    else
                    {
                        modePoint.ModelEnvelope = cacheModeInfos[modelName];
                    }

                    nPose = fcRow.FieldIndex("Geometry");
                    fcRow.SetValue(nPose, modePoint);
                    fcRows.Add(fcRow);

                    //tc
                    int nCount = Images.Count;
                    if (Images != null && nCount > 0)
                    {
                        Hashtable htImages = Images.AsHashtable();
                        foreach (DictionaryEntry item in htImages)
                        {
                            string imgName = item.Key.ToString();
                            IImage img     = item.Value as IImage;
                            if (img == null)
                            {
                                continue;
                            }
                            if (string.IsNullOrEmpty(imgName))
                            {
                                continue;
                            }

                            //如果内存中不包含
                            if (!cacheImageNames.Contains(imgName))
                            {
                                //数据库中包含
                                if (rm.ImageExist(imgName))
                                {
                                    //重名即跳过
                                }
                            }

                            //如果内存中不包含,数据库中也不包含
                            if (!rm.ImageExist(imgName) &&
                                !cacheImageNames.Contains(imgName))
                            {
                                cacheImageNames.Add(imgName);

                                rm.AddImage(imgName, img);
                            }
                        }
                    }
                    //end

                    if (fcRows.Count >= 10)
                    {
                        InsertFeatures(fc as IObjectClass, fcRows);
                        fcRows.Clear();
                    }
                }
                if (fcRows.Count > 0)
                {
                    InsertFeatures(fc as IObjectClass, fcRows);
                    fcRows.Clear();
                }
            }
            catch (System.Exception ex)
            {
                if (ex.GetType().Name.Equals("UnauthorizedAccessException"))
                {
                    MessageBox.Show("需要标准runtime授权");
                }
                else
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }
예제 #13
0
        public void ImportModelOsg(string osgFile)
        {
            //try
            {
                FileInfo         fInfo       = new FileInfo(osgFile);
                string           strFilePath = fInfo.DirectoryName;
                IObjectManager   rm          = this.axRenderControl1.ObjectManager;
                IGeometryFactory geoFactory  = new GeometryFactory();
                IResourceFactory symbolFac   = new ResourceFactory();

                //mc
                string       modelName   = fInfo.Name.Split('.')[0];
                string       osgFilePath = strFilePath + "\\" + modelName + ".osg";
                IPropertySet Images      = null;
                IModel       model       = null;
                IMatrix      matrix      = null;
                symbolFac.CreateModelAndImageFromFile(osgFilePath, out Images, out model, out matrix);
                if (model == null || model.GroupCount == 0)
                {
                    return;
                }
                rm.AddModel(modelName, model);

                //tc
                int nCount = Images.Count;
                if (Images != null && nCount > 0)
                {
                    string[] keys = Images.GetAllKeys();
                    foreach (string imgName in keys)
                    {
                        IImage img = Images.GetProperty(imgName) as IImage;

                        if (img == null)
                        {
                            continue;
                        }
                        if (string.IsNullOrEmpty(imgName))
                        {
                            continue;
                        }

                        rm.AddImage(imgName, img);
                    }
                }

                //modelpoint
                IModelPoint modelPoint = null;
                modelPoint = (IModelPoint)geoFactory.CreateGeometry(
                    gviGeometryType.gviGeometryModelPoint,
                    gviVertexAttribute.gviVertexAttributeZ);
                modelPoint.FromMatrix(matrix);
                modelPoint.ModelName  = modelName;
                modelPoint.SpatialCRS = (new CRSFactory()).CreateFromWKT(this.axRenderControl1.GetCurrentCrsWKT()) as ISpatialCRS;


                if (this.toolStripComboBoxOsgMode.SelectedIndex == 0)
                {
                    rmp = this.axRenderControl1.ObjectManager.CreateRenderModelPoint(modelPoint, null, rootId);
                    this.axRenderControl1.Camera.FlyToObject(rmp.Guid, gviActionCode.gviActionFlyTo);
                }
                else
                {
                    modelPoint.X = 0.0;
                    modelPoint.Y = 0.0;
                    modelPoint.Z = 0.0;

                    rmp = this.axRenderControl1.ObjectManager.CreateRenderModelPoint(modelPoint, null, rootId);
                    rmp.MouseSelectMask = gviViewportMask.gviViewNone;  //设置物体不可拾取,以免总是拾取到自身影响交互
                    IEulerAngle angle = new EulerAngle();
                    angle.Set(0, -50, 0);
                    this.axRenderControl1.Camera.LookAt2(modelPoint, 200, angle);

                    this.axRenderControl1.InteractMode = gviInteractMode.gviInteractEdit;
                    this.axRenderControl1.ObjectEditor.StartEditRenderGeometry(rmp, gviGeoEditType.gviGeoEditCreator);
                }
            }
            //catch (System.Exception ex)
            //{
            //    if (ex.GetType().Name.Equals("UnauthorizedAccessException"))
            //        MessageBox.Show("需要标准runtime授权");
            //    else
            //        MessageBox.Show(ex.Message);
            //}
        }
예제 #14
0
파일: ImportOSG.cs 프로젝트: batuZ/Samples
        public void ImportModelOsg(IFeatureClass fc, string osgFile, int groupId)
        {
            try
            {
                FileInfo         fInfo       = new FileInfo(osgFile);
                string           strFilePath = fInfo.DirectoryName;
                IResourceManager rm          = fc.FeatureDataSet as IResourceManager;
                IGeometryFactory geoFactory  = new GeometryFactory();
                IResourceFactory symbolFac   = new ResourceFactory();
                IRowBuffer       fcRow       = null;

                //fc
                string modelName = fInfo.Name.Split('.')[0];
                fcRow = fc.CreateRowBuffer();
                int nPose = fcRow.FieldIndex("name");
                if (nPose != -1)
                {
                    fcRow.SetValue(nPose, modelName);
                }
                nPose = fcRow.FieldIndex("groupId");
                if (nPose != -1)
                {
                    fcRow.SetValue(nPose, groupId);
                }

                //mc
                IPropertySet Images      = null;
                IModel       simpleModel = null;
                string       osgFilePath = strFilePath + "\\" + modelName + ".osg";
                IModel       fineModel   = null;
                IMatrix      matrix      = null;
                symbolFac.CreateModelAndImageFromFileEx(osgFilePath,
                                                        out Images, out simpleModel, out fineModel, out matrix);
                if (fineModel == null || fineModel.GroupCount == 0)
                {
                    return;
                }
                rm.AddModel(modelName, fineModel, simpleModel);
                //Marshal.ReleaseComObject(simpleModel);
                //Marshal.ReleaseComObject(fineModel);

                //tc
                int nCount = Images.Count;
                if (Images != null && nCount > 0)
                {
                    Hashtable htImages = Images.AsHashtable();
                    foreach (DictionaryEntry item in htImages)
                    {
                        String imgName = item.Key.ToString();
                        IImage img     = item.Value as IImage;
                        rm.AddImage(imgName, img);
                    }
                }

                //modelpoint
                IModelPoint modePoint = null;
                modePoint = (IModelPoint)geoFactory.CreateGeometry(
                    gviGeometryType.gviGeometryModelPoint,
                    gviVertexAttribute.gviVertexAttributeZ);
                modePoint.FromMatrix(matrix);
                modePoint.ModelName = modelName;
                double dModePointX = 0.0;
                double dModePointY = 0.0;
                double dModePointZ = 0.0;
                modePoint.X += dModePointX;
                modePoint.Y += dModePointY;
                modePoint.Z += dModePointZ;
                nPose        = fcRow.FieldIndex("Geometry");
                fcRow.SetValue(nPose, modePoint);

                if (fc.HasTemporal())
                {
                    ITemporalManager mgr = fc.TemporalManager;
                    mgr.Insert(DateTime.Now, fcRow);
                    //Marshal.ReleaseComObject(mgr);
                }
                else
                {
                    IRowBufferCollection fcRows = new RowBufferCollection();
                    fcRows.Add(fcRow);
                    InsertFeatures(fc as IObjectClass, fcRows);
                    fcRows.Clear();
                }
            }
            catch (System.Exception ex)
            {
                if (ex.GetType().Name.Equals("UnauthorizedAccessException"))
                {
                    MessageBox.Show("需要标准runtime授权");
                }
                else
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }