protected void InitModel(Point3Ds Bottom, Point3Ds Top)
        {
            geoModel = new GeoModel();
            n = Math.Min(Bottom.Count, Top.Count);
            surface = new Mesh[n + 2];

            surface[n] = geoModel.CreateMesh(Bottom);
            surface[n + 1] = geoModel.CreateMesh(Top);

            for (int i = 0; i < n; i++)
            {
                Point3Ds p3ds = new Point3Ds();
                p3ds.Add(Bottom[i]);
                p3ds.Add(Bottom[(i + 1) % n]);
                p3ds.Add(Top[(i + 1) % n]);
                p3ds.Add(Top[i]);
                surface[i] = geoModel.CreateMesh(p3ds);
            }

            if (this.Meshes.Count > 0)
            {
                this.Meshes.Clear();
            }
            for (int i = 0; i < surface.Length; i++)
            {
                this.Meshes.Add(surface[i]);
            }
        }
Example #2
0
        protected void InitModel(Point3Ds Bottom, Point3Ds Top)
        {
            geoModel = new GeoModel();
            n        = Math.Min(Bottom.Count, Top.Count);
            surface  = new Mesh[n + 2];

            surface[n]     = geoModel.CreateMesh(Bottom);
            surface[n + 1] = geoModel.CreateMesh(Top);

            for (int i = 0; i < n; i++)
            {
                Point3Ds p3ds = new Point3Ds();
                p3ds.Add(Bottom[i]);
                p3ds.Add(Bottom[(i + 1) % n]);
                p3ds.Add(Top[(i + 1) % n]);
                p3ds.Add(Top[i]);
                surface[i] = geoModel.CreateMesh(p3ds);
            }

            if (this.Meshes.Count > 0)
            {
                this.Meshes.Clear();
            }
            for (int i = 0; i < surface.Length; i++)
            {
                this.Meshes.Add(surface[i]);
            }
        }
Example #3
0
 /// <summary>
 /// 从vPDic和vPIndex导入顶点到Point3Ds
 /// </summary>
 /// <param name="ps"></param>
 /// <param name="vPDic"></param>
 /// <param name="vPIndex"></param>
 public static void ImportVPList(this Point3Ds ps, Dictionary <int, Vertice> vPDic, List <Index> vPIndex)
 {
     foreach (Index index in vPIndex)
     {
         ps.Add(new Point3D(vPDic[index.P1].X, vPDic[index.P1].Y, vPDic[index.P1].Z));
         ps.Add(new Point3D(vPDic[index.P2].X, vPDic[index.P2].Y, vPDic[index.P2].Z));
         ps.Add(new Point3D(vPDic[index.P3].X, vPDic[index.P3].Y, vPDic[index.P3].Z));
     }
     //foreach (KeyValuePair<int, Vertice> vP in vPDic)
     //{
     //    ps.Add(new Point3D(vP.Value.X, vP.Value.Y, vP.Value.Z));
     //}
 }
Example #4
0
        public void run()
        {
            Recordset rc = dv.GetRecordset(false, CursorType.Dynamic);
            Dictionary <int, Feature> feas = rc.GetAllFeatures();

            foreach (KeyValuePair <int, Feature> item in feas)
            {
                GeoModel gm = item.Value.GetGeometry() as GeoModel;
                Console.WriteLine("==" + gm.Position + "==");

                //GeoModel model = new ModelIncubation.CuboidModel(10, 10, 10);
                Point3Ds p3ds = new Point3Ds();
                for (int i = 0; i < 7; i++)
                {
                    double seta = 2 * Math.PI * i / 7;
                    p3ds.Add(new Point3D(Math.Sin(seta) * 10, Math.Cos(seta) * 10, 0));
                }
                GeoModel model = new ModelIncubation.PrismModel(p3ds, 30);

                //临时处理,未知原因导致Position.Z属性设置无效,手动偏移模型实体
                model.OffsetModel(new Point3D(0, 0, 1650));
                model.Position = gm.Position;
                model.MergeMeshs();
                Console.WriteLine("");

                model.Position = gm.Position;
                model.ComputeBoundingBox();
                scene.TrackingLayer.Add(model, model.Position.ToString());
                scene.Refresh();
                GeoModel m = scene.TrackingLayer.Get(0) as GeoModel;
                Thread.Sleep(1000);

                break;
            }
        }
 /// <summary>
 /// 构造一个棱柱
 /// </summary>
 /// <param name="Bottom">棱柱底面外围坐标序列</param>
 /// <param name="h">棱柱高</param>
 public PrismModel(Point3Ds Bottom,double h)
 {
     Point3Ds Top = new Point3Ds();
     for (int i = 0; i < Bottom.Count; i++)
     {
         Top.Add(new Point3D(Bottom[i].X, Bottom[i].Y, Bottom[i].Z + h));
     }
     InitModel(Bottom, Top);
 }
