Model trainer: include land mass calculation in click handler
[?]
Jul 8, 2021, 2:18 AM
3AJMKZ7CFKK7S6H3I6LCFRSTGCBNJJGOYFIT2WHQKZRI6CMEHSTQCDependencies
- [2]
ABITXOUUModel trainer: Add provisional colouration - [3]
PG7KSKJLAdd surface distance measurement to mouse click handler - [4]
FYOPJXOXModel trainer: North/South comprise the Z axis in the source data - [5]
ROQCAPZJBegin function for showing the map (for now just opens SDL window) - [6]
ALMG52BOmodel trainer: speed up by waiting 15 seconds between monitor renders - [7]
4IXWCEHMGamma correction - [8]
CWOSQTC4Trust tensorflow's thread safety (it wasn't the cause of an earlier bug) - [9]
KE43WJL7Improve provisional colouration function - [*]
E742MTJAFix segfault (don't pass pointers between functions in different SDL versions), minor refactor - [*]
6AXPZL5PTry to offload tight loop to rust (for now it segfaults) - [*]
5AMZXFS5model trainer: function to generate inputs to pass neural network for rendering equirectangular projection
Change contents
- edit in trainmodel/src/nativehelpers.py at line 17[2.183]
native.landmass_steradians.argtypes = [ctypes.POINTER(ctypes.c_double), ctypes.c_int, ctypes.c_int, ctypes.c_int, ctypes.c_int]native.landmass_steradians.restype = ctypes.c_doublelandmass_steradians = native.landmass_steradians - edit in trainmodel/src/helpers.rs at line 120
const SEA_LEVEL: f64 = 0.1; - edit in trainmodel/src/helpers.rs at line 125
const SEA_LEVEL: f64 = 0.1; - edit in trainmodel/src/helpers.rs at line 151[2.1340][13.1261]
}}}#[no_mangle]pub extern "C" fn landmass_steradians(source: *const f64, width: u32, height: u32, x: u32, y: u32) -> f64 {use std::collections::HashMap;use std::collections::HashSet;use std::collections::VecDeque;use std::f64::consts::PI;let source = unsafe {std::slice::from_raw_parts(source, (width as usize) * (height as usize))};let mut patch = HashSet::new();let mut q = VecDeque::new();q.push_back((x,y));while let Some((x,y)) = q.pop_front() {if source[(y * width + x) as usize] >= SEA_LEVEL {if patch.insert((x,y)) {let y = y as i32;let x = x as i32;for (x, y) in [(x - 1, y - 1), (x, y - 1), (x + 1, y - 1), (x + 1, y), (x + 1, y + 1), (x, y + 1), (x - 1, y + 1), (x - 1, y)].iter() {if *y > 0 && (*y as u32) < height {let np = ((x % width as i32) as u32, *y as u32);q.push_back(np);}}} - edit in trainmodel/src/helpers.rs at line 180[13.1271][13.1271]
};std::mem::drop(q);let mut lines: HashMap<u32, u32> = HashMap::new();for (_,y) in patch.iter() {lines.entry(*y).and_modify(|w| *w += 1).or_insert(1); - edit in trainmodel/src/helpers.rs at line 188[13.1277][13.1277]
std::mem::drop(patch);let dy = PI / (height as f64);let dx = PI * 2. / (width as f64);lines.iter().map(|(y,w)| dy * ((*y as f64) * dy).sin() * (*w as f64) * dx).sum() - replacement in trainmodel/src/drawmap.py at line 24[4.41]→[2.1364:1477](∅→∅),[4.100]→[4.219:262](∅→∅),[2.1477]→[4.219:262](∅→∅),[4.219]→[4.219:262](∅→∅)
outputs = tf.math.multiply(255, colourize_heightmap(tf.reshape(outputs, (512, 1024, outputs.shape[1]))))image = tensor_to_surface(outputs)image = tensor_to_surface(tf.math.multiply(255, colourize_heightmap(tf.reshape(outputs, (512, 1024, outputs.shape[1]))))) - edit in trainmodel/src/drawmap.py at line 35
solid_angle = landmass_steradians(tf.reshape(outputs, (512,1024,1)), event.button.x, event.button.y)print('Clicked land mass: %s square Km | %s square miles' % (solid_angle * 6372.0**2, solid_angle * 3959**2)) - edit in trainmodel/src/drawmap.py at line 62[2.1908]
def landmass_steradians(source, x, y):shape = source.shapesource = tf.cast(source, tf.float64).numpy()return helpers.landmass_steradians(ctypes.cast(ctypes.c_voidp(source.ctypes.data), ctypes.POINTER(ctypes.c_double)), ctypes.c_int(shape[1]), ctypes.c_int(shape[0]), ctypes.c_int(x), ctypes.c_int(y))