Skip to content

Conversation

@pjaap
Copy link
Member

@pjaap pjaap commented Jan 31, 2025

This is based on WIAS-PDELib/GridVisualizeTools.jl#20

Implementation of high level methods for line and slice plotting.
The user only has to provide a generic line or plane definition to obtain a plot.

The new coordinate systems are created by isometric rotation and therefore the angles are invariant.

Examples:

grid = simplexgrid(-1.0:0.01:1.0, -1.0:0.01:1.0)
f = map(x -> x[2]*x[1], grid)
line = [1,1,0] # plot along x + y = 0
lineplot(grid, f, line, Plotter=GLMakie)

grafik

grid = simplexgrid(-1.0:0.1:1.0, -1.0:0.1:1.0, -1.0:0.1:1.0)
f = map(x -> x[2]*x[1], grid)
plane = [1,1,0,-1.51] # plot along x + y + 0z = 1.51
sliceplot(grid, f, plane, Plotter=GLMakie) 

grafik

Note that the intersection is about of size 2 x 0.75 in the new transformed coordinates.

There is a bug in marching_tetrahedra, creating some holes in the plot if the tetrahedra are sliced along the facets:

plane = [1,1,0,-1.5] # plot along x + y + 0z = 1.5

grafik

@j-fu
Copy link
Member

j-fu commented Feb 3, 2025

Ah cool - this seems to work without need to interfere with the plotting backend code.

As for the naming: in fact, these are still scalarplots after all.

An alternative would be to just use the scalarplot method and to add a hyperplane
kwarg. So we could have

scalarplot(grid, f; hyperplane=[1,1,0],Plotter=GLMakie)

@pjaap
Copy link
Member Author

pjaap commented Feb 10, 2025

Sorry for the late answer. I somehow missed it.

Thanks for the positive feedback. I like your naming suggestion to keep it as scalarplot.
However, a hyperplane is usually used for more than three dimensions, right?
We already have the planes kwarg, which is too similar to plane.

I think the cleanest solution is slice = Plane(a,b,c,d) for an explicit dummy class Plane. And Line(a,b,c) for the line plot.
Then, we can elegantly document the plane equation coefficients.

@j-fu
Copy link
Member

j-fu commented Feb 10, 2025

IMHO "hyperplane" is the dimension independent name for an n-1 dimensional affine subspace.
So a line is a hyperplane in 2D, and a plane is a hyperplane in 3D. I am really a fan of dimension independent naming.

@j-fu
Copy link
Member

j-fu commented Feb 25, 2025

@j-fu
Copy link
Member

j-fu commented Feb 25, 2025

As for the naming: we could have a dimension type parameter in HyperPlane and make type aliases for Line and Plane.

@j-fu
Copy link
Member

j-fu commented Feb 25, 2025

After thinking more about it: slice is really good as a name for the keyword arg.

In principle it might be sufficient to pass a vector or tuple of the right dimension,
we might not need an extra type, so slice=[1,0,2] might be sufficient with proper documentation.

What really would be quite helpful in the API would be the ability to say
slice = :y => 5 or slice = "y" => 5.

We could internally have something like these and call them wherever the slice data are accessed:

function make_slice(spacedim, v::Any)
  if length(v)==spacedim+1
     return v
  else 
   error("hyperplane in dim=$spacedim needs $(spacedim+1) parameters")
end
end

and

function make_slice(spacedim, p::Pair)
   v=zeros(spacedim+1)
   if Symbol(p.first)==:x
       v[1]=1
   elseif Symbol(p.first)==:y
       v[2]=1
    ....
   end
   v[end]=p.second
return v
end

@pjaap
Copy link
Member Author

pjaap commented Feb 25, 2025

This also circumvents the problem of exporting the pretty ambiguous types Line and Plane.

I also like the idea to pass pairs, as in slice = :x => 5. I would definitely go with symbols.

Another, maybe really clean approach would be to pass an expression slice = :(x - 5) or slice = :(x + 2y + 4 ) ...
edit: we should not put a = in an expression

What do you think about this one?

@j-fu
Copy link
Member

j-fu commented Feb 25, 2025

To allow Symbols and strings is easy - the example above should already do this.
As for expressions - well why not... But this IMHO also could be released later if it takes too long
to make it robust. I don't have many experiences with this.

@pjaap
Copy link
Member Author

pjaap commented Feb 27, 2025

From my POV, the PR is now feature complete.

We need an downstream change for PlutoVista, like in src/makie.jl.
Therefore, I skipped one test for now, This should be turned on again soon.

@j-fu
Copy link
Member

j-fu commented Feb 27, 2025

Could you also add line plot and a slice plot example to the docs ? Maybe in examples/plotting.jl ?

@pjaap
Copy link
Member Author

pjaap commented Feb 27, 2025

Sure, I added some handy examples. Stupid question: How did you make the SVG files?

@j-fu
Copy link
Member

j-fu commented Feb 28, 2025

This is via the include("makeplots.jl") in docs/make.jl.
But see #66 ...

@pjaap
Copy link
Member Author

pjaap commented Feb 28, 2025

Ah, I see. Still not used to the workflows of this package.

@pjaap
Copy link
Member Author

pjaap commented Feb 28, 2025

Ok, I ran into some weird documenter issue with the doc strings of the new slice_plot.jl file.
Now the examples and doc strings should be there.

@pjaap pjaap force-pushed the feature/slice-line-plot branch from e6089bd to e96d062 Compare March 4, 2025 08:41
@pjaap pjaap force-pushed the feature/slice-line-plot branch from e96d062 to c9fe6e7 Compare March 4, 2025 08:42
@pjaap
Copy link
Member Author

pjaap commented Mar 4, 2025

Hugh. CI fails due to libpython3 no found. Looks unrelated to me. It didn't fail a few hours ago.
Locally tests are fine.
Force merge or debug the issue?

@pjaap pjaap merged commit 89e8f0d into main Mar 4, 2025
3 of 9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants