Skip to content

Commit

Permalink
UI: expose gamma slider. Fix #190
Browse files Browse the repository at this point in the history
  • Loading branch information
bmatthieu3 committed Nov 4, 2024
1 parent 73e970c commit d8940dc
Show file tree
Hide file tree
Showing 11 changed files with 100 additions and 51 deletions.
4 changes: 2 additions & 2 deletions examples/al-save-colormap.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@

aladin.setImageLayer(survey2);

/*setTimeout(() => {
setTimeout(() => {
aladin.removeHiPSFromFavorites(survey3)
}, 10000);*/
}, 5000);


aladin.addColormap('mycmap', ["lightblue", "red", "violet", "lightgreen"])
Expand Down
5 changes: 5 additions & 0 deletions src/core/src/renderable/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,7 @@ impl Layers {
.ok_or(err_layer_not_found)?;
self.layers.remove(id_layer);

al_core::log(&format!("remove layer {:?}", id_layer));
// Loop over all the meta for its longitude reversed property
// and set the camera to it if there is at least one
let longitude_reversed = self.meta.values().any(|meta| meta.longitude_reversed);
Expand All @@ -335,9 +336,13 @@ impl Layers {
// Check if the url is still used
let id_still_used = self.ids.values().any(|rem_id| rem_id == &id);
if id_still_used {
al_core::log("still used");

// Keep the resource whether it is a HiPS or a FITS
Ok(id_layer)
} else {
al_core::log("not needed");

// Resource not needed anymore
if let Some(hips) = self.hipses.remove(&id) {
// A HiPS has been found and removed
Expand Down
47 changes: 27 additions & 20 deletions src/js/Aladin.js
Original file line number Diff line number Diff line change
Expand Up @@ -424,12 +424,11 @@ export let Aladin = (function () {
}

// at least id or url is defined
let key = id || url;
let key = name || id || url;

// Merge what is already in the cache for that HiPS with new properties
// coming from the MOCServer
let hips = new HiPS(key, key, cachedSurvey)
self.hipsCache.append(key, hips);
self.hipsCache.append(key, cachedSurvey);
}
};
this._setupUI(options);
Expand Down Expand Up @@ -1443,9 +1442,11 @@ export let Aladin = (function () {
};

Aladin.prototype.removeUIByName = function(name) {
let elt = this.ui.find((elm) => elm.name === name)
if (elt) {
elt.remove()
let index = this.ui.findIndex((elm) => elm.name === name)
if (index >= 0) {
this.ui[index].remove();

this.ui.splice(index, 1);
}
};

Expand Down Expand Up @@ -1540,11 +1541,12 @@ export let Aladin = (function () {
maxOrder,
options
) {
let hips = new HiPS(id, url || id, { name, maxOrder, url, cooFrame, ...options })
let hipsOptions = { id, name, maxOrder, url, cooFrame, ...options };
let hips = new HiPS(id, url || id, hipsOptions)

if (this instanceof Aladin && !this.hipsCache.contains(id)) {
if (this instanceof Aladin && !this.hipsCache.contains(hips.name)) {
// Add it to the cache as soon as possible if we have a reference to the aladin object
this.hipsCache.append(hips.id, hips)
this.hipsCache.append(hips.name, hipsOptions)
}

return hips;
Expand Down Expand Up @@ -1591,11 +1593,14 @@ export let Aladin = (function () {
console.warn(survey + ' is among the list of HiPS currently in the view.');
}

let id;
if (typeof survey !== "string") {
survey = survey.id;
id = survey.name
} else {
id = survey
}

this.hipsCache.delete(survey);
this.hipsCache.delete(id);
}

/**
Expand Down Expand Up @@ -1847,9 +1852,9 @@ export let Aladin = (function () {
const idOrUrl = urlOrHiPSOrFITS;
// many cases here
// 1/ It has been already added to the cache
let cachedLayer = hipsCache.get(idOrUrl)
if (cachedLayer) {
imageLayer = cachedLayer
let cachedOptions = hipsCache.get(idOrUrl)
if (cachedOptions) {
imageLayer = A.HiPS(idOrUrl, cachedOptions);
} else {
// 2/ Not in the cache, then we create the hips from this url/id and
// go to the case 3
Expand All @@ -1860,18 +1865,20 @@ export let Aladin = (function () {
// 3/ It is an image survey.
imageLayer = urlOrHiPSOrFITS;

let cachedLayer = hipsCache.get(imageLayer.id)
if (!cachedLayer) {
hipsCache.append(imageLayer.id, imageLayer)
let cachedLayerOptions = hipsCache.get(imageLayer.name)

if (!cachedLayerOptions) {
hipsCache.append(imageLayer.name, imageLayer.options)
} else {
// first set the options of the cached layer to the one of the user
cachedLayer.setOptions(imageLayer.options)
// if it is in the cache we get it from the cache
imageLayer = cachedLayer
imageLayer = A.HiPS(imageLayer.id, cachedLayerOptions)
}
}
let imageLayerCopied = Object.assign(Object.create(Object.getPrototypeOf(imageLayer)), imageLayer)
imageLayerCopied.layer = layer;

return this.view.setOverlayImageLayer(imageLayer, layer);
return this.view.setOverlayImageLayer(imageLayerCopied, layer);
};

/**
Expand Down
2 changes: 1 addition & 1 deletion src/js/DefaultHiPSList.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ export let HiPSList = (function () {
{
creatorDid: "ivo://CDS/P/allWISE/color",
id: "P/allWISE/color",
name: "AllWISE color",
name: "AllWISE color Red (W4) , Green (W2) , Blue (W1) from raw Atlas Images",
maxOrder: 8,
tileSize: 512,
imgFormat: "jpeg",
Expand Down
6 changes: 3 additions & 3 deletions src/js/HiPS.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ export let HiPS = (function () {
this.id = id;

this.options = options;
this.name = (options && options.name) || undefined;
this.name = (options && options.name) || id;
this.startUrl = options.startUrl;

this.slice = 0;
Expand Down Expand Up @@ -949,8 +949,8 @@ export let HiPS = (function () {
let self = this;
let hipsCache = this.view.aladin.hipsCache;

if (hipsCache.contains(self.id)) {
hipsCache.append(self.id, this)
if (hipsCache.contains(self.name)) {
hipsCache.append(self.name, this.options)
}
};

Expand Down
4 changes: 2 additions & 2 deletions src/js/HiPSCache.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ export let HiPSCache = (function () {
/*
* key can be a CDS ID or an url. TODO could be an options.name too.
*/
HiPSCache.prototype.append = function (key, image) {
this.cache[key] = image;
HiPSCache.prototype.append = function (key, options) {
this.cache[key] = options;

ALEvent.HIPS_CACHE_UPDATED.dispatchedTo(document.body);
};
Expand Down
1 change: 1 addition & 0 deletions src/js/View.js
Original file line number Diff line number Diff line change
Expand Up @@ -1830,6 +1830,7 @@ export let View = (function () {
View.prototype.removeImageLayer = function (layer) {
// Get the survey to remove to dissociate it from the view
let imageLayer = this.imageLayers.get(layer);

if (imageLayer === undefined) {
// there is nothing to remove
return;
Expand Down
28 changes: 21 additions & 7 deletions src/js/gui/Box/HiPSBrowserBox.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,26 +63,31 @@ export class HiPSBrowserBox extends Box {
self._filterHiPSList({})
});



const _parseHiPS = (e) => {
const value = e.target.value;

let image;
let image, name;
// A user can put an url
try {
image = new URL(value).href;
name = image;
} catch (e) {
// Or he can select a HiPS from the list given
const hips = HiPSBrowserBox.HiPSList[value];
if (hips) {
image = hips.ID || hips.hips_service_url;
name = hips.obs_title || hips.ID;
} else {
// Finally if not found, interpret the input text value as the HiPS (e.g. ID)
image = value;
name = value;
}
}

if (image) {
self._addHiPS(image)
self._addHiPS(image, name)
self.searchDropdown.update({title: value});
}
};
Expand Down Expand Up @@ -116,6 +121,11 @@ export class HiPSBrowserBox extends Box {
searchDropdown.removeClass('aladin-valid')
searchDropdown.removeClass('aladin-not-valid')
},
change(e) {
e.stopPropagation();
e.preventDefault()
_parseHiPS(e)
}
},
});

Expand Down Expand Up @@ -273,10 +283,11 @@ export class HiPSBrowserBox extends Box {
};
}

_addHiPS(id) {
console.log("add hips", id)
_addHiPS(id, name) {
let self = this;

let hips = A.imageHiPS(id, {
name,
successCallback: (hips) => {
self.searchDropdown.removeClass('aladin-not-valid');
self.searchDropdown.addClass('aladin-valid');
Expand All @@ -288,6 +299,8 @@ export class HiPSBrowserBox extends Box {
}
})

self.aladin.removeUIByName("cube_displayer" + hips.layer)

if (!hips.cubeDepth)
return;

Expand Down Expand Up @@ -321,10 +334,10 @@ export class HiPSBrowserBox extends Box {
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",
name: "cube_slicer" + hips.layer,
ticks: [idxSlice],
tooltip: {content: (idxSlice + 1) + '/' + numSlices, position: {direction: 'bottom'}},
min: 0,
Expand Down Expand Up @@ -370,14 +383,15 @@ export class HiPSBrowserBox extends Box {

let cubeDisplayer = A.box({
close: true,
name: 'player' + hips.name,
name: "cube_displayer" + hips.layer,
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) => {
Expand Down
18 changes: 17 additions & 1 deletion src/js/gui/Box/HiPSSettingsBox.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
*
*****************************************************************************/
import { Form } from "../Widgets/Form.js";
import { ColorCfg } from "../../ColorCfg.js";
import { Box } from "../Widgets/Box.js";
import { ALEvent } from "../../events/ALEvent.js";
import opacityIconUrl from '../../../../assets/icons/opacity.svg';
Expand Down Expand Up @@ -165,6 +164,21 @@ import { ColorCfg } from "../../ColorCfg.js";
slider.update({value: contrast, tooltip: {content: `${contrast.toFixed(3)}`, position: {direction: 'right'}}})
}
},
{
label: 'gamma:',
tooltip: {content: 'gamma', position: {direction: 'right'}},
name: 'gamma',
type: 'range',
min: 0.1,
max: 10.0,
ticks: [1.0],
value: 1.0,
change: (e, slider) => {
const gamma = +e.target.value
self.options.layer.setGamma(gamma)
slider.update({value: gamma, tooltip: {content: `${gamma.toFixed(3)}`, position: {direction: 'right'}}})
}
},
]
});
let pixelSettingsContent = new Form({
Expand Down Expand Up @@ -274,6 +288,7 @@ import { ColorCfg } from "../../ColorCfg.js";
this.opacitySettingsContent.set('opacity', hips.getOpacity());
this.luminositySettingsContent.set('brightness', colorCfg.getBrightness());
this.luminositySettingsContent.set('contrast', colorCfg.getContrast());
this.luminositySettingsContent.set('gamma', colorCfg.getGamma());
this.luminositySettingsContent.set('saturation', colorCfg.getSaturation());
}

Expand Down Expand Up @@ -305,6 +320,7 @@ import { ColorCfg } from "../../ColorCfg.js";
this.opacitySettingsContent.set('opacity', hips.getOpacity());
this.luminositySettingsContent.set('brightness', colorCfg.getBrightness());
this.luminositySettingsContent.set('contrast', colorCfg.getContrast());
this.luminositySettingsContent.set('gamma', colorCfg.getGamma());
this.luminositySettingsContent.set('saturation', colorCfg.getSaturation());
}
});
Expand Down
Loading

0 comments on commit d8940dc

Please sign in to comment.