Grasshopper

algorithmic modeling for Rhino

Hi guys!
I want to analyse the viewport image. I know I can do that by first using capture viewport to bitmap commend in Rhino, and then dragging it back into Grasshopper.However that is not that realtime. Is there a way to get the buffer of the viewport and read the data such as RGB using VB.Net? Can anyone give me some hints on it?

Views: 776

Replies to This Discussion

The best I could find was this example here on the developer wiki, and it doesn't have a .NET example...

http://wiki.mcneel.com/developer/sdksamples/screencaptureview

There are several things about this example that are useful/intersting. First of all, you're going to end up at either Doc.DrawToDC or Doc.RenderToDC, which is the method that's doing the capturing if you will. What that method needs is a device context to write the data to. In the example it uses the MRhinoDib class, which looks pretty lean on the dotNET side. I'm not sure if its possible to create your own device context to draw to, but the one in the RhinoSDK only has a WriteToFile method. Since you're probably looking to access the data directly, as opposed to writing the file and reading it back in, I don't think this is going to be as helpful.

Hopefully that provides you with enough info to start playing around with it. Maybe some of the larger brains can swoop down and fill in the large blanks that exist in getting this kind of thing moving.
Thanks Damien, I will play with it.
You can also use Rhino Commands to copy the viewport bitmap into the clipboard, then get the image clipboard contents.

--
David Rutten
david@mcneel.com
Poprad, Slovakia
Do you mean load and run Rhino commands in VB.Net component in Grasshopper?
Yes, you should be able to run rhino commands from within a VB.NET component. It's not quite as 'nice' as doing it all in code, but it will save you from writing a lot of difficult code yourself.

--
David Rutten
david@mcneel.com
Poprad, Slovakia
Thanks David. Is it done by CRhinoScriptCommand? Sorry for bothering you, I am really new to .net and really struggling.
Hi Daniel,

Private Sub RunScript(ByRef A As Object)
   RMA.Rhino.RhUtil.RhinoApp().RunScript("-_ViewCaptureToClipboard _Enter")

   Dim img As Image = Windows.Forms.Clipboard.GetImage()

   Dim bmp As New Bitmap(20, 20, Imaging.PixelFormat.Format24bppRgb)
   Dim grp As Graphics = Graphics.FromImage(bmp)
   grp.InterpolationMode = Drawing2D.InterpolationMode.HighQualityBicubic
   grp.DrawImage(img, 0, 0, 20, 20)

   Dim R As int32 = 0
   Dim G As int32 = 0
   Dim B As Int32 = 0

   For i As Int32 = 0 To bmp.Width - 1
     For j As Int32 = 0 To bmp.Height - 1
       Dim col As Color = bmp.GetPixel(i, j)
       R += col.R
       G += col.G
       B += col.B
     Next
   Next

   R = Convert.ToInt32(R / 400)
   G = Convert.ToInt32(G / 400)
   B = Convert.ToInt32(B / 400)

   A = Color.FromArgb(R, G, B)
End Sub


--
David Rutten
david@mcneel.com
Poprad, Slovakia
File written with 0.7.0032, you'll need 0.7.X to open it. Using the old SDK instead of RhinoCommon.

--
David Rutten
david@mcneel.com
Poprad, Slovakia
Attachments:
Thanks so much for your help David!
5 mins here, and I'm already soaking up so much.. "Windows.Forms.Clipboard.GetImage" is my thought for the day!

Though I wish there was some way to 'watch' the clip board, and trigger a recompute in GH when the image would change. I know, I know.. the Timer, but perhaps some way of not recomputing all the time, but only when needed.
It's not easy, but it seems possible to make a Clipboard event watcher:

http://www.radsoftware.com.au/articles/clipboardmonitor.aspx

--
David Rutten
david@mcneel.com
Poprad, Slovakia
wonderful! one more thing to fiddle around with now.

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service