What would be the best approach to filter GeometricAttributes?

thelaythelay Posts: 4
edited July 2016 in KL Programming

For example, I have Points geometry that has an additional IntegerAttribute pointId. I want to filter out all points with pointId of more than X (just arbitrary example, not necessary IntegerAttribute).
From what I understand, there is no removePoint() method in Points geometry, as well as no erase() method for arrays/attributes like in C++ vectors, so I can think of only this approach right now:

  • Go through every pointId and if it should be removed mark it in some external Boolean array
  • Create a new GeometryAttribute container
  • For every existing attribute in existing container:

    • Go through all values and if the index of the current value is not marked then push it into external array
    • Convert the resulting array of values to attribute
    • Attach newly created attribute to the new previously created container
  • Create new Points and attach the new container to it

Is it really the only way or, hopefully, I missed something?

Best Answer

Answers

  • malbrechtmalbrecht Fabric for Houdini Posts: 752 ✭✭✭

    Thinking about it ... you could actually PEX it:

    • create that list of "points to be removed"
    • when done, use a clean up function that gets executed in parallel on the (previously created) NEW array, sized without all points-to-be-deleted
    • the INDEX for the PEX call would be the index of each individual point-to-be-deleted, so that each operator call would simply copy over a single slice from the old to the new array.

    This should be way faster if there are more than, say, four points to be deleted AND more than a couple of thousand points.

    Hmm ... tempted to write a preset for that :)

    Marc


    Marc Albrecht - marc-albrecht.de - does things.

  • thelaythelay Posts: 4

    Hey Marc,

    Thanks, out these options I've went with the initial idea I've described / the first one you've suggested. You can still you PEX, at least to create the initial points-to-be-removed list and I've managed to cram PEX a little bit later on in the method.
    The third option you've described is interesting, but is a little bit too specific for my use, although I can imagine it can be very useful in some cases.

Sign In or Register to comment.