-
-
Notifications
You must be signed in to change notification settings - Fork 313
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
float32 conversion #3663
float32 conversion #3663
Conversation
Keeping track of some thoughts/discussion. On Float64 -> Float32 transform:
Other Notes:
|
#3671 isn't strictly necessary for this pr, but I think it would be quite helpful. With stricter definitions of what data_limits and boundingbox do it's easier to reason about them and update them. That pr also should also be more or less done with converting these function to Float64. I changed For handling projection matrices with and without float32 conversion we had the following idea:
Another option would be to always patch matrices in Makie (so keeping Float32) and handle float32 conversions as another matrix in CairoMakie. Since the float conversions are just scaling + translations they are easy to turn into a matrix and merge into the project functions. Assuming we project efficiently (i.e. multiply all matrices together once, not for each point) this should be practically free. |
end | ||
|
||
# For Vector{<: Real} applying to x/y/z dimension | ||
function apply_transform_and_f32_conversion( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought we still may want a Float32Projection <: PointTransform
type, and then create one of those per scene, and apply them directly in drawing_primitives.jl
, like this
function cached_robj!(robj_func, screen, scene, plot::AbstractPlot)
...
transform = Float32Transform(scene.f32convert)
gl_attributes[:transform] = transform
....
end
function draw_atomic(screen::Screen, scene::Scene, ::Scatter)
return cached_robj!(screen, scene, plot) do gl_attributes
space = plot.space
positions = handle_view(plot[1], gl_attributes)
transform_func_obs = gl_attributes[:transform]
# Leave all the transform func lifts, just change them coming from `plot` to `gl_attributes`:
positions = lift(apply_transform, plot, transform_func_obs, positions, space)
...
end
end
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't that override the plot's native transform_func
, though?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We wouldn't want to replace existing transform_func's though, would we?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah I guess I meant:
transform = Float32Transform(scene.f32convert, plot.transform))
And then in apply_transform do the heavy lifting and apply the original transform...
We should not overwrite the plot.transform, that's why I put it in gl_attributes
Also, is this a good place to start looking at transforms for points/lines/etc? For example, if I want to convert all lines (but not polygons) to resampled geodesic paths... |
GLMakie/src/drawing_primitives.jl
Outdated
else | ||
# If we do any transformation, we have to assume things aren't on the grid anymore | ||
# so x + y need to become matrices. | ||
[apply_transform(t, Point(x, y), space) for x in x, y in y] | ||
[MAkie.f32_convert(f32c, apply_transform(t, Point(x, y), space), space) for x in x, y in y] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[MAkie.f32_convert(f32c, apply_transform(t, Point(x, y), space), space) for x in x, y in y] | |
[Makie.f32_convert(f32c, apply_transform(t, Point(x, y), space), space) for x in x, y in y] |
(typo fix)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, but I don't think it's worth reviewing details at this point. I'm currently prototyping without much care and plan to clean things up later, once we are more certain about whether this is a good direction to go.
Reviews on a more conceptual level would be more useful. For example if you see issues with how this would integrate with GeoMakie. I think I noted this somewhere before but the rough plan for the conversion pipeline here is:
- convert_arguments makes structural changes, e.g. Vector, Vector -> Vector{Point2}, leaving types alone or converting to Float32 and Float64 as appropriate
- apply transform_func, preferably keeping types
- apply Float32 conversion which may rescale data
- continue with model, camera as usual
I think Axis converts apply between 1 and 2, but I haven't paid much attention to that pr yet, tbh.
Also regarding transformed space - it's not the point of this pr to add it but I wouldn't mind. I want to add that and world space, but it's not a priority for me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think Axis converts apply between 1 and 2, but I haven't paid much attention to that pr yet, tbh.
No, axis convert shouldn't change anything about that at this point.
Does that mean you want/need |
On second thought, this is a bit tricky. What I want is: apply_transform(transform_func, plot_type, data::Vector)::(result::Vector)
# where
length(data) < length(result) but that would require us to handle per-attribute values, like colors, as well, probably by interpolating. I guess that this could be handled explicitly per atomic plot type? What I want to be able to do is dynamically resample lines (but not any other point based plot, like scatter or text) in a geo axis. Maybe this goes in the axis conversion layer, then, but there would have to be a way to indicate that this particular transformation is nondimensional. |
Yeah this is not the right place to discuss this ;) |
* remove transformations from data_limits * update plots * update blocks * do not consider child scenes in data_limits and boundingbox * put out some fires * note important changes * rename function * fix PolarAxis * cleanup Text some more * small fixes * use apply_transform_and_model * fix some bbox types * fix typing * fix typo * undo zoom change & fix data-space text * fix "Transforming lines" * consider marker bboxes in meshscatter data_limits * fix remaining test errors * boundingbox -> text_boundingbox
Closing in favor of #3681 |
As a PR against #3226, since its not working completely yet
TODO:
convert_arguments
pipeline to either let numeric types pass through OR always convert them to Float32/Float64 as appropriateproject
,data_limits
,boundingbox
to handle Real inputs, make outputs Float64 or input basedbase + offset
tick formatting (e.g.1e9 + 1 .. 1e9 + 10
)Breaking Changes:
project
functions may return Point{N, Float64} dependeing on their inputsdata_limits
and boundingbox now return Rect3d instead of Rect3ftransform_func
is now expected to keep the input type or convert to Float64