public void LayerStyle_Ctrl() { Layer3Ds layer3ds = this.m_sceneControl.Scene.Layers; if (layer3ds.Count <= 0) { return; } TreeNode treeNode = this.m_LayersControl.Layer3DsTree.SelectedNode; Layer3DsTreeNodeBase treeNodeBase = treeNode as Layer3DsTreeNodeBase; if (treeNodeBase == null) { MessageBox.Show("请先选择一矢量图层"); return; } Layer3D layer3D = treeNodeBase.GetData() as Layer3D; if (layer3D == null) { return; } if (layer3D.Type == Layer3DType.Dataset || layer3D.Type == Layer3DType.VectorFile) { if (m_DlgSetLayerStyle == null || m_DlgSetLayerStyle.IsDisposed) { m_DlgSetLayerStyle = new DlgSetLayerStyle(); } m_DlgSetLayerStyle.Initialize(m_sceneControl, layer3D, false); m_DlgSetLayerStyle.StartPosition = FormStartPosition.CenterScreen; m_DlgSetLayerStyle.Show(); } }
private void FlyToLayerToolStripMenuItem_Click(object sender, EventArgs e) { Layer3DsTreeNodeBase node = this.layersControl.Layer3DsTree.SelectedNode as Layer3DsTreeNodeBase; Layer3D layer = node.GetData() as Layer3D; this.m_sceneControl.Scene.EnsureVisible(layer.Bounds); }
//设置阴影分析范围 private void cb_ShadowType_SelectedIndexChanged(object sender, EventArgs e) { int index = this.cb_ShadowType.SelectedIndex; if (index == 0) { m_shadowType = ShadowType.ALL; m_selection = null; } else if (index == 1) { m_shadowType = ShadowType.SELECTION; } else if (index == 2) { m_shadowType = ShadowType.NONE; m_selection = null; } Layer3Ds layers = m_sceneControl.Scene.Layers; //设置阴影类型 for (int i = 0; i < layers.Count; i++) { Layer3D layer = layers[i]; layer.ShadowType = m_shadowType; } }
/// <summary> /// 删除缓冲区 /// </summary> public void DeleteWhole() { try { mRecordset.DeleteAll(); if (mLayerBuffer != null) { mSceneControl.Scene.Layers.Remove(mLayerBuffer.Name); mLayerBuffer = null; } mSceneControl.Scene.Refresh(); if (mBufferDataset != null) { mDatasource.Datasets.Delete(mBufferDataset.Name); mBufferDataset = null; } Layer3Ds mlayer = mSceneControl.Scene.Layers; foreach (Layer3D layer in mlayer) { if (layer.Selection != null) { layer.Selection.Clear(); } } } catch (System.Exception ex) { Trace.WriteLine(ex.Message); } }
//加载缓存 private void AddCache_ToolStripMenuItem_Click(object sender, EventArgs e) { this.openFileDialog.Title = "打开三维缓存文件"; this.openFileDialog.Filter = "所有支持的三维缓存文件(*.sci, *.scv, *.scp,*.sci3d, *.sct, *.sit,*.gci,*.scm)|*.sci;*.scv;*.scp;*.sci3d;*.sct;*.sit;*.gci;*.scm"; this.openFileDialog.InitialDirectory = Directory.GetCurrentDirectory(); if (this.openFileDialog.ShowDialog() == DialogResult.OK) { String fileName = this.openFileDialog.FileName; String extention = System.IO.Path.GetExtension(fileName); Layer3D layer3D = null; Layer3Ds layer3ds = this.m_sceneControl.Scene.Layers; switch (extention) { case ".sci": case ".sci3d": case ".sit": case ".gci": { layer3D = layer3ds.Add(fileName, Layer3DType.ImageFile, true); layer3D.UpdateData(); this.m_sceneControl.Scene.Refresh(); this.m_sceneControl.Scene.EnsureVisible(layer3D.Bounds); break; } case ".scv": { layer3D = layer3ds.Add(fileName, Layer3DType.VectorFile, true); //layer3D.UpdateData(); this.m_sceneControl.Scene.Refresh(); this.m_sceneControl.Scene.EnsureVisible(layer3D.Bounds); break; } case ".scp": { layer3D = layer3ds.Add(fileName, Layer3DType.OSGB, true); this.m_sceneControl.Scene.Refresh(); //this.m_sceneControl.Scene.EnsureVisible(layer3D.Bounds); if (layer3D != null) { m_layerOSGB = layer3D as Layer3DOSGBFile; } break; } case ".sct": { TerrainLayer terrainlayer3D = this.m_sceneControl.Scene.TerrainLayers.Add(fileName, true); this.m_sceneControl.Scene.Refresh(); this.m_sceneControl.Scene.EnsureVisible(terrainlayer3D.Bounds); break; } } } }
private void EditableToolStripMenuItem_Click(object sender, EventArgs e) { Layer3DsTreeNodeBase node = this.layersControl.Layer3DsTree.SelectedNode as Layer3DsTreeNodeBase; Layer3D layer = node.GetData() as Layer3D; layer.IsEditable = !(layer.IsEditable); this.layersControl.Refresh(); }
public void Apply(Layer3D layer) { layer.Enabled = Enabled; layer.Depth = Depth; layer.ZPos = ZPos; layer.NoiseAmount = Noise; layer.UseInnerPixel = UseInnerPixel; }
/// <summary> /// 加载北京地铁数据 /// </summary> public void LoadSubway() { try { if (!m_sceneControl.Scene.Layers.Contains("ditie3")) { //加载北京地铁数据集 DatasetVector dataset_subway = m_workspace.Datasources["Pipeline3D"].Datasets["BeijingSubway"] as DatasetVector; DatasetVector dataset_label = m_workspace.Datasources["Pipeline3D"].Datasets["StopsName"] as DatasetVector; Layer3DSettingVector setvetor = new Layer3DSettingVector(); setvetor.Style.AltitudeMode = AltitudeMode.RelativeToGround; setvetor.Style.BottomAltitude = 5; setvetor.Style.LineWidth = 100; setvetor.Style.LineSymbolID = 962046; //setvetor.Style.MarkerColor = Color.Blue; ; Layer3DSettingVector pointSetting = new Layer3DSettingVector(); pointSetting.Style.AltitudeMode = AltitudeMode.ClampToGround; pointSetting.Style.MarkerSize = 1; pointSetting.Style.MarkerFile = @"..\..\SampleData\Symbol3DDisplay\SubwayMarkerLibrary.png"; pointSetting.Style.IsMarkerSizeFixed = true; pointSetting.Style.MarkerScale = 1; m_sceneControl.Scene.Underground.IsVisible = false; Layer3D layer_ditie = m_sceneControl.Scene.Layers.Add(dataset_subway, setvetor, true, "ditie3"); //标签专题图 Theme3DLabel themeLabel = new Theme3DLabel(); themeLabel.LabelExpression = "Name"; themeLabel.UniformStyle.IsSizeFixed = true; themeLabel.UniformStyle.ForeColor = Color.Yellow; themeLabel.UniformStyle.BackColor = Color.Black; themeLabel.UniformStyle.Outline = true; themeLabel.UniformStyle.FontScale = 1; themeLabel.UniformStyle.Weight = 7; themeLabel.UniformStyle.FontScale = 1.0; themeLabel.UniformStyle.Alignment = TextAlignment.MiddleRight; themeLabel.UniformStyle.IsSizeFixed = true; Layer3D layer1 = m_sceneControl.Scene.Layers.Add(dataset_label, pointSetting, true); Layer3D layer_label = m_sceneControl.Scene.Layers.Add(dataset_label, themeLabel, true); Camera camera = m_sceneControl.Scene.Camera; camera.AltitudeMode = AltitudeMode.RelativeToGround; camera.Altitude = 5508.4005263671279; camera.Latitude = 39.908042501262457; camera.Longitude = 116.39138653936693; camera.Tilt = 45.45877650025642; camera.Heading = 0.016679026847733185; m_sceneControl.Scene.Fly(camera, 2); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
public void Record(Layer3D layer) { Name = layer.Name; Enabled = layer.Enabled; Depth = layer.Depth; ZPos = layer.ZPos; Noise = layer.NoiseAmount; UseInnerPixel = layer.UseInnerPixel; }
//将数据集添加到场景中 private void AddToSceneToolStripMenuItem_Click(object sender, EventArgs e) { WorkspaceTreeNodeBase node = this.workspaceControl.WorkspaceTree.SelectedNode as WorkspaceTreeNodeBase; Dataset dataset = node.GetData() as Dataset; Layer3D layer3D = null; TerrainLayer terrainLayer = null; String layerName = dataset.Name + "@" + dataset.Datasource.Alias; switch (node.NodeType) { case WorkspaceTreeNodeDataType.DatasetVector: { Random random = new Random(Guid.NewGuid().GetHashCode()); DatasetVector datasetVector = dataset as DatasetVector; Layer3DSettingVector settingVector = new Layer3DSettingVector(); GeoStyle3D style = new GeoStyle3D(); style.FillMode = FillMode3D.LineAndFill; style.MarkerColor = Color.FromArgb(random.Next(0, 255), random.Next(0, 255), random.Next(0, 255)); //Color.Red; style.LineColor = Color.FromArgb(random.Next(0, 255), random.Next(0, 255), random.Next(0, 255)); //Color.SaddleBrown; style.FillForeColor = Color.FromArgb(random.Next(0, 255), random.Next(0, 255), random.Next(0, 255)); //Color.SkyBlue; if (datasetVector.Type == DatasetType.Line3D) { style.AltitudeMode = AltitudeMode.Absolute; style.LineWidth = 4; } settingVector.Style = style; layer3D = this.m_sceneControl.Scene.Layers.Add(datasetVector, settingVector, true, layerName); break; } case WorkspaceTreeNodeDataType.DatasetGrid: { DatasetGrid datasetGrid = dataset as DatasetGrid; terrainLayer = this.m_sceneControl.Scene.TerrainLayers.Add(datasetGrid, true); break; } case WorkspaceTreeNodeDataType.DatasetImage: { DatasetImage datasetImage = dataset as DatasetImage; Layer3DSettingImage settingImage = new Layer3DSettingImage(); layer3D = this.m_sceneControl.Scene.Layers.Add(datasetImage, settingImage, true, layerName); break; } } //if (layer3D != null) //{ // this.m_sceneControl.Scene.EnsureVisible(layer3D.Bounds); //} //if (terrainLayer != null) //{ // this.m_sceneControl.Scene.EnsureVisible(terrainLayer.Bounds); //} this.m_sceneControl.Scene.Refresh(); }
//选择图层 private void cb_layers_SelectedIndexChanged(object sender, EventArgs e) { String layerName = this.cb_layers.SelectedItem as String; m_layer3D = m_sceneControl.Scene.Layers[layerName]; if (m_layer3D == null) { MessageBox.Show("获取图层失败!"); } }
//刷新场景 private void btn_RefreshScene_Click(object sender, EventArgs e) { Layer3Ds layers = this.m_sceneControl.Scene.Layers; for (int i = 0; i < layers.Count; i++) { Layer3D layer = layers[i]; layer.UpdateData(); } this.m_sceneControl.Scene.Refresh(); }
private void Scene_Opened(object sender, EventArgs e) { Layer3Ds layers = this.m_SceneControl.Scene.Layers; for (int i = 0; i < layers.Count; i++) { Layer3D layer = layers[i]; if (layer.Type == Layer3DType.OSGB) { m_LayerOSGB = layer as Layer3DOSGBFile; } } }
public void SetLayer(Layer3D layer) { _layer = layer; if (layer != null) { _layerName.SetText(layer.Name); _depthSlider.Value = layer.Depth; _zPosSlider.Value = layer.ZPos; _noiseSlider.Value = layer.NoiseAmount; _enableButton.SetText(_layer.Enabled ? "Enabled" : "Disabled"); _innerPixelButton.SetText(_layer.UseInnerPixel ? "On" : "Off"); } }
//移除图层 private void RemoveLayerToolStripMenuItem_Click(object sender, EventArgs e) { Layer3DsTreeNodeBase node = this.layersControl.Layer3DsTree.SelectedNode as Layer3DsTreeNodeBase; Layer3D layer = node.GetData() as Layer3D; if (layer.Type == Layer3DType.KML && layer.Name.Contains("Flatten")) { if (m_layerOSGB != null) { m_layerOSGB.ClearFlattenRegions(); } } this.m_sceneControl.Scene.Layers.Remove(layer.Name); }
public bool SetQueryType(OSGBQueryType queryType) { m_queryType = queryType; m_srcDatasetVector = this.GetDataset(); if (m_srcDatasetVector == null) { MessageBox.Show("找不到指定的面数据集!"); return(false); } if (m_queryType == OSGBQueryType.SQL) { this.gb_SqlQuery.Enabled = true; this.gb_BufferQuery.Enabled = false; m_sceneControl.ObjectSelected -= new SuperMap.UI.ObjectSelectedEventHandler(m_sceneControl_ObjectSelected); } else { this.gb_SqlQuery.Enabled = false; this.gb_BufferQuery.Enabled = true; //缓存区分析,需要先把原始数据集添加到场景中 if (m_sceneControl.Scene.Layers.Contains(m_srcDatasetVector.Name)) { m_layerSrcRegion = m_sceneControl.Scene.Layers[m_srcDatasetVector.Name] as Layer3DDataset; } else { m_layerSrcRegion = AddSrcRegionToScene(m_srcDatasetVector); } //将场景中其他图层设为不可见 Layer3Ds layer3Ds = m_sceneControl.Scene.Layers; for (int i = 0; i < layer3Ds.Count; i++) { Layer3D layer = layer3Ds[i]; if (layer.Name != m_layerSrcRegion.Name) { layer.IsVisible = false; } } //注册事件 m_sceneControl.ObjectSelected -= new SuperMap.UI.ObjectSelectedEventHandler(m_sceneControl_ObjectSelected); m_sceneControl.ObjectSelected += new SuperMap.UI.ObjectSelectedEventHandler(m_sceneControl_ObjectSelected); } return(true); }
/// <summary> /// 初始化 /// </summary> /// <param name="sceneControl"></param> /// <param name="layer3D"></param> /// <param name="isSelection"></param> public void Initialize(SceneControl sceneControl, Layer3D layer3D, bool isSelection) { m_sceneControl = sceneControl; m_layer3D = layer3D; m_bSelection = isSelection; this.cb_AltitudeMode.Items.Clear(); //初始化高度模式列表 if (m_bSelection) { this.cb_AltitudeMode.Items.Add("贴地"); this.cb_AltitudeMode.Items.Add("贴对象"); } else { this.cb_AltitudeMode.Items.Add("贴地"); this.cb_AltitudeMode.Items.Add("贴对象"); this.cb_AltitudeMode.Items.Add("相对地面"); this.cb_AltitudeMode.Items.Add("绝对高度"); this.cb_AltitudeMode.Items.Add("相对地下"); } //初始化m_style3D if (m_bSelection) { m_style3D = m_layer3D.Selection.Style; } else { if (m_layer3D.Type == Layer3DType.Dataset) { Layer3DDataset layer3DDataset = m_layer3D as Layer3DDataset; Layer3DSettingVector layerSetting = layer3DDataset.AdditionalSetting as Layer3DSettingVector; m_style3D = layerSetting.Style; } else if (m_layer3D.Type == Layer3DType.VectorFile) { Layer3DVectorFile layer3DFile = m_layer3D as Layer3DVectorFile; Layer3DSettingVector layerSetting = layer3DFile.AdditionalSetting as Layer3DSettingVector; m_style3D = layerSetting.Style; } } this.UpdateData(); }
////////////////////////////////////////////////////////////////////////////////////// //图层选择事件 void Layer3DsTree_SelectionChanged(object sender, SelectionChangedEventArgs e) { if (m_sceneControl.Scene.Layers.Count <= 0) { return; } TreeNode[] treeNodes = e.SelectedNodes; if (treeNodes.Length <= 0) { return; } TreeNode treeNode = treeNodes[0]; Layer3DsTreeNodeBase treeNodeBase = treeNode as Layer3DsTreeNodeBase; m_selectedLayer = treeNodeBase.GetData() as Layer3D; if (m_selectedLayer == null) { return; } if (m_selectedLayer.Type == Layer3DType.Dataset || m_selectedLayer.Type == Layer3DType.VectorFile) { if (m_selectedLayer.ShadowType == ShadowType.SELECTION) { this.ShadowSelection_ToolStripMenuItem.Checked = true; this.ShadowAll_ToolStripMenuItem.Checked = false; this.NoShadow_ToolStripMenuItem.Checked = false; } else if (m_selectedLayer.ShadowType == ShadowType.ALL) { this.ShadowAll_ToolStripMenuItem.Checked = true; this.ShadowSelection_ToolStripMenuItem.Checked = false; this.NoShadow_ToolStripMenuItem.Checked = false; } else if (m_selectedLayer.ShadowType == ShadowType.NONE) { this.NoShadow_ToolStripMenuItem.Checked = true; this.ShadowAll_ToolStripMenuItem.Checked = false; this.ShadowSelection_ToolStripMenuItem.Checked = false; } } }
protected override void OnUpdating() { base.OnUpdating(); Layer3D.DrawSpriteAdditionally( new asd.Vector3DF(-1, 0, -1), new asd.Vector3DF(1, 0, -1), new asd.Vector3DF(1, 0, 1), new asd.Vector3DF(-1, 0, 1), new asd.Color(255, 0, 0, 255), new asd.Color(0, 255, 0, 255), new asd.Color(0, 0, 255, 255), new asd.Color(255, 255, 255, 255), new asd.Vector2DF(0, 0), new asd.Vector2DF(0, 0), new asd.Vector2DF(0, 0), new asd.Vector2DF(0, 0), null, asd.AlphaBlendMode.Blend, false, true ); }
//绘制区域并开始分析 private void btn_StartAnalysis_Click(object sender, EventArgs e) { if (m_shadowType == ShadowType.SELECTION) { //目前只允许一次选择一个图层中的对象 Layer3Ds layers = m_sceneControl.Scene.Layers; for (int i = 0; i < layers.Count; i++) { Layer3D layer = layers[i]; Selection3D seletion3D = layer.Selection; if (seletion3D != null) { m_selection = seletion3D; break; } } if (m_selection == null) { MessageBox.Show("请先选择要产生阴影的对象!"); return; } } this.RegisterEvents(false); this.RegisterEvents(true); m_oldAction = m_sceneControl.Action; m_sceneControl.Action = Action3D.CreatePolygon; if (m_shadowQuery == null) { m_shadowQuery = this.CreateShadowVisibilityQuery(); } this.btn_StartAnalysis.Enabled = false; this.btn_ClearResult.Enabled = true; }
public void DeleteBuffer() { try { mRecordset.DeleteAll(); if (mLayerBuffer != null) { mSceneControl.Scene.Layers.Remove(mLayerBuffer.Name); mLayerBuffer = null; } mSceneControl.Scene.Refresh(); if (mBufferDataset != null) { mDatasource.Datasets.Delete(mBufferDataset.Name); mBufferDataset = null; } } catch (System.Exception ex) { Trace.WriteLine(ex.Message); } }
protected override void OnStart() { base.OnStart(); var lightObj = new asd.DirectionalLightObject3D(); lightObj.Rotation = new asd.Vector3DF(30, 160, 0); Layer3D.AddObject(lightObj); var t = asd.Engine.Graphics.CreateTerrain3D(); t.New(1, 16, 16); t.AddSurface( "sf1", 2, "Data/Texture/Surface/Tile_Color.png", "Data/Texture/Surface/Tile_Normal.png", "Data/Texture/Surface/Tile_Spec.png"); t.AddSurface( "sf2", 2, "Data/Texture/Surface/Cloud_Color.png", "Data/Texture/Surface/Cloud_Normal.png", "Data/Texture/Surface/Cloud_Spec.png"); var sf2ind = t.GetSurfaceIndex("sf2"); t.AssignSurfaceWithCircle(sf2ind, 0, 0, 2, 255, 0.5f); var tObj = new asd.TerrainObject3D(); tObj.SetTerrain(t); Layer3D.AddObject(tObj); }
//删除数据集 private void DelDataset_ToolStripMenuItem_Click(object sender, EventArgs e) { WorkspaceTreeNodeBase node = this.workspaceControl.WorkspaceTree.SelectedNode as WorkspaceTreeNodeBase; Dataset dataset = node.GetData() as Dataset; //如果该图层在场景中打开,移除图层 Layer3Ds layers = this.m_sceneControl.Scene.Layers; int nLayer = layers.Count; for (int i = 0; i < nLayer; i++) { Layer3D layer = layers[i]; if (layer.Caption.Contains(dataset.Name)) { layers.Remove(layer.Name); nLayer--; i--; } } Datasource datsource = dataset.Datasource; bool ret = datsource.Datasets.Delete(dataset.Name); datsource.Refresh(); }
public LayerData(Layer3D layer) { Record(layer); }
/// <summary> /// 加载地下管道线 /// </summary> public void LoadPipeLine3D() { try { m_SelectedGeoNetwork = new List <NetworkGeometry>(); DatasetVector dataset_PipeLine = m_workspace.Datasources["Pipeline3D"].Datasets["PipeLine3D"] as DatasetVector; DatasetVector dataset_PipePoint = m_workspace.Datasources["Pipeline3D"].Datasets["PipePoint3D"] as DatasetVector; Layer3DSettingVector setvetor = new Layer3DSettingVector(); setvetor.Style.AltitudeMode = AltitudeMode.RelativeToGround; setvetor.Style.LineSymbolID = 962048; setvetor.Style.LineWidth = 0.35; Layer3DDataset layer_ditie = m_sceneControl.Scene.Layers.Add(dataset_PipeLine, setvetor, true, "PipeLine3D"); Layer3DDataset layer_pipepoint = m_sceneControl.Scene.Layers.Add(dataset_PipePoint, setvetor, true, "PipePoint3D"); if (dataset_PipePoint != null) { Theme3DUnique theme = new Theme3DUnique(); theme.UniqueExpression = "SmID"; GeoStyle3D style3D = new GeoStyle3D(); style3D.AltitudeMode = AltitudeMode.RelativeToGround; style3D.Marker3DScaleX = 2.2; style3D.Marker3DScaleY = 2.2; style3D.Marker3DScaleZ = 2.2; style3D.IsMarker3D = true; theme.DefaultStyle = style3D; Recordset rs = dataset_PipePoint.Query("", CursorType.Static); rs.MoveFirst(); while (!rs.IsEOF) { Theme3DUniqueItem item = new Theme3DUniqueItem(); item.Unique = rs.GetID().ToString(); item.IsModellingStyleEnabled = true; GeoStyle3D tempStyle = new GeoStyle3D(style3D); PickNodeToLine(rs.GetID()); GeoPoint3D geoPoint3D = rs.GetGeometry() as GeoPoint3D; List <Vector3d> arrVector3d = new List <Vector3d>(); for (Int32 curIndex = 0; curIndex < m_SelectedGeoNetwork.Count; curIndex++) { NetworkGeometry geoNetWork = m_SelectedGeoNetwork[curIndex]; if (geoNetWork != null) { Vector3d vec = new Vector3d(); GeoLine3D geoLine = geoNetWork.geometry as GeoLine3D; if (geoNetWork.bIsIn) { if (geoLine != null) { Point3Ds point3D = geoLine[0]; Point3D pntTNode = point3D[1]; Point3D pntFNode = point3D[0]; Vector3d vecTNode = SphericalToCartesian(pntTNode.X * DTOR, pntTNode.Y * DTOR, pntTNode.Z); Vector3d vecFNode = SphericalToCartesian(pntFNode.X * DTOR, pntFNode.Y * DTOR, pntFNode.Z); vec = new Vector3d(vecFNode.x - vecTNode.x, vecFNode.y - vecTNode.y, vecFNode.z - vecTNode.z); vec.Normalize(); } } else { if (geoLine != null) { Point3Ds point3D = geoLine[0]; Point3D pntFNode = point3D[0]; Point3D pntTNode = point3D[1]; Vector3d vecTNode = SphericalToCartesian(pntTNode.X * DTOR, pntTNode.Y * DTOR, pntTNode.Z); Vector3d vecFNode = SphericalToCartesian(pntFNode.X * DTOR, pntFNode.Y * DTOR, pntFNode.Z); vec = new Vector3d(vecTNode.x - vecFNode.x, vecTNode.y - vecFNode.y, vecTNode.z - vecFNode.z); vec.Normalize(); } } vec = FromAngleAxis(vec, -geoPoint3D.X * DTOR, new Vector3d(0, 1, 0)); vec = FromAngleAxis(vec, geoPoint3D.Y * DTOR, new Vector3d(1, 0, 0)); vec.Normalize(); arrVector3d.Add(vec); } } Vector3d vecX = new Vector3d(); Vector3d vecY = new Vector3d(); Vector3d vecZ = new Vector3d(); switch (m_SelectedGeoNetwork.Count) { case 2: //弯头或阀门 { if (arrVector3d.Count == 2) { vecX = arrVector3d[0].Normalize().Sub(); vecY = arrVector3d[1].Normalize(); } double dAngle1_2 = vecX.DotProduct(vecY); if (Math.Abs(dAngle1_2) < 0.3) { tempStyle.MarkerSymbolID = 54441; } else if (-1 < dAngle1_2 && dAngle1_2 < 0.7) { tempStyle.MarkerSymbolID = 54442; } else { vecY.z = 0; Vector3d vec = new Vector3d(0, 0, 1); vecX = vecY.CrossProduct(vec); tempStyle.MarkerSymbolID = 54435; } } break; case 3: //三通 { tempStyle.MarkerSymbolID = 54437; if (arrVector3d.Count == 3) { Vector3d vec1 = arrVector3d[0]; Vector3d vec2 = arrVector3d[1]; Vector3d vec3 = arrVector3d[2]; double dAngle1_2 = vec1.DotProduct(vec2); double dAngle1_3 = vec1.DotProduct(vec3); double dAngle2_3 = vec2.DotProduct(vec3); if (Math.Abs(dAngle1_2) < 0.3) { if (Math.Abs(dAngle1_3) < 0.3) { vecX = vec1.Normalize().Sub(); vecY = vec2.Normalize(); } else { vecX = vec2.Normalize().Sub(); vecY = vec1.Normalize(); } } else { vecX = vec3.Normalize().Sub(); vecY = vec1.Normalize(); } } } break; case 4: //四通 { tempStyle.MarkerSymbolID = 54438; if (arrVector3d.Count == 4) { Vector3d vec1 = arrVector3d[0]; Vector3d vec2 = arrVector3d[1]; Vector3d vec3 = arrVector3d[2]; double dAngle1_2 = vec1.DotProduct(vec2); double dAngle1_3 = vec1.DotProduct(vec3); vecX = vec1; if (Math.Abs(dAngle1_2) < 0.3) { vecY = vec2.Normalize(); } else { vecY = vec3.Normalize(); } } } break; default: //结点 { tempStyle.MarkerSymbolID = 330101; } break; } if (m_SelectedGeoNetwork.Count > 1) { vecZ = vecX.CrossProduct(vecY); vecZ.Normalize(); Vector3d vecRotate = ToEulerAnglesXYZ(vecX, vecY, vecZ); tempStyle.Marker3DRotateX = -vecRotate.x * RTOD; tempStyle.Marker3DRotateY = -vecRotate.y * RTOD; tempStyle.Marker3DRotateZ = -vecRotate.z * RTOD; } item.Style = tempStyle; theme.Add(item); rs.MoveNext(); } rs.Dispose(); Layer3D layer_theme = m_sceneControl.Scene.Layers.Add(dataset_PipePoint, theme, true, "underPipeLine3D"); layer_theme.IsSelectable = false; if (m_sceneControl.Scene.Layers.Contains("PipePoint3D")) { m_sceneControl.Scene.Layers.Remove("PipePoint3D"); } Camera camera = m_sceneControl.Scene.Camera; camera.AltitudeMode = AltitudeMode.RelativeToGround; camera.Altitude = 26.978640816174448; camera.Latitude = 39.992608337161023; camera.Longitude = 116.3898561529368; camera.Tilt = 59.567389444384283; camera.Heading = 300.19323029928478; m_sceneControl.Scene.Fly(camera, 1); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private static Bitmap Regenerate3DImageForLayer(Layer3D l, int width, int height) { Bitmap b = new Bitmap(width, height); Graphics g = Graphics.FromImage(b); g.Clear(Color.White); g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.SingleBitPerPixelGridFit; Dictionary <int, LayerColor> colors = l.GetLayerColors(); int[] data = l.GenerateData(LayerFlowImageGeneration.X, LayerFlowImageGeneration.Y, LayerFlowImageGeneration.Z, RenderWidth, RenderHeight, RenderDepth); /* Our world is laid out in memory in terms of X / Y, but * we are rendering isometric, which means that the rendering * order for tiles must be like so: * * North * 1 3 5 9 13 19 25 * 2 6 10 14 20 26 32 * 4 8 15 21 27 33 37 * East 7 12 18 28 34 38 42 West * 11 17 24 31 39 43 45 * 16 23 30 36 41 46 48 * 22 29 35 40 44 47 49 * South * * We also need to account for situations where the user rotates * the isometric view. */ /* * North * 0 0.5 1 1.5 2 2.5 3 * -0.5 0 0.5 1 1.5 2 2.5 * -1 -0.5 0 0.5 1 1.5 2 * East -1.5 -1 -0.5 0 0.5 1 1.5 West * -2 -1.5 -1 -0.5 0 0.5 1 * -2.5 -2 -1.5 -1 -0.5 0 0.5 * -3 -2.5 -2 -1.5 -1 -0.5 0 * South * * v = (x - y) / 2.0 */ int[] render = GetCellRenderOrder(RenderToNE); int ztop = RenderDepth; int zbottom = 0; for (int z = zbottom; z < ztop; z++) { int rcx = width / 2 - 1; int rcy = height / 2 - 31; int rw = 2; int rh = 1; for (int i = 0; i < render.Length; i++) { // Calculate the X / Y of the tile in the grid. int x = render[i] % RenderWidth; int y = render[i] / RenderWidth; // Calculate the render position on screen. int rx = rcx + (int)((x - y) / 2.0 * rw);// (int)(x / ((RenderWidth + 1) / 2.0) * rw); int ry = rcy + (x + y) * rh - (rh / 2 * (RenderWidth + RenderHeight)) - (z - zbottom) * 1; while (true) { try { if (l.IsLayerColorsFlags()) { Color accum = Color.FromArgb(0, 0, 0, 0); foreach (KeyValuePair <int, LayerColor> kv in colors) { LayerColor lc = kv.Value; SolidBrush sb = new SolidBrush(Color.FromArgb(lc.A, lc.R, lc.G, lc.B)); if ((data[x + y * RenderWidth + z * RenderWidth * RenderHeight] & kv.Key) != 0) { accum = Color.FromArgb( Math.Min(255, accum.A + sb.Color.A), Math.Min((byte)255, (byte)(accum.R + sb.Color.R * (sb.Color.A / 255.0) / colors.Count)), Math.Min((byte)255, (byte)(accum.G + sb.Color.G * (sb.Color.A / 255.0) / colors.Count)), Math.Min((byte)255, (byte)(accum.B + sb.Color.B * (sb.Color.A / 255.0) / colors.Count)) ); } } if (accum.R == 255 && accum.G == 255 && accum.B == 255) { accum = Color.FromArgb(63, 0, 0, 0); } g.FillRectangle( new SolidBrush(accum), new Rectangle(rx, ry, rw, rh) ); break; } else { if (colors != null && colors.ContainsKey(data[x + y * RenderWidth + z * RenderWidth * RenderHeight])) { LayerColor lc = colors[data[x + y * RenderWidth + z * RenderWidth * RenderHeight]]; SolidBrush sb = new SolidBrush(Color.FromArgb(lc.A, lc.R, lc.G, lc.B)); //sb.Color = Color.FromArgb(255, sb.Color); g.FillRectangle( sb, new Rectangle(rx, ry, rw, rh) ); } break; } } catch (InvalidOperationException) { // Graphics can be in use elsewhere, but we don't care; just try again. } } } } return(b); }
public void Layer3D_Click() { OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.Title = "打开三维缓存文件"; openFileDialog.Filter = "所有支持的三维缓存文件(*.sci, *.scv, *.scp,*.sci3d, *.sct, *.sit,*.gci,*.scm)|*.sci;*.scv;*.scp;*.sci3d;*.sct;*.sit;*.gci;*.scm"; if (openFileDialog.ShowDialog() == DialogResult.OK) { string fileName = openFileDialog.FileName; String extention = System.IO.Path.GetExtension(fileName); Layer3D layer3D = null; Layer3Ds layer3ds = this.m_SceneControl.Scene.Layers; switch (extention) { case ".sci": case ".sci3d": case ".sit": case ".gci": { layer3D = layer3ds.Add(fileName, Layer3DType.ImageFile, true); layer3D.UpdateData(); this.m_SceneControl.Scene.Refresh(); this.m_SceneControl.Scene.EnsureVisible(layer3D.Bounds); break; } case ".scv": { layer3D = layer3ds.Add(fileName, Layer3DType.VectorFile, true); //layer3D.UpdateData(); this.m_SceneControl.Scene.Refresh(); this.m_SceneControl.Scene.EnsureVisible(layer3D.Bounds); break; } case ".scp": { layer3D = layer3ds.Add(fileName, Layer3DType.OSGB, true); if (layer3D != null) { m_LayerOSGB = layer3D as Layer3DOSGBFile; this.m_SceneControl.Scene.EnsureVisible(m_LayerOSGB.Bounds); this.m_SceneControl.Scene.Refresh(); } break; } case ".sct": { TerrainLayer terrainlayer3D = this.m_SceneControl.Scene.TerrainLayers.Add(fileName, true); this.m_SceneControl.Scene.Refresh(); this.m_SceneControl.Scene.EnsureVisible(terrainlayer3D.Bounds); break; } } } }
public static void PopulateLayers(ref Layer3D[] layers) { if (layers != null) { foreach (var layer in layers) { layer?.Dispose(); } } layers = new Layer3D[] { new Layer3D() { Name = "Background", ZPos = 4, Depth = 4, RenderFunction = () => { Rendering.DrawBlack(); Rendering.DrawBackgroundWater(); Rendering.DrawSceneBackground(); Rendering.DrawWalls(); } }, // Solid tiles new Layer3D() { Name = "Solid Tiles", Depth = 32, InputPlane = Layer3D.InputPlaneType.SolidTiles, RenderFunction = () => { Rendering.DrawSolidTiles(); //Rendering.PostDrawTiles(); } }, // Non Solid tiles new Layer3D() { Name = "Non Solid Tiles", Depth = 8, InputPlane = Layer3D.InputPlaneType.NoneSolidTiles, RenderFunction = () => { Rendering.DrawNonSolidTiles(); Rendering.DrawWaterFalls(); } }, //Player new Layer3D() { Name = "Characters", ZPos = -18, Depth = 6, NoiseAmount = 0, RenderFunction = () => { Rendering.DrawMoonMoon(); Rendering.DrawNPCsBehindTiles(); Rendering.SortDrawCacheWorm(); Rendering.DrawWallOfFlesh(); Rendering.DrawNPCsBehindNonSoldTiles(); Rendering.DrawNPCsInfrontOfTiles(); Rendering.DrawPlayers(); Rendering.DrawNPCsOverPlayer(); } }, // Proj new Layer3D() { Name = "Projectiles", ZPos = -20, Depth = 2, NoiseAmount = 0, RenderFunction = () => { Rendering.DrawProjsBehindNPCsAndTiles(); Rendering.DrawProjsBehindNPCs(); Rendering.DrawProjsBehindProjectiles(); Rendering.DrawProjectiles(); Rendering.DrawInfernoRings(); Rendering.DrawProjsOverWireUI(); Rendering.DrawNPCProjectiles(); } }, // Items Gore new Layer3D() { Name = "Gore - Weather - Items", ZPos = -12, Depth = 6, NoiseAmount = 0, RenderFunction = () => { Rendering.DrawGoreBehind(); Rendering.DrawGore(); Rendering.DrawDust(); Rendering.DrawRain(); Rendering.DrawSandstorm(); Rendering.DrawMoonLordDeath(); Rendering.DrawMoonlordDeathFront(); Rendering.DrawItems(); } }, new Layer3D() { Name = "Water Foreground", Depth = 32, RenderFunction = () => { Rendering.DrawForegroundWater(); } }, new Layer3D() { Name = "Wires - UI", ZPos = -32, Depth = 4, RenderFunction = () => { Rendering.DrawWires(); Rendering.DrawHitTileAnimation(); Rendering.DrawItemText(); Rendering.DrawCombatText(); Rendering.DrawChatOverPlayerHeads(); InterfaceRendering.RenderGameInterfaces(); } } }; }
/// <summary> /// 创建缓冲区 /// </summary> public void CreateBuffer() { try { Selection3D[] selection = mSceneControl.Scene.FindSelection(true); //判断选择集是否为空 if (selection == null || selection.Length == 0) { MessageBox.Show("请选择要扩建的道路线对象"); return; } Recordset mLineRecordset = selection[0].ToRecordset(); object RodeType = mLineRecordset.GetFieldValue("Name"); if (RodeType.ToString().Trim() == "大路") { mRadius += 3.5; } else if (RodeType.ToString().Trim() == "小路") { mRadius += 1.85; } else { MessageBox.Show("请选择需要扩建的道路线对象"); Layer3Ds mlayer = mSceneControl.Scene.Layers; foreach (Layer3D layer in mlayer) { if (layer.Selection != null) { layer.Selection.Clear(); } } return; } //按照模板创建模型数据集 mDatasource = mUseData.DataSource; Datasource datasource = mDatasource; DatasetVector mRegionDatasets = datasource.Datasets["New_Model"] as DatasetVector; String bufferName = "bufferModel"; if (datasource.Datasets.Contains(bufferName)) { datasource.Datasets.Delete(bufferName); } mBufferDataset = (DatasetVector)datasource.Datasets.CreateFromTemplate(bufferName, mRegionDatasets); mBufferDataset.PrjCoordSys = mLineRecordset.Dataset.PrjCoordSys; mRecordset = mBufferDataset.GetRecordset(false, CursorType.Dynamic); while (!mLineRecordset.IsEOF) { mGeo = mLineRecordset.GetGeometry() as Geometry3D; BufferAnalyst3DParameter bufferAnalyst3DParameter = new BufferAnalyst3DParameter(); bufferAnalyst3DParameter.EndType = SuperMap.Realspace.SpatialAnalyst.BufferEndType.Round; bufferAnalyst3DParameter.BufferDistance = Convert.ToDouble(mRadius); bufferAnalyst3DParameter.BufferQuality = 20; Geometry3D geo3D = Geometrist3D.CreateBuffer(mGeo, bufferAnalyst3DParameter, mLineRecordset.Dataset.PrjCoordSys); GeoStyle3D geoStyle3D = new GeoStyle3D(); mRecordset.AddNew(geo3D); mLineRecordset.MoveNext(); } mRecordset.Update(); //设置数据集容量,避免空间查询出现过多对象 mRecordset.Dataset.Tolerance.NodeSnap = 0.0002; Layer3DSettingVector layer3DSetting = new Layer3DSettingVector(); GeoStyle3D style = new GeoStyle3D(); style.FillForeColor = Color.FromArgb(170, 242, 242, 15); style.FillBackColor = Color.GreenYellow; style.AltitudeMode = AltitudeMode.RelativeToGround; style.FillMode = FillMode3D.Fill; layer3DSetting.Style = style; mLayerBuffer = mSceneControl.Scene.Layers.Add(mRecordset.Dataset, layer3DSetting, true); mLayerBuffer.UpdateData(); if (mSceneControl.Scene.Layers.Contains("道路断线[email protected]_UnderPipeLine#1")) { mSceneControl.Scene.Layers["道路断线[email protected]_UnderPipeLine#1"].Selection.Clear(); } mSceneControl.Scene.Refresh(); } catch (Exception ex) { Trace.WriteLine(ex.Message); } }
//Buffer查询 public void BufferQuery() { try { //清除已有查询结果 if (m_layerResultDataset != null) { this.ClearResult(); } //创建结果面数据集 String bufferName = "bufferRegionDataset"; if (m_workspace.Datasources[0].Datasets.Contains(bufferName)) { m_workspace.Datasources[0].Datasets.Delete(bufferName); } DatasetVector bufferDataset = (DatasetVector)m_workspace.Datasources[0].Datasets.CreateFromTemplate(bufferName, m_srcDatasetVector); BufferAnalystParameter bufferAnalystParam = new BufferAnalystParameter(); bufferAnalystParam.EndType = BufferEndType.Round; bufferAnalystParam.LeftDistance = m_bufferRadius; Boolean isTrue = SuperMap.Analyst.SpatialAnalyst.BufferAnalyst.CreateBuffer(m_selectRegion, bufferDataset, bufferAnalystParam, false, true); m_layerBufferDataset = this.AddResultToScene(bufferDataset, Color.FromArgb(100, 255, 255, 0)) as Layer3DDataset; //进行叠加分析 QueryParameter para = new QueryParameter(); para.SpatialQueryMode = SpatialQueryMode.Intersect; para.SpatialQueryObject = bufferDataset; Recordset recordset = m_srcDatasetVector.Query(para); List <Int32> ids = new List <int>(recordset.RecordCount); while (!recordset.IsEOF) { ids.Add(recordset.GetID()); recordset.MoveNext(); } String resultName = "BufferResult"; if (m_workspace.Datasources[0].Datasets.Contains(resultName)) { m_workspace.Datasources[0].Datasets.Delete(resultName); } DatasetVector dataset_result = (DatasetVector)m_workspace.Datasources[0].Datasets.CreateFromTemplate(resultName, m_srcDatasetVector); Console.Write(isTrue); // 将空间查询结果追加到新建的数据集中 dataset_result.Append(recordset); m_layerSrcRegion.IsVisible = false; //将结果数据集添加到场景中 Color color = Color.FromArgb(200, 0, 233, 0); m_layerResultDataset = this.AddResultToScene(dataset_result, color) as Layer3DDataset; //如果场景中有osgb图层,设置osgb图层可见 Layer3Ds layer3ds = m_sceneControl.Scene.Layers; for (int i = 0; i < layer3ds.Count; i++) { Layer3D layer = layer3ds[i]; if (layer.Type == Layer3DType.OSGB) { layer.IsVisible = true; } } recordset.Dispose(); m_selectRegion.Dispose(); m_selectRegion = null; } catch (System.Exception ex) { MessageBox.Show(ex.Message); } }