Skip to content

Commit fa2d666

Browse files
committed
clip and slice for the plots
1 parent 684f637 commit fa2d666

File tree

8 files changed

+83
-67
lines changed

8 files changed

+83
-67
lines changed

examples/config/cfg_data_matplotlib.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@
55

66
"style": "default" # string with a Matplotlib style
77
"legend": "best" # location of the legend box
8-
"font": 12 # reference font size of the figure
8+
"font": 12.0 # reference font size of the figure

examples/config/cfg_data_pyvista.yaml

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,23 @@
44
# Mozilla Public License Version 2.0
55

66
# options for defining cut planes
7-
"plot_clip":
8-
"clip_plot": false # add (or not) a clip plane for rendering
9-
"clip_invert": false # invert (or not) the clipping direction
10-
"clip_normal": "z" # normal of the clipping direction
11-
"clip_value": 0.0 # initial position for the clipping
7+
"plot_filter":
8+
"slice": false # add (or not) a slice plane for rendering
9+
"clip": false # add (or not) a clip plane for rendering
10+
"invert": false # invert (or not) the clipping/slicing direction
11+
"normal": "x" # normal of the clipping/slicing direction
12+
"value": 0.0 # initial position for the clipping/slicing
1213

1314
# theme of the figure
1415
"plot_theme":
1516
"text_color": "black" # color of the text elements
16-
"title_font": 10 # font size of the text displayed on the window corner
17-
"colorbar_font": 15 # font size of the color bar
18-
"colorbar_size": 5 # number of division for the colorbar
17+
"title_font": 10.0 # font size of the text displayed on the window corner
18+
"colorbar_font": 15.0 # font size of the color bar
19+
"colorbar_size": 5.0 # number of division for the colorbar
1920
"colorbar_plot": true # show (or not) the colorbar
2021
"background_color": "gray" # background color of the plot
2122
"axis_add": true # add (or not) the axis marker
22-
"axis_size": 2 # size of the axis marker
23+
"axis_size": 2.0 # size of the axis marker
2324

2425
# options controlling the view rendering
2526
"plot_view":

examples/config/viewer.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
# - title: title located at the corner of the plot (null for hiding)
2424
# - color_voxel: face color for the voxelized structure
2525
# - color_reference: face color for the reference structure
26+
# - width_voxel: edge thickness for the voxelized structure
27+
# - width_reference: edge thickness for the reference structure
2628
# - opacity_voxel: face opacity for the voxelized structure
2729
# - opacity_reference: face opacity for the reference structure
2830
#
@@ -70,6 +72,8 @@
7072
"title": "Voxelization Results"
7173
"color_voxel": "red"
7274
"color_reference": "blue"
75+
"width_voxel": 2.0
76+
"width_reference": 2.0
7377
"opacity_voxel": 0.5
7478
"opacity_reference": 0.5
7579
"connected":

examples/run_plotter.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,7 @@
2424
file_plotter = os.path.join(PATH_ROOT, FOLDER_CONFIG, "plotter.yaml")
2525

2626
# list of plots to be shown (defined in plotter.yaml)
27-
tag_plot = [
28-
"V_c_norm",
29-
"J_c_norm",
30-
"H_p_norm",
31-
"residuum",
32-
]
27+
tag_plot = ["V_c_norm", "J_c_norm", "H_p_norm", "residuum"]
3328

3429
# method used for rendering the plots
3530
plot_mode = "qt"

pypeec/data/schema_list_viewer.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@
4545
- "title"
4646
- "color_voxel"
4747
- "color_reference"
48+
- "width_voxel"
49+
- "width_reference"
4850
- "opacity_voxel"
4951
- "opacity_reference"
5052
properties:
@@ -59,6 +61,12 @@
5961
"color_reference":
6062
"type": "string"
6163
"minLength": 1
64+
"width_voxel":
65+
"type": "number"
66+
"minimum": 0
67+
"width_reference":
68+
"type": "number"
69+
"minimum": 0
6270
"opacity_voxel":
6371
"type": "number"
6472
"minimum": 0

pypeec/data/schema_plot_matplotlib.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@
1111
"type": "string"
1212
"minLength": 1
1313
"font":
14-
"type": "integer"
14+
"type": "number"
1515
"minimum": 0

