Grasshopper

algorithmic modeling for Rhino

I made a little VBscript that remove duplicate values from a single list of numbers. It's not optimized but it works. Use it, test it and letme know. As usual, hints ad upgrades are welcome. Bye.

Paolo

Tags: VB, duplicate, remove, script, value, values

Views: 3081

Attachments:

Reply to This

Replies to This Discussion

cool, thank you!

Hi Paolo,

 

see attached. It's a bit smaller (and I think quite a bit faster, especially on large lists). I added comments to the code, but here it is without:

 

Dim lut As New SortedDictionary(Of Double, Boolean)       

Dim result As New List(Of Double)      

For Each value As Double In Values            

    If (lut.ContainsKey(value)) Then Continue For            

    result.Add(value)     

    lut.Add(value, True)

Next

A = result

 

--

David Rutten

david@mcneel.com

Poprad, Slovakia

 

 

Attachments:

what to do for string duplicates?

Dim lut As New SortedDictionary(Of String, Boolean)

Dim result As New List(Of String)  

You can use any type you want as long as it provides it's own CompareTo method. If it doesn't, then you'll have to provide the SortedDictionary with a custom delegate which performs the comparison.

--

David Rutten

david@mcneel.com

Poprad, Slovakia

Hi,

How change the code for Breps?

Cheers,

Piero

You don't want to use a dictionary for comparing breps, as there are too many aspects to compare. Some aspects are geometrical, others are topological. Do you want to treat two breps that have the same shape as identical? Even if their face and edge counts differ?

Writing a brep/brep comparer will almost certainly have to take into account tolerances and different edge/vertex/face orderings. It's a difficult task, especially if you want to do it quickly, but you can start with this:

  1. (geometric aspect) Compare the bounding-boxes. If they are not identical within tolerance, the breps are not the same.
  2. (topological aspect) Compare the face counts of both breps. If they differ, the breps are not the same.
  3. (topological aspect) Compare the edge counts of both breps. If they differ, the breps are not the same.
  4. (topological aspect) Compare the vertex counts of both breps. If they differ, the breps are not the same.
  5. (geometric aspect) Measure the distance from all the vertices in Brep A to the nearest vertex in Brep B. If two vertices are further apart than your tolerance, the breps are not the same.
  6. ...
  7. ...
  8. ...

There are hundreds of rules you could come up with and it really depends on what you consider to be 'identical'.

A completely different approach (which only tests geometric equality) is to randomly generate a point on Brep A, then find the closest point on Brep B. If the distance > tolarance the breps are not identical. Then generate a random point on Brep A and measure distance to closest point on Brep A. Repeat several hundred times for medium certainty. Repeat several thousand times for high certainty.

Thank you David for the quick reply.

I got it but probably my problem is easier to solve:

I have multiple breps with same geometry and topology.

Initially, I found useful to use VB component (as in the post before) but it's just set for double value and because of my lack of experience I cannot modify the script.

Cheers,

Piero

Are they really the same breps, or are they different breps that just happen to be identical?

They are the same breps duplicate in the same place.

C# naive brep equality testing code attached.

Attachments:

My fault, probably there's a little misunderstanding

I would just to remove the duplicate breps like values in this picture:

May I throw in my one-line LINQ alternative?

A = Values.Distinct()

Linq is actually pretty awesome.

RSS

Translate

Search Grasshopper

Photos

  • Add Photos
  • View All

© 2015   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service