粗糙实现了个版本

存储波段的基本信息和数据:

 namespace RGeos.Terrain
{
//存储波段的基本信息和数据
public class RasterBandData
{
public double[] data;
public int Columns;
public int Rows;
public double NoDataValue;
public double MaxValue;
public double MinValue;
}
}

RasterBandData

显示用的渲染对象:

 using System;
using RGeos.SlimScene.Core;
using SlimDX.Direct3D9;
using System.Drawing;
using SlimDX;
using CustomVertex;
using System.IO; namespace RGeos.Terrain
{
public class RTerrain : RenderableObject
{
Device device = null;
private Bitmap bitMap = null;
private RasterBandData DataDem = null;
//定义行列数目
private int Cols = , Rows = ;
//定义像素的大小
private float cellHeight = 10f, cellWidth = 10f;
//纹理
private Texture texture = null;
//材质
private Material material;
//顶点缓冲变量
private VertexBuffer vertexBuffer;
//索引缓冲变量
private IndexBuffer indexBuffer;
// 顶点变量
private CustomVertex.PositionTextured[] vertices;
//索引号变量
private int[] indices; public RTerrain(string name, RasterBandData dem, Bitmap bitmap)
: base(name)
{
DataDem = dem;
Cols = dem.Columns;
Rows = dem.Rows;
bitMap = bitmap;
} public override void Initialize(DrawArgs drawArgs)
{
try
{
device = drawArgs.Device;
LoadTexturesAndMaterials();
VertexDeclaration();
IndicesDeclaration();//定义索引缓冲
isInitialized = true;
}
catch (Exception ex)
{
isInitialized = false;
throw ex;
} }
//导入贴图和材质
private void LoadTexturesAndMaterials()
{
material = new Material();
material.Diffuse = Color.White;
material.Specular = Color.LightGray;
material.Power = 15.0F;
device.Material = material;
System.IO.MemoryStream memory = new System.IO.MemoryStream();
bitMap.Save(memory, System.Drawing.Imaging.ImageFormat.Bmp);
memory.Seek(, SeekOrigin.Begin);
texture = Texture.FromStream(device, memory);
} public override void Update(DrawArgs drawArgs)
{
if (!isInitialized && isOn)
Initialize(drawArgs);
}
//定义顶点
private void VertexDeclaration()
{
vertexBuffer = new VertexBuffer(device, Cols * Rows * CustomVertex.PositionTextured.SizeBytes, Usage.Dynamic | Usage.WriteOnly, CustomVertex.PositionTextured.Format, Pool.Default);
DataStream vs = vertexBuffer.Lock(, Cols * Rows * CustomVertex.PositionTextured.SizeBytes, LockFlags.None);
vertices = new CustomVertex.PositionTextured[Cols * Rows];//定义顶点 for (int i = ; i < Rows; i++)
{
for (int j = ; j < Cols; j++)
{
//Color color = bitMap.GetPixel((int)(j * cellWidth), (int)(i * cellHeight));
float height = (float)DataDem.data[i * Cols + j];
if (height == DataDem.NoDataValue)
{
height = ;
}
vertices[j + i * Cols].Position = new Vector3(j * cellWidth, height, -i * cellHeight);
vertices[j + i * Cols].Tu = (float)j / (Cols - );
vertices[j + i * Cols].Tv = (float)i / (Rows - );
}
}
vs.WriteRange(vertices);
vertexBuffer.Unlock();
vs.Dispose();
}
//定义索引
private void IndicesDeclaration()
{
indexBuffer = new IndexBuffer(device, * * (Cols - ) * (Rows - ), Usage.WriteOnly, Pool.Default, true);
DataStream ds = indexBuffer.Lock(, * * (Cols - ) * (Rows - ), LockFlags.None);
indices = new int[ * (Cols - ) * (Rows - )];
int index = ;
for (int i = ; i < Rows - ; i++)
{
for (int j = ; j < Cols - ; j++)
{
indices[index] = j + i * (Cols);
indices[index + ] = j + (i + ) * Cols;
indices[index + ] = j + i * Cols + ;
indices[index + ] = j + i * Cols + ;
indices[index + ] = j + (i + ) * Cols;
indices[index + ] = j + (i + ) * Cols + ;
index += ;
}
}
ds.WriteRange(indices);
indexBuffer.Unlock();
ds.Dispose();
} public override void Render(DrawArgs drawArgs)
{
if (!isInitialized || !isOn)
return;
VertexFormat curFormat = drawArgs.Device.VertexFormat;
int curZEnable = drawArgs.Device.GetRenderState(RenderState.ZEnable);
int curLighting = drawArgs.Device.GetRenderState(RenderState.Lighting);
int curCull = drawArgs.Device.GetRenderState(RenderState.CullMode);
int curAlphaBlendEnable = drawArgs.Device.GetRenderState(RenderState.AlphaBlendEnable);
int curDepthBias = drawArgs.Device.GetRenderState(RenderState.DepthBias);
int curColorOperation = drawArgs.Device.GetTextureStageState(, TextureStage.ColorOperation);
try
{
drawArgs.Device.SetRenderState(RenderState.Lighting, false);
drawArgs.Device.VertexFormat = PositionTextured.Format;
drawArgs.Device.SetRenderState(RenderState.ZEnable, true);
drawArgs.Device.SetRenderState(RenderState.CullMode, Cull.None);
drawArgs.Device.SetTextureStageState(, TextureStage.ColorOperation, TextureOperation.Modulate);
drawArgs.Device.SetTextureStageState(, TextureStage.ColorArg1, TextureArgument.Texture);
drawArgs.Device.SetTextureStageState(, TextureStage.ColorArg2, TextureArgument.Diffuse);
drawArgs.Device.SetTextureStageState(, TextureStage.AlphaOperation, TextureOperation.Disable);
device.SetTexture(, texture);//设置贴图 device.SetStreamSource(, vertexBuffer, , PositionTextured.SizeBytes);
device.Indices = indexBuffer;
device.DrawIndexedPrimitives(PrimitiveType.TriangleList, , , (Cols * Rows), , indices.Length / );
}
catch (Exception ex)
{
}
finally
{
drawArgs.Device.VertexFormat = curFormat;
drawArgs.Device.SetRenderState(RenderState.ZEnable, curZEnable);
drawArgs.Device.SetRenderState(RenderState.Lighting, curLighting);
drawArgs.Device.SetRenderState(RenderState.CullMode, curCull);
drawArgs.Device.SetRenderState(RenderState.AlphaBlendEnable, curAlphaBlendEnable);
drawArgs.Device.SetRenderState(RenderState.DepthBias, curDepthBias);
drawArgs.Device.SetTextureStageState(, TextureStage.ColorOperation, curColorOperation);
}
} public override void Dispose()
{
if (vertexBuffer != null)
{
vertexBuffer.Dispose();
vertexBuffer = null;
texture = null;
vertices = null;
}
if (indexBuffer != null)
{
indexBuffer.Dispose();
indexBuffer = null;
indices = null;
}
} public override bool PerformSelectionAction(DrawArgs drawArgs)
{
throw new NotImplementedException();
}
}
}