pypeec/data/schema_plot_pyvista.yaml

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,31 @@
11
"type": "object"
22
"required":
3-
- "plot_clip"
3+
- "plot_filter"
44
- "plot_theme"
55
- "plot_view"
66
"properties":
7-
"plot_clip":
7+
"plot_filter":
88
"type": "object"
99
"required":
10-
- "clip_plot"
11-
- "clip_invert"
12-
- "clip_normal"
13-
- "clip_value"
10+
- "clip"
11+
- "slice"
12+
- "invert"
13+
- "normal"
14+
- "value"
1415
"properties":
15-
"plot_clip":
16+
"clip":
1617
"type": "boolean"
17-
"clip_invert":
18+
"slice":
1819
"type": "boolean"
19-
"clip_normal":
20+
"invert":
21+
"type": "boolean"
22+
"normal":
2023
"type": "string"
2124
"enum":
2225
- "x"
2326
- "y"
2427
- "z"
25-
"clip_value":
28+
"value":
2629
"type": "number"
2730
"plot_theme":
2831
"type": "object"
@@ -40,13 +43,13 @@
4043
"type": "string"
4144
"minLength": 1
4245
"title_font":
43-
"type": "integer"
46+
"type": "number"
4447
"minimum": 0
4548
"colorbar_font":
46-
"type": "integer"
49+
"type": "number"
4750
"minimum": 0
4851
"colorbar_size":
49-
"type": "integer"
52+
"type": "number"
5053
"minimum": 0
5154
"colorbar_plot":
5255
"type": "boolean"
@@ -56,7 +59,7 @@
5659
"axis_add":
5760
"type": "boolean"
5861
"axis_size":
59-
"type": "integer"
62+
"type": "number"
6063
"minimum": 0
6164
"plot_view":
6265
"type": "object"

pypeec/lib_plot/manage_pyvista.py

Lines changed: 41 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -97,26 +97,32 @@ def _get_plot_title(pl, title, plot_theme):
9797
)
9898

9999

100-
def _get_clip_mesh(pl, obj, arg, plot_clip):
100+
def _get_filter_mesh(pl, obj, arg, plot_filter):
101101
"""
102102
Add an object (either full view or clipped).
103103
"""
104104

105105
# extract
106-
clip_plot = plot_clip["clip_plot"]
107-
clip_invert = plot_clip["clip_invert"]
108-
clip_normal = plot_clip["clip_normal"]
109-
clip_value = plot_clip["clip_value"]
106+
clip = plot_filter["clip"]
107+
slice = plot_filter["slice"]
108+
invert = plot_filter["invert"]
109+
normal = plot_filter["normal"]
110+
value = plot_filter["value"]
110111

111112
# clip the plot
112-
if clip_plot:
113-
obj = obj.clip(normal=clip_normal, value=clip_value, invert=clip_invert)
113+
if clip:
114+
obj = obj.clip(normal=normal, origin=(value, value, value), invert=invert)
115+
116+
# slice the plot
117+
if slice:
118+
obj = obj.slice(normal=normal, origin=(value, value, value))
114119

115120
# add the full plot
116-
pl.add_mesh(
117-
obj,
118-
**arg,
119-
)
121+
if obj.n_cells > 0:
122+
pl.add_mesh(
123+
obj,
124+
**arg,
125+
)
120126

121127

122128
def _get_scale_norm(obj, scale):
@@ -327,7 +333,7 @@ def _get_arrow(obj, data_plot):
327333
return obj_tmp
328334

329335

330-
def _plot_scalar(pl, obj, data_plot, plot_clip, plot_theme):
336+
def _plot_scalar(pl, obj, data_plot, plot_filter, plot_theme):
331337
"""
332338
Plot a scalar variable.
333339
"""
@@ -367,11 +373,10 @@ def _plot_scalar(pl, obj, data_plot, plot_clip, plot_theme):
367373
scalar_bar_args=scalar_bar_args,
368374
render_points_as_spheres=True,
369375
)
370-
if obj.n_cells > 0:
371-
_get_clip_mesh(pl, obj, arg, plot_clip)
376+
_get_filter_mesh(pl, obj, arg, plot_filter)
372377

373378

