Grasshopper

algorithmic modeling for Rhino

Hi Everyone,

This might be a silly question.

But I have started to pass arrays between c# components in this manor:

double[][] _out = new double[1][];

_out = field; // field is an array with a scalar field

A= _out;

then I pass it onto another component where I import it as a object, which i then cast to a (double[]) like so:

double[] newfield = (double[]) inputfield;

My question is - does the array get reset? because I am having problems with my scalarfields that I am using for my new Marching Cube stuff - the values keep adding on top of each other. I have attached an example that will hopefully clarify the above, and make it possible for any one to give me a helping hand - because I am going nuts.

- Jens

Views: 382

Attachments:

Replies to This Discussion

The array does not get reset. Grasshopper will try to interpret your output data and cast it to a type Grasshopper knows about, and it will enumerate collections to see if the elements of a collection are of a known type. If you don't want any of this logic to kick in, wrap your array inside a GH_ObjectWrapper before outputting it.

Do note that if you share arrays amongst components, any changes to the array will be noticed by all components. If you want to change an array and not affect another component, you need to duplicate it.

Thanks for the reply David! always makes me understand whats going on with grasshopper better :)

that being said I was just about to say I have solved it, because I arrived at the same conclusion, where it became obvious to me that I had to bring it in like this:

double[] inputfield = (double[])((double[]) x).Clone()

Appologies for the shorthand, it could be written longer for claritys sake :)

I will try and look into that wrapper method you are mentioning, does it add a similar speed increase as it does passing arrays around?

You still pass arrays around using the wrapper, it should in fact be faster with GH_ObjectWrapper as it removes all the interpretation logic that is normally associated with outputting something non IGH_Goo-ish.

BTW: Other than the resolved Array issue I've noticed some Parallel related lines. It's questionable to use such an approach mind (at least "as-it-is"). See this very simple example (and compare as well).

Also: http://www.codeproject.com/Articles/71285/Introducing-NET-Parallel-...

And: http://www.albahari.com/threading/part5.aspx

Attachments:

RSS

About

Translate

Search

Photos

  • Add Photos
  • View All

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service