struggle with change of url between requests

This commit is contained in:
bmatthieu3
2022-07-20 18:45:24 +02:00
parent c2d9df651e
commit f5bcbd19fa
8 changed files with 165 additions and 67 deletions

View File

@@ -265,8 +265,11 @@ where
.get_view()
.get_cells()
//.flat_map(|texture_cell| texture_cell.get_tile_cells(survey.get_config()))
.map(|&c| c)
.collect::<Vec<_>>();
.flat_map(|cell| {
let texture_cell = cell.get_texture_cell(survey.get_config());
texture_cell.get_tile_cells(survey.get_config())
})
.collect::<HashSet<_>>();
if depth_tile > 3 {
// Retrieve the grand-grand parent cells but not if it is root ones as it may interfere with already done requests
@@ -534,8 +537,36 @@ where
for rsc in rscs.into_iter() {
match rsc {
Resource::Tile(tile) => {
let coverage = self.surveys.get_coverage(&tile.system, tile.cell.depth());
if (coverage.is_some() && coverage.unwrap().contains_tile(&tile.cell)) || tile.is_root {
let is_tile_root = tile.is_root;
if let Some((survey, coverage)) = self.surveys.get_survey_and_coverage(&tile) {
let cfg = survey.get_config();
let texture_cell = tile.cell.get_texture_cell(cfg);
let included_or_near_coverage = texture_cell.get_tile_cells(cfg)
.any(|neighbor_tile_cell| {
coverage.contains_tile(&neighbor_tile_cell)
});
if is_tile_root || included_or_near_coverage {
let is_missing = tile.missing();
let Tile {
cell,
image,
time_req,
..
} = tile;
survey.add_tile(&cell, image, is_missing, time_req);
self.request_redraw = true;
} else {
self.downloader.cache_rsc(Resource::Tile(tile));
}
} else {
self.downloader.cache_rsc(Resource::Tile(tile));
}
/*if (coverage.is_some() && coverage.unwrap().contains_tile(&tile.cell)) || tile.is_root {
// Find the survey is tile is refering to
let hips_url = tile.get_hips_url();
// Get the hips url from that url
@@ -551,9 +582,7 @@ where
self.request_redraw = true;
}
} else {
self.downloader.cache_rsc(Resource::Tile(tile));
}
}*/
//al_core::log(&format!("{:?} {:?}", tile.cell.depth() == coverage.depth_max(), coverage.contains(tile.cell.idx())));
@@ -578,24 +607,7 @@ where
}
}
} else {
let Allsky {
image, time_req, depth_tile, ..
} = allsky;
//al_core::log(&format!("depth tile {}", depth_tile));
{
let mutex_locked = image.lock().unwrap();
let images = mutex_locked.as_ref();
for (idx, image) in images.unwrap().iter().enumerate() {
//al_core::log(&format!("idx {}", idx));
survey.add_tile(
&HEALPixCell(depth_tile, idx as u64),
image,
false,
time_req,
);
}
}
survey.add_allsky(allsky);
// Once received ask for redraw
self.request_redraw = true;
}
@@ -806,7 +818,7 @@ where
let tile_size = survey.get_config().get_tile_size();
//Request the allsky for the small tile size
if tile_size <= 128 {
if tile_size <= 512 {
// Request the allsky
self.downloader.fetch(query::Allsky::new(survey.get_config()), false);
// tell the survey to not download tiles which order is <= 3 because the allsky
@@ -859,8 +871,7 @@ where
let tile_size = survey.get_config().get_tile_size();
//al_core::log(&format!("tile size {}", tile_size));
//Request the allsky for the small tile size
if tile_size <= 128 {
al_core::log("allsky fetching");
if tile_size <= 512 {
// Request the allsky
self.downloader.fetch(query::Allsky::new(survey.get_config()), false);
// tell the survey to not download tiles which order is <= 3 because the allsky

View File

@@ -50,8 +50,8 @@ fn linspace(a: f64, b: f64, num: usize) -> Vec<f64> {
res
}
const NUM_VERTICES_WIDTH: usize = 10;
const NUM_VERTICES_HEIGHT: usize = 10;
const NUM_VERTICES_WIDTH: usize = 5;
const NUM_VERTICES_HEIGHT: usize = 5;
const NUM_VERTICES: usize = 4 + 2 * NUM_VERTICES_WIDTH + 2 * NUM_VERTICES_HEIGHT;
// This struct belongs to the CameraViewPort
pub struct FieldOfViewVertices {

View File

@@ -179,14 +179,13 @@ async fn handle_allsky_file<F: ImageFormat>(
texture_size: i32,
tile_size: i32,
) -> Result<Vec<ImageBuffer<F>>, JsValue> {
let mut src_idx = 0;
let num_tiles_per_texture = (texture_size / tile_size)*(texture_size / tile_size);
let num_tiles = num_tiles_per_texture*12;
let mut tiles = Vec::with_capacity(num_tiles as usize);
let num_allsky_tiles_per_tile = (tile_size / allsky_tile_size)*(tile_size / allsky_tile_size);
let mut src_idx = 0;
for _ in 0..num_tiles {
let mut base_tile = ImageBuffer::<F>::allocate(&<F as ImageFormat>::P::BLACK, tile_size, tile_size);
for idx_tile in 0..num_allsky_tiles_per_tile {
@@ -196,7 +195,7 @@ async fn handle_allsky_file<F: ImageFormat>(
let sx = (src_idx % 27) * allsky_tile_size;
let sy = (src_idx / 27) * allsky_tile_size;
base_tile.tex_sub(&allsky, sx, sy, allsky_tile_size, allsky_tile_size, dx as i32, dy as i32, allsky_tile_size, allsky_tile_size);
base_tile.tex_sub(&allsky, sx as i32, sy, allsky_tile_size, allsky_tile_size, dx as i32, dy as i32, allsky_tile_size, allsky_tile_size);
src_idx += 1;
}

View File

@@ -181,6 +181,7 @@ use al_core::image::format::{ImageFormatType, R32F, R64F, RGB8U, RGBA8U};
use al_core::image::format::{R16I, R32I, R8UI};
use crate::healpix::cell::NUM_HPX_TILES_DEPTH_ZERO;
use crate::downloader::request::allsky::Allsky;
use cgmath::Vector3;
impl ImageSurveyTextures {
pub fn new(
@@ -297,6 +298,38 @@ impl ImageSurveyTextures {
Ok(())
}
pub fn push_allsky(
&mut self,
allsky: Allsky,
) {
let Allsky {
image, time_req, depth_tile, ..
} = allsky;
//al_core::log(&format!("depth tile {}", depth_tile));
{
let mutex_locked = image.lock().unwrap();
let images = mutex_locked.as_ref().unwrap();
for (idx, image) in images.iter().enumerate() {
al_core::log(&format!("idx {}", idx));
self.push(
&HEALPixCell(depth_tile, idx as u64),
image,
false,
time_req,
);
}
}
self.set_ready();
}
pub fn set_ready(&mut self) {
self.ready = true;
// The survey is ready
self.start_time = Some(Time::now());
self.num_root_textures_available = NUM_HPX_TILES_DEPTH_ZERO;
}
// This method pushes a new downloaded tile into the buffer
// It must be ensured that the tile is not already contained into the buffer
pub fn push<I: Image + std::fmt::Debug>(
@@ -306,13 +339,41 @@ impl ImageSurveyTextures {
missing: bool,
time_request: Time,
) {
// Assert here to prevent pushing doublons
if self.contains_tile(cell) {
return;
}
// Get the texture cell in which the tile has to be
let tex_cell = cell.get_texture_cell(&self.config);
// Assert here to prevent pushing doublons
/*if self.contains_tile(cell) {
let texture = self
.textures
.get_mut(&tex_cell)
.expect("the cell has to be in the tile buffer");
if missing {
send_to_gpu(
cell,
texture,
self.config.get_default_image(),
self.texture_2d_array.clone(),
&self.config,
);
} else {
send_to_gpu(
cell,
texture,
image,
self.texture_2d_array.clone(),
&self.config,
);
};
return;
}*/
if !self.textures.contains_key(&tex_cell) {
let HEALPixCell(_, idx) = tex_cell;

View File

@@ -265,6 +265,7 @@ impl HiPSConfig {
let empty_image = EmptyTileImage::new(tile_size, format);
let texture_size = std::cmp::min(512, tile_size << max_depth_tile);
//let texture_size = tile_size;
let num_tile_per_side_texture = (texture_size / tile_size) as usize;
let delta_depth = math::utils::log_2_unchecked(num_tile_per_side_texture) as u8;

View File

@@ -159,8 +159,6 @@ impl RecomputeRasterizer for Move {
// to not be too much skewed
use crate::healpix::{cell::HEALPixCell, coverage::HEALPixCoverage};
impl RecomputeRasterizer for Zoom {
// Returns:
// * The UV of the starting tile in the global 4096x4096 texture
@@ -500,6 +498,7 @@ use al_core::{
use web_sys::{WebGl2RenderingContext};
use crate::math::lonlat::LonLat;
use crate::downloader::request::allsky::Allsky;
impl ImageSurvey {
fn new(
config: HiPSConfig,
@@ -852,6 +851,13 @@ impl ImageSurvey {
self.textures.push(&cell, image, missing, time_req);
}
pub fn add_allsky(
&mut self,
allsky: Allsky,
) {
self.textures.push_allsky(allsky);
}
/* Accessors */
#[inline]
pub fn get_config(&self) -> &HiPSConfig {
@@ -1052,6 +1058,7 @@ use al_core::webgl_ctx::GlWrapper;
use std::collections::hash_map::{Entry, DefaultHasher};
use std::hash::{Hasher, Hash};
use al_api::coo_system::CooSystem;
use crate::downloader::request::tile::Tile;
impl ImageSurveys {
pub fn new<P: Projection>(
gl: &WebGlContext,
@@ -1346,7 +1353,7 @@ impl ImageSurveys {
let hips_frame = cfg.get_frame();
// Compute that depth
//let camera_depth = self::view::depth_from_pixels_on_screen(camera, cfg.get_texture_size());
let camera_tile_depth = self::view::depth_from_pixels_on_screen(camera, cfg.get_tile_size());
let camera_tile_depth = self::view::depth_from_pixels_on_screen(camera, 512);
//let camera_depth = self::view::depth_from_pixels_on_screen(camera, 512);
let depth_tile = camera_tile_depth.min(max_tile_depth);
@@ -1378,7 +1385,7 @@ impl ImageSurveys {
}
// Accessors
pub fn get_coverage(&mut self, hips_frame: &CooSystem, depth: u8) -> Option<&HEALPixCoverage> {
pub fn get_coverage(&self, hips_frame: &CooSystem, depth: u8) -> Option<&HEALPixCoverage> {
let mut hasher = DefaultHasher::new();
(depth, hips_frame).hash(&mut hasher);
let key = hasher.finish();
@@ -1386,6 +1393,20 @@ impl ImageSurveys {
self.coverages.get(&key)
}
pub fn get_survey_and_coverage(&mut self, tile: &Tile) -> Option<(&mut ImageSurvey, &HEALPixCoverage)> {
let depth = tile.cell.depth();
let hips_frame = tile.system;
let mut hasher = DefaultHasher::new();
(depth, hips_frame).hash(&mut hasher);
let key = hasher.finish();
let coverage = self.coverages.get(&key);
let survey = self.surveys.get_mut(tile.get_hips_url());
Some((survey?, coverage?))
}
pub fn get_depth(&self) -> u8 {
self.depth
}

View File

@@ -25,43 +25,47 @@ pub struct TileUVW([Vector3<f32>; 4]);
impl TileUVW {
// The texture cell passed must be a child of texture
pub fn new(
child_texture_cell: &HEALPixCell,
cell: &HEALPixCell,
texture: &Texture,
config: &HiPSConfig,
cfg: &HiPSConfig,
) -> TileUVW {
let HEALPixCell(depth, idx) = *child_texture_cell;
let HEALPixCell(parent_depth, parent_idx) = *texture.cell();
// Index of the texture in the total set of textures
let texture_idx = texture.idx();
// Index of the slice of textures
let num_textures_by_slice = cfg.num_textures_by_slice();
let idx_slice = texture_idx / num_textures_by_slice;
// Index of the texture in its slice
let idx_in_slice = texture_idx % num_textures_by_slice;
let idx_off = parent_idx << (2 * (depth - parent_depth));
// Index of the column of the texture in its slice
let num_textures_by_side_slice = cfg.num_textures_by_side_slice();
let idx_col_in_slice = idx_in_slice / num_textures_by_side_slice;
// Index of the row of the texture in its slice
let idx_row_in_slice = idx_in_slice % num_textures_by_side_slice;
debug_assert!(idx >= idx_off);
debug_assert!(depth >= parent_depth);
let nside = (1 << (depth - parent_depth)) as f32;
// Row and column indexes of the tile in its texture
let (idx_col_in_tex, idx_row_in_tex) = cell.offset_in_parent(texture.cell());
let (x, y) = utils::unmortonize(idx - idx_off);
let x = x as f32;
let y = y as f32;
debug_assert!(x < nside);
debug_assert!(y < nside);
// Offset in the slice in pixels
/*let offset = Vector3::new(
(idx_row_in_slice as i32) * texture_size + (idx_row_in_tex as i32) * tile_size,
(idx_col_in_slice as i32) * texture_size + (idx_col_in_tex as i32) * tile_size,
idx_slice,
);*/
let parent_idx_texture = texture.idx();
let idx_texture = (parent_idx_texture / config.num_textures_by_slice()) as f32;
let parent_idx_in_texture = parent_idx_texture % config.num_textures_by_slice();
let parent_idx_row = (parent_idx_in_texture / config.num_textures_by_side_slice()) as f32; // in [0; 7]
let parent_idx_col = (parent_idx_in_texture % config.num_textures_by_side_slice()) as f32; // in [0; 7]
let num_textures_by_side_slice_f32 = config.num_textures_by_side_slice() as f32;
let u = (parent_idx_col + (y / nside)) / num_textures_by_side_slice_f32;
let v = (parent_idx_row + (x / nside)) / num_textures_by_side_slice_f32;
let num_textures_by_side_slice_f32 = num_textures_by_side_slice as f32;
let nside = (1 << (cell.depth() - texture.cell().depth())) as f32;
let u = ((idx_row_in_slice as f32) + ((idx_row_in_tex as f32) / nside)) / num_textures_by_side_slice_f32;
let v = ((idx_col_in_slice as f32) + ((idx_col_in_tex as f32) / nside)) / num_textures_by_side_slice_f32;
let ds = 1_f32 / (num_textures_by_side_slice_f32 * nside);
let w = (texture_idx as f32) / (num_textures_by_slice as f32);
TileUVW([
Vector3::new(u, v, idx_texture),
Vector3::new(u + ds, v, idx_texture),
Vector3::new(u, v + ds, idx_texture),
Vector3::new(u + ds, v + ds, idx_texture),
Vector3::new(u, v, w),
Vector3::new(u + ds, v, w),
Vector3::new(u, v + ds, w),
Vector3::new(u + ds, v + ds, w),
])
}
}

View File

@@ -75,7 +75,8 @@ impl Texture {
assert!(!self.full);
self.missing &= missing;
//self.start_time = Some(Time::now());
//self.full = true;
let num_tiles_per_texture = config.num_tiles_per_texture();
if *cell == texture_cell {
self.num_tiles_written = num_tiles_per_texture;
@@ -88,7 +89,7 @@ impl Texture {
// Ensures the tile was not already present in the buffer
// This is the case because already contained cells do not
// lead to new requests
debug_assert!(new_tile);
assert!(new_tile);
self.num_tiles_written += 1;
if self.num_tiles_written == num_tiles_per_texture {