Skip to content

Commit

Permalink
use texture2darray for displaying HiPS
Browse files Browse the repository at this point in the history
  • Loading branch information
bmatthieu3 committed Oct 9, 2024
1 parent 9100d97 commit 52ea23a
Show file tree
Hide file tree
Showing 76 changed files with 1,181 additions and 1,155 deletions.
2 changes: 1 addition & 1 deletion examples/al-aas225.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
simbad.addSources([A.marker(204.97010833333336, 0.8400166666666667, {popupTitle: 'NGC 5257', popupDesc: '<em>Object type:</em> HII galaxy<br/><em>Morphological type:</em> Sbc<br/><br/>More info <a href="https://simbad.u-strasbg.fr/simbad/sim-id?Ident=NGC+5257">in Simbad</a>'}), A.marker(204.9903125, 0.8309694444444445, {popupTitle: 'NGC 5258', popupDesc: '<em>Object type:</em> Galaxy in Pair of Galaxies <br/><em>Morphological type:</em> Sb<br/><br/>More info <a href="https://simbad.u-strasbg.fr/simbad/sim-id?Ident=NGC+5258">in Simbad</a>'})]);

var overlay = A.graphicOverlay({color: '#aa2222', lineWidth: 4});
overlay.addFootprints(A.polygon([[204.970214, 0.81206], [204.97110047, 0.80993368], [204.978723, 0.79165], [204.999152, 0.800162], [204.99482125, 0.81055582], [205.002941, 0.813851], [204.99986816, 0.82141125], [205.010312, 0.825578], [205.002112, 0.846123], [204.981546, 0.837916], [204.98157771, 0.83783654], [204.962977, 0.830202], [204.9703941, 0.81213504]]));

aladin.addOverlay(overlay);
overlay.addFootprints(A.polygon([[204.970214, 0.81206], [204.97110047, 0.80993368], [204.978723, 0.79165], [204.999152, 0.800162], [204.99482125, 0.81055582], [205.002941, 0.813851], [204.99986816, 0.82141125], [205.010312, 0.825578], [205.002112, 0.846123], [204.981546, 0.837916], [204.98157771, 0.83783654], [204.962977, 0.830202], [204.9703941, 0.81213504]]));

aladin.displayJPG('http://images.ipac.caltech.edu/esahubble/heic0810at/esahubble_heic0810at_1600.jpg');
});
Expand Down
2 changes: 1 addition & 1 deletion examples/al-init-custom-options.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
showSimbadPointerControl: true,
survey: 'P/allWISE/color', // set initial image survey
projection: 'AIT', // set a projection
fov: 1.5, // initial field of view in degrees
fov: 360, // initial field of view in degrees
target: 'orion', // initial target
cooFrame: 'icrs', // set galactic frame
reticleColor: '#ff89ff', // change reticle color
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
"HiPS"
],
"scripts": {
"wasm": "wasm-pack build ./src/core --target web --release --out-name core -- --features webgl2 -Z build-std=panic_abort,std -Z build-std-features=panic_immediate_abort ",
"wasm:dbg": "wasm-pack build --dev ./src/core --target web --out-name core -- --features=webgl2,dbg -Z build-std=panic_abort,std -Z build-std-features=panic_immediate_abort ",
"wasm": "wasm-pack build ./src/core --target web --release --out-name core -- --features webgl2",
"wasm:dbg": "wasm-pack build --dev ./src/core --target web --out-name core -- --features=webgl2,dbg",
"predeploy": "npm run build && rm -rf aladin-lite*.tgz && npm pack",
"deploy": "python3 deploy/deploy.py",
"build": "npm run wasm && vite build",
Expand Down
8 changes: 4 additions & 4 deletions src/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ url-lite = "0.1.0"
serde_json = "1.0.104"
serde-wasm-bindgen = "0.5"
enum_dispatch = "0.3.8"
wasm-bindgen = "0.2.79"
wasm-bindgen = "0.2.92"
wasm-streams = "0.3.0"
async-channel = "1.8.0"
mapproj = "0.3.0"
Expand Down Expand Up @@ -55,8 +55,8 @@ branch = "master"

[dependencies.moclib]
package = "moc"
git = "https://github.com/bmatthieu3/cds-moc-rust"
branch = "overlap"
git = "https://github.com/cds-astro/cds-moc-rust"
branch = "main"

[dependencies.serde]
version = "^1.0.183"
Expand All @@ -82,7 +82,7 @@ features = [ "jpeg", "png",]
debug = true

[profile.release]
opt-level = "z"
opt-level = 'z'
debug = false
debug-assertions = false
overflow-checks = false
Expand Down
13 changes: 1 addition & 12 deletions src/core/al-api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ js-sys = "0.3.47"
cgmath = "*"
serde = { version = "^1.0.59", features = ["derive"] }
serde-wasm-bindgen = "0.4"
wasm-bindgen = "0.2.79"
wasm-bindgen = "0.2.92"
colorgrad = "0.6.2"

[features]
Expand Down Expand Up @@ -76,16 +76,5 @@ incremental = true
codegen-units = 256
rpath = false

[profile.release]
opt-level = 'z'
debug = false
debug-assertions = false
overflow-checks = false
lto = true
panic = 'unwind'
incremental = false
codegen-units = 16
rpath = false

[package.metadata.wasm-pack.profile.release]
wasm-opt = true
13 changes: 1 addition & 12 deletions src/core/al-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ futures = "0.3.25"
colorgrad = "0.6.2"

[dependencies.wasm-bindgen]
version = "0.2.79"
version = "0.2.92"

[dev-dependencies]
fontdue = "0.7.2"
Expand Down Expand Up @@ -88,16 +88,5 @@ incremental = true
codegen-units = 256
rpath = false

[profile.release]
opt-level = 'z'
debug = false
debug-assertions = false
overflow-checks = false
lto = true
panic = 'unwind'
incremental = false
codegen-units = 16
rpath = false

[package.metadata.wasm-pack.profile.release]
wasm-opt = true
17 changes: 12 additions & 5 deletions src/core/al-core/src/image/bitmap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,23 @@ where
}
}
}
use wasm_bindgen::JsValue;
use crate::texture::Texture2DArray;
use wasm_bindgen::JsValue;
impl<F> Image for Bitmap<F>
where
F: ImageFormat + Clone,
{
fn tex_sub_image_3d(&self, textures: &Texture2DArray, offset: &Vector3<i32>) -> Result<(), JsValue> {
textures[offset.z as usize]
.bind()
.tex_sub_image_2d_with_u32_and_u32_and_image_bitmap(offset.x, offset.y, &self.image);
fn tex_sub_image_3d(
&self,
textures: &Texture2DArray,
offset: &Vector3<i32>,
) -> Result<(), JsValue> {
textures.bind().tex_sub_image_3d_with_image_bitmap(
offset.z,
offset.x,
offset.y,
&self.image,
);

Ok(())
}
Expand Down
17 changes: 8 additions & 9 deletions src/core/al-core/src/image/canvas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ where
}
}

use cgmath::Vector3;
use wasm_bindgen::JsValue;
use crate::image::format::ImageFormat;
use crate::image::Image;
use crate::texture::Texture2DArray;
use cgmath::Vector3;
use wasm_bindgen::JsValue;
impl<F> Image for Canvas<F>
where
F: ImageFormat,
Expand All @@ -33,13 +33,12 @@ where
// An offset to write the image in the texture array
offset: &Vector3<i32>,
) -> Result<(), JsValue> {
textures[offset.z as usize]
.bind()
.tex_sub_image_2d_with_u32_and_u32_and_html_canvas_element(
offset.x,
offset.y,
&self.canvas,
);
textures.bind().tex_sub_image_3d_with_html_canvas_element(
offset.z,
offset.x,
offset.y,
&self.canvas,
);

Ok(())
}
Expand Down
68 changes: 32 additions & 36 deletions src/core/al-core/src/image/fits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,51 +129,47 @@ impl Image for Fits<'_> {
match &self.data {
Data::U8(data) => {
let view = unsafe { R8UI::view(&data) };
textures[offset.z as usize]
.bind()
.tex_sub_image_2d_with_i32_and_i32_and_u32_and_type_and_opt_array_buffer_view(
offset.x,
offset.y,
self.size.x,
self.size.y,
Some(view.as_ref()),
);
textures.bind().tex_sub_image_3d_with_opt_array_buffer_view(
offset.z,
offset.x,
offset.y,
self.size.x,
self.size.y,
Some(view.as_ref()),
);
}
Data::I16(data) => {
let view = unsafe { R16I::view(&data) };
textures[offset.z as usize]
.bind()
.tex_sub_image_2d_with_i32_and_i32_and_u32_and_type_and_opt_array_buffer_view(
offset.x,
offset.y,
self.size.x,
self.size.y,
Some(view.as_ref()),
);
textures.bind().tex_sub_image_3d_with_opt_array_buffer_view(
offset.z,
offset.x,
offset.y,
self.size.x,
self.size.y,
Some(view.as_ref()),
);
}
Data::I32(data) => {
let view = unsafe { R32I::view(&data) };
textures[offset.z as usize]
.bind()
.tex_sub_image_2d_with_i32_and_i32_and_u32_and_type_and_opt_array_buffer_view(
offset.x,
offset.y,
self.size.x,
self.size.y,
Some(view.as_ref()),
);
textures.bind().tex_sub_image_3d_with_opt_array_buffer_view(
offset.z,
offset.x,
offset.y,
self.size.x,
self.size.y,
Some(view.as_ref()),
);
}
Data::F32(data) => {
let view = unsafe { R32F::view(&data) };
textures[offset.z as usize]
.bind()
.tex_sub_image_2d_with_i32_and_i32_and_u32_and_type_and_opt_array_buffer_view(
offset.x,
offset.y,
self.size.x,
self.size.y,
Some(view.as_ref()),
);
textures.bind().tex_sub_image_3d_with_opt_array_buffer_view(
offset.z,
offset.x,
offset.y,
self.size.x,
self.size.y,
Some(view.as_ref()),
);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/core/al-core/src/image/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ impl ImageFormat for RGB8U {
const NUM_CHANNELS: usize = 3;

const FORMAT: u32 = WebGlRenderingCtx::RGB as u32;
const INTERNAL_FORMAT: i32 = WebGlRenderingCtx::RGB as i32;
const INTERNAL_FORMAT: i32 = WebGlRenderingCtx::RGB8 as i32;
const TYPE: u32 = WebGlRenderingCtx::UNSIGNED_BYTE;

const CHANNEL_TYPE: ChannelType = ChannelType::RGB8U;
Expand Down Expand Up @@ -71,7 +71,7 @@ impl ImageFormat for RGBA8U {
const NUM_CHANNELS: usize = 4;

const FORMAT: u32 = WebGlRenderingCtx::RGBA as u32;
const INTERNAL_FORMAT: i32 = WebGlRenderingCtx::RGBA as i32;
const INTERNAL_FORMAT: i32 = WebGlRenderingCtx::RGBA8 as i32;
const TYPE: u32 = WebGlRenderingCtx::UNSIGNED_BYTE;

const CHANNEL_TYPE: ChannelType = ChannelType::RGBA8U;
Expand Down
17 changes: 8 additions & 9 deletions src/core/al-core/src/image/html.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ where
}
}

use cgmath::Vector3;
use wasm_bindgen::JsValue;
use crate::image::format::ImageFormat;
use crate::image::Image;
use crate::texture::Texture2DArray;
use cgmath::Vector3;
use wasm_bindgen::JsValue;
impl<F> Image for HTMLImage<F>
where
F: ImageFormat,
Expand All @@ -33,13 +33,12 @@ where
// An offset to write the image in the texture array
offset: &Vector3<i32>,
) -> Result<(), JsValue> {
textures[offset.z as usize]
.bind()
.tex_sub_image_2d_with_u32_and_u32_and_html_image_element(
offset.x,
offset.y,
&self.image,
);
textures.bind().tex_sub_image_3d_with_html_image_element(
offset.z,
offset.x,
offset.y,
&self.image,
);

Ok(())
}
Expand Down
2 changes: 0 additions & 2 deletions src/core/al-core/src/image/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,9 +229,7 @@ where
Ok(())
}
}
use crate::Abort;