RTerrain

调用方法:

   OpenFileDialog dlg = new OpenFileDialog();
dlg.Title = "";
dlg.Filter = "Img(*.img)|*.img";
if (dlg.ShowDialog() == DialogResult.OK)
{
string file = dlg.FileName;
string NameOf = System.IO.Path.GetFileNameWithoutExtension(file);
DemHelper dem = new DemHelper();
dem.Start();
dem.Read(file);
RasterBandData bandata = dem.ReadDate(, );
Bitmap bitmap = dem.MakeGrayScale(, );
Vector3 position = new Vector3(-100f, 0f, 100f);
//SimpleRasterShow simRaster = new SimpleRasterShow(NameOf, position, bitmap.Width, bitmap.Height);
//simRaster.IsOn = true;
//simRaster.RenderPriority = RenderPriority.Custom;
//simRaster.bitmap = bitmap;
//mSceneControl.CurrentWorld.RenderableObjects.ChildObjects.Add(simRaster);
RTerrain terrain = new RTerrain(NameOf, bandata, bitmap);
terrain.IsOn = true;
mSceneControl.CurrentWorld.RenderableObjects.ChildObjects.Add(terrain);
}

[GDAL]在三维场景中显示DEM的更多相关文章

  1. 三维场景中使用BillBoard技术

    三维场景中对于渲染效果不是很精致的物体可以使用BillBoard技术实现,使用该技术需要将物体实时朝向摄像机,即计算billboard的旋转矩阵M. 首先根据摄像机位置cameraPos和billBo ...

  2. MATLAB在三维坐标中显示图片 并 使得图片部分透明

    要画一个光路图,本来可以用proe,但是鼠标不好用,有些操作也忘了,用MATLAB画了个.下面是用到的图片. 但是三维坐标中显示彩色图片的目标没有搞定,做了个灰度图,然后用仿射程序将彩色图片贴到了二维 ...

  3. ArcMap应用——三维场景中井盖的属性配置

    在精细三维场景中,有地面(包括道路面.马路牙子).有部件数据(包括井盖).我们会发现有马路牙子的地方比道路面要高出一部分,比如0.1米,但是雨水井盖却有些在路面上.有些在道路以外.就是说在道路面上的井 ...

  4. 在三维场景中加载shp(skyline)

    在场景中添加shp图层有两个方法: (1)直接调用Command命令,SGWorld.Command.Execute(1013,5);这样的话,和在场景中的工程树中右键添加特征图层的过程是一样的.有个 ...

  5. 三维计算机视觉 — 中层次视觉 — Point Pair Feature

    机器人视觉中有一项重要人物就是从场景中提取物体的位置,姿态.图像处理算法借助Deep Learning 的东风已经在图像的物体标记领域耍的飞起了.而从三维场景中提取物体还有待研究.目前已有的思路是先提 ...

  6. [Unity3D]Unity3D游戏开发之在3D场景中选择物体并显示轮廓效果

    大家好,我是秦元培,欢迎大家关注我的博客,我的博客地址是blog.csdn.net/qinyuanpei. 在<仙剑奇侠传>.<古剑奇谭>等游戏中,常常须要玩家在一个3D场景中 ...

  7. 从WW中剥离一个三维场景框架

    从WW中剥离一个三维场景框架,初步实现的一个.可以绘制一个三角形,但是不能够控制摄像机,没有增加鼠标事件.没有投影,世界变幻之类的东西.以后会不断学习逐步增加进来. 下载地址 下载V1.0.0.2

  8. 3D游戏引擎中常见的三维场景管理方法

    对于一个有很多物体的3D场景来说,渲染这个场景最简单的方式就是用一个List将这些物体进行存储,并送入GPU进行渲染.当然,这种做法在效率上来说是相当低下的,因为真正需要渲染的物体应该是视椎体内的物体 ...

  9. 三维场景如何嵌入到PPT中展示?

    今天要跟大家一起交流的大体内容如标题所示,日常生活中,ppt已经成为人们工作学习生活中不可或缺的工具之一,那么三维场景是如何在ppt中加载展示的呢?请大家慢慢往下看. 1.创建命令按钮和web bro ...

