Grasshopper PointCloud on XYZ grid - C#

Hi :slight_smile:

The question is about the fastest way to display an X,Y,Z grid Pointcloud :

I know that Grasshopper doesn’t support pointclouds and that the points have to be generated for grasshopper.

But in my exemple I don’t need to be able to use the points. I just want to see them, so I found some solution, but can’t achieve to order the points onto a grid when generating the point cloud.

I have these points…

I would like to order them like this without loosing the speed:

The File : (11.0 KB)

Thanks for your interrest :slight_smile:

Sample of the C# code of the pointcloud :

for (int i = 0; i < n; i++)
double u = random.NextDouble();
double v = random.NextDouble();
double w = random.NextDouble();
Point3d pt = box.PointAt(u, v, w);

  Color col = Color.FromArgb(255, 255, 255);
  _cloud.Add(pt, col);

Sample of the code with 3dPoint version

for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
for (int k = 0; k < n; k++)
double x = i * iSize;
double y = j * iSize;
double z = k * iSize;

      points.Add((new Point3d(x, y, z));

I know that the random.NextDouble() will never give regular grid, but when I try to do as for the GH_Point exemple It crash after putting like 4 points… :-/

for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
for (int k = 0; k < n; k++)

I don’t follow, there is no GH_Point in your code. Also points.Add(new Point3d(new Point3d(x, y, z))); is using the Point3d constructor twice, you can get rid of one of those.

Hello David,
Sorry I just forgot to put the GH_Point version in the file (wich is faster then the Point3d Version).

GH_points version :

List<GH_Point> gridPoints = new List<GH_Point>();

for (int i = 0; i < n; i++)
  for (int j = 0; j < n; j++)
    for (int k = 0; k < n; k++)
      double x = i * iSize;
      double y = j * iSize;
      double z = k * iSize;

      gridPoints.Add(new GH_Point(new Point3d(x, y, z)));
outputPoints = gridPoints;

I don’t know if I was clear in my question, but my idea is to find the fastest way to display a pointcloud for the user, I don’t need to be able to retrieve the points, just to see it in the view port. I made a little test just to explain what I’m talking about.

Benchmark 1 :

// 170ms for 1 000 000 points - with PointCloud
// 4.8s for 1 000 000 points - with Point3d
// 193ms for 1 000 000 points - with GH_Point (its sparing the double cast to Point3d I guess).

I mean… The choice is then obvious between GH_Points and Point3d ^^
The problem there is that GH_Points need to be converted to be customizable and then its a lot slower. But point cloud are already witch a choosen color and still offer really nice performances.

And when come the time to move the view port camera… doing so with GH_Points i’ve got an horrible framerate, but with pointclouds is very fluid.
I would like to display the pointclouds in a grid and not random, maybe you could help.

The file version2 : (27.2 KB)

Just to make sure… because inputs are a bit confusing about number of points :

1 000 000 Points
// 171ms PointCloud (Color) camera very fluid.
// 4,9s Point3d (no Color) impossible to move camera.
// 123 ms GH_Point (no Color) impossible to move camera but a bit better.
// 5.0s GH_Point (Color) impossible to move camera.

Cheers :slight_smile:

This isn’t C# but I wrote it to generate color palettes - there is a disabled random reduce feature off to the right. I just increased the ‘Steps’ slider maximum from 10 to 100 and it generates a grid of 103823 points (47 X 47 X 47) in roughly six seconds. (25.9 KB)

Thanks Joseph for the input,
But this is way too slow for what I want to use it for ^^

Play around with the PoinCloud version the last file you’ll see is quiet fast and also for camera moves.
I could add the possiblity to change the color palette if you want to.


No thanks! Don’t need it. Cheers.

If it’s only display speed you’re after you should use PointCloud and do your own drawing. It will allow you to specify colours per location and since the data is stored inside the C++ part of Rhino it’s faster to pump it to the screen.

Thanks David,

Of course, I want to use PointCloud
But as I said, when I do three for loops like on the GH_point and Point3d exemple but for the pointcloud exemple it crashes.

Could you provide me a simple exemple how to display a grid of pointsCloud ?
Or maybe look at the file, maybe its just matter of on line to change but I’m not finding it.

Thanks for your help :slight_smile:

Maybe the attached can shed some light on that matter. (118.4 KB) (247.1 KB) (5.3 KB)

Thanks guys for the help.
And many thanks David for your solution, you sent exactely what I needed to unlock the situation with that component.