粗糙实现了个版本

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

 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. js 停止事件冒泡 阻止浏览器的默认行为

    在前端开发工作中,由于浏览器兼容性等问题,我们会经常用到“停止事件冒泡”和“阻止浏览器默认行为”. 浏览器默认行为: 在form中按回车键就会提交表单:单击鼠标右键就会弹出context menu. ...

  2. select自定义小三角样式

    这段代码是网上大部分的解决办法,在这里总结一下: 让select透明,上面加一个span,来替换select框,可以自定义小三角样式,也可以做出select文字居中的效果. <div class ...

  3. Oracle收购Apiary来加强其API集成云

        Oracle宣布计划于1月19日收购Apiary,一家专注于API设计和协作的API管理公司.Apiary最为人所知的是API flow,其API管理平台.     Oracle并没有宣布计划 ...

  4. 【java】java内存模型 (1)--基础

    并发编程模型的分类 在并发编程中,我们需要处理两个关键问题:线程之间如何通信及线程之间如何同步(这里的线程是指并发执行的活动实体).通信是指线程之间以何种机制来交换信息.在命令式编程中,线程之间的通信 ...

  5. 为KindEditor编辑器中的内容添加样式,使得自己定义前台页面显示效果与编辑器效果一致

    KindEditor 本身自带有一定的样式,且为内部样式,在使用过程中,难免会发现部分效果不是我们想要的,因此.KindEditor提代了两种方式供使用着调用 1.内部样式.通过 cssData 属性 ...

  6. HDU2717BFS

    /* WA了12发简直不能忍! . 题意非常简单.从正整数a变为b有三种方法: +1,-1.*2 特殊情况一:a与b相等不须要搜索 特殊情况二:a>b时.结果必定是a-b不需搜 特殊情况三:比較 ...

  7. swift - 之 UIColor使用自定义的RGB配色

    1.10进制颜色 UIColor(red: /, green: /, blue: /, alpha: 0.5) 2.16进制颜色 UIColor(red: , green: , blue: , alp ...

  8. hadoop命令fsck命令

    在HDFS中,提供了fsck命令,用于检查HDFS上文件和目录的健康状态.获取文件的block块信息和位置信息等. 具体命令介绍: -move: 移动损坏的文件到/lost+found目录下 -del ...

  9. ActiveMQ伪集群部署

    本文借鉴http://www.cnblogs.com/guozhen/p/5984915.html,在此基础上进行了完善,使之成为一个完整版的伪分布式部署说明,在此记录一下! 一.本文目的 介绍如何在 ...

  10. 查看进程动态:top

    top命令用于查看进程动态,即进程使用系统资源的情况,常见用法如下: [root@localhost ~]$ top # 动态查看进程使用资源的情况,每三秒刷新一次 [root@localhost ~ ...