pub struct Mesh3D { /* private fields */ }Expand description
A structure representing a 3D mesh plot.
The Mesh3D struct is designed to create and customize 3D mesh visualizations
with support for explicit triangulation, intensity-based coloring, and various
lighting effects. It can handle both auto-triangulated point clouds and
explicitly defined mesh connectivity through triangle indices.
§Arguments
data- A reference to theDataFramecontaining the mesh data.x- A string slice specifying the column name for x-axis vertex coordinates.y- A string slice specifying the column name for y-axis vertex coordinates.z- A string slice specifying the column name for z-axis vertex coordinates.i- An optional string slice specifying the column name for first vertex indices of triangles.j- An optional string slice specifying the column name for second vertex indices of triangles.k- An optional string slice specifying the column name for third vertex indices of triangles.intensity- An optional string slice specifying the column name for intensity values used in gradient coloring.intensity_mode- An optionalIntensityModespecifying whether intensity applies to vertices or cells.color- An optionalRgbvalue for uniform mesh coloring.color_bar- An optional reference to aColorBarfor customizing the color legend.color_scale- An optionalPalettedefining the color gradient for intensity mapping.reverse_scale- An optional boolean to reverse the color scale direction.show_scale- An optional boolean to show/hide the color bar.opacity- An optionalf64value specifying mesh transparency (range: 0.0 to 1.0).flat_shading- An optional boolean for angular (true) vs smooth (false) shading.lighting- An optional reference to aLightingstruct for custom lighting settings.light_position- An optional tuple(x, y, z)specifying the light source position.delaunay_axis- An optional string specifying the axis for Delaunay triangulation (“x”, “y”, or “z”).contour- An optional boolean to enable contour lines on the mesh.facet- An optional string slice specifying the column name to be used for faceting (creating multiple subplots).facet_config- An optional reference to aFacetConfigstruct for customizing facet behavior (grid dimensions, scales, gaps, etc.).plot_title- An optionalTextstruct specifying the plot title.x_title- An optionalTextstruct for the x-axis title.y_title- An optionalTextstruct for the y-axis title.z_title- An optionalTextstruct for the z-axis title.legend- An optional reference to aLegendstruct for legend customization.
§Example
use plotlars::{Lighting, Mesh3D, Plot, Rgb, Text};
use polars::prelude::*;
let mut x = Vec::new();
let mut y = Vec::new();
let mut z = Vec::new();
let n = 20;
for i in 0..n {
for j in 0..n {
let xi = (i as f64 / (n - 1) as f64) * 2.0 - 1.0;
let yj = (j as f64 / (n - 1) as f64) * 2.0 - 1.0;
x.push(xi);
y.push(yj);
z.push(0.3 * ((xi * 3.0).sin() + (yj * 3.0).cos()));
}
}
let dataset = DataFrame::new(vec![
Column::new("x".into(), x),
Column::new("y".into(), y),
Column::new("z".into(), z),
])
.unwrap();
Mesh3D::builder()
.data(&dataset)
.x("x")
.y("y")
.z("z")
.color(Rgb(200, 200, 255))
.lighting(
&Lighting::new()
.ambient(0.5)
.diffuse(0.8)
.specular(0.5)
.roughness(0.2)
.fresnel(0.2),
)
.light_position((1, 1, 2))
.opacity(1.0)
.flat_shading(false)
.contour(true)
.plot_title(
Text::from("Mesh 3D Plot")
.font("Arial")
.size(22),
)
.build()
.plot();
Implementations§
Source§impl Mesh3D
impl Mesh3D
Sourcepub fn builder<'f1, 'f2, 'f3, 'f4, 'f5, 'f6, 'f7, 'f8, 'f9, 'f10, 'f11, 'f12, 'f13, 'f14>() -> Mesh3DBuilder<'f1, 'f2, 'f3, 'f4, 'f5, 'f6, 'f7, 'f8, 'f9, 'f10, 'f11, 'f12, 'f13, 'f14>
pub fn builder<'f1, 'f2, 'f3, 'f4, 'f5, 'f6, 'f7, 'f8, 'f9, 'f10, 'f11, 'f12, 'f13, 'f14>() -> Mesh3DBuilder<'f1, 'f2, 'f3, 'f4, 'f5, 'f6, 'f7, 'f8, 'f9, 'f10, 'f11, 'f12, 'f13, 'f14>
Examples found in repository?
examples/mesh3d.rs (line 23)
11fn example_basic_mesh() {
12 let x = vec![0.0, 1.0, 2.0, 0.0, 1.0, 2.0];
13 let y = vec![0.0, 0.0, 0.0, 1.0, 1.0, 1.0];
14 let z = vec![0.0, 0.5, 0.0, 0.0, 0.8, 0.0];
15
16 let dataset = DataFrame::new(vec![
17 Column::new("x".into(), x),
18 Column::new("y".into(), y),
19 Column::new("z".into(), z),
20 ])
21 .unwrap();
22
23 Mesh3D::builder()
24 .data(&dataset)
25 .x("x")
26 .y("y")
27 .z("z")
28 .color(Rgb(100, 150, 200))
29 .opacity(0.8)
30 .plot_title("Basic Mesh3D")
31 .build()
32 .plot();
33}
34
35fn example_with_indices() {
36 let x = vec![0.0, 1.0, 0.5, 0.5];
37 let y = vec![0.0, 0.0, 0.866, 0.289];
38 let z = vec![0.0, 0.0, 0.0, 0.816];
39 let i = vec![0, 0, 0, 1];
40 let j = vec![1, 2, 3, 2];
41 let k = vec![2, 3, 1, 3];
42
43 let dataset = DataFrame::new(vec![
44 Column::new("x".into(), x),
45 Column::new("y".into(), y),
46 Column::new("z".into(), z),
47 Column::new("i".into(), i),
48 Column::new("j".into(), j),
49 Column::new("k".into(), k),
50 ])
51 .unwrap();
52
53 Mesh3D::builder()
54 .data(&dataset)
55 .x("x")
56 .y("y")
57 .z("z")
58 .i("i")
59 .j("j")
60 .k("k")
61 .color(Rgb(255, 100, 100))
62 .opacity(0.9)
63 .flat_shading(true)
64 .plot_title("Tetrahedron with Explicit Indices")
65 .build()
66 .plot();
67}
68
69fn example_with_intensity() {
70 let mut x = Vec::new();
71 let mut y = Vec::new();
72 let mut z = Vec::new();
73 let mut intensity = Vec::new();
74
75 for i in 0..10 {
76 for j in 0..10 {
77 let xi = i as f64 * 0.1;
78 let yj = j as f64 * 0.1;
79 x.push(xi);
80 y.push(yj);
81 z.push(
82 (xi * 2.0 * std::f64::consts::PI).sin()
83 * (yj * 2.0 * std::f64::consts::PI).cos()
84 * 0.3,
85 );
86 intensity.push(xi * yj);
87 }
88 }
89
90 let dataset = DataFrame::new(vec![
91 Column::new("x".into(), x),
92 Column::new("y".into(), y),
93 Column::new("z".into(), z),
94 Column::new("intensity".into(), intensity),
95 ])
96 .unwrap();
97
98 Mesh3D::builder()
99 .data(&dataset)
100 .x("x")
101 .y("y")
102 .z("z")
103 .intensity("intensity")
104 .intensity_mode(IntensityMode::Vertex)
105 .color_scale(Palette::Viridis)
106 .reverse_scale(false)
107 .show_scale(true)
108 .color_bar(&ColorBar::new().x(0.85).title("Intensity"))
109 .opacity(0.95)
110 .plot_title(
111 Text::from("Mesh3D with Intensity Coloring")
112 .font("Arial")
113 .size(20),
114 )
115 .build()
116 .plot();
117}
118
119fn example_with_lighting() {
120 // Create a simple wavy surface mesh without explicit indices
121 // The mesh will be auto-triangulated
122 let mut x = Vec::new();
123 let mut y = Vec::new();
124 let mut z = Vec::new();
125
126 let n = 20;
127 for i in 0..n {
128 for j in 0..n {
129 let xi = (i as f64 / (n - 1) as f64) * 2.0 - 1.0;
130 let yj = (j as f64 / (n - 1) as f64) * 2.0 - 1.0;
131 x.push(xi);
132 y.push(yj);
133 // Create a wavy surface
134 z.push(0.3 * ((xi * 3.0).sin() + (yj * 3.0).cos()));
135 }
136 }
137
138 let dataset = DataFrame::new(vec![
139 Column::new("x".into(), x),
140 Column::new("y".into(), y),
141 Column::new("z".into(), z),
142 ])
143 .unwrap();
144
145 Mesh3D::builder()
146 .data(&dataset)
147 .x("x")
148 .y("y")
149 .z("z")
150 .color(Rgb(200, 200, 255))
151 .lighting(
152 &Lighting::new()
153 .ambient(0.5)
154 .diffuse(0.8)
155 .specular(0.5)
156 .roughness(0.2)
157 .fresnel(0.2),
158 )
159 .light_position((1, 1, 2))
160 .opacity(1.0)
161 .flat_shading(false)
162 .contour(true)
163 .plot_title(Text::from("Mesh 3D").font("Arial").size(22))
164 .build()
165 .plot();
166}More examples
examples/faceting.rs (line 374)
333fn mesh3d_example() {
334 let mut x_vals = Vec::new();
335 let mut y_vals = Vec::new();
336 let mut z_vals = Vec::new();
337 let mut surface_type = Vec::new();
338
339 let n = 25;
340
341 for surface in ["Gaussian", "Saddle", "Ripple"].iter() {
342 for i in 0..n {
343 for j in 0..n {
344 let x = (i as f64 / (n - 1) as f64) * 4.0 - 2.0;
345 let y = (j as f64 / (n - 1) as f64) * 4.0 - 2.0;
346
347 let z = match *surface {
348 "Gaussian" => (-0.5 * (x * x + y * y)).exp(),
349 "Saddle" => 0.3 * (x * x - y * y),
350 "Ripple" => 0.4 * ((x * 3.0).sin() + (y * 3.0).cos()),
351 _ => 0.0,
352 };
353
354 x_vals.push(x);
355 y_vals.push(y);
356 z_vals.push(z);
357 surface_type.push(surface.to_string());
358 }
359 }
360 }
361
362 let dataset = DataFrame::new(vec![
363 Column::new("x".into(), x_vals),
364 Column::new("y".into(), y_vals),
365 Column::new("z".into(), z_vals),
366 Column::new("surface_type".into(), surface_type),
367 ])
368 .unwrap();
369
370 let config = FacetConfig::new().cols(3).rows(1);
371
372 let lighting = Lighting::new().ambient(0.6).diffuse(0.8).specular(0.4);
373
374 Mesh3D::builder()
375 .data(&dataset)
376 .x("x")
377 .y("y")
378 .z("z")
379 .facet("surface_type")
380 .facet_config(&config)
381 .color(Rgb(100, 150, 200))
382 .lighting(&lighting)
383 .plot_title(
384 Text::from("Mathematical Surfaces Comparison")
385 .font("Arial")
386 .size(20),
387 )
388 .build()
389 .plot();
390}Trait Implementations§
Auto Trait Implementations§
impl Freeze for Mesh3D
impl !RefUnwindSafe for Mesh3D
impl !Send for Mesh3D
impl !Sync for Mesh3D
impl Unpin for Mesh3D
impl !UnwindSafe for Mesh3D
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more