common update
This commit is contained in:
parent
c30f183a38
commit
1c1f2925cf
12
src/data.rs
12
src/data.rs
@ -17,7 +17,7 @@ pub enum DataError {
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
pub enum CoorType {
|
||||
pub enum CoordType {
|
||||
Polar,
|
||||
LatLon,
|
||||
}
|
||||
@ -33,7 +33,7 @@ where
|
||||
pub dim1: Array1<X>,
|
||||
pub dim2: Array1<Y>,
|
||||
pub data: ArrayBase<Raw, Ix2>,
|
||||
pub coord_type: CoorType,
|
||||
pub coord_type: CoordType,
|
||||
}
|
||||
|
||||
struct RadarData3d<T, X = f64, Y = f64, Z = f64>
|
||||
@ -74,8 +74,8 @@ where
|
||||
let width_rate = width_rate.min(1.0);
|
||||
let height_rate = height_rate.min(1.0);
|
||||
match self.coord_type {
|
||||
CoorType::Polar => Err(DataError::FormatError),
|
||||
CoorType::LatLon => {
|
||||
CoordType::Polar => Err(DataError::FormatError),
|
||||
CoordType::LatLon => {
|
||||
let width_filtered: ArrayBase<ndarray::OwnedRepr<T>, Ix2> =
|
||||
Self::_resample(&self.data, width_rate, filter_len);
|
||||
|
||||
@ -319,7 +319,7 @@ where
|
||||
dim1: dim1,
|
||||
dim2: dim2,
|
||||
data: value,
|
||||
coord_type: CoorType::LatLon,
|
||||
coord_type: CoordType::LatLon,
|
||||
})
|
||||
}
|
||||
}
|
||||
@ -330,7 +330,7 @@ impl<T: Num + Clone> RadarData2d<T, OwnedRepr<T>> {
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Radar2d<T: Num + Clone>(RadarData2d<T, OwnedRepr<T>>);
|
||||
pub struct Radar2d<T: Num + Clone>(pub RadarData2d<T, OwnedRepr<T>>);
|
||||
|
||||
impl<T: Num + Clone> Radar2d<T> {
|
||||
pub fn load(
|
||||
|
||||
106
src/main.rs
106
src/main.rs
@ -1,20 +1,21 @@
|
||||
use geo_types::{MultiPolygon, Polygon};
|
||||
use gtk::builders::DrawingAreaBuilder;
|
||||
use gtk::gdk::Display;
|
||||
use gtk::{
|
||||
gio, glib, style_context_add_provider_for_display, Application, ApplicationWindow, CssProvider,
|
||||
StyleContext,
|
||||
};
|
||||
use gtk::{prelude::*, DrawingArea};
|
||||
use npyz::npz::{self, NpzArchive};
|
||||
use painter::wgs84::*;
|
||||
use painter::Painter;
|
||||
// use plotters::prelude::DrawingArea;
|
||||
use window::Window;
|
||||
// mod backend;
|
||||
mod data;
|
||||
// mod painter;
|
||||
mod painter;
|
||||
// mod trees;
|
||||
mod window;
|
||||
|
||||
use data::{Npz,Radar2d, levels};
|
||||
use data::{CoordType, Npz, Radar2d};
|
||||
|
||||
const APP_ID: &str = "org.gtk_rs.HelloWorld2";
|
||||
|
||||
@ -28,16 +29,6 @@ fn main() -> glib::ExitCode {
|
||||
// Connect to "activate" signal of `app`
|
||||
app.connect_activate(build_ui);
|
||||
|
||||
let path = "/home/ruomu/Desktop/test.npz";
|
||||
|
||||
let data = Radar2d::<i8>::load(path, Npz).unwrap();
|
||||
|
||||
let result = levels(data, 3);
|
||||
|
||||
for i in result.iter(){
|
||||
println!("{:?}", i.0.depth());
|
||||
}
|
||||
|
||||
// Run the application
|
||||
app.run()
|
||||
}
|
||||
@ -49,88 +40,17 @@ fn build_ui(app: &Application) {
|
||||
|
||||
let drawing_area = DrawingArea::new();
|
||||
|
||||
// drawing_area.set_draw_func(|a, b, c, d| {
|
||||
// let root = CairoBackend::new(b, (500, 500))
|
||||
// .expect("fuck")
|
||||
// .into_drawing_area();
|
||||
let path = "/home/ruomu/Desktop/test.npz";
|
||||
|
||||
// root.fill(&WHITE);
|
||||
let data = Radar2d::<i8>::load(path, Npz).unwrap();
|
||||
|
||||
// use trees::get;
|
||||
drawing_area.set_draw_func(move |a, b, c, d| {
|
||||
let projection = Mercator::new();
|
||||
let coord = LatLonCoord::new(None, None, ((0, c), (0, d)), projection);
|
||||
let painter: Painter<'_, f64, LatLonCoord<Mercator>> = Painter::new(b, coord, c as u32, c as u32);
|
||||
painter.draw_radar_2d(&data.0);
|
||||
|
||||
// let mut npz_file = NpzArchive::open("/Users/ruomu/test.npz").unwrap();
|
||||
|
||||
// // let value = npz_file.by_name("value").unwrap().unwrap();
|
||||
// let lon = npz_file.by_name("lon").unwrap().unwrap();
|
||||
// // let lat = npz_file.by_name("lat").unwrap().unwrap();
|
||||
|
||||
// let mut polygons: Vec<(shapefile::Polygon, _)> =
|
||||
// shapefile::read_as::<_, shapefile::Polygon, shapefile::dbase::Record>(
|
||||
// "/Users/ruomu/china/省界_region.shp",
|
||||
// )
|
||||
// .unwrap();
|
||||
|
||||
// let (polygon, polygon_record) = polygons.first_mut().unwrap();
|
||||
|
||||
// let proj = Mercator::new().change_min_latitude(-80f64);
|
||||
|
||||
// let mut chart = ChartBuilder::on(&root)
|
||||
// .build_geo_coord(
|
||||
// Some(std::ops::Range {
|
||||
// start: 119.0,
|
||||
// end: 121.0,
|
||||
// }),
|
||||
// Some(std::ops::Range {
|
||||
// start: 29.0,
|
||||
// end: 30.0,
|
||||
// }),
|
||||
// proj,
|
||||
// )
|
||||
// .unwrap();
|
||||
|
||||
// // chart.draw_mesh_lines(
|
||||
// // (10, 5),
|
||||
// // (true, true),
|
||||
// // &ShapeStyle {
|
||||
// // color: RGBAColor(0, 0, 0, 1f64),
|
||||
// // filled: false,
|
||||
// // stroke_width: 1,
|
||||
// // },
|
||||
// // );
|
||||
|
||||
// let ring = polygon.ring(0).unwrap();
|
||||
|
||||
// chart.draw_series(
|
||||
// lon.into_vec::<f64>().unwrap().into_iter().map(|lon| {
|
||||
// Rectangle::new([(lon, 29.1), (lon + 0.001, 29.1 + 0.001)], BLACK.filled())
|
||||
// }),
|
||||
// );
|
||||
|
||||
// // chart.draw_series(lon.into_vec::<f32>().unwrap().into_iter().map(|lon| {
|
||||
// // lat.into_vec::<f32>().unwrap().into_iter().map(|lat| {
|
||||
// // Rectangle::new(
|
||||
// // [
|
||||
// // (lon as f64, lat as f64),
|
||||
// // (lon as f64 + 0.001, lat as f64 + 0.001),
|
||||
// // ],
|
||||
// // BLACK.filled(),
|
||||
// // )
|
||||
// // })
|
||||
// // }));
|
||||
|
||||
// for (polygon, _) in polygons.into_iter() {
|
||||
// chart
|
||||
// .draw_series(
|
||||
// AreaSeries::new(
|
||||
// polygon.ring(0).unwrap().points().iter().map(|x| (x.x, x.y)),
|
||||
// 0.0,
|
||||
// &RED.mix(0.2),
|
||||
// )
|
||||
// .border_style(&RED),
|
||||
// )
|
||||
// .unwrap();
|
||||
// }
|
||||
// });
|
||||
});
|
||||
|
||||
// window.set_child(Some(&drawing_area));
|
||||
window.set_default_width(1000);
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
use num_traits::Num;
|
||||
mod wgs84;
|
||||
pub mod wgs84;
|
||||
|
||||
pub type ScreenCoord = (i32, i32);
|
||||
|
||||
pub(super) trait Coord<T: Num> {
|
||||
pub trait Coord<T: Num> {
|
||||
fn map(&self, axis_1: T, axis_2: T) -> ScreenCoord;
|
||||
}
|
||||
|
||||
@ -197,8 +197,8 @@ impl ProjectionS for Mercator {
|
||||
});
|
||||
|
||||
let lat_range = Range {
|
||||
0: lat_range.start.max(self.min_latitude),
|
||||
1: lat_range.end.min(self.max_latitude),
|
||||
0: lat_range.0.max(self.min_latitude),
|
||||
1: lat_range.0.min(self.max_latitude),
|
||||
};
|
||||
(lon_range, lat_range)
|
||||
}
|
||||
|
||||
@ -1,2 +1,5 @@
|
||||
mod coords;
|
||||
mod painter;
|
||||
|
||||
pub use painter::Painter;
|
||||
pub use coords::wgs84;
|
||||
@ -1,25 +1,36 @@
|
||||
use std::marker::PhantomData;
|
||||
|
||||
use crate::data::RadarData2d;
|
||||
|
||||
use super::coords::{Coord, ScreenCoord};
|
||||
use gtk::{cairo::*, gdk::RGBA};
|
||||
pub struct Painter<T: Coord> {
|
||||
use num_traits::Num;
|
||||
pub struct Painter<'a, T: Num, C: Coord<T>> {
|
||||
width: u32,
|
||||
height: u32,
|
||||
context: Context,
|
||||
coord: T,
|
||||
context: &'a Context,
|
||||
coord: C,
|
||||
marker: PhantomData<T>,
|
||||
}
|
||||
|
||||
impl<T: Coord> Painter<T> {
|
||||
pub fn new(context: Context, coord: T, width: u32, height: u32) -> Self {
|
||||
impl<'a, T: Num + Clone, C: Coord<T>> Painter<'a, T, C> {
|
||||
pub fn new(context: &'a Context, coord: C, width: u32, height: u32) -> Self {
|
||||
Self {
|
||||
context,
|
||||
coord,
|
||||
width,
|
||||
height,
|
||||
marker: PhantomData,
|
||||
}
|
||||
}
|
||||
|
||||
fn set_color(&self, color: &RGBA) {
|
||||
self.context
|
||||
.set_source_rgba(color.red(), color.green(), color.blue(), color.alpha());
|
||||
self.context.set_source_rgba(
|
||||
color.red() as f64,
|
||||
color.green() as f64,
|
||||
color.blue() as f64,
|
||||
color.alpha() as f64,
|
||||
);
|
||||
}
|
||||
|
||||
fn draw_pixel(&self, point: ScreenCoord) {}
|
||||
@ -27,11 +38,13 @@ impl<T: Coord> Painter<T> {
|
||||
fn draw_rect(&self, point: ScreenCoord, width: f64, height: f64) {}
|
||||
|
||||
fn draw_line(&self, start: ScreenCoord, end: ScreenCoord) {}
|
||||
}
|
||||
|
||||
impl<'a, C: Coord<f64>> Painter<'a, f64, C> {
|
||||
pub fn draw_radar_2d<T: Num + Clone, D>(&self, data: &RadarData2d<T, D>)
|
||||
where
|
||||
D: ndarray::Data<Elem = T> + Clone + ndarray::RawDataClone,
|
||||
{
|
||||
|
||||
pub fn draw_2d_data(&self, data: &RadarArray2) {
|
||||
data.dim1.iter().zip(data.dim2.iter()).for_each(|(x, y)| {
|
||||
let (x, y) = self.coord.map(*x, *y);
|
||||
self.draw_pixel((x, y));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user