Includes code for doing batched transforms in both directions#1025
Includes code for doing batched transforms in both directions#1025
Conversation
fastplotlib/graphics/_base.py
Outdated
| if len(position) == 2: | ||
| # use z of the graphic | ||
| position = [*position, self.offset[-1]] |
There was a problem hiding this comment.
if this is only used for model <-> world, we should enforce that z should always be provided.
if they want to do model -> world then using the world z (which is the offset) will give the wrong result
There was a problem hiding this comment.
yep was thinking this
fastplotlib/graphics/_base.py
Outdated
| raise ValueError( | ||
| f"position can either be shape (num_points, [2, 3]) or ([2, 3],)" | ||
| ) |
There was a problem hiding this comment.
"position must be of shape [3] or [n, 3]"
fastplotlib/graphics/_base.py
Outdated
| if position.shape[-1] == 2: | ||
| z_data = np.zeros((position.shape[0], 1)) | ||
| z_data[:] = self.offset[-1] | ||
| position = np.concatenate( | ||
| [position, z_data], axis=1 | ||
| ) # Shape (num_points, 3) |
There was a problem hiding this comment.
we shouldn't guess a z, user should provide it always
fastplotlib/graphics/_base.py
Outdated
| Converts position data (in the form of tuple or np.ndarray) into a (num_points, 3)-shaped np.ndarray for processing | ||
| """ | ||
|
|
||
| if isinstance(position, tuple): |
There was a problem hiding this comment.
just convert it to array at the beginning, np.asarray(position) and use one code block.
fastplotlib/graphics/_base.py
Outdated
| ) # Shape (num_points, 3) | ||
| elif position.shape[-1] != 3: | ||
| raise ValueError( | ||
| "position must be a tuple or array indicating (x, y, z). The last dimension should be either 2 or 3" |
There was a problem hiding this comment.
[x, y, z] position or [n, 3]
fastplotlib/graphics/_base.py
Outdated
| Converts position data (in the form of tuple or np.ndarray) into a (num_points, 3)-shaped np.ndarray for processing | ||
| """ | ||
|
|
||
| if isinstance(position, tuple): |
There was a problem hiding this comment.
No if clause, always call np.asarray, it's free if the obj is already an array.
fastplotlib/graphics/_base.py
Outdated
| """ | ||
| Converts position data (in the form of tuple or np.ndarray) into a (num_points, 3)-shaped np.ndarray for processing | ||
| """ | ||
| if not isinstance(position, (np.ndarray, tuple)): |
There was a problem hiding this comment.
Just use np.asarray with no type checks, if numpy can't convert it to an array it'll raise, so it'll also handle a list etc.
This PR allows you to do batched coordinate transforms. You have a graphic, the graphic has data points stored in model space. You want to transform all of those model points to world space (or go from world space to model space). Easy to batch/vectorize this via pylinalg but the fpl functions didn't allow for this.
You can do this now:
graphic.map_world_to_model also supports this now