Skip to content

Commit

Permalink
add an API example for putting an image as overlay with a WCS given a…
Browse files Browse the repository at this point in the history
…s JS objec
  • Loading branch information
bmatthieu3 committed Jul 12, 2024
1 parent 7da91d7 commit c8a4fb2
Show file tree
Hide file tree
Showing 54 changed files with 1,316 additions and 831 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
## 3.4.3-beta

* [bugfix] zoom control buttons
* [feat] save a MOC as a JSON file from the UI <https://github.com/cds-astro/aladin-lite/issues/154>
* [feat] save a source selection from the measurement table as a CSV file
* [feat] allow to display jpeg/jpg images with a wcs passed as a JS dictionary: <https://github.com/cds-astro/aladin-lite/issues/173>

## 3.4.2-beta

Expand Down
2 changes: 2 additions & 0 deletions assets/icons/HiPS.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion examples/al-displayJPG.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
'https://noirlab.edu/public/media/archives/images/large/noirlab1912a.jpg',
// no options
{
transparency: 0.6,
transparency: 1.0,
},
// A callback fn once the overlay is set
callback
Expand Down
46 changes: 46 additions & 0 deletions examples/al-image-with-WCS.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<!doctype html>
<html>
<head>
</head>
<body>
<div id="aladin-lite-div" style="width: 1024px; height: 768px"></div>
<script type="module">
import A from '../src/js/A.js';
A.init.then(() => {
let aladin = A.aladin('#aladin-lite-div', {fov: 30, survey: "CDS/P/GALEXGR6/AIS/FUV", target: "280 +0", projection: "AIT", showShareControl:true, showContextMenu:true});

aladin.setOverlayImageLayer(A.image(
"https://nova.astrometry.net/image/25038473?filename=M61.jpg",
{
name: "M61",
imgFormat: 'jpeg',
wcs: {
NAXIS: 0, // Minimal header
CTYPE1: 'RA---TAN', // TAN (gnomic) projection + SIP distortions
CTYPE2: 'DEC--TAN', // TAN (gnomic) projection + SIP distortions
EQUINOX: 2000.0, // Equatorial coordinates definition (yr)
LONPOLE: 180.0, // no comment
LATPOLE: 0.0, // no comment
CRVAL1: 185.445488837, // RA of reference point
CRVAL2: 4.47896032431, // DEC of reference point
CRPIX1: 588.995094299, // X reference pixel
CRPIX2: 308.307905197, // Y reference pixel
CUNIT1: 'deg', // X pixel scale units
CUNIT2: 'deg', // Y pixel scale units
CD1_1: -0.000223666022989, // Transformation matrix
CD1_2: 0.000296578064584, // no comment
CD2_1: -0.000296427555509, // no comment
CD2_2: -0.000223774308964, // no comment
NAXIS1: 1080, // Image width, in pixels.
NAXIS2: 705 // Image height, in pixels.
},
successCallback: (ra, dec, fov, image) => {
aladin.gotoRaDec(ra, dec);
aladin.setFoV(fov * 5)
}
},
));
});
</script>
</body>
</html>
4 changes: 2 additions & 2 deletions examples/al-init-custom-options.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
reticleColor: '#ff89ff', // change reticle color
reticleSize: 64, // change reticle size
showContextMenu: true,
showCooGrid: true,
showFrame: true,
showZoomControl:true
showZoomControl:true,
showSettingsControl:true,
}
);

Expand Down
2 changes: 2 additions & 0 deletions examples/al-moc-sdss9.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
// moc is ready
console.log(moc.contains(205.9019247, +2.4492764));
console.log(moc.contains(-205.9019247, +2.4492764));

console.log(moc.serialize("json"))
});
var moc10 = A.MOCFromURL('https://alasky.unistra.fr/MocServer/query?ivorn=ivo%3A%2F%2FCDS%2FV%2F139%2Fsdss9&get=moc&order=11&fmt=fits', {color: '#ffffff', perimeter: true, fillColor: '#aabbcc', opacity: 0.3, lineWidth: 3});
var moc9 = A.MOCFromURL('https://alasky.unistra.fr/MocServer/query?ivorn=ivo%3A%2F%2FCDS%2FV%2F139%2Fsdss9&get=moc&order=4&fmt=fits', {color: '#00ff00', opacity: 0.5, lineWidth: 3, perimeter: true});
Expand Down
2 changes: 2 additions & 0 deletions src/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ async-channel = "1.8.0"
mapproj = "0.3.0"
fitsrs = "0.2.9"
wcs = { git = "https://github.com/cds-astro/wcs-rs", branch = 'master' }
#wcs = { path = "../../../wcs" }

colorgrad = "0.6.2"

[features]
Expand Down
5 changes: 2 additions & 3 deletions src/core/al-api/src/fov.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ use wasm_bindgen::prelude::*;

use serde::{Deserialize, Serialize};