Example #6
0
 private Point3Ds ConvertPoint2DsToPoint3Ds(Point2Ds point2Ds)
 {
     m_point3DsAll.Clear();
     for (int i = 0; i < point2Ds.Count; i++)
     {
         m_point3DsAll.Add(new Point3D(point2Ds[i].X, point2Ds[i].Y,
                                       scontrol.Scene.GetAltitude(point2Ds[i].X, point2Ds[i].Y) + 30));
     }
     return(m_point3DsAll);
 }
Example #7
0
        /// <summary>
        /// 构造一个棱柱
        /// </summary>
        /// <param name="Bottom">棱柱底面外围坐标序列</param>
        /// <param name="h">棱柱高</param>
        public PrismModel(Point3Ds Bottom, double h)
        {
            Point3Ds Top = new Point3Ds();

            for (int i = 0; i < Bottom.Count; i++)
            {
                Top.Add(new Point3D(Bottom[i].X, Bottom[i].Y, Bottom[i].Z + h));
            }
            InitModel(Bottom, Top);
        }
 /// <summary>
 /// 空构造函数,生成单位正方体
 /// </summary>
 public PrismModel()
 {
     Point3Ds Bottom = new Point3Ds();
     Point3Ds Top = new Point3Ds();
     for (int i = 0; i < 4; i++)
     {
         Bottom.Add(new Point3D(i%2,i/2,0));
         Top.Add(new Point3D(i%2,i/2,1));
     }
     InitModel(Bottom, Top);
 }
Example #9
0
        void m_sceneControl_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
        {
            // 鼠标左键
            if (e.Button == System.Windows.Forms.MouseButtons.Left &&
                !Double.IsNaN(scontrol.Scene.PixelToGlobe(e.Location).X))
            {
                //RouteStop stop = new RouteStop();
                //TreeNode treeNode = new TreeNode();
                //m_treeView.Nodes[0].Nodes.Add(treeNode);
                //if (treeNode.Index > 0)
                //{
                //    treeNode.Text = GetStopName(treeNode.PrevNode.Text);
                //    //stop.Name = GetStopName(treeNode.PrevNode.Text);
                //}
                //else
                //{
                //    treeNode.Text = "Stop1";
                //    //stop.Name = "Stop1";

                //}
                //m_treeView.Nodes[0].ExpandAll();

                Point3D point3D = scontrol.Scene.PixelToGlobe(e.Location);
                point3D.Z = scontrol.Scene.GetAltitude(point3D.X, point3D.Y) + 30;
                m_point3Ds.Add(point3D);

                //stop.Camera = new Camera(point3D.X,point3D.Y,point3D.Z);



                GeoPoint3D geoPoint3D = new GeoPoint3D(point3D);
                geoPoint3D.Style3D = GetPointGeoStyle3D(geoPoint3D.Z);
                geoPoint3D.Z       = 0;

                //m_routeStops.Add(stop);

                scontrol.Scene.TrackingLayer.Add(geoPoint3D, m_pointName);
            }
            //鼠标右键,结束绘制,将实时生成的路线加到FlyManager中
            else if (e.Button == System.Windows.Forms.MouseButtons.Right)
            {
                if (m_point3Ds.Count > 1)
                {
                    SetGeoLine3DToTrackingLayer(m_point3Ds.ToPoint2Ds(), 20);

                    m_flyManager.Routes.Add(GetRoute());
                }
                else
                {
                    ResumeDefault();
                }
                RegisterEvents(false);
            }
        }
