数据实体:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using SlimDX;
using RGeos.SlimScene.Core; namespace RGeos.Framework.OTL.Geometries
{ /// <summary>
/// LineString.
/// </summary>
public class LineString
{
public Point3d[] Coordinates = null;
public Color Color = Color.Yellow;
public float LineWidth = 1.0f;
public bool Visible = true;
public bool Remove = false;
public RenderableObject ParentRenderable = null; public BoundingBox GetBoundingBox()
{
if (Coordinates == null || Coordinates.Length == )
return new BoundingBox(); double minX = Coordinates[].X;
double maxX = Coordinates[].X;
double minY = Coordinates[].Y;
double maxY = Coordinates[].Y;
double minZ = Coordinates[].Z;
double maxZ = Coordinates[].Z; for (int i = ; i < Coordinates.Length; i++)
{
if (Coordinates[i].X < minX)
minX = Coordinates[i].X;
if (Coordinates[i].X > maxX)
maxX = Coordinates[i].X; if (Coordinates[i].Y < minY)
minY = Coordinates[i].Y;
if (Coordinates[i].Y > maxY)
maxY = Coordinates[i].Y; if (Coordinates[i].Z < minZ)
minZ = Coordinates[i].Z;
if (Coordinates[i].Z > maxZ)
maxZ = Coordinates[i].Z;
} return new BoundingBox(new Vector3(
(float)maxY, (float)minY, (float)minX), new Vector3((float)maxX, (float)minZ, (float)maxZ));
}
} }
LineString
渲染对象
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using RGeos.SlimScene.Core;
using SlimDX.Direct3D9;
using SlimDX; namespace RGeos.Framework.OTL.Geometries
{
public class RenderableLineString : RenderableObject
{
#region Static Members
#endregion #region Private Members
double m_distanceAboveSurface = ;
Point3d[] m_points = null;
CustomVertex.PositionColoredTextured[] m_wallVertices = null; CustomVertex.PositionColored[] m_topVertices = null;
CustomVertex.PositionColored[] m_bottomVertices = null;
CustomVertex.PositionColored[] m_sideVertices = null; System.Drawing.Color m_lineColor = System.Drawing.Color.Black;
float m_verticalExaggeration = ;
double m_minimumDisplayAltitude = ;
double m_maximumDisplayAltitude = double.MaxValue;
string m_imageUri = null;
Texture m_texture = null;
System.Drawing.Color m_polygonColor = System.Drawing.Color.Black;
bool m_outline = true;
float m_lineWidth = 1.0f;
bool m_extrude = false;
AltitudeMode m_altitudeMode = AltitudeMode.Absolute;
long m_numPoints = ;
#endregion /// <summary>
/// Boolean indicating whether or not the line needs rebuilding.
/// </summary>
public bool NeedsUpdate = true; public bool Extrude
{
get { return m_extrude; }
set { m_extrude = value; }
} public AltitudeMode AltitudeMode
{
get { return m_altitudeMode; }
set { m_altitudeMode = value; }
} public System.Drawing.Color LineColor
{
get { return m_lineColor; }
set
{
m_lineColor = value;
NeedsUpdate = true;
}
} public float LineWidth
{
get { return m_lineWidth; }
set
{
m_lineWidth = value;
NeedsUpdate = true;
}
} public double DistanceAboveSurface
{
get { return m_distanceAboveSurface; }
set
{
m_distanceAboveSurface = value;
if (m_topVertices != null)
{
NeedsUpdate = true;
//UpdateVertices();
}
}
} public System.Drawing.Color PolygonColor
{
get { return m_polygonColor; }
set
{
m_polygonColor = value;
if (m_topVertices != null)
{
NeedsUpdate = true;
//UpdateVertices();
}
}
} public bool Outline
{
get { return m_outline; }
set
{
m_outline = value;
if (m_topVertices != null)
{
NeedsUpdate = true;
//UpdateVertices();
}
}
} public Point3d[] Points
{
get
{
// if the array size is correct just return it
if (m_numPoints == m_points.LongLength)
return m_points; // return an array the correct size.
Point3d[] points = new Point3d[m_numPoints];
for (int i = ; i < m_numPoints; i++)
{
points[i] = m_points[i];
}
return points;
}
set
{
m_points = value;
m_numPoints = m_points.LongLength;
NeedsUpdate = true;
}
} public long NumPoints
{
get { return m_numPoints; }
} public double MinimumDisplayAltitude
{
get { return m_minimumDisplayAltitude; }
set { m_minimumDisplayAltitude = value; }
} public double MaximumDisplayAltitude
{
get { return m_maximumDisplayAltitude; }
set { m_maximumDisplayAltitude = value; }
} public override byte Opacity
{
get
{
return base.Opacity;
}
set
{
base.Opacity = value;
if (m_topVertices != null)
{
UpdateVertices();
}
}
} public RenderableLineString(string name, World parentWorld, Point3d[] points, System.Drawing.Color lineColor)
: base(name, parentWorld)
{
m_points = points;
m_lineColor = lineColor;
m_polygonColor = lineColor;
m_numPoints = m_points.LongLength; // RenderPriority = WorldWind.Renderable.RenderPriority.LinePaths;
} public RenderableLineString(string name, World parentWorld, Point3d[] points, string imageUri)
: base(name, parentWorld)
{
m_points = points;
m_imageUri = imageUri;
m_numPoints = m_points.LongLength; // RenderPriority = WorldWind.Renderable.RenderPriority.LinePaths;
} public override void Dispose()
{
if (m_texture != null && !m_texture.Disposed)
{
m_texture.Dispose();
m_texture = null;
} if (m_lineString != null)
{
m_lineString.Remove = true;
m_lineString = null;
}
NeedsUpdate = true;
} public override void Initialize(DrawArgs drawArgs)
{
if (m_points == null)
{
isInitialized = true;
return;
} if (m_imageUri != null)
{
//load image
//if (m_imageUri.ToLower().StartsWith("http://"))
//{
// string savePath = string.Format("{0}\\image", ConfigurationLoader.GetRenderablePathString(this));
// System.IO.FileInfo file = new System.IO.FileInfo(savePath);
// if (!file.Exists)
// {
// WorldWind.Net.WebDownload download = new WorldWind.Net.WebDownload(m_imageUri); // if (!file.Directory.Exists)
// file.Directory.Create(); // download.DownloadFile(file.FullName, WorldWind.Net.DownloadType.Unspecified);
// } // m_texture = ImageHelper.LoadTexture(file.FullName);
//}
//else
//{
// m_texture = ImageHelper.LoadTexture(m_imageUri);
//}
} UpdateVertices(); isInitialized = true;
} /// <summary>
/// Adds a point to the line at the end of the line.
/// </summary>
/// <param name="point">The Point3d object to add.</param>
public void AddPoint(Point3d point)
{
// if the array is too small grow it.
if (m_numPoints >= m_points.LongLength)
{
long growSize = m_points.LongLength / ;
if (growSize < ) growSize = ; Point3d[] points = new Point3d[m_points.LongLength + growSize]; for (int i = ; i < m_numPoints; i++)
{
points[i] = m_points[i];
}
m_points = points;
}
m_points[m_numPoints] = point;
m_numPoints++;
NeedsUpdate = true;
} private void UpdateVertices()
{
try
{
// m_verticalExaggeration = World.Settings.VerticalExaggeration; UpdateTexturedVertices(); if (m_lineString != null && m_outline && m_wallVertices != null && m_wallVertices.Length > m_topVertices.Length)
{
UpdateOutlineVertices();
} NeedsUpdate = false;
}
catch (Exception ex)
{
Utility.Log.Write(ex);
}
} private void UpdateOutlineVertices()
{
m_bottomVertices = new CustomVertex.PositionColored[m_numPoints];
m_sideVertices = new CustomVertex.PositionColored[m_numPoints * ]; for (int i = ; i < m_numPoints; i++)
{
m_sideVertices[ * i] = m_topVertices[i]; Vector3 xyzVertex = new Vector3(
m_wallVertices[ * i + ].Position.X,
m_wallVertices[ * i + ].Position.Y,
m_wallVertices[ * i + ].Position.Z); m_bottomVertices[i].Position.X = xyzVertex.X;
m_bottomVertices[i].Position.Y = xyzVertex.Y;
m_bottomVertices[i].Position.Z = xyzVertex.Z;
m_bottomVertices[i].Color = m_lineColor.ToArgb(); m_sideVertices[ * i + ] = m_bottomVertices[i];
}
} LineString m_lineString = null;
private void UpdateTexturedVertices()
{
if (m_altitudeMode == AltitudeMode.ClampedToGround)
{
if (m_lineString != null)
{
m_lineString.Remove = true;
m_lineString = null;
} m_lineString = new LineString();
m_lineString.Coordinates = Points;
m_lineString.Color = LineColor;
m_lineString.LineWidth = LineWidth;
m_lineString.ParentRenderable = this;
// this.World.ProjectedVectorRenderer.Add(m_lineString); if (m_wallVertices != null)
m_wallVertices = null; return;
} if (m_extrude || m_altitudeMode == AltitudeMode.RelativeToGround)
{
m_wallVertices = new CustomVertex.PositionColoredTextured[m_numPoints * ];
} float textureCoordIncrement = 1.0f / (float)(m_numPoints - );
// m_verticalExaggeration = World.Settings.VerticalExaggeration;
int vertexColor = m_polygonColor.ToArgb(); m_topVertices = new CustomVertex.PositionColored[m_numPoints]; for (int i = ; i < m_numPoints; i++)
{
double terrainHeight = ; Vector3 xyzVertex = new Vector3((float)m_points[i].X, (float)m_points[i].Y, (float)m_points[i].Z); m_topVertices[i].Position.X = xyzVertex.X;
m_topVertices[i].Position.Y = xyzVertex.Y;
m_topVertices[i].Position.Z = xyzVertex.Z;
m_topVertices[i].Color = m_lineColor.ToArgb(); if (m_extrude || m_altitudeMode == AltitudeMode.RelativeToGround)
{
m_wallVertices[ * i].Position.X = xyzVertex.X;
m_wallVertices[ * i].Position.Y = xyzVertex.Y;
m_wallVertices[ * i].Position.Z = xyzVertex.Z;
m_wallVertices[ * i].Color = vertexColor;
m_wallVertices[ * i].Tu = i * textureCoordIncrement;
m_wallVertices[ * i].Tv = 1.0f; m_wallVertices[ * i + ].Position.X = xyzVertex.X;
m_wallVertices[ * i + ].Position.Y = xyzVertex.Y;
m_wallVertices[ * i + ].Position.Z = xyzVertex.Z;
m_wallVertices[ * i + ].Color = vertexColor;
m_wallVertices[ * i + ].Tu = i * textureCoordIncrement;
m_wallVertices[ * i + ].Tv = 0.0f;
}
}
} public override bool PerformSelectionAction(DrawArgs drawArgs)
{
return false;
} public override void Update(DrawArgs drawArgs)
{
if (drawArgs.WorldCamera.Distance >= m_minimumDisplayAltitude && drawArgs.WorldCamera.Distance <= m_maximumDisplayAltitude)
{
if (!isInitialized)
Initialize(drawArgs); if (NeedsUpdate)
UpdateVertices();
} } public override void Render(DrawArgs drawArgs)
{
if (!isInitialized || drawArgs.WorldCamera.Distance < m_minimumDisplayAltitude || drawArgs.WorldCamera.Distance > m_maximumDisplayAltitude)
{
return;
} try
{
if (m_lineString != null)
return; int currentCull = drawArgs.Device.GetRenderState(RenderState.CullMode);
drawArgs.Device.SetRenderState(RenderState.CullMode, Cull.None); if (m_wallVertices != null)
{
drawArgs.Device.SetRenderState(RenderState.ZEnable, true); if (m_texture != null && !m_texture.Disposed)
{
drawArgs.Device.SetTexture(, m_texture);
drawArgs.Device.SetTextureStageState(, TextureStage.AlphaOperation, TextureOperation.Modulate);
drawArgs.Device.SetTextureStageState(, TextureStage.ColorOperation, TextureOperation.Add);
drawArgs.Device.SetTextureStageState(, TextureStage.AlphaArg1, TextureArgument.Texture);
}
else
{
drawArgs.Device.SetTextureStageState(, TextureStage.ColorOperation, TextureOperation.Disable);
} drawArgs.Device.VertexFormat = CustomVertex.PositionColoredTextured.Format; drawArgs.Device.DrawUserPrimitives(PrimitiveType.TriangleStrip, m_wallVertices.Length - , m_wallVertices); if (m_outline)
{ drawArgs.Device.SetTextureStageState(, TextureStage.ColorOperation, TextureOperation.Disable);
drawArgs.Device.VertexFormat = CustomVertex.PositionColored.Format;
drawArgs.Device.DrawUserPrimitives(PrimitiveType.LineStrip, m_topVertices.Length - , m_topVertices); if (m_bottomVertices != null)
drawArgs.Device.DrawUserPrimitives(PrimitiveType.LineStrip, m_bottomVertices.Length - , m_bottomVertices); if (m_sideVertices != null)
drawArgs.Device.DrawUserPrimitives(PrimitiveType.LineList, m_sideVertices.Length / , m_sideVertices); }
}
else
{
drawArgs.Device.SetTextureStageState(, TextureStage.ColorOperation, TextureOperation.Disable);
drawArgs.Device.VertexFormat = CustomVertex.PositionColored.Format;
drawArgs.Device.DrawUserPrimitives(PrimitiveType.LineStrip, m_topVertices.Length - , m_topVertices);
} drawArgs.Device.SetTransform(TransformState.World, drawArgs.WorldCamera.WorldMatrix);
drawArgs.Device.SetRenderState(RenderState.CullMode, currentCull);
}
catch//(Exception ex)
{
//Utility.Log.Write(ex);
}
}
}
}
RenderableLineString
使用方法:
private void tspPolyline_Click(object sender, EventArgs e)
{
Point3d[] pts=new Point3d[];
Point3d pt1=new Point3d(,,);
Point3d pt2=new Point3d(,,);
Point3d pt3=new Point3d(,,);
Point3d pt4=new Point3d(,,);
Point3d pt5=new Point3d(,,);
pts[]=pt1;
pts[]=pt2;
pts[]=pt3;
pts[]=pt4;
pts[]=pt5;
RenderableLineString rend = new RenderableLineString("Hello", null, pts, Color.White);
rend.IsOn = true;
rend.RenderPriority = RenderPriority.Custom;
mSceneControl.CurrentWorld.RenderableObjects.ChildObjects.Add(rend);
}
[3D]绘制线的更多相关文章
-
Unity3D研究院之游戏对象的访问绘制线与绘制面详解(十七)
一眨眼学习Unity3D 也有一段时间了,基本已经拿下了这套游戏引擎,回过头来想想以前写的RPG 游戏引擎,越来越发现以前写的就是垃圾.人果然是要不断学习与不断进步,好好学习,天天向上.哇咔咔- 加油 ...
-
R绘图 第六篇:绘制线图(ggplot2)
线图是由折线构成的图形,线图是把散点从左向右用直线连接起来而构成的图形,在以时间序列为x轴的线图中,可以看到数据增长的趋势. geom_line(mapping = NULL, data = NULL ...
-
3D 室内装修线设计软件
3D 室内装修线设计软件 WebGL & canvas https://threejs.org/ xgqfrms 2012-2020 www.cnblogs.com 发布文章使用:只允许注册用 ...
-
3D车道线检测:Gen-LaneNet
3D车道线检测:Gen-LaneNet Gen-LaneNet: A Generalized and Scalable Approach for 3D Lane Detection 论文链接:http ...
-
canvas绘制线和矩形
###canvas绘制矩形 HTML中的元素canvas只支持一种原生的图形绘制:矩形.所有其他的图形的绘制都至少需要生成一条路径 1.绘制矩形 canvas提供了三种方法绘制矩形: ----> ...
-
unity绘制线和绘制面
绘制线条代码,其实就是指定至少两个点,然后赋予贴图即可,不废话,上代码: using UnityEngine; using System.Collections; public class LineT ...
-
[3D]绘制XYZ小坐标轴
源码: using System; using System.Collections.Generic; using System.Linq; using System.Text; using Slim ...
-
Marble 绘制线
#include <QtGui/QApplication> #include <marble/MarbleWidget.h> #include <marble/GeoPa ...
-
WebGL绘制有端头的线
关于WebGL绘制线原理不明白的小伙伴,可以看看我之前的文章WebGL绘制有宽度的线.这一篇我们主要来介绍端头的绘制,先看效果图. 端头一般被称为lineCap,主要有以下三种形式: butt最简单等 ...
随机推荐
-
Session for SSRS Report of Microsoft Dynamics AX
Session for SSRS Report of Microsoft Dynamics AX 版权声明:本文为博主原创文章,未经博主允许不得转载. Contract •A data contrac ...
-
TYVJ计算几何
今天讲了计算几何,发几道水水的tyvj上的题解... 计算几何好难啊!@Mrs.General....怎么办.... 这几道题都是在省选之前做的,所以前面的Point运算啊,dcmp啊,什么什么的,基 ...
-
POJ 3349 Snowflake Snow Snowflakes
Snowflake Snow Snowflakes Time Limit: 4000MS Memory Limit: 65536K Total Submissions: 27598 Accepted: ...
-
maven Ubuntu14.04 安装
参考:linux上安装使用maven 下载链接:官网Download 解压. 在root用户下执行: cd /opt mkdir maven chmod 755 /opt/maven tar -zvx ...
-
apple-touch-icon,shortcut icon和icon的区别
apple-touch-icon 可以了解到这是一个类似网站favicon的图标文件,用来在iphone和ipod上创建快捷键时使用. 这个文件应当是png格式,57x57像素大小,放在网站根目录之下 ...
-
HDU 5795 A Simple Nim
打表找SG函数规律. #pragma comment(linker, "/STACK:1024000000,1024000000") #include<cstdio> ...
-
Javascript中获取浏览器类型和操作系统版本等客户端信息常用代码
/** * @author hechen */ var gs = { /**获得屏幕宽度**/ ScreenWidth: function () { return window.screen.widt ...
-
Kafka生产者发送消息的三种方式
Kafka是一种分布式的基于发布/订阅的消息系统,它的高吞吐量.灵活的offset是其它消息系统所没有的. Kafka发送消息主要有三种方式: 1.发送并忘记 2.同步发送 3.异步发送+回调函数 下 ...
-
微信小程序的概要
微信小程序的概要 学习小程序要了解一下什么事小程序,小程序开发前需要做哪些准备,微信小程序开发工具的使用,小程序中的目录结构解析,视图和渲染,事件. 小程序的配置详解,小程序的生命周期与app对象的使 ...
-
XML 和 JSON
1. XML介绍 必须要有节点:根节点必须且只有一个,用户节点可以自定义. 2. JSON介绍: 3.生成json方法 json_encode() 4.xml生成字符串方法有几种 拼装字符串,或者ph ...