#[derive(Deserialize, Serialize)]
#[derive(Clone)]
#[derive(Deserialize, Serialize, Clone, Debug)]
#[wasm_bindgen]
pub struct CenteredFoV {
/// Position of the field of view
Expand All @@ -12,4 +11,4 @@ pub struct CenteredFoV {

/// Aperture
pub fov: f64,
}
}
10 changes: 0 additions & 10 deletions src/core/al-api/src/hips.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,6 @@ impl HiPSCfg {
}
}

#[derive(Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct FITSCfg {
/// Layer name
pub layer: String,
pub url: String,
/// Its color
pub meta: ImageMetadata,
}

use crate::coo_system::CooSystem;

#[derive(Deserialize, Debug, Clone)]
Expand Down
14 changes: 4 additions & 10 deletions src/core/al-api/src/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,10 @@ use serde::{Deserialize, Serialize};
use crate::fov::CenteredFoV;
// This struct is intended to be returned
// to the javascript to create a layer based on it
#[derive(Deserialize, Serialize)]
#[derive(Clone)]
#[derive(Deserialize, Serialize, Clone)]
pub struct ImageParams {
pub centered_fov: CenteredFoV,

// a new layer
pub layer: String,
// and its url
pub url: String,

pub automatic_min_cut: f32,
pub automatic_max_cut: f32,
}
pub min_cut: Option<f32>,
pub max_cut: Option<f32>,
}
32 changes: 32 additions & 0 deletions src/core/al-core/src/convert.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
pub trait Cast<T>: Clone + Copy {
fn cast(self) -> T;
}

impl Cast<f32> for u8 {
fn cast(self) -> f32 {
self as f32
}
}
impl Cast<f32> for i16 {
fn cast(self) -> f32 {
self as f32
}
}

impl Cast<f32> for i32 {
fn cast(self) -> f32 {
self as f32
}
}

impl Cast<f32> for f32 {
fn cast(self) -> f32 {
self
}
}

