public IGeometry CreateGeometry(double radius, IPolyline polyline, double qdgc, double zdgc) { IPointCollection pointCollection = CreatePointCollectionForCircle(radius); IVector3D pVectorZ = new Vector3DClass(); pVectorZ.SetComponents(0, 0, 1); IConstructMultiPatch patch = new MultiPatchClass(); IZAware zAware = pointCollection as IZAware; if (zAware == null) { return(null); } zAware.ZAware = true; // 依据管线长度拉伸 patch.ConstructExtrude(polyline.Length, pointCollection as IGeometry); // 依据管线角度旋转 IVector3D pVector3D = new Vector3DClass(); pVector3D.SetComponents(polyline.ToPoint.X - polyline.FromPoint.X, polyline.ToPoint.Y - polyline.FromPoint.Y, zdgc - qdgc); double rotateAngle = Math.Acos(pVector3D.ZComponent / pVector3D.Magnitude); IVector3D vectorAxis = pVectorZ.CrossProduct(pVector3D) as IVector3D; ITransform3D transform3D = patch as ITransform3D; transform3D.RotateVector3D(vectorAxis, rotateAngle); // 平移到指定位置 transform3D.Move3D(polyline.FromPoint.X, polyline.FromPoint.Y, qdgc); return(patch as IGeometry); }
public override IGeometry CreateGeometry() { IPointCollection pointCollection = new PolygonClass(); IZAware zAware = pointCollection as IZAware; zAware.ZAware = true; double angle = 2 * Math.PI / _division; for (int i = 0; i < _division; i++) { IPoint point = new PointClass(); point.X = _diameter * Math.Cos(angle * i) / 2; point.Y = _diameter * Math.Sin(angle * i) / 2; point.Z = 0; pointCollection.AddPoint(point); } ((IPolygon)pointCollection).Close(); IConstructMultiPatch patch = new MultiPatchClass(); patch.ConstructExtrude(0 - _depth, pointCollection as IGeometry); ITransform3D transform3D = patch as ITransform3D; transform3D.Move3D(_x, _y, _z); return(patch as IGeometry); }
private void RotateGeometry(IMarker3DSymbol pSymbol, IVector3D pAxis, double dDegree) { if ((pAxis != null) && (dDegree != 0.0)) { IMarker3DPlacement placement = pSymbol as IMarker3DPlacement; IGeometry shape = placement.Shape; IEnvelope envelope = shape.Envelope; IPoint point = new PointClass { X = envelope.XMin + (envelope.XMax - envelope.XMin), Y = envelope.YMin + (envelope.YMax - envelope.YMin), Z = envelope.ZMin + (envelope.ZMax - envelope.ZMin) }; double rotationAngle = this.DegreesToRadians(dDegree); ITransform3D transformd = shape as ITransform3D; transformd.Move3D(-point.X, -point.Y, -point.Z); transformd.RotateVector3D(pAxis, rotationAngle); transformd.Move3D(point.X, point.Y, point.Z); } }
public override IGeometry CreateGeometry() { IPointCollection pointCollection = new PolygonClass(); IZAware zAware = pointCollection as IZAware; zAware.ZAware = true; IPoint point = new PointClass(); point.X = -_width / 2; point.Y = -_height / 2; point.Z = 0; pointCollection.AddPoint(point); point = new PointClass(); point.X = -_width / 2; point.Y = _height / 2; point.Z = 0; pointCollection.AddPoint(point); point = new PointClass(); point.X = _width / 2; point.Y = _height / 2; point.Z = 0; pointCollection.AddPoint(point); point = new PointClass(); point.X = _width / 2; point.Y = -_height / 2; point.Z = 0; pointCollection.AddPoint(point); ((IPolygon)pointCollection).Close(); IConstructMultiPatch patch = new MultiPatchClass(); patch.ConstructExtrude(_polyline.Length, pointCollection as IGeometry); IVector3D vectorZ = new Vector3DClass(); vectorZ.SetComponents(0, 0, 1); IVector3D vector3D = new Vector3DClass(); vector3D.SetComponents(_polyline.ToPoint.X - _polyline.FromPoint.X, _polyline.ToPoint.Y - _polyline.FromPoint.Y, _zdgc - _qdgc); double rotateAngle = Math.Acos(vector3D.ZComponent / vector3D.Magnitude); IVector3D vectorAxis = vectorZ.CrossProduct(vector3D) as IVector3D; ITransform3D transform3D = patch as ITransform3D; transform3D.RotateVector3D(vectorAxis, rotateAngle); transform3D.Move3D(_polyline.FromPoint.X, _polyline.FromPoint.Y, _qdgc); return(patch as IGeometry); }
//平移得到所有的等值面点及其地质属性概率 public void GetSurfaceNode() { IPoint originPoint = Material.ConstructPoint3D(0, 0, 0); SurfacePoints = new IPoint[NodeCount, SurfaceCount]; Pcolumn = new IPoint[3, DenseCount]; SurfaceProbability = new double[NodeCount, SurfaceCount]; SurfaceRegardP = new double[NodeCount, SurfaceCount]; int CV = 0; for (int i = 0; i < NodeCount - 4; i++) { for (int j = 0; j < SurfaceCount; j++) { //复制一遍好平移 SurfacePoints[i, j] = new PointClass(); MakeZAware(SurfacePoints[i, j]); SurfacePoints[i, j].X = SinglePoints[i, j].X; SurfacePoints[i, j].Y = SinglePoints[i, j].Y; SurfacePoints[i, j].Z = SinglePoints[i, j].Z; SurfaceProbability[i, j] = SingleProbability[i, j]; SurfaceRegardP[i, j] = RegardP[i, j]; //平移 ITransform3D Transform3D = SurfacePoints[i, j] as ITransform3D; Transform3D.Move3D(OSPoints[i].X - originPoint.X, OSPoints[i].Y - originPoint.Y, OSPoints[i].Z - originPoint.Z); } //平移色阶钻孔(编号) if (pattern != 0) { if ((i == ChooseBoreForEN[0]) || (i == ChooseBoreForEN[1]) || (i == ChooseBoreForEN[2])) { for (int j = 0; j < DenseCount; j++) { Pcolumn[CV, j] = new PointClass(); MakeZAware(Pcolumn[CV, j]); Pcolumn[CV, j].X = DensePoints[j].X; Pcolumn[CV, j].Y = DensePoints[j].Y; Pcolumn[CV, j].Z = DensePoints[j].Z; //平移 ITransform3D Transform3D = Pcolumn[CV, j] as ITransform3D; Transform3D.Move3D(OSPoints[i].X - originPoint.X, OSPoints[i].Y - originPoint.Y, OSPoints[i].Z - originPoint.Z); } CV++; } } } }
public static IGeometry GetExample1() { const double XOffset = 7.5; const double YOffset = 7.5; const double ZOffset = -10; //Transform3D: Cylinder Repositioned Via Move3D() IGeometry geometry = Vector3DExamples.GetExample3(); ITransform3D transform3D = geometry as ITransform3D; transform3D.Move3D(XOffset, YOffset, ZOffset); return(geometry); }
public override IGeometry CreateGeometry() { IPointCollection pointCollection = new PolygonClass(); IZAware zAware = pointCollection as IZAware; zAware.ZAware = true; IPoint point = new PointClass(); point.X = -_width / 2; point.Y = -_length / 2; point.Z = 0; pointCollection.AddPoint(point); point = new PointClass(); point.X = -_width / 2; point.Y = _length / 2; point.Z = 0; pointCollection.AddPoint(point); point = new PointClass(); point.X = _width / 2; point.Y = _length / 2; point.Z = 0; pointCollection.AddPoint(point); point = new PointClass(); point.X = _width / 2; point.Y = -_length / 2; point.Z = 0; pointCollection.AddPoint(point); ((IPolygon)pointCollection).Close(); IConstructMultiPatch patch = new MultiPatchClass(); patch.ConstructExtrude(0 - _depth, pointCollection as IGeometry); ITransform3D transform3D = patch as ITransform3D; IVector3D vector3D = ConstructVector3D(0, 0, 1); transform3D.RotateVector3D(vector3D, _radian); transform3D.Move3D(_x, _y, _z); return(patch as IGeometry); }
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); }
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); }
public override void OnMouseDown(int Button, int Shift, int X, int Y) { // TODO: Add ToolAddCraterOnTIN.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; 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; pF.Store(); if (pMapCtr != null) { pMapCtr.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null); } } catch (SystemException e) { 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, "Crater"); } else { m_pModel.x = mapPoint.X; m_pModel.y = mapPoint.Y; pManualSetPara = new FrmManualSetModelPara(m_pModel); } //FrmManualSetModelPara pManualSetPara = new FrmManualSetModelPara(ptCurrent, "Crater"); 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); //根据设置的参数生成相应的模型 TriType triType = TriType.TriForward; LibModelGen.MappingType mappingType = LibModelGen.MappingType.Flat; String szModelOutputFilename = System.IO.Path.GetTempFileName(); szModelOutputFilename = szModelOutputFilename.Substring(0, szModelOutputFilename.LastIndexOf('.')) + ".3ds"; ModelBase crater = new CraterGen(m_pModel.dbSize, m_pModel.dbDepth); crater.OutputFilename = szModelOutputFilename; crater.triype = triType; crater.mappingType = mappingType; //将撞击坑模型添加到相应图层 if (crater.generate()) { 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; 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); pT3D.Move3D(pManualSetPara.m_pModel.x, pManualSetPara.m_pModel.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.15); //[0.03 0.06] //double dbRandomSize = pRasterProps.MeanCellSize().X * 300; //double dbScale = pManualSetPara.m_pModel.dbSize;// / Math.Max(dbModelRangeX, dbModelRangeY); //pT3D.Scale3D(mapPoint, dbScale, dbScale, dbScale); 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); } } } } }
private void buttonXZIncrease_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); IMultiPatch pMpatch = pFeature.Shape as IMultiPatch; ITransform3D pTf3D = pMpatch as ITransform3D; 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(); } } } } pF = pFeatureCollection.Next(); } }
public static IGeometry GetExample1() { //Composite: Multiple, Disjoint Geometries Contained Within A Single MultiPatch IGeometryCollection multiPatchGeometryCollection = new MultiPatchClass(); IMultiPatch multiPatch = multiPatchGeometryCollection as IMultiPatch; //Vector3D Example 2 IGeometry vector3DExample2Geometry = Vector3DExamples.GetExample2(); ITransform3D vector3DExample2Transform3D = vector3DExample2Geometry as ITransform3D; vector3DExample2Transform3D.Move3D(5, 5, 0); IGeometryCollection vector3DExample2GeometryCollection = vector3DExample2Geometry as IGeometryCollection; for (int i = 0; i < vector3DExample2GeometryCollection.GeometryCount; i++) { multiPatchGeometryCollection.AddGeometry(vector3DExample2GeometryCollection.get_Geometry(i), ref _missing, ref _missing); } //Vector3D Example 3 IGeometry vector3DExample3Geometry = Vector3DExamples.GetExample3(); ITransform3D vector3DExample3Transform3D = vector3DExample3Geometry as ITransform3D; vector3DExample3Transform3D.Move3D(5, -5, 0); IGeometryCollection vector3DExample3GeometryCollection = vector3DExample3Geometry as IGeometryCollection; for (int i = 0; i < vector3DExample3GeometryCollection.GeometryCount; i++) { multiPatchGeometryCollection.AddGeometry(vector3DExample3GeometryCollection.get_Geometry(i), ref _missing, ref _missing); } //Vector3D Example 4 IGeometry vector3DExample4Geometry = Vector3DExamples.GetExample4(); ITransform3D vector3DExample4Transform3D = vector3DExample4Geometry as ITransform3D; vector3DExample4Transform3D.Move3D(-5, -5, 0); IGeometryCollection vector3DExample4GeometryCollection = vector3DExample4Geometry as IGeometryCollection; for (int i = 0; i < vector3DExample4GeometryCollection.GeometryCount; i++) { multiPatchGeometryCollection.AddGeometry(vector3DExample4GeometryCollection.get_Geometry(i), ref _missing, ref _missing); } //Vector3D Example 5 IGeometry vector3DExample5Geometry = Vector3DExamples.GetExample5(); ITransform3D vector3DExample5Transform3D = vector3DExample5Geometry as ITransform3D; vector3DExample5Transform3D.Move3D(-5, 5, 0); IGeometryCollection vector3DExample5GeometryCollection = vector3DExample5Geometry as IGeometryCollection; for (int i = 0; i < vector3DExample5GeometryCollection.GeometryCount; i++) { multiPatchGeometryCollection.AddGeometry(vector3DExample5GeometryCollection.get_Geometry(i), ref _missing, ref _missing); } return(multiPatchGeometryCollection as IGeometry); }
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(); } } }
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); } } } }