Grasshopper

algorithmic modeling for Rhino

Has anyone written a component to split a list based on data type?  I'm thinking:

Inputs: List of assorted geometry

Outputs: Point, Curve, Surface, BRep, Mesh

Cheers,

Marc

Views: 2654

Replies to This Discussion

I have a deserialization component in Slingshot! that does basically this under the hood.  

I'll see about getting a more general purpose version up that will just sort objects as you describe....

-Nate

While we wait for Nathan to do the job properly :) here's my take... one easily extensible GH version and a scripted version for the 5 types you mentioned. 

Attachments:

I had a feeling you'd whip something up.  Glad you took the bait.  :)

Incidentally, I had the hacky way of doing it working, but thought a scripted version might be more efficient.  Looks like it actually uses more computational cycles.  Any idea why that might be?

Marc

Oh no... you've figured out that I can't resist a little scripting problem :-p

It's weird though... on my machine the scripted version is markedly faster, with the "Contains" function as the bottleneck of the GH-only approach. Not sure why you'd be seeing something different. 

I think there must be some kind of one-time start-up penalty for the scripting components.  The first time it ran I was getting 187ms on the scripting component, but I can't repeat that now.  Anyway, after playing with it for a bit, it turns out that the C# script maintains complex data tree structures while the hacky way does not (without some serious gymnastics).

So anyway, I am now trying to add text objects to this list... no success thus far.  My modifications below (not working):

List<Rhino.Geometry.Point> Pts = new List<Rhino.Geometry.Point>();
List<Curve> Crvs = new List<Curve>();
List<Mesh> Meshes = new List<Mesh>();
List<Brep> Breps = new List<Brep>();
List<Brep> Srfs = new List<Brep>();
List<String> Txts = new List<String>();

foreach(GeometryBase x in geo){
Rhino.DocObjects.ObjectType objectType = x.ObjectType;
switch(objectType){
case Rhino.DocObjects.ObjectType.TextEntity: Txts.Add(x as String);
break;
case Rhino.DocObjects.ObjectType.Point: Pts.Add(x as Rhino.Geometry.Point);
break;
case Rhino.DocObjects.ObjectType.Curve: Crvs.Add(x as Curve);
break;
case Rhino.DocObjects.ObjectType.Mesh: Meshes.Add(x as Mesh);
break;
case Rhino.DocObjects.ObjectType.Brep:
Brep brepObj = x as Brep;
if(brepObj.IsSurface){
Srfs.Add(brepObj);
} else {
Breps.Add(brepObj);
}
break;


}
}
Pt = Pts;
Crv = Crvs;
Mesh = Meshes;
Brep = Breps;
Srf = Srfs;
Txt = Txts;

Any suggestions?  Is it perhaps because TextEntity is not a member of GeometryBase?  Also, I wouldn't mind having an "Other" category to pick up things like shaders/materials, etc.  I had that working in the GH environment but again, the scripted version is better for a number of reasons.

Thanks,

Marc

The first time a new script runs it will need to be compiled. This is quite a performance hit. But, it only happens the first time. It should run much faster after that.

There is also a penalty the first time you run a regular component as the JIT compiler needs to consume the MSIL code and generate machine code. If you want to see more realistic times on the profiler then you should press F5 to recompute the entire file without any startup overheads.

--

David Rutten

david@mcneel.com

Poprad, Slovakia

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