-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from co1emi11er2:makie_extension
Create Makie Extension
- Loading branch information
Showing
7 changed files
with
148 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,4 +34,6 @@ del_dist_load! | |
get_node_u_g | ||
get_element_u_l | ||
get_element_f_l | ||
plotmodel | ||
plotmodel! | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
module HephaestusMakieExt | ||
using Hephaestus | ||
using Makie | ||
|
||
import Hephaestus: plotmodel, plotmodel! | ||
|
||
Makie.@recipe(PlotModel, Model) do scene | ||
Makie.Attributes( | ||
# Nodes: | ||
node_color = :red , | ||
node_marker = :circle, | ||
node_markersize = 6, | ||
node_strokecolor = :black, | ||
node_strokewidth = 1, | ||
|
||
# Node labels: | ||
label_nodes = true, | ||
align_node_labels = (:center, :bottom), | ||
node_label_color = :red, | ||
|
||
# Elements: | ||
element_color = :black, | ||
element_linestyle = :solid, | ||
element_linewidth = 1, | ||
|
||
# Element labels: | ||
label_elements = true, | ||
align_element_labels = (:center, :bottom), | ||
element_label_color = :black) | ||
end | ||
|
||
function Makie.plot!(P::PlotModel) | ||
model = P[:Model] | ||
|
||
for element in values(model[].elements) | ||
x_i, y_i, z_i = element.x_i, element.y_i, element.z_i | ||
x_j, y_j, z_j = element.x_j, element.y_j, element.z_j | ||
|
||
lines!(P, [x_i, x_j], [y_i, y_j], [z_i, z_j], | ||
color = P[:element_color ], | ||
linestyle = P[:element_linestyle], | ||
linewidth = P[:element_linewidth]) | ||
|
||
if P[:label_elements][] | ||
x_m = (x_i + x_j) / 2 | ||
y_m = (y_i + y_j) / 2 | ||
z_m = (z_i + z_j) / 2 | ||
|
||
text!(P, [x_m], [y_m], [z_m], | ||
text = string(element.ID), | ||
color = P[:element_label_color ], | ||
align = P[:align_element_labels]) | ||
end | ||
end | ||
|
||
for node in values(model[].nodes) | ||
x, y, z = node.x, node.y, node.z | ||
|
||
scatter!(P, [x], [y], [z], | ||
color = P[:node_color ], | ||
marker = P[:node_marker ], | ||
markersize = P[:node_markersize ], | ||
strokecolor = P[:node_strokecolor], | ||
strokewidth = P[:node_strokewidth], | ||
overdraw = true) | ||
|
||
if P[:label_nodes][] | ||
text!(P, [x], [y], [z], | ||
text = string(node.ID), | ||
color = P[:node_label_color ], | ||
align = P[:align_node_labels]) | ||
end | ||
end | ||
|
||
# Return the updated model plot: | ||
return P | ||
end | ||
|
||
Makie.preferred_axis_type(P::PlotModel) = Makie.Axis3 | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,73 +1,49 @@ | ||
using MakieCore | ||
""" | ||
plotmodel(model::Model, [options]) | ||
MakieCore.@recipe(PlotModel, Model) do scene | ||
MakieCore.Attributes( | ||
# Nodes: | ||
node_color = :red , | ||
node_marker = :circle, | ||
node_markersize = 6, | ||
node_strokecolor = :black, | ||
node_strokewidth = 1, | ||
Plots a model of a structure of interest ([`Model`](@ref)) into a new `Makie.jl` scene. | ||
# Node labels: | ||
label_nodes = true, | ||
align_node_labels = (:center, :bottom), | ||
node_label_color = :red, | ||
# Plotting Options | ||
# Elements: | ||
element_color = :black, | ||
element_linestyle = :solid, | ||
element_linewidth = 1, | ||
|
||
# Element labels: | ||
label_elements = true, | ||
align_element_labels = (:center, :bottom), | ||
element_label_color = :black) | ||
end | ||
## Nodes | ||
function MakieCore.plot!(P::PlotModel) | ||
model = P[:Model] | ||
| Option | Description | Default | | ||
| :--- | :--- | :--- | | ||
| `node_color` | Color of the nodes | `:red` | | ||
| `node_marker` | Marker of the nodes | `:circle` | | ||
| `node_markersize`| Size of the nodes | `6` | | ||
| `node_strokecolor`| Stroke color of the nodes | `:black` | | ||
| `node_strokewidth`| Stroke width of the nodes | `1` | | ||
for element in values(model[].elements) | ||
x_i, y_i, z_i = element.x_i, element.y_i, element.z_i | ||
x_j, y_j, z_j = element.x_j, element.y_j, element.z_j | ||
## Node Labels | ||
lines!(P, [x_i, x_j], [y_i, y_j], [z_i, z_j], | ||
color = P[:element_color ], | ||
linestyle = P[:element_linestyle], | ||
linewidth = P[:element_linewidth]) | ||
| Option | Description | Default | | ||
| :--- | :--- | :--- | | ||
| `label_nodes` | Whether to label the nodes| `true` | | ||
| `align_node_labels`| Alignment of the node labels | `(:center, :bottom)` | | ||
| `node_label_color`| Color of the node labels | `:red` | | ||
if P[:label_elements][] | ||
x_m = (x_i + x_j) / 2 | ||
y_m = (y_i + y_j) / 2 | ||
z_m = (z_i + z_j) / 2 | ||
## Elements | ||
text!(P, [x_m], [y_m], [z_m], | ||
text = string(element.ID), | ||
color = P[:element_label_color ], | ||
align = P[:align_element_labels]) | ||
end | ||
end | ||
| Option | Description | Default | | ||
| :--- | :--- | :--- | | ||
| `element_color` | Color of the elements | `:black` | | ||
| `element_linestyle`| Line style of the elements | `:solid` | | ||
| `element_linewidth`| Line width of the elements | `1` | | ||
for node in values(model[].nodes) | ||
x, y, z = node.x, node.y, node.z | ||
## Element Labels | ||
scatter!(P, [x], [y], [z], | ||
color = P[:node_color ], | ||
marker = P[:node_marker ], | ||
markersize = P[:node_markersize ], | ||
strokecolor = P[:node_strokecolor], | ||
strokewidth = P[:node_strokewidth], | ||
overdraw = true) | ||
| Option | Description | Default | | ||
| :--- | :--- | :--- | | ||
| `label_elements` | Whether to label the elements | `true` | | ||
| `align_element_labels`| Alignment of the element labels | `(:center, :bottom)` | | ||
| `element_label_color`| Color of the element labels | `:black` | | ||
""" | ||
function plotmodel end | ||
|
||
if P[:label_nodes][] | ||
text!(P, [x], [y], [z], | ||
text = string(node.ID), | ||
color = P[:node_label_color ], | ||
align = P[:align_node_labels]) | ||
end | ||
end | ||
""" | ||
plotmodel!(model::Model, [options]) | ||
# Return the updated model plot: | ||
return P | ||
end | ||
Plots a model of a structure of interest ([`Model`](@ref)) into an existing scene. The plotting options are the same as in [`plotmodel()`](@ref) function. | ||
""" | ||
function plotmodel! end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters