Skip to content

Commit

Permalink
wip: hips3d struct and hips enum
Browse files Browse the repository at this point in the history
  • Loading branch information
bmatthieu3 committed Oct 21, 2024
1 parent d00d3aa commit 59a679a
Show file tree
Hide file tree
Showing 34 changed files with 1,990 additions and 849 deletions.
52 changes: 52 additions & 0 deletions examples/al-hips-cube.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<!doctype html>
<html>
<head>
</head>
<body>


<div id="aladin-lite-div" style="width: 768px; height: 512px"></div>
<script>let aladin; let hips;</script>
<script type="module">
import A from '../src/js/A.js';
A.init.then(() => {
aladin = A.aladin(
'#aladin-lite-div',
{
showSimbadPointerControl: true,
projection: 'AIT', // set a projection
fov: 360, // initial field of view in degrees
target: '169.58868 +45.74914', // initial target
cooFrame: 'icrs', // set galactic frame
reticleColor: '#ff89ff', // change reticle color
reticleSize: 64, // change reticle size
showContextMenu: true,
showFrame: true,
showZoomControl:true,
showSettingsControl:true,
showCooGrid: true,
fullScreen: true,
samp: true,
}
);

hips = aladin.newImageSurvey("https://alasky.cds.unistra.fr/CALIFA/V500DR2/");
aladin.setImageLayer(hips)

/*let id;
aladin.on("zoomChanged", () => {
if (id)
clearTimeout(id);
id = setTimeout(() => {
console.log("wheel stopped, new cone search here")
}, 500);
})*/
});
</script>
<style>
.aladin-cat-browser-box {
width: 600px;
}
</style>
</body>
</html>
6 changes: 2 additions & 4 deletions src/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,11 @@ optional = true

[dependencies.healpix]
package = "cdshealpix"
git = "https://github.com/cds-astro/cds-healpix-rust"
branch = "master"
version = "0.7.0"

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

[dependencies.serde]
version = "^1.0.183"
Expand Down
2 changes: 1 addition & 1 deletion src/core/al-core/src/image/bitmap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ where
}
}
}
use crate::texture::{Tex3D, Texture2DArray};
use crate::texture::Tex3D;
use wasm_bindgen::JsValue;
impl<F> Image for Bitmap<F>
where
Expand Down
2 changes: 1 addition & 1 deletion src/core/al-core/src/image/canvas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ where

use crate::image::format::ImageFormat;
use crate::image::Image;
use crate::texture::{Tex3D, Texture2DArray};
use crate::texture::Tex3D;
use cgmath::Vector3;
use wasm_bindgen::JsValue;
impl<F> Image for Canvas<F>
Expand Down
1 change: 0 additions & 1 deletion src/core/al-core/src/image/fits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ impl<'a> Fits<'a> {
}
}*/

