Skip to content

Commit

Permalink
add channel slider when adding from the hips browser window
Browse files Browse the repository at this point in the history
  • Loading branch information
bmatthieu3 committed Oct 22, 2024
1 parent 59a679a commit ce735ab
Show file tree
Hide file tree
Showing 14 changed files with 123 additions and 46 deletions.
28 changes: 3 additions & 25 deletions src/core/src/renderable/hips/d3/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,36 +185,14 @@ impl HpxTileBuffer for HiPS3DBuffer {
}
}

/*
use al_core::shader::SendUniforms;
use al_core::shader::ShaderBound;
impl SendUniforms for HiPS3DBuffer {
// Send only the allsky textures
fn attach_uniforms<'a>(&self, shader: &'a ShaderBound<'a>) -> &'a ShaderBound<'a> {
// Send the textures
/*let textures = &self.base_textures;
for (idx, texture) in textures.iter().enumerate() {
let texture_uniforms = TextureUniforms::new(texture, idx as i32);
shader.attach_uniforms_from(&texture_uniforms);
}*/
//if self.raytracing {
for idx in 0..NUM_HPX_TILES_DEPTH_ZERO {
let cell = HEALPixCell(0, idx as u64);
let texture = self.get(&cell).unwrap();
let texture_uniforms = TextureUniforms::new(texture, idx as i32);
shader.attach_uniforms_from(&texture_uniforms);
}
//}
let shader = shader
.attach_uniforms_from(&self.config)
.attach_uniform("tex", &self.texture_2d_array)
.attach_uniform("num_slices", &(self.texture_2d_array.num_slices as i32));
shader
shader.attach_uniforms_from(&self.config)
}
}
*/

