# Grasshopper PointCloud on XYZ grid - C#

**URL:** <https://discourse.mcneel.com/t/grasshopper-pointcloud-on-xyz-grid-c/53571>\
**Category:** Grasshopper\
**Tags:** script, rhinocommon, grasshopper, grasshopper2\
**Created:** [January 22, 2018, 5:39am UTC](https://discourse.mcneel.com/t/grasshopper-pointcloud-on-xyz-grid-c/53571 "2018-01-22T05:39:08Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![sato](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/sato/32/203945_2.png) [@sato](https://discourse.mcneel.com/u/sato)\
**Post date:** [January 22, 2018, 5:39am UTC](https://discourse.mcneel.com/t/grasshopper-pointcloud-on-xyz-grid-c/53571/1 "2018-01-22T05:39:08Z")

</div>

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…

 ![pointcloud_version](https://global.discourse-cdn.com/mcneel/original/3X/b/0/b0671ffab3ff9a64bd922d7a7d740dfb1882b749.JPG)

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

 ![GH_point version](https://global.discourse-cdn.com/mcneel/original/3X/a/2/a24940411ec3eefe2c7c9b72825c5a2f5ad0bb81.JPG)

The File : [GH\_Pointcloud.gh](https://global.discourse-cdn.com/mcneel/uploads/default/original/3X/b/0/b037cb2025e37a9f5cca4801f620c7064f49a446.gh) (11.0 KB)

Thanks for your interrest 🙂  
//Adrian

---

<div class="post-metadata">

**Author:** ![sato](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/sato/32/203945_2.png) [@sato](https://discourse.mcneel.com/u/sato)\
**Post date:** [January 22, 2018, 5:40am UTC](https://discourse.mcneel.com/t/grasshopper-pointcloud-on-xyz-grid-c/53571/2 "2018-01-22T05:40:04Z")

</div>

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++)

---

<div class="post-metadata">

**Author:** ![DavidRutten](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/davidrutten/32/755688_2.png) [@DavidRutten](https://discourse.mcneel.com/u/DavidRutten)\
**Post date:** [January 22, 2018, 10:52am UTC](https://discourse.mcneel.com/t/grasshopper-pointcloud-on-xyz-grid-c/53571/3 "2018-01-22T10:52:09Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![sato](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/sato/32/203945_2.png) [@sato](https://discourse.mcneel.com/u/sato)\
**Post date:** [January 22, 2018, 2:33pm UTC](https://discourse.mcneel.com/t/grasshopper-pointcloud-on-xyz-grid-c/53571/4 "2018-01-22T14:33:51Z")

</div>

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 :**

 ![pointcloud_version2-2](https://global.discourse-cdn.com/mcneel/original/3X/5/3/53989b1564773363fc020ca06076ca8169b47102.JPG)  
**// 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](https://global.discourse-cdn.com/mcneel/uploads/default/original/3X/f/7/f704807ac867e5d6b49c3d26fcd60ef7615b7220.gh) (27.2 KB)

---

<div class="post-metadata">

**Author:** ![sato](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/sato/32/203945_2.png) [@sato](https://discourse.mcneel.com/u/sato)\
**Post date:** [January 22, 2018, 3:02pm UTC](https://discourse.mcneel.com/t/grasshopper-pointcloud-on-xyz-grid-c/53571/5 "2018-01-22T15:02:53Z")

</div>

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

 ![pointcloud_version2-3](https://global.discourse-cdn.com/mcneel/original/3X/2/9/29d1a6687a0a9661c94dfdbf8180d7e57c9ba612.JPG)

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 🙂  
//Adrian

---

<div class="post-metadata">

**Author:** ![Joseph\_Oster](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/joseph_oster/32/549124_2.png) [@Joseph\_Oster](https://discourse.mcneel.com/u/Joseph_Oster)\
**Post date:** [January 22, 2018, 3:08pm UTC](https://discourse.mcneel.com/t/grasshopper-pointcloud-on-xyz-grid-c/53571/6 "2018-01-22T15:08:34Z")

</div>

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](https://global.discourse-cdn.com/mcneel/original/3X/6/b/6b6bfb9e23a288b0ce6b0561cc72c2d77e581c85.png)  
[colors\_2017Nov1a.gh](https://global.discourse-cdn.com/mcneel/uploads/default/original/3X/5/7/57176bab6648dc3343fab5715b407c00f42f11c8.gh) (25.9 KB)

---

<div class="post-metadata">

**Author:** ![sato](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/sato/32/203945_2.png) [@sato](https://discourse.mcneel.com/u/sato)\
**Post date:** [January 22, 2018, 3:15pm UTC](https://discourse.mcneel.com/t/grasshopper-pointcloud-on-xyz-grid-c/53571/7 "2018-01-22T15:15:56Z")

</div>

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.  
//Adrian

---

<div class="post-metadata">

**Author:** ![Joseph\_Oster](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/joseph_oster/32/549124_2.png) [@Joseph\_Oster](https://discourse.mcneel.com/u/Joseph_Oster)\
**Post date:** [January 22, 2018, 3:33pm UTC](https://discourse.mcneel.com/t/grasshopper-pointcloud-on-xyz-grid-c/53571/8 "2018-01-22T15:33:05Z")

</div>

> [@sato](#):
>
> Play around with the PoinCloud version the last file you’ll see is quiet fast and also for camera moves.

No thanks! Don’t need it. Cheers.

---

<div class="post-metadata">

**Author:** ![DavidRutten](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/davidrutten/32/755688_2.png) [@DavidRutten](https://discourse.mcneel.com/u/DavidRutten)\
**Post date:** [January 22, 2018, 4:01pm UTC](https://discourse.mcneel.com/t/grasshopper-pointcloud-on-xyz-grid-c/53571/9 "2018-01-22T16:01:53Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![sato](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/sato/32/203945_2.png) [@sato](https://discourse.mcneel.com/u/sato)\
**Post date:** [January 22, 2018, 4:05pm UTC](https://discourse.mcneel.com/t/grasshopper-pointcloud-on-xyz-grid-c/53571/10 "2018-01-22T16:05:49Z")

</div>

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 🙂

---

<div class="post-metadata">

**Author:** ![PeterFotiadis](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/peterfotiadis/32/472316_2.png) [@PeterFotiadis](https://discourse.mcneel.com/u/PeterFotiadis)\
**Post date:** [January 22, 2018, 6:29pm UTC](https://discourse.mcneel.com/t/grasshopper-pointcloud-on-xyz-grid-c/53571/11 "2018-01-22T18:29:11Z")

</div>

Maybe the attached can shed some light on that matter.

[PointClouds\_V2.gh](https://global.discourse-cdn.com/mcneel/uploads/default/original/3X/9/6/968bef7b229ecdabc7b89e0f694fb7278c96c38b.gh) (118.4 KB)  
[bunnyData.zip](https://global.discourse-cdn.com/mcneel/uploads/default/original/3X/1/e/1e599689e64e5e1c2ee090482c7d9b606d970219.zip) (247.1 KB)

 ![Screen Shot 009](https://global.discourse-cdn.com/mcneel/original/3X/b/6/b6512b25b3a4ded754f51102334f729bbefe8380.JPG)

---

<div class="post-metadata">

**Author:** ![DavidRutten](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/davidrutten/32/755688_2.png) [@DavidRutten](https://discourse.mcneel.com/u/DavidRutten)\
**Post date:** [January 22, 2018, 6:53pm UTC](https://discourse.mcneel.com/t/grasshopper-pointcloud-on-xyz-grid-c/53571/12 "2018-01-22T18:53:09Z")

</div>

[pointcloud.gh](https://global.discourse-cdn.com/mcneel/uploads/default/original/3X/7/c/7c2ca8d3d9e0b4c4b74ed981d4ab3889638d968d.gh) (5.3 KB)

---

<div class="post-metadata">

**Author:** ![sato](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/sato/32/203945_2.png) [@sato](https://discourse.mcneel.com/u/sato)\
**Post date:** [January 23, 2018, 6:19pm UTC](https://discourse.mcneel.com/t/grasshopper-pointcloud-on-xyz-grid-c/53571/13 "2018-01-23T18:19:37Z")

</div>

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.

Cheers,  
//Adrian
