Пример #1
0
        public static IGeometry GetExample2()
        {
            const double XScale = 2;
            const double YScale = 2;
            const double ZScale = 3;

            //Transform3D: Cylinder Scaled Via Scale3D()

            IGeometry geometry = Vector3DExamples.GetExample3();

            //Define Origin At Which Scale Operation Should Be Performed

            IPoint originPoint = GeometryUtilities.ConstructPoint3D(0, 0, 0);

            ITransform3D transform3D = geometry as ITransform3D;

            transform3D.Scale3D(originPoint, XScale, YScale, ZScale);

            return(geometry);
        }
Пример #2
0
        private static void DrawEnd(IGraphicsContainer3D endGraphicsContainer3D, IPoint endPoint, IVector3D axisOfRotationVector3D, double degreesOfRotation, IColor endColor, double endRadius)
        {
            IGeometry endGeometry = Vector3DExamples.GetExample2();

            ITransform3D transform3D = endGeometry as ITransform3D;

            IPoint originPoint = GeometryUtilities.ConstructPoint3D(0, 0, 0);

            transform3D.Scale3D(originPoint, endRadius, endRadius, 2 * endRadius);

            if (degreesOfRotation != 0)
            {
                double angleOfRotationInRadians = GeometryUtilities.GetRadians(degreesOfRotation);

                transform3D.RotateVector3D(axisOfRotationVector3D, angleOfRotationInRadians);
            }

            transform3D.Move3D(endPoint.X - originPoint.X, endPoint.Y - originPoint.Y, endPoint.Z - originPoint.Z);

            GraphicsLayer3DUtilities.AddMultiPatchToGraphicsLayer3D(endGraphicsContainer3D, endGeometry, endColor);
        }
Пример #3
0
        public static IGeometry GetExample4()
        {
            const double XScale            = 0.5;
            const double YScale            = 0.5;
            const double ZScale            = 2;
            const double XOffset           = -5;
            const double YOffset           = -5;
            const double ZOffset           = -8;
            const double DegreesOfRotation = 90;

            //Transform3D: Cylinder Scaled, Rotated, Repositioned Via Move3D(), Scale3D(), RotateVector3D()

            IGeometry geometry = Vector3DExamples.GetExample3();

            ITransform3D transform3D = geometry as ITransform3D;

            //Stretch The Cylinder So It Looks Like A Tube

            IPoint originPoint = GeometryUtilities.ConstructPoint3D(0, 0, 0);

            transform3D.Scale3D(originPoint, XScale, YScale, ZScale);

            //Rotate The Cylinder So It Lies On Its Side

            IVector3D axisOfRotationVector3D = GeometryUtilities.ConstructVector3D(0, 10, 0);

            double angleOfRotationInRadians = GeometryUtilities.GetRadians(DegreesOfRotation);

            transform3D.RotateVector3D(axisOfRotationVector3D, angleOfRotationInRadians);

            //Reposition The Cylinder So It Is Located Underground

            transform3D.Move3D(XOffset, YOffset, ZOffset);

            return(geometry);
        }
