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.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("Wavy Surface with Custom Lighting")
.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>() -> Mesh3DBuilder<'f1, 'f2, 'f3, 'f4, 'f5, 'f6, 'f7, 'f8, 'f9, 'f10, 'f11, 'f12>
pub fn builder<'f1, 'f2, 'f3, 'f4, 'f5, 'f6, 'f7, 'f8, 'f9, 'f10, 'f11, 'f12>() -> Mesh3DBuilder<'f1, 'f2, 'f3, 'f4, 'f5, 'f6, 'f7, 'f8, 'f9, 'f10, 'f11, 'f12>
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(
109 &ColorBar::new()
110 .x(0.85) // Move color bar very close to the plot
111 .title("Intensity"),
112 )
113 .opacity(0.95)
114 .plot_title(
115 Text::from("Mesh3D with Intensity Coloring")
116 .font("Arial")
117 .size(20),
118 )
119 .build()
120 .plot();
121}
122
123fn example_with_lighting() {
124 // Create a simple wavy surface mesh without explicit indices
125 // The mesh will be auto-triangulated
126 let mut x = Vec::new();
127 let mut y = Vec::new();
128 let mut z = Vec::new();
129
130 let n = 20;
131 for i in 0..n {
132 for j in 0..n {
133 let xi = (i as f64 / (n - 1) as f64) * 2.0 - 1.0;
134 let yj = (j as f64 / (n - 1) as f64) * 2.0 - 1.0;
135 x.push(xi);
136 y.push(yj);
137 // Create a wavy surface
138 z.push(0.3 * ((xi * 3.0).sin() + (yj * 3.0).cos()));
139 }
140 }
141
142 let dataset = DataFrame::new(vec![
143 Column::new("x".into(), x),
144 Column::new("y".into(), y),
145 Column::new("z".into(), z),
146 ])
147 .unwrap();
148
149 Mesh3D::builder()
150 .data(&dataset)
151 .x("x")
152 .y("y")
153 .z("z")
154 .color(Rgb(200, 200, 255))
155 .lighting(
156 &Lighting::new()
157 .ambient(0.5)
158 .diffuse(0.8)
159 .specular(0.5)
160 .roughness(0.2)
161 .fresnel(0.2),
162 )
163 .light_position((1, 1, 2))
164 .opacity(1.0)
165 .flat_shading(false)
166 .contour(true)
167 .plot_title(
168 Text::from("Wavy Surface with Custom Lighting")
169 .font("Arial")
170 .size(22),
171 )
172 .build()
173 .plot();
174}Trait Implementations§
Source§impl PlotHelper for Mesh3D
impl PlotHelper for Mesh3D
fn get_layout(&self) -> &LayoutPlotly
fn get_traces(&self) -> &Vec<Box<dyn Trace + 'static>>
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