Example #10
0
        /// <summary>
        /// 空构造函数,生成单位正方体
        /// </summary>
        public PrismModel()
        {
            Point3Ds Bottom = new Point3Ds();
            Point3Ds Top    = new Point3Ds();

            for (int i = 0; i < 4; i++)
            {
                Bottom.Add(new Point3D(i % 2, i / 2, 0));
                Top.Add(new Point3D(i % 2, i / 2, 1));
            }
            InitModel(Bottom, Top);
        }
        /// <summary>
        /// 正方体
        /// </summary>
        public CuboidModel(double a = 1, double b = 1, double c = 1)
        {
            Point3Ds Bottom = new Point3Ds();
            Point3Ds Top    = new Point3Ds();

            for (int i = 0; i < 4; i++)
            {
                Bottom.Add(new Point3D(((i + 1) / 2) % 2 * a - a / 2, i / 2 * b - b / 2, 0));
                Top.Add(new Point3D(((i + 1) / 2) % 2 * a - a / 2, i / 2 * b - b / 2, c));
            }
            InitModel(Bottom, Top);
        }
Example #12
0
        private void button3_Click(object sender, EventArgs e)
        {
            Point3Ds p3ds = new Point3Ds();

            p3ds.Add(new Point3D(0, 0, 0));
            p3ds.Add(new Point3D(0, 0.8, 0));
            p3ds.Add(new Point3D(0.8, 0.8, 0));
            p3ds.Add(new Point3D(0.8, 0, 0));
            scon.Scene.EnsureVisible(new Rectangle2D(new Point2D(0, 0), new Size2D(0.5, 0.5)));
            GeoModel gm = new PrismModel(p3ds, 0.2);

            gm.Position = new Point3D(0, 0, 0);
            gm.OffsetModel(new Point3D(0, 0, scon.Scene.GetAltitude(0, 0) + 100));
            for (int i = 0; i < 30; i++)
            {
                for (int j = 0; j < 40; j++)
                {
                    gm.OffsetModel(new Point3D(i, j, 0));
                    scon.Scene.TrackingLayer.Add(gm, string.Format("{0}-{1}", i, j));
                    gm.OffsetModel(new Point3D(0 - i, 0 - j, 0));
                }
            }
        }
Example #13
0
        public void OutputMeasureArea(SuperMap.UI.Tracking3DEventArgs e1)
        {
            try
            {
                Point location = mSceneControl.PointToClient(Cursor.Position);
                mTempPoint = new Point3D(e1.X, e1.Y, e1.Z);
                mPoint3Ds.Add(mTempPoint);
                GeoRegion3D geoRegion3D = null;

                if (mPoint3Ds.Count >= 3)
                {
                    geoRegion3D                   = new GeoRegion3D(mPoint3Ds);
                    mGeoStyle3DTemp               = new GeoStyle3D();
                    mGeoStyle3DTemp.MarkerColor   = Color.FromArgb(255, 0, 0);
                    mGeoStyle3DTemp.LineColor     = Color.FromArgb(0, 255, 0);
                    mGeoStyle3DTemp.LineWidth     = 1;
                    mGeoStyle3DTemp.FillForeColor = Color.FromArgb(180, Color.Violet);
                    mGeoStyle3DTemp.AltitudeMode  = AltitudeMode.RelativeToGround;
                    geoRegion3D.Style3D           = mGeoStyle3DTemp.Clone();

                    location.Offset(30, 30);
                    if (location.X > mSceneControl.Bounds.Width / 4 * 3)
                    {
                        location.X = mSceneControl.Bounds.Width / 4 * 3;
                    }
                    if (location.Y > mSceneControl.Bounds.Height)
                    {
                        location.Y = location.Y - 60;
                    }

                    int index = mSceneControl.Scene.TrackingLayer.IndexOf(mMessageTrackingTag);
                    if (index >= 0)
                    {
                        mSceneControl.Scene.TrackingLayer.Remove(index);
                    }
                }
            }
            catch (System.Exception ex)
            {
                Trace.WriteLine(ex.Message);
            }
        }
        /// <summary>
        /// 地理坐标向投影坐标转换
        /// </summary>
        /// <param name="point3Ds"></param>
        /// <returns></returns>
        private Point3Ds coordinateTrans3D(Point3Ds point3Ds)
        {
            Point2Ds point2Ds = new Point2Ds();

            foreach (Point3D p3d in point3Ds)
            {
                Point2D point2D = new Point2D(p3d.X, p3d.Y);
                point2Ds.Add(point2D);
            }
            //Assume Wgs1984WorldMercator as target project coordinate system
            PrjCoordSys prjTarget = new PrjCoordSys(PrjCoordSysType.Wgs1984Utm50N);
            bool        b         = CoordSysTranslator.Forward(point2Ds, prjTarget);

            Point3Ds result = new Point3Ds();

            for (int i = 0; i < point2Ds.Count; i++)
            {
                Point3D point3D = new Point3D(point2Ds[i].X, point2Ds[i].Y, point3Ds[i].Z);
                result.Add(point3D);
            }
            return(result);
        }