Пример #4
0
        private void buttonXBigger_Click(object sender, EventArgs e)
        {
            ISelection pSelection = null;

            // ISelection pSelection
            if (m_SceneCtrl != null)
            {
                pSelection = m_SceneCtrl.Scene.FeatureSelection;
            }
            if (m_MapCtrl != null)
            {
                pSelection = m_MapCtrl.Map.FeatureSelection;
            }
            //从Map.FeatureSelection获得ISelection不能读到Feature的其他属性,
            //这是因为从axMapControl1.Map.FeatureSelection QI到IEnumFeature 时,
            //ArcGIS中FeatureSelection默认的时候只存入Feature 的Shape,而不是整个Feature的字段数据。
            //如果要查看其他数据,必须要进行以下转换才可以:
            IEnumFeatureSetup pSelectionsetup = pSelection as IEnumFeatureSetup;

            pSelectionsetup.AllFields = true;//这里是关键
            IEnumFeature pFeatureCollection = pSelectionsetup as IEnumFeature;
            IFeature     pF = pFeatureCollection.Next();

            while (pF != null)
            {
                if ((pF.Shape is IMultiPatch))
                {
                    int           OID = pF.OID;
                    IFeatureClass pFC = pF.Table as IFeatureClass;
                    IQueryFilter  pQF = new QueryFilterClass();
                    pQF.WhereClause = "\"OBJECTID\" = " + OID.ToString();
                    IFeatureCursor pFCursor = pFC.Update(pQF, false);
                    IFeature       pFeature = pFCursor.NextFeature();

                    //    StartEditing(pFeature);
                    try
                    {
                        IMultiPatch  pMpatch = pFeature.Shape as IMultiPatch;
                        ITransform3D pTf3D   = pMpatch as ITransform3D;

                        IPoint originPoint = GetMultiPatchCenter(pMpatch);
                        MakeZAware(originPoint as IGeometry);

                        double dbScaleCoef = dbiScaleCoef.Value;
                        pTf3D.Scale3D(originPoint, dbScaleCoef, dbScaleCoef, dbScaleCoef);
                        //pTf3D.Scale3D(originPoint, 2, 2, 2);
                        //  pTf3D.Move3D(0, 0, doubleInputZIncrement.Value);

                        pFeature.Shape = pMpatch as IGeometry;
                        pFeature.Store();
                        //  StopEditing(pFeature);
                        AxMapControl ms = pmapcontrol as AxMapControl;
                        ms.Refresh();
                        //刷新三维视图
                        for (int i = 0; i < m_SceneCtrl.Scene.LayerCount; i++)
                        {
                            ILayer player = m_SceneCtrl.Scene.get_Layer(i);
                            if (player is IFeatureLayer)
                            {
                                IFeatureLayer pFlayer = player as IFeatureLayer;
                                if (pFlayer.FeatureClass.Equals(pFC))
                                {
                                    IActiveView pActiveView = m_SceneCtrl.Scene as IActiveView;
                                    pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, pFlayer, null);
                                    //ps.Refresh();
                                }
                            }
                        }
                    }
                    catch (System.Exception ex)
                    {
                        if (ex.Message == "The spatial index grid size is invalid.")
                        {
                            IFeatureClassLoad pFCL = pFC as IFeatureClassLoad;
                            //pFCL.LoadOnlyMode = true;
                            //pFeature.Store();
                            //pFCL.LoadOnlyMode = false;
                            MessageBox.Show(ex.Message + " 无法再放大!");
                        }
                        else
                        {
                            MessageBox.Show(ex.Message);
                        }
                    }
                }
                pF = pFeatureCollection.Next();
            }
        }
