I am trying to visualize a point cloud of ~170000 points using WPF's Viewport3D control. After generating the 3D point coordinates I create a triangle with a certain size at each point and add it to a Model3DGroup object which I append to my Viewport aftwerwards.
My problem is that the code below responsible for this takes 3 seconds alone to run. After the Model3DGroup has been added to the Viewport the UI is frozen for another 3-5 seconds more.
How can I make this work faster? Also if Viewport3D can't handle models of this number can anyone recommend an alternative way of visualizing a point cloud in a WPF control?
viewport.Children.Clear();
Model3DGroup triangles = new Model3DGroup();
foreach (Point3D point in workspace.PointCloud)
{
double x = point.X;
double y = point.Y;
double z = point.Z;
Point3D p1 = new Point3D(x + 0.005, y, z);
Point3D p2 = new Point3D(x, y + 0.005, z);
MeshGeometry3D mymesh = new MeshGeometry3D();
mymesh.Positions.Add(point);
mymesh.Positions.Add(p1);
mymesh.Positions.Add(p2);
mymesh.TriangleIndices.Add(0);
mymesh.TriangleIndices.Add(1);
mymesh.TriangleIndices.Add(2);
Vector3D Normal = GeometryHelper.CalculateTraingleNormal(p0, p1, p2);
mymesh.Normals.Add(Normal);
mymesh.Normals.Add(Normal);
mymesh.Normals.Add(Normal);
Material Material = new DiffuseMaterial(
new SolidColorBrush(Colors.Red) { Opacity = 0.5 });
GeometryModel3D model = new GeometryModel3D(
mymesh, Material);
triangles.Children.Add(model);
}
ModelVisual3D modelVisual = new ModelVisual3D();
modelVisual.Content = triangles;
viewport.Children.Add(modelVisual);