374-
def _plot_arrow(pl, grid, obj, data_plot, plot_clip, plot_theme):
379+
def _plot_arrow(pl, grid, obj, data_plot, plot_filter, plot_theme):
375380
"""
376381
Plot a vector variable with an arrow plot (quiver plot).
377382
A scalar variable is used to determine the color of the arrows.
@@ -417,10 +422,10 @@ def _plot_arrow(pl, grid, obj, data_plot, plot_clip, plot_theme):
417422
)
418423
if obj.n_cells > 0:
419424
glyph_tmp = obj.glyph(orient="vector", scale=False, factor=factor)
420-
_get_clip_mesh(pl, glyph_tmp, arg, plot_clip)
425+
_get_filter_mesh(pl, glyph_tmp, arg, plot_filter)
421426

422427

423-
def _plot_material(pl, voxel, data_plot, plot_clip, plot_theme):
428+
def _plot_material(pl, voxel, data_plot, plot_filter, plot_theme):
424429
"""
425430
Plot the material and source description.
426431
"""
@@ -455,11 +460,10 @@ def _plot_material(pl, voxel, data_plot, plot_clip, plot_theme):
455460
scalars="material_tag",
456461
cmap=cmap,
457462
)
458-
if voxel_tmp.n_cells > 0:
459-
_get_clip_mesh(pl, voxel_tmp, arg, plot_clip)
463+
_get_filter_mesh(pl, voxel_tmp, arg, plot_filter)
460464

461465

462-
def _plot_geometry(pl, voxel, data_plot, plot_clip, plot_theme, var):
466+
def _plot_geometry(pl, voxel, data_plot, plot_filter, plot_theme, var):
463467
"""
464468
Plot an integer variable on the voxel structure (material or connection).
465469
"""
@@ -482,18 +486,19 @@ def _plot_geometry(pl, voxel, data_plot, plot_clip, plot_theme, var):
482486
cmap=colormap,
483487
opacity=opacity,
484488
)
485-
if voxel_tmp.n_cells > 0:
486-
_get_clip_mesh(pl, voxel_tmp, arg, plot_clip)
489+
_get_filter_mesh(pl, voxel_tmp, arg, plot_filter)
487490

488491

489-
def _plot_voxelization(pl, voxel, reference, data_plot, plot_clip, plot_theme):
492+
def _plot_voxelization(pl, voxel, reference, data_plot, plot_filter, plot_theme):
490493
"""
491494
Plot the reference and voxelized structures in order to assess the voxelization error.
492495
"""
493496

494497
# extract the data
495498
color_voxel = data_plot["color_voxel"]
496499
color_reference = data_plot["color_reference"]
500+
width_voxel = data_plot["width_voxel"]
501+
width_reference = data_plot["width_reference"]
497502
opacity_voxel = data_plot["opacity_voxel"]
498503
opacity_reference = data_plot["opacity_reference"]
499504
title = data_plot["title"]
@@ -510,18 +515,18 @@ def _plot_voxelization(pl, voxel, reference, data_plot, plot_clip, plot_theme):
510515
show_scalar_bar=False,
511516
color=color_voxel,
512517
opacity=opacity_voxel,
518+
line_width=width_voxel,
513519
)
514-
if voxel_tmp.n_cells > 0:
515-
_get_clip_mesh(pl, voxel_tmp, arg, plot_clip)
520+
_get_filter_mesh(pl, voxel_tmp, arg, plot_filter)
516521

517522
# add the resulting plot to the plotter
518523
arg = dict(
519524
show_scalar_bar=False,
520525
color=color_reference,
521526
opacity=opacity_reference,
527+
line_width=width_reference,
522528
)
523-
if voxel_tmp.n_cells > 0:
524-
_get_clip_mesh(pl, reference_tmp, arg, plot_clip)
529+
_get_filter_mesh(pl, reference_tmp, arg, plot_filter)
525530

526531

527532
def get_plot_viewer(pl, grid, voxel, point, reference, layout, data_plot, data_options):
@@ -533,17 +538,17 @@ def get_plot_viewer(pl, grid, voxel, point, reference, layout, data_plot, data_o
533538
"""
534539

535540
# extract the data
536-
plot_clip = data_options["plot_clip"]
541+
plot_filter = data_options["plot_filter"]
537542
plot_view = data_options["plot_view"]
538543
plot_theme = data_options["plot_theme"]
539544

540545
# plot the geometry
541546
if layout == "domain":
542-
_plot_geometry(pl, voxel, data_plot, plot_clip, plot_theme, "domain_tag")
547+
_plot_geometry(pl, voxel, data_plot, plot_filter, plot_theme, "domain_tag")
543548
elif layout == "component":
544-
_plot_geometry(pl, voxel, data_plot, plot_clip, plot_theme, "component_tag")
549+
_plot_geometry(pl, voxel, data_plot, plot_filter, plot_theme, "component_tag")
545550
elif layout == "voxelization":
546-
_plot_voxelization(pl, voxel, reference, data_plot, plot_clip, plot_theme)
551+
_plot_voxelization(pl, voxel, reference, data_plot, plot_filter, plot_theme)
547552
else:
548553
raise ValueError("invalid plot layout")
549554

@@ -561,7 +566,7 @@ def get_plot_plotter(pl, grid, voxel, point, layout, data_plot, data_options):
561566
"""
562567

563568
# extract the data
564-
plot_clip = data_options["plot_clip"]
569+
plot_filter = data_options["plot_filter"]
565570
plot_view = data_options["plot_view"]
566571
plot_theme = data_options["plot_theme"]
567572

@@ -577,16 +582,16 @@ def get_plot_plotter(pl, grid, voxel, point, layout, data_plot, data_options):
577582

578583
# plot the geometry
579584
if layout == "material":
580-
_plot_material(pl, voxel, data_plot, plot_clip, plot_theme)
585+
_plot_material(pl, voxel, data_plot, plot_filter, plot_theme)
581586
elif layout in ["norm_voxel", "norm_point"]:
582587
obj = _get_norm(obj, data_plot)
583-
_plot_scalar(pl, obj, data_plot, plot_clip, plot_theme)
588+
_plot_scalar(pl, obj, data_plot, plot_filter, plot_theme)
584589
elif layout in ["phasor_voxel", "phasor_point"]:
585590
obj = _get_phasor(obj, data_plot)
586-
_plot_scalar(pl, obj, data_plot, plot_clip, plot_theme)
591+
_plot_scalar(pl, obj, data_plot, plot_filter, plot_theme)
587592
elif layout in ["arrow_voxel", "arrow_point"]:
588593
obj = _get_arrow(obj, data_plot)
589-
_plot_arrow(pl, grid, obj, data_plot, plot_clip, plot_theme)
594+
_plot_arrow(pl, grid, obj, data_plot, plot_filter, plot_theme)
590595
else:
591596
raise ValueError("invalid plot layout")
592597

0 commit comments

Comments
 (0)