寻求WPF显示3D点云的方法? 目前能够用Viewport3D显示3D图像,但是不知道怎样显示点云。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 WPF支持3D,但是不直接支持底层3D命令。如果点云的点量很大,可能效率上会跟不上。点本身是没有大小的,你可以把点画成一个小的立方(缺点是从不同方向观察,亮度可能随角度变化)。以下例子用1万个点,每点画成一个面对观察点的小三角形。<Window x:Class="WpfApp1.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="MainWindow" Height="450" Width="800"> <Grid Background="DarkGray"> <Viewport3D> <Viewport3D.Camera> <PerspectiveCamera Position="0,0,100" LookDirection="0,0,-1" FieldOfView="60" /> </Viewport3D.Camera> <ModelVisual3D> <ModelVisual3D.Content> <GeometryModel3D> <GeometryModel3D.Geometry> <MeshGeometry3D x:Name="mesh" /> </GeometryModel3D.Geometry> <GeometryModel3D.Material> <EmissiveMaterial Brush="Green" /> </GeometryModel3D.Material> </GeometryModel3D> </ModelVisual3D.Content> </ModelVisual3D> </Viewport3D> </Grid></Window>using System;using System.Collections.Generic;using System.Linq;using System.Windows;using System.Windows.Media;using System.Windows.Media.Media3D;namespace WpfApp1{ public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); var points = GenerateRandomPoints(10000); AddPointCloudMesh(points); } void AddPointCloudMesh(IEnumerable<Point3D> points) { var positions = new Point3DCollection(); foreach(var p in points) { positions.Add(p); positions.Add(new Point3D(p.X, p.Y - 0.2, p.Z)); positions.Add(new Point3D(p.X + 0.2, p.Y, p.Z)); } this.mesh.Positions = positions; this.mesh.TriangleIndices = new Int32Collection(Enumerable.Range(0, positions.Count)); } IEnumerable<Point3D> GenerateRandomPoints(int count) { Random random = new Random(); for (int i = 0; i < count; i++) { yield return new Point3D() { X = random.Next(random.Next(200000)) / 10000d * (1 - random.Next(2) * 2), Y = random.Next(random.Next(200000)) / 10000d * (1 - random.Next(2) * 2), Z = random.Next(random.Next(200000)) / 10000d * (1 - random.Next(2) * 2), }; } } }} 这样是一个办法,但是如果放大了就全是三角形,我现在用的PCL库,目前直接将PCL的代码编译成dll,然后c#调用dll显示 查询数据赋值给变量 C# 2维定义问题 已经得到excel的某个sheet,我将他复制到另一个excel文件中,怎么办啊?急等 strlen出错 c#如何解决指向数组的指针的问题 如何在c#中模拟鼠标单击事件。 求助问题:未能创建默认证书。正在中止发布。 如何实现在任务栏中的进度条??? datagirdview to datagidview Java接口和C#的接口有什么区别么? 我是搞自动化的,现单位有个项目用到C#我该如何学习?以前就编辑过触摸屏的宏指令 c# 用socket tcp接收收据,如何去判断接收数据的长度
以下例子用1万个点,每点画成一个面对观察点的小三角形。<Window x:Class="WpfApp1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="450" Width="800">
<Grid Background="DarkGray">
<Viewport3D>
<Viewport3D.Camera>
<PerspectiveCamera Position="0,0,100" LookDirection="0,0,-1" FieldOfView="60" />
</Viewport3D.Camera>
<ModelVisual3D>
<ModelVisual3D.Content>
<GeometryModel3D>
<GeometryModel3D.Geometry>
<MeshGeometry3D x:Name="mesh" />
</GeometryModel3D.Geometry>
<GeometryModel3D.Material>
<EmissiveMaterial Brush="Green" />
</GeometryModel3D.Material>
</GeometryModel3D>
</ModelVisual3D.Content>
</ModelVisual3D>
</Viewport3D>
</Grid>
</Window>using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows;
using System.Windows.Media;
using System.Windows.Media.Media3D;namespace WpfApp1
{
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
var points = GenerateRandomPoints(10000);
AddPointCloudMesh(points);
}
void AddPointCloudMesh(IEnumerable<Point3D> points)
{
var positions = new Point3DCollection();
foreach(var p in points)
{
positions.Add(p);
positions.Add(new Point3D(p.X, p.Y - 0.2, p.Z));
positions.Add(new Point3D(p.X + 0.2, p.Y, p.Z));
}
this.mesh.Positions = positions;
this.mesh.TriangleIndices = new Int32Collection(Enumerable.Range(0, positions.Count));
}
IEnumerable<Point3D> GenerateRandomPoints(int count)
{
Random random = new Random();
for (int i = 0; i < count; i++)
{
yield return new Point3D()
{
X = random.Next(random.Next(200000)) / 10000d * (1 - random.Next(2) * 2),
Y = random.Next(random.Next(200000)) / 10000d * (1 - random.Next(2) * 2),
Z = random.Next(random.Next(200000)) / 10000d * (1 - random.Next(2) * 2),
};
}
}
}
}