impl Drop for HiPS3DBuffer {
fn drop(&mut self) {
Expand Down
5 changes: 3 additions & 2 deletions src/core/src/renderable/hips/d3/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -580,14 +580,14 @@ impl HiPS3D {
// * there are new available tiles for the GPU
let mut off_idx = 0;

let shader = get_raster_shader(cmap, &self.gl, shaders, &hips_cfg)?.bind(&self.gl);

for (slice_idx, (cell, num_indices)) in self
.slice_indices
.iter()
.zip(self.cells.iter().zip(self.num_indices.iter()))
{
blend_cfg.enable(&self.gl, || {
let shader = get_raster_shader(cmap, &self.gl, shaders, &hips_cfg)?.bind(&self.gl);

shader
.attach_uniform(
"tex",
Expand All @@ -597,6 +597,7 @@ impl HiPS3D {
.get_3d_block_from_slice(*slice_idx as u16)
.unwrap(),
)
.attach_uniforms_from(&self.buffer)
.attach_uniforms_with_params_from(cmap, colormaps)
.attach_uniforms_from(color)
.attach_uniforms_from(camera)
Expand Down
11 changes: 0 additions & 11 deletions src/core/src/renderable/hips/d3/texture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,6 @@ impl HpxTexture3D {
};
let m1 = (!m2) & !(1 << (31 - slice_idx));

al_core::log(&format!("m1 {:#x} m2 {:#x} {:?}", m1, m2, slice_idx));

let lb = ((block & m1) >> (32 - slice_idx)) as u32;
let rb = (block & m2) as u32;

Expand All @@ -91,15 +89,6 @@ impl HpxTexture3D {
let no_more_left_bits = slice_idx - (lb_trailing_zeros as u32) == 0;
let no_more_right_bits = slice_idx + (rb_leading_zeros as u32) == 31;

al_core::log(&format!(
"{:?} {:?} slice idx {:?}, {:x?} rb {:?}",
no_more_left_bits,
no_more_right_bits,
slice_idx,
lb,
lb_trailing_zeros as u32
));

match (no_more_left_bits, no_more_right_bits) {
(false, false) => {
if lb_trailing_zeros <= rb_leading_zeros {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ out vec4 out_frag_color;
uniform float opacity;

void main() {
vec4 color = get_colormap_from_grayscale_texture(frag_uv);
vec4 color = get_colormap_from_grayscale_texture(vec3(frag_uv.xy, mod(frag_uv.z, 32.0) / 32.0));

out_frag_color = color;
out_frag_color.a = out_frag_color.a * opacity;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ out vec4 out_frag_color;
uniform float opacity;

void main() {
vec4 color = get_colormap_from_grayscale_texture(frag_uv);
vec4 color = get_colormap_from_grayscale_texture(vec3(frag_uv.xy, mod(frag_uv.z, 32.0) / 32.0));

out_frag_color = color;
out_frag_color.a = out_frag_color.a * opacity;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ out vec4 out_frag_color;
uniform float opacity;

void main() {
vec4 color = get_colormap_from_grayscale_texture(frag_uv);
vec4 color = get_colormap_from_grayscale_texture(vec3(frag_uv.xy, mod(frag_uv.z, 32.0) / 32.0));

out_frag_color = color;
out_frag_color.a = out_frag_color.a * opacity;
Expand Down
7 changes: 7 additions & 0 deletions src/js/Aladin.js
Original file line number Diff line number Diff line change
Expand Up @@ -1442,6 +1442,13 @@ export let Aladin = (function () {
// see MOC.setView for sending it to outside the UI
};

Aladin.prototype.removeUIByName = function(name) {
let elt = this.ui.find((elm) => elm.name === name)
if (elt) {
elt.remove()
}
};

Aladin.prototype.addUI = function (ui) {
ui = [].concat(ui);

Expand Down
7 changes: 7 additions & 0 deletions src/js/HiPS.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,8 @@ export let HiPS = (function () {
this.name = (options && options.name) || undefined;
this.startUrl = options.startUrl;

this.slice = 0;

if (location instanceof FileList) {
let localFiles = {};
for (var file of location) {
Expand Down Expand Up @@ -290,6 +292,7 @@ export let HiPS = (function () {

// Cube depth
self.cubeDepth = properties && properties.hips_cube_depth && +properties.hips_cube_depth;
self.cubeFirstFrame = properties && properties.hips_cube_firstframe && +properties.hips_cube_firstframe;

// Max order
self.maxOrder =
Expand Down Expand Up @@ -707,6 +710,8 @@ export let HiPS = (function () {
};

HiPS.prototype.setSliceNumber = function(slice) {
this.slice = slice;

if (this.added) {
this.view.wasm.setSliceNumber(this.layer, slice);
}
Expand Down Expand Up @@ -1012,6 +1017,8 @@ export let HiPS = (function () {

return Promise.resolve(this)
.then((hips) => {
this.added = true;

if (hips.successCallback) {
hips.successCallback(hips)
}
Expand Down
4 changes: 2 additions & 2 deletions src/js/MocServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ export class MocServer {
static getAllHiPSes() {
if (!this._allHiPSes) {
const params = {
//expr: "dataproduct_type=image||dataproduct_type=cube",
expr: "dataproduct_type=image",
expr: "dataproduct_type=image||dataproduct_type=cube",
//expr: "dataproduct_type=image",
get: "record",
fmt: "json",
fields: "ID,hips_creator,hips_copyright,hips_order,hips_tile_width,hips_frame,hips_tile_format,obs_title,obs_description,obs_copyright,obs_regime",
Expand Down
2 changes: 1 addition & 1 deletion src/js/View.js
Original file line number Diff line number Diff line change
Expand Up @@ -1693,7 +1693,7 @@ export let View = (function () {
this.imageLayers.delete(layerName);
}

imageLayer.added = true;
//imageLayer.added = true;

this.imageLayers.set(layerName, imageLayer);

Expand Down
93 changes: 92 additions & 1 deletion src/js/gui/Box/HiPSBrowserBox.js
Original file line number Diff line number Diff line change
Expand Up @@ -283,13 +283,104 @@ export class HiPSBrowserBox extends Box {
self.searchDropdown.removeClass('aladin-not-valid');
self.searchDropdown.addClass('aladin-valid');


self.infoCurrentHiPSBtn.update({
disable: false,
action(e) {
window.open(hips.url);
}
})

if (!hips.cubeDepth)
return;

let numSlices = hips.cubeDepth;
let idxSlice = hips.cubeFirstFrame;

hips.setSliceNumber(idxSlice)

let toStr = (n, paddingBegin = false) => {
let s = n.toString();
let maxNumDigits = numSlices.toString().length;

if (s.length < maxNumDigits) {
let r = '&nbsp;'.repeat(maxNumDigits - s.length)
if (paddingBegin) {
s = r + s
} else {
s += r
}
}

return s;
}

let updateSlice = () => {
slicer.update({
value: idxSlice,
tooltip: {content: (idxSlice + 1) + '/' + numSlices, position: {direction: 'bottom'}},
})

hips.setSliceNumber(idxSlice)
cubeDisplayer.update({position: cubeDisplayer.position, content: Layout.horizontal([prevBtn, nextBtn, slicer, toStr(idxSlice + 1, true) + '/' + toStr(numSlices, false)])})
};

let slicer = Input.slider({
label: "Slice",
name: "cube slicer",
ticks: [idxSlice],
tooltip: {content: (idxSlice + 1) + '/' + numSlices, position: {direction: 'bottom'}},
min: 0,
max: numSlices - 1,
value: idxSlice,
actions: {
change: (e) => {
idxSlice = Math.round(e.target.value);

updateSlice();
},
input: (e) => {
idxSlice = Math.round(e.target.value);

slicer.update({
value: idxSlice,
tooltip: {content: (idxSlice + 1) + '/' + numSlices, position: {direction: 'bottom'}},
})
}
},
cssStyle: {
width: '300px'
}
});

let prevBtn = A.button({
size: 'small',
content: '<',
action(o) {
idxSlice = Math.max(idxSlice - 1, 0);
updateSlice()
}
})

let nextBtn = A.button({
size: 'small',
content: '>',
action(o) {
idxSlice = Math.min(idxSlice + 1, numSlices - 1);
updateSlice()
}
})

let cubeDisplayer = A.box({
close: true,
name: 'player' + hips.name,
header: {
title: 'Player for: ' + hips.name,
draggable: true,
},
content: Layout.horizontal([prevBtn, nextBtn, slicer, toStr(idxSlice + 1, true) + '/' + toStr(numSlices, false)]),
position: {anchor: 'center top'},
});
self.aladin.addUI(cubeDisplayer)
},
errorCallback: (e) => {
self.searchDropdown.removeClass('aladin-valid');
Expand Down
2 changes: 2 additions & 0 deletions src/js/gui/Box/StackBox.js
Original file line number Diff line number Diff line change
Expand Up @@ -964,6 +964,8 @@ export class OverlayStackBox extends Box {
tooltip: { content: "Remove", position: { direction: "top" } },
action(e) {
self.aladin.removeImageLayer(layer.layer);
// remove HiPS cube player if any
self.aladin.removeUIByName("player" + layer.name)
},
});

Expand Down
1 change: 0 additions & 1 deletion src/js/gui/Widgets/Selector.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import { DOMElement } from "./Widget";
import { FSM } from "../../FiniteStateMachine";
import { ActionButton } from "./ActionButton";
import { ContextMenu } from "./ContextMenu";
import { Layout } from "../Layout";

/******************************************************************************
* Aladin Lite project
Expand Down
3 changes: 3 additions & 0 deletions src/js/gui/Widgets/Widget.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
// along with Aladin Lite.
//

import { Utils } from "../../Utils";

/******************************************************************************
* Aladin Lite project
*
Expand All @@ -43,6 +45,7 @@ export class DOMElement {

this.el = element;
this.options = options;
this.name = options && options.name || Utils.uuidv4()
this.isHidden = true;
}

Expand Down

0 comments on commit ce735ab

Please sign in to comment.