use crate::Texture2DArray;
use crate::{image::Image, texture::Tex3D};
impl Image for Fits<'_> {
fn insert_into_3d_texture<T: Tex3D>(
Expand Down
84 changes: 84 additions & 0 deletions src/core/al-core/src/texture/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use crate::image::format::ImageFormat;
use web_sys::HtmlCanvasElement;
use web_sys::WebGlTexture;

use crate::texture::pixel::Pixel;
use crate::texture::Texture2DMeta;
use crate::webgl_ctx::WebGlContext;
use crate::webgl_ctx::WebGlRenderingCtx;
Expand Down Expand Up @@ -80,6 +81,89 @@ impl Texture2DArray {
.active_texture(WebGlRenderingCtx::TEXTURE0 + idx_tex_unit as u32);
self
}

pub fn read_pixel(&self, x: i32, y: i32, slice_idx: i32) -> Result<JsValue, JsValue> {
// Create and bind the framebuffer
let reader = self.gl.create_framebuffer();
self.gl
.bind_framebuffer(WebGlRenderingCtx::FRAMEBUFFER, reader.as_ref());

// Attach the texture as the first color attachment
self.gl.framebuffer_texture_layer(
WebGlRenderingCtx::READ_FRAMEBUFFER,
WebGlRenderingCtx::COLOR_ATTACHMENT0,
self.texture.as_ref(),
0,
slice_idx,
);

let status = self
.gl
.check_framebuffer_status(WebGlRenderingCtx::FRAMEBUFFER);
if status != WebGlRenderingCtx::FRAMEBUFFER_COMPLETE {
// Unbind the framebuffer
self.gl
.bind_framebuffer(WebGlRenderingCtx::FRAMEBUFFER, None);
// Delete the framebuffer
self.gl.delete_framebuffer(reader.as_ref());

Err(JsValue::from_str("incomplete framebuffer"))
} else {
// set the viewport as the FBO won't be the same dimension as the screen
let metadata = self.metadata.as_ref().unwrap_abort().borrow();
self.gl
.viewport(0, 0, metadata.width as i32, metadata.height as i32);

#[cfg(feature = "webgl2")]
let value = match (metadata.format, metadata.type_) {
(WebGlRenderingCtx::RED_INTEGER, WebGlRenderingCtx::UNSIGNED_BYTE) => {
let p = <[u8; 1]>::read_pixel(&self.gl, x, y)?;
Ok(serde_wasm_bindgen::to_value(&p[0])?)
}
(WebGlRenderingCtx::RED_INTEGER, WebGlRenderingCtx::SHORT) => {
let p = <[i16; 1]>::read_pixel(&self.gl, x, y)?;
Ok(serde_wasm_bindgen::to_value(&p[0])?)
}
(WebGlRenderingCtx::RED_INTEGER, WebGlRenderingCtx::INT) => {
let p = <[i32; 1]>::read_pixel(&self.gl, x, y)?;
Ok(serde_wasm_bindgen::to_value(&p[0])?)
}
(WebGlRenderingCtx::RED, WebGlRenderingCtx::FLOAT) => {
let p = <[f32; 1]>::read_pixel(&self.gl, x, y)?;
Ok(serde_wasm_bindgen::to_value(&p[0])?)
}
(WebGlRenderingCtx::RGB, WebGlRenderingCtx::UNSIGNED_BYTE) => {
let p = <[u8; 3]>::read_pixel(&self.gl, x, y)?;
Ok(serde_wasm_bindgen::to_value(&p)?)
}
(WebGlRenderingCtx::RGBA, WebGlRenderingCtx::UNSIGNED_BYTE) => {
let p = <[u8; 4]>::read_pixel(&self.gl, x, y)?;
Ok(serde_wasm_bindgen::to_value(&p)?)
}
_ => Err(JsValue::from_str(
"Pixel retrieval not implemented for that texture format.",
)),
};

// Unbind the framebuffer
self.gl
.bind_framebuffer(WebGlRenderingCtx::FRAMEBUFFER, None);
// Delete the framebuffer
self.gl.delete_framebuffer(reader.as_ref());

// set the viewport as the FBO won't be the same dimension as the screen
let canvas = self
.gl
.canvas()
.unwrap_abort()
.dyn_into::<web_sys::HtmlCanvasElement>()
.unwrap_abort();
self.gl
.viewport(0, 0, canvas.width() as i32, canvas.height() as i32);

value
}
}
}

impl Drop for Texture2DArray {
Expand Down
2 changes: 1 addition & 1 deletion src/core/al-core/src/texture/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ impl Texture2D {
// set the viewport as the FBO won't be the same dimension as the screen
let metadata = self.metadata.as_ref().unwrap_abort().borrow();
self.gl
.viewport(x, y, metadata.width as i32, metadata.height as i32);
.viewport(0, 0, metadata.width as i32, metadata.height as i32);

#[cfg(feature = "webgl2")]
let value = match (metadata.format, metadata.type_) {
Expand Down
Loading

0 comments on commit 59a679a

Please sign in to comment.