use std::sync::{Arc, Mutex};
/*impl<I> Image for Arc<Mutex<Option<I>>>
where
I: Image,
Expand Down
32 changes: 15 additions & 17 deletions src/core/al-core/src/image/raw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,14 @@ where
Self { data, size }
}

pub fn from_encoded_raw_bytes(raw_bytes: &[u8], width: i32, height: i32) -> Result<Self, JsValue> {
pub fn from_encoded_raw_bytes(
raw_bytes: &[u8],
width: i32,
height: i32,
) -> Result<Self, JsValue> {
let mut decoded_bytes = match T::decode(raw_bytes).map_err(|e| JsValue::from_str(e))? {
Bytes::Borrowed(bytes) => bytes.to_vec(),
Bytes::Owned(bytes) => bytes
Bytes::Owned(bytes) => bytes,
};

let decoded_pixels = unsafe {
Expand Down Expand Up @@ -80,12 +84,7 @@ where
ImageBuffer::<T>::new(data, width, height)
}

pub fn tex_sub(
&mut self,
src: &Self,
s: &ImageBufferView,
d: &ImageBufferView,
) {
pub fn tex_sub(&mut self, src: &Self, s: &ImageBufferView, d: &ImageBufferView) {
let mut di = d.x;
let mut dj = d.y;

Expand Down Expand Up @@ -153,15 +152,14 @@ where
) -> Result<(), JsValue> {
let js_array =
<<<I as ImageFormat>::P as Pixel>::Container as ArrayBuffer>::new(&self.data);
textures[offset.z as usize]
.bind()
.tex_sub_image_2d_with_i32_and_i32_and_u32_and_type_and_opt_array_buffer_view(
offset.x,
offset.y,
self.size.x,
self.size.y,
Some(js_array.as_ref()),
);
textures.bind().tex_sub_image_3d_with_opt_array_buffer_view(
offset.z,
offset.x,
offset.y,
self.width(),
self.height(),
Some(js_array.as_ref()),
);

Ok(())
}
Expand Down
Loading

0 comments on commit 52ea23a

Please sign in to comment.