目前能够用Viewport3D显示3D图像,但是不知道怎样显示点云。

解决方案 »

  1.   

    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),
                    };
                }
            }
        }
    }
      

  2.   

    这样是一个办法,但是如果放大了就全是三角形,我现在用的PCL库,目前直接将PCL的代码编译成dll,然后c#调用dll显示