# Grasshopper PointCloud on XYZ grid - C#

Hi

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 : GH_Pointcloud.gh (11.0 KB)

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

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;

}
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 : GH_Pointcloud2.gh (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

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.

colors_2017Nov1a.gh (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.

Thanks.

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.