Skip to content

Commit

Permalink
doc: add MOC and GraphicOverlay method documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
bmatthieu3 committed Oct 10, 2024
1 parent d94a93c commit 278bba0
Show file tree
Hide file tree
Showing 4 changed files with 113 additions and 114 deletions.
11 changes: 3 additions & 8 deletions src/core/src/renderable/hips/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ use std::collections::HashSet;
// Recursively compute the number of subdivision needed for a cell
// to not be too much skewed

use crate::survey::buffer::ImageSurveyTextures;
use crate::survey::buffer::HiPS2DBuffer;
use crate::survey::texture::Texture;

use raytracing::RayTracer;
Expand Down Expand Up @@ -210,7 +210,7 @@ pub fn get_raytracer_shader<'a>(
pub struct HiPS {
//color: Color,
// The image survey texture buffer
textures: ImageSurveyTextures,
textures: HiPS2DBuffer,

// The projected vertices data
// For WebGL2 wasm, the data are interleaved
Expand Down Expand Up @@ -328,7 +328,7 @@ impl HiPS {
.unbind();

let num_idx = 0;
let textures = ImageSurveyTextures::new(gl, config)?;
let textures = HiPS2DBuffer::new(gl, config)?;

let gl = gl.clone();
let footprint_moc = None;
Expand Down Expand Up @@ -786,11 +786,6 @@ impl HiPS {
self.textures.config_mut()
}

#[inline]
pub fn get_ready_time(&self) -> &Option<Time> {
&self.textures.start_time
}

pub fn draw(
&self,
shaders: &mut ShaderManager,
Expand Down
114 changes: 13 additions & 101 deletions src/core/src/survey/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ use al_api::hips::ImageExt;
use al_core::webgl_ctx::WebGlRenderingCtx;

use al_core::image::format::ImageFormat;
#[cfg(feature = "webgl2")]
use al_core::image::format::{R16I, R32I, R8UI};
use al_core::image::format::{R32F, R64F, RGB8U, RGBA8U};
use al_core::image::format::{R16I, R32F, R32I, R64F, R8UI, RGB8U, RGBA8U};
use al_core::image::Image;
use al_core::shader::{SendUniforms, ShaderBound};
use al_core::Texture2DArray;
Expand Down Expand Up @@ -124,29 +122,21 @@ impl HEALPixCellHeap {
}

// Fixed sized binary heap
pub struct ImageSurveyTextures {
pub struct HiPS2DBuffer {
// Some information about the HiPS
pub config: HiPSConfig,
config: HiPSConfig,
heap: HEALPixCellHeap,

num_root_textures_available: u8,
size: usize,

pub textures: HashMap<HEALPixCell, Texture>,
pub base_textures: [Texture; NUM_HPX_TILES_DEPTH_ZERO],
//pub cutoff_values_tile: Rc<RefCell<HashMap<HEALPixCell, (f32, f32)>>>,
textures: HashMap<HEALPixCell, Texture>,
base_textures: [Texture; NUM_HPX_TILES_DEPTH_ZERO],

// Array of 2D textures
pub texture_2d_array: Texture2DArray,

// A boolean ensuring the root textures
// have already been loaded
//ready: bool,
pub start_time: Option<Time>,
texture_2d_array: Texture2DArray,

available_tiles_during_frame: bool,
//num_base_textures: usize,
//exec: Rc<RefCell<TaskExecutor>>,
}

// Define a set of textures compatible with the HEALPix tile format and size
Expand Down Expand Up @@ -189,8 +179,8 @@ fn create_texture_array<F: ImageFormat>(
)
}

impl ImageSurveyTextures {
pub fn new(gl: &WebGlContext, config: HiPSConfig) -> Result<ImageSurveyTextures, JsValue> {
impl HiPS2DBuffer {
pub fn new(gl: &WebGlContext, config: HiPSConfig) -> Result<HiPS2DBuffer, JsValue> {
let size = 128 - NUM_HPX_TILES_DEPTH_ZERO;
// Ensures there is at least space for the 12
// root textures
Expand Down Expand Up @@ -231,25 +221,20 @@ impl ImageSurveyTextures {
ChannelType::R64F => create_texture_array::<R64F>(gl, &config)?,
};
// The root textures have not been loaded
//let ready = false;

let num_root_textures_available = 0;
let available_tiles_during_frame = false;
let start_time = None;
//let num_base_textures = 0;
Ok(ImageSurveyTextures {

Ok(HiPS2DBuffer {
config,
heap,

size,
num_root_textures_available,
textures,
base_textures,
//num_base_textures,
texture_2d_array,
available_tiles_during_frame,

//ready,
start_time,
})
}

Expand Down Expand Up @@ -295,7 +280,6 @@ impl ImageSurveyTextures {
//self.ready = false;
self.num_root_textures_available = 0;
self.available_tiles_during_frame = false;
self.start_time = None;

Ok(())
}
Expand All @@ -316,18 +300,9 @@ impl ImageSurveyTextures {
}
}

//self.set_ready();

Ok(())
}

/*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>(
Expand Down Expand Up @@ -355,29 +330,10 @@ impl ImageSurveyTextures {
let mut texture = self.textures.remove(&oldest_texture.cell).expect(
"Texture (oldest one) has not been found in the buffer of textures",
);
// Clear and assign it to tex_cell
/*let idx = if tex_cell_is_root {
self.num_base_textures += 1;
Some(tex_cell.idx() as i32)
} else {
None
};*/
texture.replace(&tex_cell, time_request);

texture
} else {
// The heap buffer is not full, let's create a new
// texture with an unique idx
// The idx is computed based on the current size of the buffer

/*let idx = if tex_cell_is_root {
self.num_base_textures += 1;
tex_cell.idx() as usize
} else {
//NUM_HPX_TILES_DEPTH_ZERO + (self.heap.len() - self.num_base_textures)
self.heap.len()
};*/
//let idx = NUM_HPX_TILES_DEPTH_ZERO + (self.heap.len() - self.num_base_textures);
let idx = NUM_HPX_TILES_DEPTH_ZERO + self.heap.len();

Texture::new(&tex_cell, idx as i32, time_request)
Expand Down Expand Up @@ -411,7 +367,6 @@ impl ImageSurveyTextures {
&mut self.base_textures[idx as usize]
};

//let missing = image.is_none();
send_to_gpu(
cell,
texture,
Expand All @@ -423,25 +378,9 @@ impl ImageSurveyTextures {
texture.append(
cell, // The tile cell
&self.config,
//missing,
);

self.available_tiles_during_frame = true;
//self.ready = true;
/*if self.start_time.is_none() {
self.start_time = Some(Time::now());
}*/

/*if tex_cell.is_root(self.config.delta_depth()) && texture.is_available() {
self.num_root_textures_available += 1;
debug_assert!(self.num_root_textures_available <= NUM_HPX_TILES_DEPTH_ZERO);
if self.num_root_textures_available == NUM_HPX_TILES_DEPTH_ZERO {
self.ready = true;
// The survey is ready
//self.start_time = Some(Time::now());
}
}*/
}

Ok(())
Expand Down Expand Up @@ -614,33 +553,6 @@ impl ImageSurveyTextures {
&mut self.config
}

/*pub fn is_ready(&self) -> bool {
self.ready
}*/

// Get the textures in the buffer
// The resulting array is uniq sorted
/*fn get_allsky_textures(&self) -> [Option<&Texture>; NUM_HPX_TILES_DEPTH_ZERO] {
//debug_assert!(self.is_ready());
/*let mut textures = self.textures.values().collect::<Vec<_>>();
textures.sort_unstable();
textures*/
[
self.textures.get(&HEALPixCell(0, 0)),
self.textures.get(&HEALPixCell(0, 1)),
self.textures.get(&HEALPixCell(0, 2)),
self.textures.get(&HEALPixCell(0, 3)),
self.textures.get(&HEALPixCell(0, 4)),
self.textures.get(&HEALPixCell(0, 5)),
self.textures.get(&HEALPixCell(0, 6)),
self.textures.get(&HEALPixCell(0, 7)),
self.textures.get(&HEALPixCell(0, 8)),
self.textures.get(&HEALPixCell(0, 9)),
self.textures.get(&HEALPixCell(0, 10)),
self.textures.get(&HEALPixCell(0, 11)),
]
}*/

pub fn get_texture_array(&self) -> &Texture2DArray {
&self.texture_2d_array
}
Expand Down Expand Up @@ -678,7 +590,7 @@ fn send_to_gpu<I: Image>(
Ok(())
}

impl SendUniforms for ImageSurveyTextures {
impl SendUniforms for HiPS2DBuffer {
// Send only the allsky textures
fn attach_uniforms<'a>(&self, shader: &'a ShaderBound<'a>) -> &'a ShaderBound<'a> {
// Send the textures
Expand Down Expand Up @@ -707,7 +619,7 @@ impl SendUniforms for ImageSurveyTextures {
}
}

impl Drop for ImageSurveyTextures {
impl Drop for HiPS2DBuffer {
fn drop(&mut self) {
// Cleanup the heap
self.heap.clear();
Expand Down
26 changes: 23 additions & 3 deletions src/js/MOC.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ export let MOC = (function() {
/**
* Return a value between 0 and 1 denoting the fraction of the sky
* covered by the MOC
*
* @memberof MOC
*
* @returns {number} The sky fraction covered by the MOC
*/
MOC.prototype.skyFraction = function() {
return this.skyFrac;
Expand Down Expand Up @@ -190,6 +194,11 @@ export let MOC = (function() {
}
};

/**
* Show the MOC object
*
* @memberof MOC
*/
MOC.prototype.show = function() {
if (this.isShowing) {
return;
Expand All @@ -198,6 +207,11 @@ export let MOC = (function() {
this.reportChange();
};

/**
* Hide the MOC object
*
* @memberof MOC
*/
MOC.prototype.hide = function() {
if (! this.isShowing) {
return;
Expand All @@ -206,9 +220,15 @@ export let MOC = (function() {
this.reportChange();
};

// Tests whether a given (ra, dec) point on the sky is within the current MOC object
//
// returns true if point is contained, false otherwise
/**
* Tests whether a given (ra, dec) point on the sky is within the current MOC object
*
* @memberof MOC
* @param {number} ra - Right-Ascension of the location in degrees and ICRS frame
* @param {number} dec - Declination of the location in degrees and ICRS frame
*
* @returns {boolean} True if the point is contained, false otherwise
*/
MOC.prototype.contains = function(ra, dec) {
if (!this.ready) {
throw this.name + " is not yet ready, either because it has not been downloaded yet or because it has not been added to the aladin instance."
Expand Down
Loading

0 comments on commit 278bba0

Please sign in to comment.