hashing - Fast access to space associated data

This modules provide tools for accessing data using its space location (not for final user).

The complexity and therefore the cost of those operations are most of the time close to the hashmap complexity O(1). It means data is found in time independently of the actual size of the mesh or whatever storage it is.

class PositionMap(cellsize, iterable=None)[source]

Holds objects associated with their location. Every object can be bound to multiple locations, and each location can hold multiple objects. cellsize defines the box size for location hashing (the smaller it is, the bigger the memory footprint will be for non-point primitives)

Attributes defined here:
cellsize:the boxing parameter (DON’T CHANGE IT IF NON-EMPTY)
dict:the hashmap from box to objects lists
__contains__(space)[source]

check if any stored object is potentially intersecting the given primitive

add(space, obj)[source]

add an object associated with a primitive check keysfor for a description of allowed primitives

display(scene)[source]
get(space)[source]

get the objects potentially intersecting the given primitive check keysfor for a description of allowed primitives

keysfor(space)[source]

Rasterize the primitive, yielding the successive position keys currently allowed primitives are

points:vec3
segments:(vec3,vec3)
triangles:(vec3,vec3,vec3)
update(other)[source]

Add the elements from an other PositionMap or from an iterable

meshcellsize(mesh)[source]

Returns a good cell size to index primitives of a mesh with a PositionMap

See implementation.

class PointSet(cellsize, iterable=None, manage=None)[source]

Holds a list of points and hash them. The points are holds using indices, that allows to get the point buffer at any time, or to retrieve only a point index. cellsize defines the box size in which two points are considered to be the same

Methods are inspired from the builtin type set

Attributes defined here:
points:the point buffer (READ-ONLY PURPOSE)
cellsize:the boxing parameter (DON’T CHANGE IT IF NON-EMPTY). mendatory and is the distance at which you want to distinguish points
dict:the hashmap from box to point indices
Build parameters:
iterable:use it to build the set by inserting elements
manage:pass a list for inplace use it, only indexing will be built
__add__(iterable)[source]
__contains__(pt) bool[source]

true if there is a point at the given location in the set

__getitem__(pt) int[source]

return the index of the point at given location in the set

__iadd__(iterable)

add points from an iterable

__isub__(iterable)

Remove the points from an iterable

__sub__(iterable)[source]
add(pt) int[source]

add a point to the set if no equivalent point is at this position return the index of the created point or the pre-existing point at this position.

difference_update(iterable)[source]

Remove the points from an iterable

discard(pt)[source]

remove all points at positions equivalent to the given location (if any)

keyfor(pt)[source]

hash key for a point. points with the same key will be considered equivalent and merged in the set

remove(pt) int[source]

remove the point at given position point from the set, returning its former index. raise if no point exist at this position

update(iterable)[source]

add points from an iterable