Пример #5
0
        public void CreateFeature()
        {
            //移动放缩矢量箭头
            IVector3D VerticalVector = Material.ConstructVector3D(0, 0, 1);
            IPoint    originPoint    = Material.ConstructPoint3D(0, 0, 0);

            Material.MakeZAware(originPoint as IGeometry);

            //创建所有要素
            for (int i = 0; i < VectorModel.TinCount; i++)
            {
                IFeature BarycentreFeature = BarycentreFeatureClass.CreateFeature();
                BarycentreFeature.Shape = BARYCENTRE[i];
                int index1 = BarycentreFeature.Fields.FindField("X");
                BarycentreFeature.set_Value(index1, BARYCENTRE[i].X);
                int index2 = BarycentreFeature.Fields.FindField("Y");
                BarycentreFeature.set_Value(index2, BARYCENTRE[i].Y);
                int index3 = BarycentreFeature.Fields.FindField("Z");
                BarycentreFeature.set_Value(index3, BARYCENTRE[i].Z);
                int index4 = BarycentreFeature.Fields.FindField("Probability");
                BarycentreFeature.set_Value(index4, 0.95 - (0.9 / 49) * i);
                BarycentreFeature.Store();

                if (i == 0)
                {
                    Ctxt.WriteLine("GOCAD VSet" + "\r\n"
                                   + "HEADER" + "\r\n"
                                   + "{name: Borehole}" + "\r\n"
                                   + "GOCAD_ORIGINAL_COORDINATE_SYSTEM\nNAME" + "\r\n"
                                   + "PROJECTION Unknown" + "\r\n"
                                   + "DATUM Unknown" + "\r\n"
                                   + "AXIS_NAME X Y Z" + "\r\n"
                                   + "AXIS_UNIT m m m" + "\r\n"
                                   + "ZPOSITIVE Elevation" + "\r\n"
                                   + "END_ORIGINAL_COORDINATE_SYSTEM" + "\r\n"
                                   + "PROPERTIES P" + "\r\n"
                                   + "PROP_LEGAL_RANGES **none**  **none**" + "\r\n"
                                   + "NO_DATA_VALUES -99999" + "\r\n"
                                   + "PROPERTY_CLASSES p" + "\r\n"
                                   + "PROPERTY_KINDS \"Real Number\"" + "\r\n"
                                   + "PROPERTY_SUBCLASSES QUANTITY Float" + "\r\n"
                                   + "ESIZES 1" + "\r\n"
                                   + "UNITS unitless" + "\r\n"
                                   + "PROPERTY_CLASS_HEADER X {" + "\r\n" + "kind: X" + "\r\n" + "unit: m" + "\r\n" + "pclip: 99}" + "\r\n"
                                   + "PROPERTY_CLASS_HEADER Y {" + "\r\n" + "kind: Y" + "\r\n" + "unit: m" + "\r\n" + "pclip: 99}" + "\r\n"
                                   + "PROPERTY_CLASS_HEADER Z {" + "\r\n" + "kind: Depth\nunit: m" + "\r\n" + "is_z: on" + "\r\n" + "pclip: 99}" + "\r\n"
                                   + "PROPERTY_CLASS_HEADER p {" + "\r\n" + "kind: Real Number" + "\r\n" + "unit: unitless" + "\r\n" + "pclip: 99}" + "\r\n"
                                   );
                }
                Ctxt.Write("PVRTX " + i + " ");
                Ctxt.Write(BARYCENTRE[i].X + " ");
                Ctxt.Write(BARYCENTRE[i].Y + " ");
                Ctxt.Write(BARYCENTRE[i].Z + " ");
                if (i == VectorModel.TinCount - 1)
                {
                    Ctxt.WriteLine("0.5" + " ");
                }
                else
                {
                    Ctxt.WriteLine(0.95 - (0.9 / 49) * i + " ");
                }

                if (i == VectorModel.TinCount - 1)
                {
                    Ctxt.Write("END");
                    Ctxt.Close();
                }


                ////创建重力线
                IFeature VectorFeature = GravityVectorFeatureClass.CreateFeature();
                IPoint   endPoint      = new PointClass();
                Material.MakeZAware(endPoint as IGeometry);
                //根据体积设置末端点
                endPoint.X = BARYCENTRE[i].X;
                endPoint.Y = BARYCENTRE[i].Y;
                endPoint.Z = BARYCENTRE[i].Z - VOLUME[i] * gLength;                                        //
                //添加两点构成向量
                IPointCollection VectorPointCollection = new PolylineClass();
                Material.MakeZAware(VectorPointCollection as IGeometry);
                VectorPointCollection.AddPoint(BARYCENTRE[i], ref _missing, ref _missing);
                VectorPointCollection.AddPoint(endPoint, ref _missing, ref _missing);
                VectorFeature.Shape = VectorPointCollection as IGeometry;
                int index5 = VectorFeature.Fields.FindField("Gravity");
                VectorFeature.set_Value(index5, VOLUME[i]);
                int index6 = VectorFeature.Fields.FindField("Probability");
                VectorFeature.set_Value(index6, 0.95 - (0.9 / 49) * i);
                VectorFeature.Store();

                ////添加矢量箭头
                //得到重力矢量
                IVector3D Gvector     = Material.CreateVector3DTwoPoints(endPoint, BARYCENTRE[i]);
                IGeometry Arrow       = Material.GetArrow();
                double    Inclination = Gvector.Inclination;
                //计算与竖向矢量夹角
                double       degreesOfRotation = Math.Acos((Gvector.DotProduct(VerticalVector)) / ((Gvector.Magnitude) * (VerticalVector.Magnitude)));
                ITransform3D transform3D       = Arrow as ITransform3D;
                //放缩
                transform3D.Scale3D(originPoint, XScale, YScale, ZScale);
                //转动
                if (degreesOfRotation != 0)
                {
                    double    angleOfRotationInRadians = degreesOfRotation;
                    IVector3D axisOfRotationVector3D   = new Vector3DClass();
                    axisOfRotationVector3D.XComponent = 1;
                    axisOfRotationVector3D.YComponent = 0;
                    axisOfRotationVector3D.ZComponent = 0;
                    transform3D.RotateVector3D(axisOfRotationVector3D, angleOfRotationInRadians);
                }
                //平移
                if (endPoint.IsEmpty)
                {
                    continue;
                }
                transform3D.Move3D(endPoint.X - originPoint.X, endPoint.Y - originPoint.Y, endPoint.Z - originPoint.Z);
                IFeature ArrowFeature = ArrowFeatureClass.CreateFeature();
                ArrowFeature.Shape = Arrow as IMultiPatch;
                int index7 = ArrowFeature.Fields.FindField("Probability");
                ArrowFeature.set_Value(index7, 0.95 - (0.9 / 49) * i);
                ArrowFeature.Store();
                //墙壁
                IFeature EnCloseFeature = EncloseFeatureClass[i].CreateFeature();
                EnCloseFeature.Shape = multiPatchGeometryCollection[i] as IMultiPatch;
                int index17 = EnCloseFeature.Fields.FindField("Probability");
                EnCloseFeature.set_Value(index7, 0.95 - (0.9 / 49) * i);
                EnCloseFeature.Store();

                Vtxt.WriteLine(VOLUME[i]);
                if (i == VectorModel.TinCount - 1)
                {
                    Vtxt.Close();
                }
            }
        }