impl Cast<f32> for f64 {
fn cast(self) -> f32 {
self as f32
}
}
42 changes: 18 additions & 24 deletions src/core/al-core/src/image/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ pub trait ImageFormat {
const INTERNAL_FORMAT: i32;
const TYPE: u32;

const CHANNEL_TYPE: ChannelType;

/// Creates a JS typed array which is a view into wasm's linear memory at the slice specified.
/// This function returns a new typed array which is a view into wasm's memory. This view does not copy the underlying data.
///
Expand All @@ -42,6 +44,8 @@ impl ImageFormat for RGB8U {
const INTERNAL_FORMAT: i32 = WebGlRenderingCtx::RGB as i32;
const TYPE: u32 = WebGlRenderingCtx::UNSIGNED_BYTE;

const CHANNEL_TYPE: ChannelType = ChannelType::RGB8U;

fn decode(raw_bytes: &[u8]) -> Result<Bytes<'_>, &'static str> {
let mut decoder = jpeg::Decoder::new(raw_bytes);
let bytes = decoder
Expand Down Expand Up @@ -70,30 +74,7 @@ impl ImageFormat for RGBA8U {
const INTERNAL_FORMAT: i32 = WebGlRenderingCtx::RGBA as i32;
const TYPE: u32 = WebGlRenderingCtx::UNSIGNED_BYTE;

fn decode(raw_bytes: &[u8]) -> Result<Bytes<'_>, &'static str> {
let mut decoder = jpeg::Decoder::new(raw_bytes);
let bytes = decoder
.decode()
.map_err(|_| "Cannot decoder png. This image may not be compressed.")?;

Ok(Bytes::Owned(bytes))
}

type ArrayBufferView = js_sys::Uint8Array;

unsafe fn view(s: &[<Self::P as Pixel>::Item]) -> Self::ArrayBufferView {
Self::ArrayBufferView::view(s)
}
}
#[cfg(feature = "webgl1")]
impl ImageFormat for RGBA8U {
type P = [u8; 4];

const NUM_CHANNELS: usize = 4;

const FORMAT: u32 = WebGlRenderingCtx::RGBA as u32;
const INTERNAL_FORMAT: i32 = WebGlRenderingCtx::RGBA as i32;
const TYPE: u32 = WebGlRenderingCtx::UNSIGNED_BYTE;
const CHANNEL_TYPE: ChannelType = ChannelType::RGBA8U;

fn decode(raw_bytes: &[u8]) -> Result<Bytes<'_>, &'static str> {
let mut decoder = jpeg::Decoder::new(raw_bytes);
Expand Down Expand Up @@ -125,6 +106,8 @@ impl ImageFormat for RGBA32F {
#[cfg(feature = "webgl1")]
const INTERNAL_FORMAT: i32 = WebGlRenderingCtx::RGBA as i32;

const CHANNEL_TYPE: ChannelType = ChannelType::RGBA32F;

const TYPE: u32 = WebGlRenderingCtx::FLOAT;

fn decode(raw_bytes: &[u8]) -> Result<Bytes<'_>, &'static str> {
Expand All @@ -151,6 +134,8 @@ impl ImageFormat for RGB32F {
#[cfg(feature = "webgl1")]
const INTERNAL_FORMAT: i32 = WebGlRenderingCtx::RGB as i32;

const CHANNEL_TYPE: ChannelType = ChannelType::RGB32F;

const TYPE: u32 = WebGlRenderingCtx::FLOAT;

fn decode(raw_bytes: &[u8]) -> Result<Bytes<'_>, &'static str> {
Expand Down Expand Up @@ -183,6 +168,8 @@ impl ImageFormat for R32F {

const TYPE: u32 = WebGlRenderingCtx::FLOAT;

const CHANNEL_TYPE: ChannelType = ChannelType::R32F;

fn decode(raw_bytes: &[u8]) -> Result<Bytes<'_>, &'static str> {
Ok(Bytes::Borrowed(raw_bytes))
}
Expand Down Expand Up @@ -215,6 +202,8 @@ impl ImageFormat for R64F {

const TYPE: u32 = WebGlRenderingCtx::FLOAT;

const CHANNEL_TYPE: ChannelType = ChannelType::R64F;

fn decode(raw_bytes: &[u8]) -> Result<Bytes<'_>, &'static str> {
Ok(Bytes::Borrowed(raw_bytes))
}
Expand All @@ -239,6 +228,8 @@ impl ImageFormat for R8UI {
const INTERNAL_FORMAT: i32 = WebGlRenderingCtx::R8UI as i32;
const TYPE: u32 = WebGlRenderingCtx::UNSIGNED_BYTE;

const CHANNEL_TYPE: ChannelType = ChannelType::R8UI;

fn decode(raw_bytes: &[u8]) -> Result<Bytes<'_>, &'static str> {
Ok(Bytes::Borrowed(raw_bytes))
}
Expand All @@ -262,6 +253,7 @@ impl ImageFormat for R16I {
const FORMAT: u32 = WebGlRenderingCtx::RED_INTEGER as u32;
const INTERNAL_FORMAT: i32 = WebGlRenderingCtx::R16I as i32;
const TYPE: u32 = WebGlRenderingCtx::SHORT;
const CHANNEL_TYPE: ChannelType = ChannelType::R16I;

fn decode(raw_bytes: &[u8]) -> Result<Bytes<'_>, &'static str> {
Ok(Bytes::Borrowed(raw_bytes))
Expand All @@ -287,6 +279,8 @@ impl ImageFormat for R32I {
const INTERNAL_FORMAT: i32 = WebGlRenderingCtx::R32I as i32;
const TYPE: u32 = WebGlRenderingCtx::INT;

const CHANNEL_TYPE: ChannelType = ChannelType::R32I;

fn decode(raw_bytes: &[u8]) -> Result<Bytes<'_>, &'static str> {
Ok(Bytes::Borrowed(raw_bytes))
}
Expand Down
11 changes: 7 additions & 4 deletions src/core/al-core/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
extern crate futures;
extern crate jpeg_decoder as jpeg;
extern crate png;
extern crate serde_json;
extern crate futures;
extern crate wasm_streams;

pub mod convert;
pub mod image;
mod object;
pub mod shader;
Expand All @@ -17,8 +18,8 @@ pub mod colormap;
pub use colormap::{Colormap, Colormaps};

pub use texture::pixel;
pub use texture::{Texture2D, Texture2DBound};
pub use texture::Texture2DArray;
pub use texture::{Texture2D, Texture2DBound};

pub use webgl_ctx::WebGlContext;

Expand All @@ -36,12 +37,14 @@ pub use object::vertex_array_object::vao::{

pub trait Abort {
type Item;
fn unwrap_abort(self) -> Self::Item where Self: Sized;
fn unwrap_abort(self) -> Self::Item
where
Self: Sized;
}

impl<T> Abort for Option<T> {
type Item = T;

#[inline]
fn unwrap_abort(self) -> Self::Item {
use std::process;
Expand Down
27 changes: 0 additions & 27 deletions src/core/al-core/src/log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,30 +23,3 @@ pub fn console_warn(s: impl Into<JsValue>) {
pub fn console_error(s: impl Into<JsValue>) {
web_sys::console::error_1(&s.into());
}

#[macro_export]
macro_rules! log {
// The pattern for a single `eval`
($($arg:tt)*) => {
$( self::log(&format!("{:?}", $arg)); )*
};
}

#[macro_export]
macro_rules! inforec {
// The pattern for a single `eval`
// Base case:
($x:tt) => (format!("{:?}", $x));
// `$x` followed by at least one `$y,`
($x:tt, $($y:tt),+) => {
// Call `find_min!` on the tail `$y`
( format!( "{} {}", inforec!($x), inforec!($($y),+) ) );
}
}

#[macro_export]
macro_rules! info {
($($arg:tt),*) => {
self::log( &inforec!( $( $arg ),* ) );
};
}
Loading

0 comments on commit c8a4fb2

Please sign in to comment.