粗糙实现了个版本

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

 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. UGUI之Canvas Group

    可以通过Canvas Group影响该组UI元素的部分性质,而不需要费力的对该组UI下的每个元素逐个调整.Canvas Group是同时作用于该组UI下的全部元素. 参数:Alpha:该组UI元素的透 ...

  2. mysqldump如何针对某些数据库进行备份?针对某个数据库进行备份?

    需求描述: 通过mysqldump工具对mysql服务器中的某几个数据库进行备份. 或者就对其中的一个数据库进行备份. 操作过程: 1.通过--databases参数后面加上数据库的名字进行备份 [m ...

  3. HTML性能优化

    摘要: 页面优化是对网页中的HTML代码进行必要的调整,可以有效地精简页面中的冗余代码,加快网页显示速度,减少网页占用搜索引擎服务器的存储空间,提高用户体验和搜索引擎友好性,当然也可以更好的突出页面的 ...

  4. 编译ros程序包--4

    编译程序包(原创博文,转载请标明出处--周学伟http://www.cnblogs.com/zxouxuewei/) 1.编译程序包: 一旦安装了所需的系统依赖项,我们就可以开始编译刚才创建的程序包了 ...

  5. 第四章 Spring.Net 如何管理您的类___对象的自动装配

    由于这几天都比较忙,所以对笔记暂时没有更新. Spring.NET具有自动装配的能力,也就是说,Spring.NET可以通过对象的定义自动分辨某个对象的协作对象.自动装配是针对单个对象(按:针对每个协 ...

  6. java总结(1)——java的特点

    之前学习java仅仅是单纯的学习,老师要求学习.所以就学习.可是没有细致考虑过java的一些特别之处,比方,我们为什么要学习java而不是其它的语言,它必定有选择它的特点.所以,从如今開始,仅仅有埋头 ...

  7. redis安装之zmalloc.h:55:2: error: #error "Newer version of jemalloc required"错误

    redis是C语言编写的软件,安装前需要编译,需要gcc编译环境,确认安装gcc编译环境后(安装gcc命令:yum install gcc-c++) 在redis解压目录下,确认有Makefile文件 ...

  8. PopupMenu弹出菜单

    CMenu MoviePopupMenu;//声明 MoviePopupMenu.CreatePopupMenu();//创建弹出菜单 根据对象类型增加弹出项 ) // FLASH对象 { CStri ...

  9. linux的setup命令设置网卡和防火墙等

    以前在centos上配置网卡都是纯命令行,今天发现linux原来还有一个setup那么好用的命令,真是相见恨晚,以后防火墙.网卡.其他网络配置.系统配置(开机启动项)都可用他来完成了

  10. 通过身份证分析出生年月日、性别、年龄的SQL语句

    ),) ) ),)<>'X' ) ) )<>'X' ),)),)),)) ),)),)),)) ) as int)) where [出生日期]<>'' #字符串格式 ...