Пример #6
0
        public override void OnMouseDown(int Button, int Shift, int X, int Y)
        {
            // TODO:  Add ToolAddStone.OnMouseDown implementation
            if (pTinLayer != null)
            {
                ITin         pTin     = pTinLayer.Dataset;
                ISurface     pSurface = ((ITinAdvanced)pTin).Surface;
                IMapControl2 pMapCtr  = (((IToolbarControl)m_hookHelper.Hook).Buddy) as IMapControl2;
                //在mapctr操作
                if (pMapCtr != null)
                {
                    IPoint  mapPoint = pMapCtr.ToMapPoint(X, Y);
                    IZAware za       = mapPoint as IZAware;
                    za.ZAware = true;
                    double zVal;
                    zVal = pSurface.GetElevation(mapPoint);
                    if (double.IsNaN(zVal))
                    {
                        MessageBox.Show("获取模型的高度失败!");
                        return;
                    }
                    if (m_listModels.Count == 0)
                    {
                        MessageBox.Show("请先生成模型!");
                        return;
                    }
                    mapPoint.Z = zVal;
                    IFeature pfeature = null;
                    try
                    {
                        //IMultiPatch pMP = new MultiPatchClass();
                        IFeatureClass pFC  = pFeatureLayer.FeatureClass;
                        IFeature      pF   = pFC.CreateFeature();
                        IImport3DFile pI3D = new Import3DFileClass();
                        pI3D.CreateFromFile(m_listModels[m_listModels.Count - 1]);
                        IMultiPatch  pMP  = pI3D.Geometry as IMultiPatch;
                        ITransform3D pT3D = pMP as ITransform3D;
                        pT3D.Move3D(mapPoint.X, mapPoint.Y, mapPoint.Z);
                        pF.Shape = pMP as IGeometry;
                        pfeature = pF as IFeature;
                        pF.Store();
                        if (pMapCtr != null)
                        {
                            pMapCtr.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null);
                        }
                    }
                    catch (SystemException e)
                    {
                        if (e.Message == "The spatial index grid size is invalid.")
                        {
                            IFeatureClassLoad pFCL = pFeatureLayer.FeatureClass as IFeatureClassLoad;
                            pFCL.LoadOnlyMode = true;
                            pfeature.Store();
                            pFCL.LoadOnlyMode = false;
                        }
                        else
                        {
                            MessageBox.Show(e.Message);
                        }
                    }



                    //IMultiPatch pMP = new MultiPatchClass();
                    //for (int i = 0; i < 5; i++)
                    //{
                    //    IFeature pF = pFC.CreateFeature();
                    //    IImport3DFile pI3D = new Import3DFileClass();
                    //    pI3D.CreateFromFile(@"C:\Users\Administrator\Desktop\sampleAnalysis\1002.3ds");
                    //    IMultiPatch pMP = pI3D.Geometry as IMultiPatch;
                    //   // ITransform3D pT3D = pMP as ITransform3D;
                    //    pF.Shape = pMP as IGeometry;
                    //    ITransform3D pT3D = pF.Shape as ITransform3D;
                    //    pT3D.Move3D(5293 + 1600, -20427 , 800 + i*400);
                    //    // pF.Shape = pI3D.Geometry;
                }
            }
            if (pRasterLayer != null)
            {
                //ITin pTin = pTinLayer.Dataset;
                //ISurface pSurface = ((ITinAdvanced)pTin).Surface;
                IMapControl2 pMapCtr = (((IToolbarControl)m_hookHelper.Hook).Buddy) as IMapControl2;
                //在mapctr操作
                if (pMapCtr != null)
                {
                    IPoint mapPoint = pMapCtr.ToMapPoint(X, Y);

                    //添加手工编辑窗口
                    FrmManualSetModelPara pManualSetPara = null;
                    if (m_pModel == null)
                    {
                        Pt2d ptCurrent = new Pt2d();
                        ptCurrent.X    = mapPoint.X;
                        ptCurrent.Y    = mapPoint.Y;
                        pManualSetPara = new FrmManualSetModelPara(ptCurrent, "Rock");
                    }
                    else
                    {
                        m_pModel.x     = mapPoint.X;
                        m_pModel.y     = mapPoint.Y;
                        pManualSetPara = new FrmManualSetModelPara(m_pModel);
                    }

                    if (pManualSetPara.ShowDialog() == DialogResult.OK)
                    {
                        if (m_pModel == null)
                        {
                            m_pModel = new Model();
                        }

                        //bool bFlag = m_pModel.compareModelPara(pManualSetPara.m_pModel);
                        //if (!bFlag)//模型参数已经被修改,需要重新生成新的模型文件
                        //{
                        //    m_pModel.copyFromModel(pManualSetPara.m_pModel);

                        //    //获得当前文件路径下的石头模型文件,并随机获得石块模型
                        //    String szAppPathName = GetParentPathofExe() + @"Resource\RockModel";
                        //    String[] szFileList = Directory.GetFiles(szAppPathName);
                        //    if (szFileList.Length > 0)
                        //    {
                        //        Random r = new Random(TerrainGen.Chaos_GetRandomSeed());
                        //        int nRandomPos = r.Next(szFileList.Length);
                        //        String szModelOutputFilename = szFileList[nRandomPos];
                        //        m_listModels.Add(szModelOutputFilename);
                        //    }
                        //}

                        m_pModel.copyFromModel(pManualSetPara.m_pModel);

                        //获得当前文件路径下的石头模型文件,并随机获得石块模型
                        String   szAppPathName = ClsGlobal.GetParentPathofExe() + @"Resource\RockModel";
                        String[] szFileList    = Directory.GetFiles(szAppPathName);
                        if (szFileList.Length > 0)
                        {
                            Random r                     = new Random(TerrainGen.Chaos_GetRandomSeed());
                            int    nRandomPos            = r.Next(szFileList.Length);
                            String szModelOutputFilename = szFileList[nRandomPos];
                            m_listModels.Add(szModelOutputFilename);
                        }

                        //保存当前添加的模型参数
                        Model pTmpModel = new Model();
                        pTmpModel.copyFromModel(pManualSetPara.m_pModel);
                        m_manualAddModels.Add(pTmpModel);
                    }
                    else
                    {
                        return;
                    }

                    IZAware za = mapPoint as IZAware;
                    za.ZAware = true;
                    double   zVal;
                    IRaster2 pRaster2 = pRasterLayer.Raster as IRaster2;
                    int      col, row;
                    pRaster2.MapToPixel(mapPoint.X, mapPoint.Y, out col, out row);
                    zVal = Convert.ToDouble(pRaster2.GetPixelValue(0, col, row));
                    if (double.IsNaN(zVal))
                    {
                        MessageBox.Show("获取模型的高度失败!");
                        return;
                    }
                    if (m_listModels.Count == 0)
                    {
                        MessageBox.Show("请先生成模型!");
                        return;
                    }
                    mapPoint.Z = zVal;
                    try
                    {
                        //IMultiPatch pMP = new MultiPatchClass();
                        IFeatureClass pFC  = pFeatureLayer.FeatureClass;
                        IFeature      pF   = pFC.CreateFeature();
                        IImport3DFile pI3D = new Import3DFileClass();
                        pI3D.CreateFromFile(m_listModels[m_listModels.Count - 1]);
                        IMultiPatch  pMP  = pI3D.Geometry as IMultiPatch;
                        ITransform3D pT3D = pMP as ITransform3D;
                        pT3D.Move3D(mapPoint.X, mapPoint.Y, mapPoint.Z);
                        IRasterProps pRasterProps = pRasterLayer.Raster as IRasterProps;
                        double       xmax         = pRasterProps.Extent.XMax;
                        double       xmin         = pRasterProps.Extent.XMin;
                        double       ymax         = pRasterProps.Extent.YMax;
                        double       ymin         = pRasterProps.Extent.YMin;
                        //生成地形的地理范围
                        double dbGeoRangeX = xmax - xmin;
                        double dbGeoRangeY = ymax - ymin;

                        double dbModelRangeX = pMP.Envelope.Width;
                        double dbModelRangeY = pMP.Envelope.Height;
                        double dbModelRangeZ = pMP.Envelope.ZMax - pMP.Envelope.ZMin;

                        //根据地形大小改变石块大小
                        //double dbRandomSize = Math.Min(dbGeoRangeX, dbGeoRangeY) * (0.03 ); //[0.03 0.06]
                        //double dbScale = dbRandomSize / Math.Max(dbModelRangeX, dbModelRangeY);
                        double dbScale = m_pModel.dbSize / Math.Max(dbModelRangeX, Math.Max(dbModelRangeY, dbModelRangeZ));
                        pT3D.Scale3D(mapPoint, dbScale, dbScale, dbScale);


                        pF.Shape = pMP as IGeometry;
                        pF.Store();
                        if (pMapCtr != null)
                        {
                            pMapCtr.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null);
                        }
                    }
                    catch (SystemException e)
                    {
                        MessageBox.Show(e.Message);
                    }
                }
            }
        }