diff --git a/down.py b/down.py
deleted file mode 100644
index 648049e..0000000
--- a/down.py
+++ /dev/null
@@ -1,197 +0,0 @@
-def _downsample_2d(src, mask, use_mask, method, fill_value, mode_rank, out):
- src_w = src.shape[-1]
- src_h = src.shape[-2]
- out_w = out.shape[-1]
- out_h = out.shape[-2]
-
- if src_w == out_w and src_h == out_h:
- return src
-
- if out_w > src_w or out_h > src_h:
- raise ValueError("invalid target size")
-
- scale_x = src_w / out_w
- scale_y = src_h / out_h
-
- if method == DS_FIRST or method == DS_LAST:
- for out_y in range(out_h):
- src_yf0 = scale_y * out_y
- src_yf1 = src_yf0 + scale_y
- src_y0 = int(src_yf0)
- src_y1 = int(src_yf1)
- if src_y1 == src_yf1 and src_y1 > src_y0:
- src_y1 -= 1
- for out_x in range(out_w):
- src_xf0 = scale_x * out_x
- src_xf1 = src_xf0 + scale_x
- src_x0 = int(src_xf0)
- src_x1 = int(src_xf1)
- if src_x1 == src_xf1 and src_x1 > src_x0:
- src_x1 -= 1
- done = False
- value = fill_value
- for src_y in range(src_y0, src_y1 + 1):
- for src_x in range(src_x0, src_x1 + 1):
- v = src[src_y, src_x]
- if np.isfinite(v) and not (use_mask and mask[src_y, src_x]):
- value = v
- if method == DS_FIRST:
- done = True
- break
- if done:
- break
- out[out_y, out_x] = value
-
- elif method == DS_MODE:
- max_value_count = int(scale_x + 1) * int(scale_y + 1)
- values = np.zeros((max_value_count,), dtype=src.dtype)
- frequencies = np.zeros((max_value_count,), dtype=np.uint32)
- for out_y in range(out_h):
- src_yf0 = scale_y * out_y
- src_yf1 = src_yf0 + scale_y
- src_y0 = int(src_yf0)
- src_y1 = int(src_yf1)
- wy0 = 1.0 - (src_yf0 - src_y0)
- wy1 = src_yf1 - src_y1
- if wy1 < _EPS:
- wy1 = 1.0
- if src_y1 > src_y0:
- src_y1 -= 1
- for out_x in range(out_w):
- src_xf0 = scale_x * out_x
- src_xf1 = src_xf0 + scale_x
- src_x0 = int(src_xf0)
- src_x1 = int(src_xf1)
- wx0 = 1.0 - (src_xf0 - src_x0)
- wx1 = src_xf1 - src_x1
- if wx1 < _EPS:
- wx1 = 1.0
- if src_x1 > src_x0:
- src_x1 -= 1
- value_count = 0
- for src_y in range(src_y0, src_y1 + 1):
- wy = wy0 if (src_y == src_y0) else wy1 if (src_y == src_y1) else 1.0
- for src_x in range(src_x0, src_x1 + 1):
- wx = wx0 if (src_x == src_x0) else wx1 if (src_x == src_x1) else 1.0
- v = src[src_y, src_x]
- if np.isfinite(v) and not (use_mask and mask[src_y, src_x]):
- w = wx * wy
- found = False
- for i in range(value_count):
- if v == values[i]:
- frequencies[i] += w
- found = True
- break
- if not found:
- values[value_count] = v
- frequencies[value_count] = w
- value_count += 1
- w_max = -1.
- value = fill_value
- if mode_rank == 1:
- for i in range(value_count):
- w = frequencies[i]
- if w > w_max:
- w_max = w
- value = values[i]
- elif mode_rank <= max_value_count:
- max_frequencies = np.full(mode_rank, -1.0, dtype=np.float64)
- indices = np.zeros(mode_rank, dtype=np.int64)
- for i in range(value_count):
- w = frequencies[i]
- for j in range(mode_rank):
- if w > max_frequencies[j]:
- max_frequencies[j] = w
- indices[j] = i
- break
- value = values[indices[mode_rank - 1]]
-
- out[out_y, out_x] = value
-
- elif method == DS_MEAN:
- for out_y in range(out_h):
- src_yf0 = scale_y * out_y
- src_yf1 = src_yf0 + scale_y
- src_y0 = int(src_yf0)
- src_y1 = int(src_yf1)
- wy0 = 1.0 - (src_yf0 - src_y0)
- wy1 = src_yf1 - src_y1
- if wy1 < _EPS:
- wy1 = 1.0
- if src_y1 > src_y0:
- src_y1 -= 1
- for out_x in range(out_w):
- src_xf0 = scale_x * out_x
- src_xf1 = src_xf0 + scale_x
- src_x0 = int(src_xf0)
- src_x1 = int(src_xf1)
- wx0 = 1.0 - (src_xf0 - src_x0)
- wx1 = src_xf1 - src_x1
- if wx1 < _EPS:
- wx1 = 1.0
- if src_x1 > src_x0:
- src_x1 -= 1
- v_sum = 0.0
- w_sum = 0.0
- for src_y in range(src_y0, src_y1 + 1):
- wy = wy0 if (src_y == src_y0) else wy1 if (src_y == src_y1) else 1.0
- for src_x in range(src_x0, src_x1 + 1):
- wx = wx0 if (src_x == src_x0) else wx1 if (src_x == src_x1) else 1.0
- v = src[src_y, src_x]
- if np.isfinite(v) and not (use_mask and mask[src_y, src_x]):
- w = wx * wy
- v_sum += w * v
- w_sum += w
- if w_sum < _EPS:
- out[out_y, out_x] = fill_value
- else:
- out[out_y, out_x] = v_sum / w_sum
-
- elif method == DS_VAR or method == DS_STD:
- for out_y in range(out_h):
- src_yf0 = scale_y * out_y
- src_yf1 = src_yf0 + scale_y
- src_y0 = int(src_yf0)
- src_y1 = int(src_yf1)
- wy0 = 1.0 - (src_yf0 - src_y0)
- wy1 = src_yf1 - src_y1
- if wy1 < _EPS:
- wy1 = 1.0
- if src_y1 > src_y0:
- src_y1 -= 1
- for out_x in range(out_w):
- src_xf0 = scale_x * out_x
- src_xf1 = src_xf0 + scale_x
- src_x0 = int(src_xf0)
- src_x1 = int(src_xf1)
- wx0 = 1.0 - (src_xf0 - src_x0)
- wx1 = src_xf1 - src_x1
- if wx1 < _EPS:
- wx1 = 1.0
- if src_x1 > src_x0:
- src_x1 -= 1
- v_sum = 0.0
- w_sum = 0.0
- wv_sum = 0.0
- wvv_sum = 0.0
- for src_y in range(src_y0, src_y1 + 1):
- wy = wy0 if (src_y == src_y0) else wy1 if (src_y == src_y1) else 1.0
- for src_x in range(src_x0, src_x1 + 1):
- wx = wx0 if (src_x == src_x0) else wx1 if (src_x == src_x1) else 1.0
- v = src[src_y, src_x]
- if np.isfinite(v) and not (use_mask and mask[src_y, src_x]):
- w = wx * wy
- v_sum += v
- w_sum += w
- wv_sum += w * v
- wvv_sum += w * v * v
- if w_sum < _EPS:
- out[out_y, out_x] = fill_value
- else:
- out[out_y, out_x] = (wvv_sum * w_sum - wv_sum * wv_sum) / w_sum / w_sum
- if method == DS_STD:
- out = np.sqrt(out).astype(out.dtype)
- else:
- raise ValueError('invalid upsampling method')
-
- return out
\ No newline at end of file
diff --git a/shp/ne_110m_admin_0_countries.README.html b/shp/ne_110m_admin_0_countries.README.html
new file mode 100644
index 0000000..87125d2
--- /dev/null
+++ b/shp/ne_110m_admin_0_countries.README.html
@@ -0,0 +1,547 @@
+
+
+
+
+
+
+Natural Earth » Blog Archive » Admin 0 – Countries - Free vector and raster map data at 1:10m, 1:50m, and 1:110m scales
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Admin 0 – Countries
+
+
+
+
+
+
About
+
Countries distinguish between metropolitan (homeland) and independent and semi-independent portions of sovereign states. If you want to see the dependent overseas regions broken out (like in ISO codes, see France for example), use map units instead.
+
Each country is coded with a world region that roughly follows the United Nations setup .
+
Includes some thematic data from the United Nations, U.S. Central Intelligence Agency, and elsewhere.
+
Disclaimer
+
Natural Earth Vector draws boundaries of countries according to defacto status. We show who actually controls the situation on the ground. Please feel free to mashup our disputed areas (link) theme to match your particular political outlook.
+
Known Problems
+
None.
+
Version History
+
+
+
The master changelog is available on Github »
+
+
+
+
+
+ This entry was posted
+ on Monday, September 21st, 2009 at 10:21 am and is filed under 110m-cultural-vectors .
+ You can follow any responses to this entry through the RSS 2.0 feed.
+
+ Both comments and pings are currently closed.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/shp/ne_110m_admin_0_countries.VERSION.txt b/shp/ne_110m_admin_0_countries.VERSION.txt
new file mode 100644
index 0000000..d7445e2
--- /dev/null
+++ b/shp/ne_110m_admin_0_countries.VERSION.txt
@@ -0,0 +1 @@
+5.1.1
diff --git a/shp/ne_110m_admin_0_countries.cpg b/shp/ne_110m_admin_0_countries.cpg
new file mode 100644
index 0000000..3ad133c
--- /dev/null
+++ b/shp/ne_110m_admin_0_countries.cpg
@@ -0,0 +1 @@
+UTF-8
\ No newline at end of file
diff --git a/shp/ne_110m_admin_0_countries.dbf b/shp/ne_110m_admin_0_countries.dbf
new file mode 100755
index 0000000..e0acd06
Binary files /dev/null and b/shp/ne_110m_admin_0_countries.dbf differ
diff --git a/shp/ne_110m_admin_0_countries.prj b/shp/ne_110m_admin_0_countries.prj
new file mode 100755
index 0000000..b13a717
--- /dev/null
+++ b/shp/ne_110m_admin_0_countries.prj
@@ -0,0 +1 @@
+GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137.0,298.257223563]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.017453292519943295]]
\ No newline at end of file
diff --git a/shp/ne_110m_admin_0_countries.shp b/shp/ne_110m_admin_0_countries.shp
new file mode 100755
index 0000000..9318e45
Binary files /dev/null and b/shp/ne_110m_admin_0_countries.shp differ
diff --git a/shp/ne_110m_admin_0_countries.shx b/shp/ne_110m_admin_0_countries.shx
new file mode 100755
index 0000000..c3728e0
Binary files /dev/null and b/shp/ne_110m_admin_0_countries.shx differ
diff --git a/src/components/render_panel.rs b/src/components/render_panel.rs
index cc76392..2be6d6b 100644
--- a/src/components/render_panel.rs
+++ b/src/components/render_panel.rs
@@ -18,8 +18,6 @@ impl SimpleComponent for RenderPanelModel {
#[root]
Monitor::new(
Render::new(
- BackgroundWidget::new(BackgroundConfig{ show_lat_lines: true, show_lon_lines: true, ..Default::default() }),
- ForegroundWidget::new(ForegroundConfig::default()),
Some(Mercator::new().into())
)
),
diff --git a/src/main.rs b/src/main.rs
index 58e95e1..52110c8 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -53,40 +53,4 @@ fn main() {
// app.run()
let relm = relm4::RelmApp::new(APP_ID);
relm.run::
(AppMode::Edit);
-}
-
-fn build_ui(app: &Application) {
- // Create a window and set the title
- let window = ApplicationWindow::builder()
- .application(app)
- .title("My GTK App")
- .build();
-
- let mut background_config = BackgroundConfig::new()
- .change_painter(Paint::color(Color::white()))
- .change_show_lat_lines(true)
- .change_show_lon_lines(true);
- let mut foreground_config = ForegroundConfig::new();
-
- let background_widget = BackgroundWidget::new(background_config);
- let foreground_widget = ForegroundWidget::new(foreground_config);
- let render = Render::new(background_widget, foreground_widget,None);
-
- let path = "/Users/ruomu/projects/cinrad_g/test2.npz";
- let data = Radar2d::::load(path, Npz).unwrap();
- let projection = Mercator::new();
-
- let mut mapper: Mapper = projection.into();
- mapper.set_lat_range(29.960..30.764);
- mapper.set_lon_range(120.038..120.965);
-
- render.set_mapper(mapper);
- let monitor = Monitor::new(render);
- monitor.load_data_2d(data).unwrap();
-
- window.set_child(Some(&monitor));
- window.set_default_width(1000);
- window.set_default_height(800);
-
- window.present();
-}
+}
\ No newline at end of file
diff --git a/src/monitor/mod.rs b/src/monitor/mod.rs
index ef59eb5..aec304e 100644
--- a/src/monitor/mod.rs
+++ b/src/monitor/mod.rs
@@ -21,11 +21,10 @@ impl Monitor {
let this: Self = glib::Object::new();
let pointer_location_detecture = gtk::EventControllerMotion::new();
pointer_location_detecture.connect_motion(
- clone!(@weak this as s => move |_context, x, y| {
- s.imp().renderer.borrow_mut().change_pointer(x as f32, y as f32);
- let c = s.imp().renderer.borrow();
- let cc = c.imp().config.borrow();
- println!("pointer location: {},{}", cc.pointer_lon_lat.0, cc.pointer_lon_lat.1);
+ clone!(@weak this as s, @weak render as r => move |_context, x, y| {
+ r.update_status(|s| {
+ s.pointer_location = (x as f32, y as f32);
+ });
}
),
);
@@ -33,21 +32,13 @@ impl Monitor {
scale_detecture.connect_scroll(clone!(
@weak this as s, @weak render as r => @default-panic,move |_context, _x, y| {
let renderer = s.imp().renderer.borrow();
- let p = r.imp().config.borrow().pointer_lon_lat;
- let (px,py) = r.imp().mapper.borrow().map(p).unwrap();
-
let mut scale = 1.0;
-
- renderer.change_cfg(|cfg| {
- let current_scale = cfg.scale;
- let s = (current_scale - y as f32 / 10.0).max(1.0).min(5.0);
- cfg.scale = s;
+ r.update_status(|status|{
+ let current_scale = status.scale;
+ let s = (current_scale - y as f32 / 5.0).max(1.0).min(5.0);
+ status.scale = s;
scale = s;
});
- r.set_translate((
- px as f32 * (scale - 1.0),
- (1.0-py) as f32 * (scale - 1.0)
- ));
r.queue_render();
Inhibit(false)
}
@@ -57,15 +48,15 @@ impl Monitor {
drag_detecture.connect_drag_update(clone!(
@weak render as r => move |this, _, _| {
let (ox, oy) = this.offset().unwrap_or((0.0,0.0));
- r.change_cfg(|cfg|{
- cfg.updated_translate = ( - ox as f32, -oy as f32);
- } );
+ r.update_status(|s| {
+ s.updated_translate = ( - ox as f32, -oy as f32);
+ });
r.queue_render();
}));
drag_detecture.connect_drag_end(clone!(
@weak render as r => move |this,_,_|{
let t = r.imp().translate();
- r.change_cfg(|cfg| {
+ r.update_status(|cfg| {
cfg.translate = t ;
cfg.updated_translate = (0.0,0.0);
})
diff --git a/src/render/background/mod.rs b/src/render/background/mod.rs
index 4eb22cd..1124169 100644
--- a/src/render/background/mod.rs
+++ b/src/render/background/mod.rs
@@ -23,7 +23,7 @@ impl BackgroundWidget {
let this: Self = glib::Object::new();
let imp = this.imp();
let polygons = shapefile::read_as::<_, shapefile::Polygon, shapefile::dbase::Record>(
- "/Users/tsuki/Downloads/ne_110m_admin_0_countries/ne_110m_admin_0_countries.shp",
+ "shp/ne_110m_admin_0_countries.shp",
)
.unwrap();
@@ -153,30 +153,15 @@ impl BackgroundWidget {
canvas: &mut Canvas,
scale: f32,
dpi: i32,
+ width: f32,
+ hdight: f32,
translate: (f32, f32),
mapper: Ref<'_, Mapper>,
bound: (Range, Range),
) {
- let canvas_width = canvas.width();
- let canvas_height = canvas.height();
let config = self.imp().config.borrow();
- self.mesh_lines(
- canvas,
- scale,
- translate,
- canvas_width,
- canvas_height,
- &mapper,
- bound,
- );
- self.shp(
- mapper,
- canvas,
- translate,
- scale,
- canvas_width,
- canvas_height,
- );
+ self.mesh_lines(canvas, scale, translate, width, hdight, &mapper, bound);
+ self.shp(mapper, canvas, translate, scale, width, hdight);
}
fn shp(
diff --git a/src/render/exterior/mod.rs b/src/render/exterior/mod.rs
index ce2f0b9..84a81c6 100644
--- a/src/render/exterior/mod.rs
+++ b/src/render/exterior/mod.rs
@@ -5,6 +5,8 @@ use geo_types::{line_string, LineString, Point};
use glib::subclass::types::ObjectSubclassIsExt;
use std::cell::Ref;
+use super::imp::{RenderStatus, RenderConfig};
+
glib::wrapper! {
pub struct ExteriorWidget(ObjectSubclass);
}
@@ -21,7 +23,7 @@ impl ExteriorWidget {
this
}
- pub(super) fn draw(&self, canvas: &mut Canvas, mapper: Ref<'_, Mapper>) {
+ pub(super) fn draw(&self, canvas: &mut Canvas, mapper: Ref<'_, Mapper>, status:Ref<'_, RenderStatus>, _c:Ref<'_, RenderConfig>) {
let imp = self.imp();
let canvas_width = canvas.width();
let canvas_height = canvas.height();
diff --git a/src/render/imp.rs b/src/render/imp.rs
index 0e0f91c..34380da 100644
--- a/src/render/imp.rs
+++ b/src/render/imp.rs
@@ -1,5 +1,6 @@
use super::background::BackgroundWidget;
use super::exterior::ExteriorWidget;
+use super::interior::InteriorWidget;
use super::foreground::ForegroundWidget;
use super::WindowCoord;
use crate::coords::proj::Mercator;
@@ -17,9 +18,14 @@ use std::num::NonZeroU32;
pub struct RenderConfig {
pub dim1: Option>,
pub dim2: Option>,
+ pub padding: [f32; 4],
+ // pub pointer_lon_lat: (f64, f64),
+}
+
+#[derive(Debug, Default, Clone)]
+pub struct RenderStatus{
pub scale: f32,
pub pointer_location: WindowCoord,
- pub pointer_lon_lat: (f64, f64),
pub translate: WindowCoord,
pub updated_translate: WindowCoord,
}
@@ -31,10 +37,10 @@ struct Fonts {
}
pub struct Render {
- pub(super) background: RefCell,
- pub(super) foreground: RefCell,
pub(super) exterior: RefCell,
+ pub(super) interior: RefCell,
pub config: RefCell,
+ pub status: RefCell,
pub mapper: RefCell,
pub(super) canvas: RefCell>>,
}
@@ -42,10 +48,10 @@ pub struct Render {
impl Default for Render {
fn default() -> Self {
Self {
- background: RefCell::new(BackgroundWidget::default()),
- foreground: RefCell::new(ForegroundWidget::default()),
exterior: RefCell::new(ExteriorWidget::default()),
+ interior: RefCell::new(InteriorWidget::default()),
config: RefCell::new(RenderConfig::default()),
+ status: RefCell::new(RenderStatus::default()),
mapper: RefCell::new(Mercator::new().into()),
canvas: RefCell::new(None),
}
@@ -65,7 +71,6 @@ impl ObjectImpl for Render {
self.parent_constructed();
let area = self.obj();
area.set_has_stencil_buffer(true);
-
// area.add_tick_callback(|area, _| {
// area.queue_render();
// glib::Continue(true)
@@ -105,9 +110,12 @@ impl GLAreaImpl for Render {
(h as i32 * dpi) as u32,
Color::rgba(0, 0, 0, 255),
);
+
let mapper = self.mapper.borrow();
- let (lon_range, lat_range) = mapper.range.clone();
+ self.interior.borrow().draw(canvas, mapper, self.status.borrow(), configs);
+
+ // let (lon_range, lat_range) = mapper.range.clone();
// {
// let background_widget = self.background.borrow_mut();
// background_widget.set_lat_lines(lat_range.key_points(9));
@@ -116,9 +124,9 @@ impl GLAreaImpl for Render {
// let background_widget = self.background.borrow_mut();
// background_widget.set_lon_lines(lon_range.key_points(20));
// }
- let translate = self.translate();
+ // let translate = self.translate();
- self.exterior.borrow().draw(canvas,self.mapper.borrow());
+ // self.exterior.borrow().draw(canvas,self.mapper.borrow());
// self.foreground
// .borrow()
// .draw(canvas, configs.scale, dpi, self.mapper.borrow());
@@ -171,7 +179,7 @@ impl Render {
}
pub fn translate(&self) -> WindowCoord {
- let cfg = self.config.borrow();
+ let cfg = self.status.borrow();
let (rx, ry) = cfg.translate;
let (ux, uy) = cfg.updated_translate;
diff --git a/src/render/interior/imp.rs b/src/render/interior/imp.rs
new file mode 100644
index 0000000..515a396
--- /dev/null
+++ b/src/render/interior/imp.rs
@@ -0,0 +1,20 @@
+use gtk::glib;
+use gtk::subclass::prelude::*;
+use std::cell::RefCell;
+use crate::render::background::BackgroundWidget;
+use crate::render::foreground::ForegroundWidget;
+
+
+#[derive(Default)]
+pub struct InteriorWidget {
+ pub(super) background: RefCell,
+ pub(super) foreground: RefCell,
+}
+
+#[glib::object_subclass]
+impl ObjectSubclass for InteriorWidget {
+ const NAME: &'static str = "InteriorWidget";
+ type Type = super::InteriorWidget;
+}
+
+impl ObjectImpl for InteriorWidget{}
diff --git a/src/render/interior/mod.rs b/src/render/interior/mod.rs
new file mode 100644
index 0000000..8518a7b
--- /dev/null
+++ b/src/render/interior/mod.rs
@@ -0,0 +1,58 @@
+mod imp;
+use crate::coords::{Mapper, Range};
+use femtovg::{renderer::OpenGl, Canvas, Color, Paint, Path};
+use geo_types::{line_string, LineString, Point};
+use glib::subclass::types::ObjectSubclassIsExt;
+use std::cell::Ref;
+
+use super::imp::{RenderConfig, RenderStatus};
+
+glib::wrapper! {
+ pub struct InteriorWidget(ObjectSubclass);
+}
+
+impl Default for InteriorWidget {
+ fn default() -> Self {
+ Self::new()
+ }
+}
+
+impl InteriorWidget {
+ pub fn new() -> Self {
+ let this: Self = glib::Object::new();
+ this
+ }
+
+ pub(super) fn draw(
+ &self,
+ canvas: &mut Canvas,
+ mapper: Ref<'_, Mapper>,
+ status: Ref<'_, RenderStatus>,
+ _c: Ref<'_, RenderConfig>,
+ ) {
+ let imp = self.imp();
+ let canvas_width = canvas.width();
+ let canvas_height = canvas.height();
+
+ let padding = _c.padding;
+
+ let w = canvas_width - padding[1] - padding[3];
+ let h = canvas_height - padding[0] - padding[2];
+ let scale = status.scale;
+ let dpi = 2;
+
+ let (tx, ty) = status.translate;
+ let range = mapper.range.clone();
+
+ self.imp().background.borrow().draw(
+ canvas,
+ scale,
+ dpi,
+ w,
+ h,
+ (tx + padding[3], ty + padding[0]),
+ mapper,
+ range,
+ );
+ }
+}
diff --git a/src/render/mod.rs b/src/render/mod.rs
index b3c32ba..caa99a3 100644
--- a/src/render/mod.rs
+++ b/src/render/mod.rs
@@ -1,23 +1,21 @@
mod background;
-mod foreground;
mod exterior;
+mod foreground;
mod imp;
+mod interior;
use crate::coords::Mapper;
-use crate::data::{MultiDimensionData, RadarData2d};
+use crate::data::RadarData2d;
use crate::pipeline::ProjPipe;
use crate::pipeline::{Pipeline, ShadePipe};
use std::fmt::Debug;
pub use self::background::{BackgroundConfig, BackgroundWidget};
-use self::exterior::ExteriorWidget;
pub use self::foreground::{ForegroundConfig, ForegroundWidget};
-use self::imp::RenderConfig;
-use crate::data::DownSampleMeth;
+use self::imp::{RenderConfig, RenderStatus};
use adw::prelude::WidgetExt;
use femtovg::Color;
pub use glib::subclass::prelude::*;
-use image::RgbImage;
-use ndarray::{self, s, Array2, Axis, Dimension, Ix2, Zip};
+use ndarray::{self, Array2};
use num_traits::{AsPrimitive, FromPrimitive, Num};
use proj::ProjError;
@@ -30,26 +28,17 @@ glib::wrapper! {
impl Default for Render {
fn default() -> Self {
- Self::new(
- BackgroundWidget::default(),
- ForegroundWidget::default(),
- None,
- )
+ Self::new(None)
}
}
impl Render {
- pub fn new(
- background: BackgroundWidget,
- foreground: ForegroundWidget,
- mapper: Option,
- ) -> Self {
+ pub fn new(mapper: Option) -> Self {
let this: Self = glib::Object::new();
- this.imp().background.replace(background);
- this.imp().foreground.replace(foreground);
{
let mut configs = this.imp().config.borrow_mut();
- configs.scale = 1.0;
+ let mut status = this.imp().status.borrow_mut();
+ status.scale = 1.0;
}
if let Some(mapper) = mapper {
this.set_mapper(mapper);
@@ -65,33 +54,41 @@ impl Render {
f(&mut cfg);
}
- pub fn change_pointer(&mut self, x: f32, y: f32) {
- if let Some(canvas) = self.imp().canvas.borrow().as_ref() {
- let dpi = self.scale_factor();
- let cw = canvas.width();
- let ch = canvas.height();
- let (tx, ty) = self.imp().translate();
- let scale = self.imp().config.borrow().scale;
- let (lon, lat) = self
- .imp()
- .mapper
- .borrow()
- .fore_map((
- (x * dpi as f32 + tx) / cw / scale,
- (1.0 - (y * dpi as f32 + ty) / ch / scale),
- ))
- .unwrap();
- let mut cfg = self.imp().config.borrow_mut();
- cfg.pointer_lon_lat = (lon, lat);
- cfg.pointer_location = (x, y);
- }
+ pub fn update_status(&self, mut f: F)
+ where
+ F: FnMut(&mut RenderStatus),
+ {
+ let mut status = self.imp().status.borrow_mut();
+ f(&mut status);
}
- pub fn set_translate(&self, trans: (f32, f32)) {
- if let Some(c) = self.imp().canvas.borrow().as_ref() {
- self.imp().config.borrow_mut().translate = (c.width() * trans.0, c.height() * trans.1);
- }
- }
+ // pub fn change_pointer(&mut self, x: f32, y: f32) {
+ // if let Some(canvas) = self.imp().canvas.borrow().as_ref() {
+ // let dpi = self.scale_factor();
+ // let cw = canvas.width();
+ // let ch = canvas.height();
+ // let (tx, ty) = self.imp().translate();
+ // let scale = self.imp().config.borrow().scale;
+ // let (lon, lat) = self
+ // .imp()
+ // .mapper
+ // .borrow()
+ // .fore_map((
+ // (x * dpi as f32 + tx) / cw / scale,
+ // (y * dpi as f32 + ty) / ch / scale,
+ // ))
+ // .unwrap();
+ // let mut cfg = self.imp().config.borrow_mut();
+ // cfg.pointer_lon_lat = (lon, lat);
+ // cfg.pointer_location = (x, y);
+ // }
+ // }
+
+ // pub fn set_translate(&self, trans: (f32, f32)) {
+ // if let Some(c) = self.imp().canvas.borrow().as_ref() {
+ // self.imp().config.borrow_mut().translate = (c.width() * trans.0, c.height() * trans.1);
+ // }
+ // }
pub fn set_mapper(&self, mapper: Mapper) {
self.imp().mapper.replace(mapper);
@@ -140,11 +137,8 @@ impl Render {
let pjp = ProjPipe::new(&mapper);
let rrp = ShadePipe::new(levels, colors.into_iter().map(|v| v.into()).collect());
-
let rainbow = pjp.run(&data).unwrap();
- self.imp().foreground.borrow_mut().set_data(rainbow);
let pbow: Array2> = rrp.run(&data).unwrap();
- self.imp().foreground.borrow_mut().set_colors(pbow);
Ok(())
}
}
[…] earlier. It’s the result of a conversion of a polygon shapefile of country boundaries (from Natural Earth, a fantastic, public domain, physical/cultural spatial data source) to a raster data […]
+ + +[…] Le mappe sono scaricate da https://www.naturalearthdata.com […]
+ + +[…] Le mappe sono scaricate da https://www.naturalearthdata.com […]
+ + +