随机推荐

  1. 再不学会这些技巧,你就OUT了!

    俗话说的好:技多不压身!这句话真是一点都没错,尤其是在21世纪的今天,作为老师的你,如果不会使用下面所要说的这款神器,恐怕你就像玩游戏一样,要被get out!那到底是什么呢?它就是现在正在全国初高中 ...

  2. mysql中,查看当前数据库下所有的基表,不包括视图

    环境描述: mysql版本:5.5.57-log 操作系统版本:Red Hat Enterprise Linux Server release 6.6 (Santiago) 需求描述: 查看当前使用的 ...

  3. SqlBulkCopy类进行大数据(10000万条以上)插入测试

    好多天没写博客了,刚刚毕业一个多月,在IT的路上真是迷茫啊! 关于上一篇博客中提到的,在进行批量数据插入数据库的时候可以通过给存储过程传递一个类型为Table的参数进行相关操作,在这个过程中本人没有进 ...

  4. Messages: java.lang.NullPointerExceptionFile: org/apache/jsp/test_jsp.javaLine number: 23

    Messages: java.lang.NullPointerExceptionFile: org/apache/jsp/test_jsp.javaLine number: 23 . . . Caus ...

  5. Effective C++ Item 18 Make interfaces easy to use correctly and hard to use incorrectly

    1. A good API will provide easy to use interfaces but also provide hard to miss-use interfaces. Usua ...

  6. ExtJS6的中sencha cmd中自动创建案例项目代码分析

    在之前的博文中,我们按照sencha cmd的指点,在自己win7虚拟机上创建了一个案例项目,相当于创建了一个固定格式的文档目录结构,然后里面自动创建了一系列js代码.这是使用sencha cmd自动 ...

  7. js的声明提前

    由于js声明提前的作用,所以在js中后面定义的函数也可以再前面使用. 不过,项目中看到过这样的写法 var a = function(){}, b = function(){}; 这种写法使代码看上去 ...

  8. setTimeout/setInterval伪异步

    setTimeout(function(){alert(1);}, 1000); 在使用setTimeout.setInterval的时候,会传一个时间来控制代码的执行时机.在经过了设置的时间段后,代 ...

  9. struts2 中redirectAction如何传递参数!

    在struts2中,初学者因为参数传递的问题往往会出现一些错误. 比如页面跳转的问题,在用户注册中,以一下代码作为案例: <struts> <constant name=" ...

  10. MACOS配置VIM成简单IDE傻瓜式操作

    零.参考文献: https://www.jianshu.com/p/f0513d18742a 一.安照我的配置:保存文件 " Configuration file for vim " ...