Example #15
0
        public void run()
        {
            Recordset rc = dv.GetRecordset(false, CursorType.Dynamic);

            Dictionary<int, Feature> feas = rc.GetAllFeatures();

            foreach (KeyValuePair<int, Feature> item in feas)
            {
                GeoModel gm = item.Value.GetGeometry() as GeoModel;
                Console.WriteLine("==" + gm.Position + "==");

                GeoModel model = new GeoModel();
                model.Position = gm.Position;
                foreach (Mesh m in gm.Meshes)
                {
                    if (m.Material.TextureFile.Length > 1)
                    {
                        //Console.WriteLine(m.Material.TextureFile.ToString());
                        Point3Ds p3ds = new Point3Ds();

                        for (int i = 0; i < m.Vertices.Length; i += 3)
                        {
                            bool repition = false;
                            foreach (Point3D p in p3ds)
                            {
                                if (p.X == m.Vertices[i] && p.Y == m.Vertices[i + 1] && p.Z == m.Vertices[i + 2])
                                {
                                    repition = true;
                                }
                            }
                            if (!repition)
                            {
                                p3ds.Add(new Point3D(m.Vertices[i], m.Vertices[i + 1], m.Vertices[i + 2]));

                            }
                        }

                        foreach (Point3D p3d in p3ds)
                        {
                            Console.WriteLine(string.Format(" {0},{1},{2}", p3d.X, p3d.Y, p3d.Z));
                            scene.TrackingLayer.Add(new GeoPoint3D(p3d.X, p3d.Y, p3d.Z), "");
                        }
                        //model.Meshes.Add(MakeMeshPot(p3ds));
                        Mesh mesh = new Mesh(m);
                        mesh.Material.TextureFile = @".\78310a55b319ebc41f7810198326cffc1e171629.png";
                        model.Meshes.Add(mesh);

                        #region 写属性表
                        Dictionary<string, double> fields = new Dictionary<string, double>();
                        fields.Add("FaceMeshCenterX", model.Position.X);
                        fields.Add("FaceMeshCenterY", model.Position.Y);
                        fields.Add("FaceMeshCenterZ", model.Position.Z);
                        fields.Add("FaceMeshLx", p3ds.leftbottom().X);
                        fields.Add("FaceMeshLy", p3ds.leftbottom().Y);
                        fields.Add("FaceMeshLz", p3ds.leftbottom().Z);
                        fields.Add("FaceMeshUx", p3ds.rightup().X);
                        fields.Add("FaceMeshUy", p3ds.rightup().Y);
                        fields.Add("FaceMeshUz", p3ds.rightup().Z);

                        foreach (KeyValuePair<string, double> field in fields)
                        {
                            if (dv.FieldInfos.IndexOf(field.Key) < 0)
                            {
                                FieldInfo fieldInf = new FieldInfo(field.Key, FieldType.Double);
                                dv.FieldInfos.Add(fieldInf);
                            }

                            string fieldName = field.Key;
                            double fieldValue = field.Value;
                            try
                            {
                                rc.SeekID(item.Value.GetID());
                                rc.Edit();
                                rc.SetFieldValue(fieldName, fieldValue);
                                rc.Update();
                            }
                            catch
                            {
                                Console.WriteLine("error!");
                            }
                            //Console.WriteLine(string.Format("{0},{1},{2}", item.GetID(), fieldName, fieldValue));
                        }
                        #endregion
                    }
                }
                Console.WriteLine("");

                model.ComputeBoundingBox();
                scene.TrackingLayer.Add(model, gm.Position.ToString());
                scene.Refresh();
            }
        }
        void mSceneControlSelected(object sender, ObjectSelectedEventArgs e)
        {
            Recordset recordset = null;

            Selection3D[] selection3d = null;
            mGeoLine3D = new GeoLine3D();
            //水平及竖直净距
            if (mSceneControl.Action == Action3D.Select && mFlag == 1 ||
                mSceneControl.Action == Action3D.Select && mFlag == 2)
            {
                if (e.Count > 0)
                {
                    selection3d = mSceneControl.Scene.FindSelection(true);
                    recordset   = selection3d[0].ToRecordset();
                    if (recordset.GetGeometry().Type != mGeoLine3D.Type)
                    {
                        MessageBox.Show("请选择三维线对象!");
                    }
                    else
                    {
                        mGeoLine3D = recordset.GetGeometry() as GeoLine3D;
                        if (TempGeoLine.Count > 0 && TempGeoLine[0].Bounds == mGeoLine3D.Bounds)
                        {
                            MessageBox.Show("请不要选择同一条三维线对象!");
                        }
                        else
                        {
                            mTextPoint3Ds.Add(mGeoLine3D.InnerPoint3D);
                            TempGeoLine.Add(mGeoLine3D);
                        }
                    }
                    if (TempGeoLine.Count == 2)
                    {
                        this.SetPoint(TempGeoLine);
                    }
                }
            }
            //覆土分析
            if (mSceneControl.Action == Action3D.Select && mFlag == 3)
            {
                string str = "";
                object obj;
                selection3d = mSceneControl.Scene.FindSelection(true);
                recordset   = selection3d[0].ToRecordset();
                if (e.Count > 0)
                {
                    selection3d = mSceneControl.Scene.FindSelection(true);
                    recordset   = selection3d[0].ToRecordset();
                    if (recordset.GetGeometry().Type != mGeoLine3D.Type)
                    {
                        MessageBox.Show("请选择三维线对象!");
                    }
                    else
                    {
                        mGeoLine3D = recordset.GetGeometry() as GeoLine3D;
                        mTextPoint3Ds.Add(mGeoLine3D.InnerPoint3D);
                        Point3D cPoint3D = new Point3D(mGeoLine3D.InnerPoint3D.X, mGeoLine3D.InnerPoint3D.Y, 0);
                        mTextPoint3Ds.Add(cPoint3D);
                        for (int i = 0; i < recordset.FieldCount; i++)
                        {
                            str = recordset.GetFieldInfos()[i].Name;
                            if (str == "BottomAltitude")
                            {
                                obj       = recordset.GetFieldValue(i);
                                mAltitude = Convert.ToDouble(obj);
                            }
                            if (str == "PipeDiameter")
                            {
                                obj       = recordset.GetFieldValue(i);
                                mDiameter = new double[] { Convert.ToDouble(obj) };
                            }
                        }
                    }
                    GetCoverRusult();
                }
            }
            //碰撞检测
            if (mSceneControl.Action == Action3D.Select && mFlag == 4)
            {
                if (e.Count > 0)
                {
                    string str = "";
                    object obj;
                    selection3d = mSceneControl.Scene.FindSelection(true);
                    recordset   = selection3d[0].ToRecordset();
                    if (recordset.GetGeometry().Type != mGeoLine3D.Type)
                    {
                        MessageBox.Show("请选择三维线对象!");
                    }
                    else
                    {
                        mGeoLine3D = recordset.GetGeometry() as GeoLine3D;
                        if (TempGeoLine.Count > 0 && TempGeoLine[0].Bounds == mGeoLine3D.Bounds)
                        {
                            MessageBox.Show("请不要选择同一条三维线对象!");
                        }
                        else if (TempGeoLine.Count > 0 && recordset.Dataset.Name == TempRecordset.Dataset.Name)
                        {
                            MessageBox.Show("请不要选择同一数据集线对象!");
                        }
                        else
                        {
                            mTextPoint3Ds.Add(mGeoLine3D.InnerPoint3D);
                            TempGeoLine.Add(mGeoLine3D);
                            TempRecordset = recordset;
                            for (int i = 0; i < recordset.FieldCount; i++)
                            {
                                str = recordset.GetFieldInfos()[i].Name;
                                if (str == "PipeDiameter")
                                {
                                    obj = recordset.GetFieldValue(i);
                                    if (TempGeoLine.Count == 2)
                                    {
                                        mDiameter[1] = Convert.ToDouble(obj);
                                    }
                                    else
                                    {
                                        mDiameter    = new double[2];
                                        mDiameter[0] = Convert.ToDouble(obj);
                                    }
                                }
                            }
                        }
                    }
                    if (TempGeoLine.Count == 2)
                    {
                        this.SetPoint(TempGeoLine);
                    }
                }
            }
        }
        /// <summary>
        /// 鼠标动作Up
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void SceneControlMouseUp(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Right)
            {
                EndOneMeasure();
            }

            if (e.Button == MouseButtons.Left)
            {
                if (mPoint3Ds.Count == 0)
                {
                    //ClearMeasureResult();
                }

                if (mTempPoint != Point3D.Empty && mPoint3Ds.Count > 1)
                {
                    mPoint3Ds.Remove(mPoint3Ds.Count - 1);
                    mTempPoint = Point3D.Empty;
                }

                Point   location = mSceneControl.PointToClient(Cursor.Position);
                Point3D point3D  = new Point3D();

                if (mSceneControl.Action == Action3D.MeasureDistance && mIndex == 8 ||
                    mSceneControl.Action == Action3D.MeasureAltitude && mIndex == 9 ||
                    mSceneControl.Action == Action3D.MeasureHorizontalDistance)
                {
                    point3D = mSceneControl.Scene.PixelToGlobe(new Point(e.X, e.Y), SuperMap.Realspace.PixelToGlobeMode.TerrainAndModel);
                }
                else
                {
                    point3D = mSceneControl.Scene.PixelToGlobe(new Point(e.X, e.Y));
                }

                if (!Double.IsNaN(point3D.X) && !Double.IsNaN(point3D.Y) && !Double.IsNaN(point3D.Z))
                {
                    mPoint3Ds.Add(point3D);


                    if (mSceneControl.Action == Action3D.MeasureHorizontalDistance ||
                        mSceneControl.Action == Action3D.MeasureDistance && mIndex == 8)
                    {
                        //添加部分段长度
                        if (!Toolkit.IsZero(mCurLength))
                        {
                            if (mPoint3Ds.Count >= 2)
                            {
                                mPoint3Ds.RemoveRange(0, mPoint3Ds.Count - 2);
                                String     distanceUnit = "米";
                                GeoLine3D  geoLine3D    = new GeoLine3D(mPoint3Ds);
                                TextPart3D textPart3D   = new TextPart3D();
                                textPart3D.AnchorPoint = new Point3D(0, 0, 0);
                                Double tempCurLength = mCurLength;
                                textPart3D.Text = String.Format("{0:F2}{1}", tempCurLength, " " + distanceUnit);
                                if (mPoint3Ds[0].X > 0 && mPoint3Ds[1].X > 0 ||
                                    mPoint3Ds[0].X < 0 && mPoint3Ds[1].X < 0)
                                {
                                    textPart3D.X = geoLine3D.InnerPoint3D.X;
                                }
                                else
                                {
                                    textPart3D.X = 180;
                                }

                                textPart3D.Y = geoLine3D.InnerPoint3D.Y;
                                textPart3D.Z = geoLine3D.InnerPoint3D.Z;

                                GeoText3D text3d = mCurrentGeoText3DMessage == null?GetGeoText3DMessage() : mCurrentGeoText3DMessage;

                                text3d.AddPart(textPart3D);

                                //设置文字样式
                                text3d.TextStyle.FontHeight = 6;
                                text3d.TextStyle.Alignment  = TextAlignment.BottomLeft;
                                text3d.TextStyle.BackColor  = Color.Black;
                                text3d.TextStyle.Outline    = true;
                                text3d.Style3D.AltitudeMode = AltitudeMode.Absolute;

                                int index = mSceneControl.Scene.TrackingLayer.IndexOf(MessageTag);
                                if (index >= 0)
                                {
                                    mSceneControl.Scene.TrackingLayer.Remove(index);
                                }
                                //ClearTextMessageTag();
                                mSceneControl.Scene.TrackingLayer.Add(text3d, MessageTag);
                            }
                        }

                        //测地形距离
                        else if (mSceneControl.Action == Action3D.MeasureTerrainDistance)
                        {
                            //添加部分段长度
                            if (!Toolkit.IsZero(mCurLength))
                            {
                                if (mPoint3Ds.Count >= 2)
                                {
                                    mPoint3Ds.RemoveRange(0, mPoint3Ds.Count - 2);

                                    GeoLine3D  geoLine3D    = new GeoLine3D(mPoint3Ds);
                                    String     distanceUnit = "米";
                                    TextPart3D textPart3D   = new TextPart3D();
                                    textPart3D.AnchorPoint = new Point3D(0, 0, 0);
                                    Double tempCurLength = mCurLength;
                                    textPart3D.Text = String.Format("{0:F2}{1}", tempCurLength, " " + distanceUnit);
                                    if (mPoint3Ds[0].X > 0 && mPoint3Ds[1].X > 0 ||
                                        mPoint3Ds[0].X < 0 && mPoint3Ds[1].X < 0)
                                    {
                                        textPart3D.X = geoLine3D.InnerPoint.X;
                                        textPart3D.Y = geoLine3D.InnerPoint.Y;
                                    }
                                    else
                                    {
                                        textPart3D.X = 180;
                                        textPart3D.Y = geoLine3D.InnerPoint.Y;
                                    }
                                    textPart3D.Z = 0;
                                    GeoText3D text3d = GetGeoText3DMessage();
                                    text3d.AddPart(textPart3D);
                                    text3d.TextStyle.FontHeight = 6;
                                    text3d.TextStyle.Alignment  = TextAlignment.BottomLeft;
                                    text3d.TextStyle.BackColor  = Color.Black;
                                    text3d.TextStyle.Outline    = true;
                                    text3d.Style3D.AltitudeMode = AltitudeMode.ClampToGround;//贴地高程模式
                                    ClearTextMessageTag();
                                    mSceneControl.Scene.TrackingLayer.Add(text3d, MessageTag);
                                }
                            }
                        }
                        else if (mSceneControl.Action == Action3D.MeasureArea && mIndex == 10)
                        {
                        }
                        else if (mSceneControl.Action == Action3D.MeasureAltitude && mIndex == 9)
                        {
                            //清除量算高度信息
                            if (!(Toolkit.IsZero(mCurAltitude)))
                            {
                                EndOneMeasure();
                            }
                        }
                    }
                }
            }
        }
