1use crate::{Quaternion, Vector3, SCALE, ZPARITY};
15use cgmath::{Deg, Euler};
16use serde::{Deserialize, Serialize};
17
18#[derive(Serialize, Deserialize, Debug, Clone)]
19pub enum ColorMapType {
20 Viridis,
21 Magma,
22 Inferno,
23 Plasma,
24}
25
26#[derive(Serialize, Deserialize, Debug, Clone)]
28pub struct ViewerSettings {
29 pub window_width: u32,
30 pub window_height: u32,
31 pub vsync: bool,
32 pub gpu_idx: i32,
33 pub slice_pos_x: f32,
34 pub slice_pos_y: f32,
35 pub slice_pos_z: f32,
36 pub slice_width: f32,
37 pub slice_height: f32,
38 pub slice_pixel_size: f32,
39 pub camera_pos_x: f32,
40 pub camera_pos_y: f32,
41 pub camera_pos_z: f32,
42 pub camera_near_clip: f32,
43 pub camera_far_clip: f32,
44 pub sound_speed: f32,
45 pub slice_rot_x: f32,
46 pub slice_rot_y: f32,
47 pub slice_rot_z: f32,
48 pub slice_color_scale: f32,
49 pub slice_alpha: f32,
50 pub color_map_type: ColorMapType,
51 pub show_radiation_pressure: bool,
52 pub camera_rot_x: f32,
53 pub camera_rot_y: f32,
54 pub camera_rot_z: f32,
55 pub camera_fov: f32,
56 pub font_size: f32,
57 pub background: [f32; 4],
58 pub show_mod_plot: bool,
59 pub show_mod_plot_raw: bool,
60 pub mod_enable: bool,
61 pub mod_auto_play: bool,
62 pub stm_auto_play: bool,
63 pub image_save_path: String,
64 pub port: u16,
65 pub camera_move_speed: f32,
66}
67
68impl ViewerSettings {
69 pub fn new() -> ViewerSettings {
70 Self::default()
71 }
72
73 pub(crate) fn slice_pos(&self) -> Vector3 {
74 Vector3::new(self.slice_pos_x, self.slice_pos_y, self.slice_pos_z)
75 }
76
77 pub(crate) fn slice_rotation(&self) -> Quaternion {
78 Quaternion::from(Euler {
79 x: Deg(self.slice_rot_x),
80 y: Deg(self.slice_rot_y),
81 z: Deg(self.slice_rot_z),
82 })
83 }
84
85 pub(crate) fn set_camera_pos(&mut self, v: Vector3) {
86 self.camera_pos_x = v.x;
87 self.camera_pos_y = v.y;
88 self.camera_pos_z = v.z;
89 }
90
91 pub(crate) fn set_camera_rot(&mut self, rot: Quaternion) {
92 let euler = Euler::from(rot);
93 self.camera_rot_x = Deg::from(euler.x).0;
94 self.camera_rot_y = Deg::from(euler.y).0;
95 self.camera_rot_z = Deg::from(euler.z).0;
96 }
97}
98
99impl Default for ViewerSettings {
100 fn default() -> Self {
101 ViewerSettings {
102 window_width: 800,
103 window_height: 600,
104 vsync: true,
105 gpu_idx: 0,
106 slice_pos_x: 86.6252 * SCALE,
107 slice_pos_y: 66.7133 * SCALE,
108 slice_pos_z: 150.0 * SCALE * ZPARITY,
109 slice_width: 300.0 * SCALE,
110 slice_height: 300.0 * SCALE,
111 slice_pixel_size: 1.0 * SCALE,
112 camera_pos_x: 86.6252 * SCALE,
113 camera_pos_y: -533.2867 * SCALE,
114 camera_pos_z: 150.0 * SCALE * ZPARITY,
115 camera_near_clip: 0.1 * SCALE,
116 camera_far_clip: 1000. * SCALE,
117 sound_speed: 340.0e3 * SCALE,
118 slice_rot_x: 90.0 * ZPARITY,
119 slice_rot_y: 0.,
120 slice_rot_z: 0.,
121 slice_color_scale: 2.,
122 slice_alpha: 1.,
123 color_map_type: ColorMapType::Inferno,
124 show_radiation_pressure: false,
125 camera_rot_x: 90.0 * ZPARITY,
126 camera_rot_y: 0.,
127 camera_rot_z: 0.,
128 camera_fov: 45.,
129 font_size: 16.,
130 background: [0.3, 0.3, 0.3, 1.],
131 show_mod_plot: false,
132 show_mod_plot_raw: false,
133 mod_enable: false,
134 mod_auto_play: false,
135 stm_auto_play: false,
136 image_save_path: "image.png".to_string(),
137 port: 8080,
138 camera_move_speed: 10. * SCALE,
139 }
140 }
141}