Example #18
0
        public void run()
        {
            Recordset rc = dv.GetRecordset(false, CursorType.Dynamic);

            Dictionary <int, Feature> feas = rc.GetAllFeatures();

            foreach (KeyValuePair <int, Feature> item in feas)
            {
                GeoModel gm = item.Value.GetGeometry() as GeoModel;
                Console.WriteLine("==" + gm.Position + "==");

                GeoModel model = new GeoModel();
                model.Position = gm.Position;
                foreach (Mesh m in gm.Meshes)
                {
                    if (m.Material.TextureFile.Length > 1)
                    {
                        //Console.WriteLine(m.Material.TextureFile.ToString());
                        Point3Ds p3ds = new Point3Ds();

                        for (int i = 0; i < m.Vertices.Length; i += 3)
                        {
                            bool repition = false;
                            foreach (Point3D p in p3ds)
                            {
                                if (p.X == m.Vertices[i] && p.Y == m.Vertices[i + 1] && p.Z == m.Vertices[i + 2])
                                {
                                    repition = true;
                                }
                            }
                            if (!repition)
                            {
                                p3ds.Add(new Point3D(m.Vertices[i], m.Vertices[i + 1], m.Vertices[i + 2]));
                            }
                        }

                        foreach (Point3D p3d in p3ds)
                        {
                            Console.WriteLine(string.Format(" {0},{1},{2}", p3d.X, p3d.Y, p3d.Z));
                            scene.TrackingLayer.Add(new GeoPoint3D(p3d.X, p3d.Y, p3d.Z), "");
                        }
                        //model.Meshes.Add(MakeMeshPot(p3ds));
                        Mesh mesh = new Mesh(m);
                        mesh.Material.TextureFile = @".\78310a55b319ebc41f7810198326cffc1e171629.png";
                        model.Meshes.Add(mesh);


                        #region 写属性表
                        Dictionary <string, double> fields = new Dictionary <string, double>();
                        fields.Add("FaceMeshCenterX", model.Position.X);
                        fields.Add("FaceMeshCenterY", model.Position.Y);
                        fields.Add("FaceMeshCenterZ", model.Position.Z);
                        fields.Add("FaceMeshLx", p3ds.leftbottom().X);
                        fields.Add("FaceMeshLy", p3ds.leftbottom().Y);
                        fields.Add("FaceMeshLz", p3ds.leftbottom().Z);
                        fields.Add("FaceMeshUx", p3ds.rightup().X);
                        fields.Add("FaceMeshUy", p3ds.rightup().Y);
                        fields.Add("FaceMeshUz", p3ds.rightup().Z);


                        foreach (KeyValuePair <string, double> field in fields)
                        {
                            if (dv.FieldInfos.IndexOf(field.Key) < 0)
                            {
                                FieldInfo fieldInf = new FieldInfo(field.Key, FieldType.Double);
                                dv.FieldInfos.Add(fieldInf);
                            }

                            string fieldName  = field.Key;
                            double fieldValue = field.Value;
                            try
                            {
                                rc.SeekID(item.Value.GetID());
                                rc.Edit();
                                rc.SetFieldValue(fieldName, fieldValue);
                                rc.Update();
                            }
                            catch
                            {
                                Console.WriteLine("error!");
                            }
                            //Console.WriteLine(string.Format("{0},{1},{2}", item.GetID(), fieldName, fieldValue));
                        }
                        #endregion
                    }
                }
                Console.WriteLine("");

                model.ComputeBoundingBox();
                scene.TrackingLayer.Add(model, gm.Position.ToString());
                scene.Refresh();
            }
        }
 /// <summary>
 /// 获取两点之间的距离
 /// </summary>
 /// <param name="point3D1"></param>
 /// <param name="point3D2"></param>
 /// <returns></returns>
 public double GetLengthBy2Point(Point3D point3D1, Point3D point3D2)
 {
     double tempR = 0.0;
     GeoLine3D tempL = new GeoLine3D();
     Point3Ds temp3Ds = new Point3Ds();
     temp3Ds.Add(point3D1);
     temp3Ds.Add(point3D2);
     tempL.AddPart(temp3Ds);
     tempR = Geometrist.ComputeLength(tempL, new PrjCoordSys(PrjCoordSysType.EarthLongitudeLatitude));
     return tempR == 0.0 ? 10000.0 : tempR;
 }