Compare commits

...

92 Commits

Author SHA1 Message Date
Matthieu Baumann
4781ffdef2 versionning 3.8 2026-01-31 16:44:06 +01:00
Matthieu Baumann
0a48b016f9 fix cargo clippy 2026-01-31 16:41:32 +01:00
Matthieu Baumann
b699a4bc12 toolbar functional 2026-01-31 16:01:51 +01:00
Matthieu Baumann
95dfcc2cff fix some bgs before beta 2026-01-30 01:11:24 +01:00
Matthieu Baumann
c3eca21aee colorpicker valid tooltip 2026-01-29 23:44:45 +01:00
Matthieu Baumann
4524586145 add toolbar 2026-01-29 19:56:42 +01:00
Matthieu Baumann
13c5dc1aa1 toggle refac + toolbar 2026-01-29 19:21:24 +01:00
Matthieu Baumann
b84a444634 fix local hips bug 2026-01-27 18:58:51 +01:00
Matthieu Baumann
e16f34fdad fix displacement bug when the inertia is triggered after a zoom/unzoom 2026-01-22 16:55:03 +01:00
Matthieu Baumann
c7fcf3d451 HiPS browser adjustements 2026-01-22 14:23:21 +01:00
Matthieu Baumann
7960ef9bde wip hips composite ui 2026-01-22 11:30:34 +01:00
Matthieu Baumann
c2e7838930 fix polygonal selection #339 2026-01-22 11:29:50 +01:00
Matthieu Baumann
601928bc8c add settings for catalogs 2026-01-16 14:46:03 +01:00
Matthieu Baumann
feb892fa03 simplify UI Layout 2026-01-15 18:23:33 +01:00
Matthieu Baumann
60022b2659 enhance hips browsing window stability 2026-01-13 16:51:01 +01:00
Matthieu Baumann
c69aa990b6 add floating tooltip 2026-01-10 15:26:05 +01:00
Matthieu Baumann
42209b166e first commit 2026-01-08 17:56:19 +01:00
Matthieu Baumann
2ef5e47c27 update changelog 2026-01-07 11:39:10 +01:00
Matthieu Baumann
337618d6ef remove logs 2026-01-07 10:09:13 +01:00
Matthieu Baumann
832e8cd4bd bugfix allsky fits not appearing 2026-01-07 10:05:04 +01:00
Matthieu Baumann
28869645cd fix opacity restore in UI, and screen size shrinking 2025-12-12 11:27:03 +01:00
Matthieu Baumann
da8eb6f76e feat: swap layer orders 2025-12-08 17:46:34 +01:00
Matthieu Baumann
0e3a359108 wip base layer 2025-12-08 14:33:31 +01:00
Matthieu Baumann
af89535a91 first commit tree 2025-12-08 14:33:29 +01:00
Matthieu Baumann
8d244596ba 3.7.3-beta 2025-11-05 15:16:36 +01:00
Matthieu Baumann
2a23e83c13 update fitsrs version 2025-10-20 14:41:30 +02:00
Matthieu Baumann
7b8272795d cargo clippy 2025-10-20 10:12:58 +02:00
Matthieu Baumann
4d8b4bfb21 Many fixes
* fix: HiPS3D probing spectra in galactic frame
* ui: new more option in the HiPS selector allowing to change the base layer with an arbitrary HiPS from the UI
* fits: support tile compressed image in bintable extensions (SRCNet feature: https://jira.skatelescope.org/browse/MAN-559)
2025-10-20 09:59:49 +02:00
Matthieu Baumann
ebf8845e83 fix opacity param for PolyLines #316 2025-09-29 15:35:02 +02:00
Matthieu Baumann
f863ac902c fix 0.5 pixel offset when plotting FITS image files 2025-09-29 14:29:38 +02:00
Matthieu Baumann
75123e6bc8 first commit 2025-09-25 10:37:40 +02:00
Matthieu Baumann
d5d7d2a650 3.7.2 2025-09-25 10:36:14 +02:00
Matthieu Baumann
d22c25ea8a add npm deploy routine in package json 2025-09-24 17:13:24 +02:00
Matthieu Baumann
acef664b45 cargo clippy 2025-09-24 17:08:32 +02:00
Matthieu Baumann
9e8db0379b cargo clippy & fmt 2025-09-24 16:59:31 +02:00
Matthieu Baumann
032bb57517 rotation improve perf and numerical instabilities 2025-09-23 17:20:16 +02:00
Matthieu Baumann
f0fc39d2c8 drag outside the projection domain 2025-09-22 15:38:58 +02:00
Matthieu Baumann
2df32cb643 change u-strasbg to cds.unistra urls + enhance/simplify inertia effect 2025-09-22 11:11:12 +02:00
Matthieu Baumann
904d449006 fix: setCuts with imageFormat, Add more HiPS search 2025-09-19 13:59:25 +02:00
Matthieu Baumann
2594aff1b6 fix: crossOrigin set for HtmlImageElement from requestCredentials 2025-09-17 17:02:40 +02:00
Matthieu Baumann
547c5422d4 add minified shaders 2025-09-17 14:26:45 +02:00
Matthieu Baumann
9bcc93877b change changelog 2025-09-15 14:11:52 +02:00
Matthieu Baumann
3f6f247735 add changelog 3.7.0 2025-09-15 11:58:51 +02:00
Matthieu Baumann
c6c7ad44c9 add a prod routine only for internal production deployment on our server. npm run serve should behave like before 2025-09-12 18:04:08 +02:00
Matthieu Baumann
cdc1733c4f Add label to checkbox UI filter enabler 2025-09-12 11:05:32 +02:00
Matthieu Baumann
6e40dbbfc1 update testing snapshots 2025-09-11 17:52:27 +02:00
Matthieu Baumann
e03b16119b several fixes: panic when delaying resources treatments + ICRS sexa 2025-09-11 17:49:05 +02:00
Matthieu Baumann
e3162426be fix: restore polyselect 2025-09-11 15:35:39 +02:00
Matthieu Baumann
5a285dabed cargo clippy 2025-09-11 15:00:53 +02:00
Matthieu Baumann
2d04730623 fix: read pixel for jpg (works like rgba) and fits (1px offset fix + switch bytes order) 2025-09-11 14:31:45 +02:00
bmatthieu3
390c9096d7 NED tap access 2025-09-10 11:52:15 +02:00
Thomas Boch
0e9998a7fc Merge pull request #327 from cds-astro/customize-share-url-function
Customize share URL function
2025-09-10 11:22:42 +02:00
Thomas Boch
22cfc972e2 Add customizeShareURLFunction method and associated example, solves issue #273 2025-09-10 11:19:06 +02:00
Matthieu Baumann
a1386c2a13 fmt 2025-09-09 17:09:55 +02:00
Matthieu Baumann
7bdf0cc912 run clippy + fmt 2025-09-09 17:09:55 +02:00
Matthieu Baumann
634d652c54 final commit 2025-09-09 17:09:55 +02:00
Matthieu Baumann
a10699c271 fix spectral display bug, add a new display/hide icon for the spectra displayer 2025-09-09 17:09:55 +02:00
Matthieu Baumann
52b0b6fc4f wip 2025-09-09 17:09:55 +02:00
Matthieu Baumann
9739b87439 wip commit: not finished 2025-09-09 17:09:55 +02:00
Matthieu Baumann
9db098ce6a add some button to the spectral tool 2025-09-09 17:09:55 +02:00
Matthieu Baumann
b35f79ad0a add button to change unit 2025-09-09 17:09:55 +02:00
Matthieu Baumann
6cab5f9efd compute max/min values per order 2025-09-09 17:09:55 +02:00
Matthieu Baumann
556388e260 refac SpectraDisplayer 2025-09-09 17:09:55 +02:00
Matthieu Baumann
e186713aa1 fix fits f64 tiles hips 2025-09-09 17:09:55 +02:00
Matthieu Baumann
97995834bf widget: add spectral line on mouse hovering on the spectra 2025-09-09 17:09:55 +02:00
Matthieu Baumann
11a87901e1 spectra displayer tool: event handling 2025-09-09 17:09:55 +02:00
Matthieu Baumann
5948e6063b wip spectral tool 2025-09-09 17:09:55 +02:00
bmatthieu3
a91b2154a1 wip: optimisation retrieving tiles from blob + imagebitmap when supported by the browser 2025-09-09 17:09:55 +02:00
bmatthieu3
c6c17f0ba2 cargo clippy 2025-09-09 17:09:55 +02:00
bmatthieu3
6879c22b02 fix warnings 2025-09-09 17:09:55 +02:00
bmatthieu3
48802d4494 fix bug to retrieve the correct spectra under the mouse 2025-09-09 17:09:55 +02:00
Matthieu Baumann
5c6405bf8b WIP: spectra plot 2025-09-09 17:09:55 +02:00
Matthieu Baumann
e4689cf674 get spectra under the cursor 2025-09-09 17:09:55 +02:00
Matthieu Baumann
a4fad91abf increase cubic tile buffer size 2025-09-09 17:09:55 +02:00
Matthieu Baumann
0462a451b3 keep the true data of the cubic tiles. This will be needed to get the spectra at a specific sky location 2025-09-09 17:09:55 +02:00
Matthieu Baumann
1dca5b1845 fix fits parsing and jpg/png cubic tiles 2025-09-09 17:09:55 +02:00
Matthieu Baumann
d73cc1c66d code is compiling, HiPSCube is soon to work again. HiPS3D not yet tested/debugged 2025-09-09 17:09:55 +02:00
Matthieu Baumann
560696a6e1 DO NOT COMPILE. first very basic impl. Need testing. 2025-09-09 17:09:55 +02:00
Matthieu Baumann
258bc47d47 refac tile binary heap 2025-09-09 17:09:55 +02:00
Matthieu Baumann
729f86066e refac querying of HiPS3D tiles and HiPSCube tiles + fix rendering fits 2025-09-09 17:09:55 +02:00
Matthieu Baumann
86002f3e89 fix the HiPSCube work again 2025-09-09 17:09:55 +02:00
Matthieu Baumann
9ea92b3bff refact querying ressources (moc, tiles, allsky map) 2025-09-09 17:09:55 +02:00
Matthieu Baumann
f9722a69ff first HiPS3D commit 2025-09-09 17:09:55 +02:00
Matthieu Baumann
c1dcb4b7e6 fix footprints 2025-09-05 14:53:35 +02:00
Matthieu Baumann
a1a8142b32 API doc: share url + send only requestedOptions 2025-09-05 14:49:48 +02:00
Matthieu Baumann
4294976105 final commit 2025-09-04 14:12:51 +02:00
Matthieu Baumann
12947ba9c9 show sources of obscore table 2025-09-04 14:12:51 +02:00
Matthieu Baumann
dd7ae10e0d new onlyFootprint catalog option. If set to false, pointed sources are also shown with the footprint 2025-09-04 14:12:51 +02:00
Matthieu Baumann
610d22fd23 ellipse intersectBBox very coarse approx 2025-09-04 14:12:51 +02:00
Matthieu Baumann
9558bae25c refac: compose Footprint inside Source and not the opposite 2025-09-04 14:12:51 +02:00
Matthieu Baumann
dd00d0db27 wip commit 2025-09-04 14:12:51 +02:00
Matthieu Baumann
1b10c59dca Allow customizing size and color source from its data content
sourceSize and color properties when creating a new Catalog now accepts a function
allowing to set different sizes/colors in function of the source catalog row
2025-09-02 15:06:08 +02:00
193 changed files with 17452 additions and 5199 deletions

View File

@@ -32,7 +32,7 @@ jobs:
npm install
- name: "Build Aladin Lite"
run: |
npm run build
npm run build:npm
- name: "Publish Aladin Lite to npm"
run: |
npm publish

8
.gitignore vendored
View File

@@ -15,9 +15,11 @@ package-lock.json
src/core/Cargo.lock
src/core/target/
# this rust file is generated when compiling the code, so it is not
# useful to put it on git
src/core/src/shaders.rs
# the tmp glsl files used when minifying the shaders into the wasm (build.rs)
src/glsl/webgl2/**/*.min
src/glsl/webgl2/**/*.tmp
package/
## python related
# python environment

View File

@@ -4,11 +4,48 @@
### What's Changed
* [perf] perform CPU computations with Vec3 and Matrix3 and not 4 dimensions matrices/vectors
* [feat] lockNorthUp Aladin object new option locking the north pole up to the view center
## Released
### 3.8.0
* [fix] horizontal/vertical overlay lines appearing correctly <https://github.com/cds-astro/aladin-lite/issues/334>
* [fix] layer opacity restored when switching from not visible to visible <https://github.com/cds-astro/aladin-lite/issues/332>
* [feat] dark/light mode for the interface
* [fix] polylines shapes size not consistent w.r.t to div size <https://github.com/cds-astro/aladin-lite/issues/331>
* [feat] 'stackChanged' new event informing when a layer has been added, removed or swapped.
* [ui] a new HiPS browser window to search and find HiPS among the HiPS worldwide network.
* [ui] new settings panel for Catalog overlays to change the size, color or shapes of sources
* [ui] possibility to swap 2 layers. Functional but not definitive, it would be better to allow drag and drop amond the layers.
* [fix] fix local HiPS loading.
* [ui] WIP. A toolbar object
* [fix] fix selection of footprints. In the future allow a skew selection mode and a additive selection shortkey.
* [fix] inertia bug when zooming in/out
### 3.7.0-beta
#### What's Changed
* [feat] flip longitude axis global method on Aladin by [@bmatthieu3][bmatthieu3] in <https://github.com/cds-astro/aladin-lite/pull/245>
* [feat] add rotation event by [@ManonMarchand][ManonMarchand] in <https://github.com/cds-astro/aladin-lite/pull/283>
* [docs] just fixing typo in image's doc by [@ManonMarchand][ManonMarchand] in <https://github.com/cds-astro/aladin-lite/pull/284>
* [docs] change to an image with correct astrometry in example by [@ManonMarchand][ManonMarchand] in <https://github.com/cds-astro/aladin-lite/pull/290>
* [docs] clarify use of precision in Coo by [@alexgoff][alexgoff] in <https://github.com/cds-astro/aladin-lite/pull/294>
* [feat] allow setting HiPS CORS and credential options by [@pmatsson][pmatsson] in <https://github.com/cds-astro/aladin-lite/pull/281>
* [feat] color picker and read pixel(s) API methods by [@bmatthieu3][bmatthieu3] in <https://github.com/cds-astro/aladin-lite/pull/280>
* [fix] chandra hips display and akari by [@bmatthieu3][bmatthieu3] in <https://github.com/cds-astro/aladin-lite/pull/306>
* [enhancement] update to the new version of fitsrs by [@bmatthieu3][bmatthieu3] in <https://github.com/cds-astro/aladin-lite/pull/310>
* [fix] 26 channel color offset by [@bmatthieu3][bmatthieu3] in <https://github.com/cds-astro/aladin-lite/pull/320>
* [fix] Circle intersectsBBox by [@emellega][emellega] in <https://github.com/cds-astro/aladin-lite/pull/309>
* [feat] anti aliasing on lines plotted by the GPU by [@bmatthieu3][bmatthieu3] in <https://github.com/cds-astro/aladin-lite/pull/239>
* [feat] source custom color and size from its data content by [@bmatthieu3][bmatthieu3] in <https://github.com/cds-astro/aladin-lite/pull/321>
* [feat] catalog new select method by [@bmatthieu3][bmatthieu3] in <https://github.com/cds-astro/aladin-lite/pull/322>
* [feat] HiPS 3D impl by [@bmatthieu3][bmatthieu3] in <https://github.com/cds-astro/aladin-lite/pull/314>
* [feat] customize share URL function by [@tboch][tboch] in <https://github.com/cds-astro/aladin-lite/pull/327>
* enhancement: use TAP entry point to query NED by [@bmatthieu3][bmatthieu3] in <https://github.com/cds-astro/aladin-lite/pull/257>
* [perf] refac geometrical computations using Vec3/Mat3 instead of Vec4/Mat4 [@bmatthieu3][bmatthieu3] in <https://github.com/cds-astro/aladin-lite/pull/276>
* [fix] distortion at poles by [@bmatthieu3][bmatthieu3] in <https://github.com/cds-astro/aladin-lite/pull/247>
* [feat] new aladin option `lockNorthUp` to keep north pole up [@bmatthieu3][bmatthieu3] in <https://github.com/cds-astro/aladin-lite/pull/272>
### 3.6.3
#### What's Changed

View File

@@ -1,4 +1,4 @@
# [Aladin Lite](https://aladin.u-strasbg.fr/AladinLite)
# [Aladin Lite](https://aladin.cds.unistra.fr/AladinLite)
**An astronomical HiPS visualizer in the browser** <img src="aladin-logo.png" alt="Aladin Lite logo" width="220">
@@ -8,14 +8,14 @@ See [A&A 578, A114 (2015)](https://arxiv.org/abs/1505.02291) and [IVOA HiPS Reco
Aladin Lite is built to be easily embeddable in any web page. It powers astronomical portals like [ESASky](https://sky.esa.int/), [ESO Science Archive portal](http://archive.eso.org/scienceportal/) and [ALMA Portal](https://almascience.eso.org/asax/).
More details on [Aladin Lite documentation page](http://aladin.u-strasbg.fr/AladinLite/doc/).
More details on [Aladin Lite documentation page](http://aladin.cds.unistra.fr/AladinLite/doc/).
A new [API technical documentation](https://cds-astro.github.io/aladin-lite/) is now available.
[![Run tests](https://github.com/cds-astro/aladin-lite/actions/workflows/test.yml/badge.svg)](https://github.com/cds-astro/aladin-lite/actions/workflows/test.yml)
[![API Documentation](https://img.shields.io/badge/API-documentation-blue.svg)](https://cds-astro.github.io/aladin-lite)
[![Release page](https://img.shields.io/badge/Release-download-yellow.svg)](https://aladin.cds.unistra.fr/AladinLite/doc/release/)
Try Aladin Lite [here](https://aladin.u-strasbg.fr/AladinLite).
Try Aladin Lite [here](https://aladin.cds.unistra.fr/AladinLite).
Aladin Lite is made possible thanks to pure Rust core libraries:
* [cdshealpix](https://github.com/cds-astro/cds-healpix-rust) - for HEALPix projection and unprojection to/from sky coordinates

17
assets/icons/enlarge.svg Normal file
View File

@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Uploaded to: SVG Repo, www.svgrepo.com, Generator: SVG Repo Mixer Tools -->
<svg width="800px" height="800px" viewBox="-9 0 32 32" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:sketch="http://www.bohemiancoding.com/sketch/ns">
<title>arrow-up-down</title>
<desc>Created with Sketch Beta.</desc>
<defs>
</defs>
<g id="Page-1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd" sketch:type="MSPage">
<g id="Icon-Set-Filled" sketch:type="MSLayerGroup" transform="translate(-213.000000, -1193.000000)" fill="#000000">
<path d="M225,1217 L222,1217 L222,1201 L225,1201 C225.643,1201 226.293,1201.02 226.687,1200.62 C227.08,1200.23 227.08,1199.6 226.687,1199.2 L220.747,1193.28 C220.537,1193.07 220.259,1192.98 219.984,1193 C219.71,1192.98 219.432,1193.07 219.222,1193.28 L213.283,1199.2 C212.89,1199.6 212.89,1200.23 213.283,1200.62 C213.676,1201.02 214.294,1201 215,1201 L218,1201 L218,1217 L215,1217 C214.357,1217 213.676,1216.98 213.283,1217.38 C212.89,1217.77 212.89,1218.4 213.283,1218.8 L219.222,1224.72 C219.432,1224.93 219.71,1225.02 219.984,1225 C220.259,1225.02 220.537,1224.93 220.747,1224.72 L226.687,1218.8 C227.08,1218.4 227.08,1217.77 226.687,1217.38 C226.293,1216.98 225.737,1217 225,1217" id="arrow-up-down" sketch:type="MSShapeGroup">
</path>
</g>
</g>
</svg>

After

Width:  |  Height:  |  Size: 1.4 KiB

4
assets/icons/folder.svg Normal file
View File

@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?><!-- Uploaded to: SVG Repo, www.svgrepo.com, Generator: SVG Repo Mixer Tools -->
<svg width="800px" height="800px" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M0 1H5L8 3H13V5H3.7457L2.03141 11H4.11144L5.2543 7H16L14 14H0V1Z" fill="#000000"/>
</svg>

After

Width:  |  Height:  |  Size: 322 B

View File

@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<svg viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
<path
d="M15.7955 15.8111L21 21M18 10.5C18 14.6421 14.6421 18 10.5 18C6.35786 18 3 14.6421 3 10.5C3 6.35786 6.35786 3 10.5 3C14.6421 3 18 6.35786 18 10.5Z"
stroke="#ffffff"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
/>
</svg>

After

Width:  |  Height:  |  Size: 393 B

View File

@@ -1,4 +0,0 @@
<?xml version="1.0" encoding="utf-8"?><!-- Uploaded to: SVG Repo, www.svgrepo.com, Generator: SVG Repo Mixer Tools -->
<svg width="800px" height="800px" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
<path d="M15.7955 15.8111L21 21M18 10.5C18 14.6421 14.6421 18 10.5 18C6.35786 18 3 14.6421 3 10.5C3 6.35786 6.35786 3 10.5 3C14.6421 3 18 6.35786 18 10.5Z" stroke="white" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
</svg>

Before

Width:  |  Height:  |  Size: 455 B

View File

@@ -1,4 +1,10 @@
<?xml version="1.0" encoding="utf-8"?><!-- Uploaded to: SVG Repo, www.svgrepo.com, Generator: SVG Repo Mixer Tools -->
<svg width="800px" height="800px" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M15.7955 15.8111L21 21M18 10.5C18 14.6421 14.6421 18 10.5 18C6.35786 18 3 14.6421 3 10.5C3 6.35786 6.35786 3 10.5 3C14.6421 3 18 6.35786 18 10.5Z" stroke="#000000" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
</svg>
<?xml version="1.0" encoding="utf-8"?>
<svg viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
<path
d="M15.7955 15.8111L21 21M18 10.5C18 14.6421 14.6421 18 10.5 18C6.35786 18 3 14.6421 3 10.5C3 6.35786 6.35786 3 10.5 3C14.6421 3 18 6.35786 18 10.5Z"
stroke="#000000"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
/>
</svg>

Before

Width:  |  Height:  |  Size: 469 B

After

Width:  |  Height:  |  Size: 393 B

View File

@@ -1,6 +1,4 @@
<?xml version="1.0" encoding="utf-8"?><!-- Uploaded to: SVG Repo, www.svgrepo.com, Generator: SVG Repo Mixer Tools -->
<svg width="800px" height="800px" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
<path fill-rule="evenodd" clip-rule="evenodd" d="M13.1546 3.36026C12.4835 3.00999 11.5741 3.00459 10.8976 3.35396C8.30466 4.6931 5.95279 6.22853 3.89182 7.93154C3.57311 8.19489 3.34693 8.57758 3.35079 9.02802C3.35463 9.47662 3.58541 9.85419 3.90218 10.1132C5.94604 11.7844 8.29985 13.3212 10.8453 14.6497C11.5165 15 12.4258 15.0054 13.1023 14.656C15.6953 13.3169 18.0472 11.7815 20.1081 10.0785C20.4268 9.8151 20.653 9.43242 20.6492 8.98197C20.6453 8.53338 20.4145 8.1558 20.0978 7.89679C18.0539 6.22562 15.7001 4.6888 13.1546 3.36026ZM11.5859 4.68671C11.8256 4.56294 12.2193 4.56411 12.4606 4.69004C14.8899 5.95796 17.1283 7.41666 19.0675 8.99223C17.1167 10.5932 14.885 12.0471 12.414 13.3233C12.1744 13.4471 11.7807 13.4459 11.5394 13.32C9.11004 12.052 6.87163 10.5933 4.9324 9.01777C6.88321 7.41684 9.11496 5.96285 11.5859 4.68671Z" fill="#000000"/>
<path d="M21.197 12.698C21.4164 13.0494 21.3094 13.512 20.958 13.7314L14.8508 17.5443C14.022 18.0617 12.9938 18.3009 11.9999 18.301C11.006 18.301 9.9777 18.0619 9.14884 17.5446L3.10851 13.7749C2.75711 13.5556 2.65003 13.093 2.86934 12.7416C3.08864 12.3902 3.55128 12.2831 3.90268 12.5024L9.94301 16.2721C10.4872 16.6117 11.2264 16.801 11.9998 16.801C12.7732 16.8009 13.5124 16.6116 14.0564 16.2719L20.1636 12.459C20.515 12.2397 20.9776 12.3467 21.197 12.698Z" fill="#000000"/>
<path d="M21.197 16.4527C21.4164 16.804 21.3094 17.2667 20.9581 17.4861L15.6692 20.7889C14.6115 21.4494 13.2886 21.7602 11.9998 21.7602C10.7111 21.7603 9.38808 21.4497 8.3303 20.7894L3.10843 17.5296C2.75706 17.3102 2.65004 16.8476 2.86938 16.4962C3.08873 16.1448 3.55139 16.0378 3.90276 16.2572L9.12462 19.517C9.89764 19.9995 10.9316 20.2603 11.9998 20.2602C13.068 20.2602 14.1018 19.9993 14.8746 19.5167L20.1635 16.2138C20.5149 15.9944 20.9776 16.1013 21.197 16.4527Z" fill="#000000"/>
<svg width="800px" height="800px" viewBox="0 0 16 16" xmlns="http://www.w3.org/2000/svg" version="1.1" fill="none" stroke="#000000" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5">
<path d="m1.75 11 6.25 3.25 6.25-3.25m-12.5-3 6.25 3.25 6.25-3.25m-6.25-6.25-6.25 3.25 6.25 3.25 6.25-3.25z"/>
</svg>

Before

Width:  |  Height:  |  Size: 2.0 KiB

After

Width:  |  Height:  |  Size: 437 B

15
assets/icons/swap.svg Normal file
View File

@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Uploaded to: SVG Repo, www.svgrepo.com, Generator: SVG Repo Mixer Tools -->
<svg width="800px" height="800px" viewBox="0 0 48 48" xmlns="http://www.w3.org/2000/svg">
<title>swap-vertical-circle</title>
<g id="Layer_2" data-name="Layer 2">
<g id="invisible_box" data-name="invisible box">
<rect width="48" height="48" fill="none"/>
</g>
<g id="icons_Q2" data-name="icons Q2">
<path d="M19.4,36.4l5-4.9a2.1,2.1,0,0,0,.2-2.7,1.9,1.9,0,0,0-3-.2L20,30.2V15a2,2,0,0,0-4,0V30.2l-1.6-1.6a1.9,1.9,0,0,0-3,.2,2.1,2.1,0,0,0,.2,2.7l5,4.9A1.9,1.9,0,0,0,19.4,36.4Z"/>
<path d="M32,33V17.8l1.6,1.6a1.9,1.9,0,0,0,3-.2,2.1,2.1,0,0,0-.2-2.7l-5-4.9a1.9,1.9,0,0,0-2.8,0l-5,4.9a2.1,2.1,0,0,0-.2,2.7,1.9,1.9,0,0,0,3,.2L28,17.8V33a2,2,0,0,0,4,0Z"/>
<path d="M24,42A18,18,0,1,1,42,24,18.1,18.1,0,0,1,24,42m0,4A22,22,0,1,0,2,24,21.9,21.9,0,0,0,24,46Z"/>
</g>
</g>

After

Width:  |  Height:  |  Size: 948 B

6
assets/icons/tree.svg Normal file
View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?><!-- Uploaded to: SVG Repo, www.svgrepo.com, Generator: SVG Repo Mixer Tools -->
<svg fill="#000000" width="800px" height="800px" viewBox="0 0 36 36" version="1.1" preserveAspectRatio="xMidYMid meet" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<title>tree-view-line</title>
<path d="M15,32H11a1,1,0,0,1-1-1V27a1,1,0,0,1,1-1h4a1,1,0,0,1,1,1v4A1,1,0,0,1,15,32Zm-3-2h2V28H12Z" class="clr-i-outline clr-i-outline-path-1"></path><path d="M15,16H11a1,1,0,0,0-1,1v1.2H5.8V12H7a1,1,0,0,0,1-1V7A1,1,0,0,0,7,6H3A1,1,0,0,0,2,7v4a1,1,0,0,0,1,1H4.2V29.8h6.36a.8.8,0,0,0,0-1.6H5.8V19.8H10V21a1,1,0,0,0,1,1h4a1,1,0,0,0,1-1V17A1,1,0,0,0,15,16ZM4,8H6v2H4ZM14,20H12V18h2Z" class="clr-i-outline clr-i-outline-path-2"></path><path d="M34,9a1,1,0,0,0-1-1H10v2H33A1,1,0,0,0,34,9Z" class="clr-i-outline clr-i-outline-path-3"></path><path d="M33,18H18v2H33a1,1,0,0,0,0-2Z" class="clr-i-outline clr-i-outline-path-4"></path><path d="M33,28H18v2H33a1,1,0,0,0,0-2Z" class="clr-i-outline clr-i-outline-path-5"></path>
<rect x="0" y="0" width="36" height="36" fill-opacity="0"/>
</svg>

After

Width:  |  Height:  |  Size: 1.1 KiB

View File

@@ -8,8 +8,8 @@
"dateModified": "2023-01-31",
"issueTracker": "https://github.com/cds-astro/aladin-lite/issues",
"name": "Aladin Lite",
"version": "3.6.5",
"softwareVersion": "3.6.5",
"version": "3.7.3-beta",
"softwareVersion": "3.7.3-beta",
"description": "An astronomical HiPS visualizer in the browser.",
"identifier": "10.5281/zenodo.7638833",
"applicationCategory": "Astronomy, Visualization",

View File

@@ -30,7 +30,7 @@
fov *= 0.997;
rotation += 0.07;
aladin.setViewCenter2NorthPoleAngle(rotation)
aladin.setRotation(rotation)
aladin.setFoV(fov);
if (fov < 3 && fov > 0.5) {

View File

@@ -7,7 +7,7 @@
<script type="module">
import A from '../src/js/A.js';
A.init.then(() => {
let aladin = A.aladin('#aladin-lite-div', {fov: 70,projection: "AIT"});
let aladin = A.aladin('#aladin-lite-div', {target: "23 28 32.46 -00 10 38.9", fov: 4, projection: "AIT"});
let hsc = aladin.newImageSurvey("P/HSC/DR2/deep/g", {colormap:"Purples", imgFormat: "fits"});
aladin.setBaseImageLayer(hsc);

View File

@@ -11,7 +11,7 @@
import A from '../src/js/A.js';
let aladin;
A.init.then(() => {
aladin = A.aladin('#aladin-lite-div', {survey: 'P/DSS2/red', target: 'M50', fov: 0.3});
aladin = A.aladin('#aladin-lite-div', {survey: 'P/DSS2/red', target: '05 23 07.72 -69 46 09.1', fov: 0.3});
var customImg = new Image();
customImg.onload = function() {

View File

@@ -26,8 +26,17 @@
limit: 1000,
//orderBy: 'nb_ref',
onClick: 'showTable',
color: 'yellow',
hoverColor: 'blue',
onlyFootprints: false,
color: (s) => {
let coo = A.coo();
coo.parse(s.data['RAJ2000'] + ' ' + s.data['DEJ2000'])
let a = (0.1 * Math.pow(10, +s.data.logD25)) / 60;
let b = (1.0 / Math.pow(10, +s.data.logR25)) * a
return `rgb(${s.data["logR25"]*255.0}, ${s.data["logR25"]*255.0}, 255)`
},
hoverColor: 'red',
shape: (s) => {
let coo = A.coo();
coo.parse(s.data['RAJ2000'] + ' ' + s.data['DEJ2000'])

View File

@@ -16,8 +16,6 @@
fov: 10,
showContextMenu: true,
fullScreen: true,
showSimbadPointerControl: true,
showShareControl: true,
showSettingsControl: true,
showStackLayerControl: true,
samp: true,
@@ -31,15 +29,21 @@
hoverColor: 'yellow',
selectionColor: 'white',
// Footprint associated to sources
shape: (s) => {
color: (s) => {
// discard drawing a vector for big pm
let totalPmSquared = s.data.pmra*s.data.pmra + s.data.pmdec*s.data.pmdec;
if (totalPmSquared > 6) {
return;
}
let color = rainbowColorMap((totalPmSquared - 2.5) / 2)
return rainbowColorMap((totalPmSquared - 2.5) / 2)
},
shape: (s) => {
// discard drawing a vector for big pm
let totalPmSquared = s.data.pmra*s.data.pmra + s.data.pmdec*s.data.pmdec;
if (totalPmSquared > 6) {
return;
}
// Compute the mean of pm over the catalog sources
if (!pmraMean || !pmdecMean) {
pmraMean = 0, pmdecMean = 0;
@@ -62,13 +66,24 @@
s.dec,
s.ra + dra,
s.dec + ddec,
{color}
)
}
},
() => {
aladin.addCatalog(pmCat);
pmCat.select((s) => {
let totalPmSquared = s.data.pmra*s.data.pmra + s.data.pmdec*s.data.pmdec;
if (totalPmSquared > 6) {
return false;
}
return totalPmSquared < 3.0;
});
});
aladin.addCatalog(pmCat);
});
function rainbowColorMap(value) {
// Ensure value is within range [0, 1]
value = Math.max(0, Math.min(1, value));

View File

@@ -4,13 +4,16 @@
</head>
<body>
<div id="aladin-lite-div" style="width: 512px; height: 512px"></div>
<div id="aladin-lite-div" style="width: 512px; height: 512px">
<div id="toolbar"></div>
</div>
<script type="module">
import showUrl from './../assets/icons/show.svg';
import A from '../src/js/A.js';
let aladin;
A.init.then(() => {
aladin = A.aladin('#aladin-lite-div', {samp: true, survey: "data/hips/PanSTARRS_DR1_color-z-zg-g", fov:2.0, target: "22 35 58.39 +33 57 57.8", showSettingsControl: true, log: false});
aladin = A.aladin('#aladin-lite-div', {toolbar: {divSelector: '#toolbar'}, samp: true, survey: "data/hips/PanSTARRS_DR1_color-z-zg-g", fov:2.0, target: "22 35 58.39 +33 57 57.8", showSettingsControl: true, log: false});
aladin.setProjection('AIT');
let cfht = aladin.createImageSurvey("CFHT", "CFHT MegaCam u+g+r", "./data/hips/CFHT", "equatorial", 10, {imgFormat: 'png'});
let jwst1 = aladin.createImageSurvey("CDS/P/JWST/Stephans-Quintet/NIRCam+MIRI", "JWST NIRCam+MIRI", "data/hips/JWST_NIRCam_MIRI", null, null, {imgFormat: 'png'});
@@ -20,6 +23,16 @@
aladin.setOverlayImageLayer('JWST2', 'overlay_JWST2');
aladin.getOverlayImageLayer('overlay_JWST1').setAlpha(0.0);
aladin.getOverlayImageLayer('overlay_JWST2').setAlpha(0.0);
aladin.toolbar.add('action_custom', {
icon: {
url: showUrl,
size: "medium"
},
action(_) {
console.log("do a thing")
}
});
});
</script>

View File

@@ -37,7 +37,10 @@
colorPicker.value = cat.color;
colorPicker.addEventListener('input', function (e) {
// Change the color of the catalog
cat.updateShape({color: this.value});
console.log(this.value)
cat.updateShape({color: () => {
return '#00ff00'
}});
})
// Define the box

View File

@@ -19,7 +19,6 @@
<meta name="viewport" content="viewport-fit=cover, width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
</head>
<body>
<script src="https://code.jquery.com/jquery-1.10.1.min.js"></script>
<script type="text/javascript">
let aladin;
@@ -38,8 +37,8 @@
<!-- fin temporaire gestion cercle -->
<b>Orientation</b><br>
<button id="hips-coronelli" class="pure-button" name="ref-hips" onclick="longitudeReversed = false; aladin.reverseLongitude(longitudeReversed)">Normal</button><br>
<button id="hips-illenoroc" class="pure-button" name="ref-hips" onclick="longitudeReversed = true; aladin.reverseLongitude(longitudeReversed)">Inversé</button>
<button id="hips-coronelli" class="pure-button" name="ref-hips" onclick="aladin.reverseLongitude(false)">Normal</button><br>
<button id="hips-illenoroc" class="pure-button" name="ref-hips" onclick="aladin.reverseLongitude(true);">Inversé</button>
<br><br>
<b>Constellations</b>
@@ -75,6 +74,13 @@
<a href="#"><img id="coronelli-stars-red" class="catcoro coro-star" src="star_red.png"></a>
<a href="#"><img id="coronelli-stars-blue" class="catcoro coro-star" src="star_blue.png"></a>
</div>
<div>Coronelli2<br>
<!--a id="coronelli-stars" class="pure-button catcoro" href="#">Coronelli</a-->
<a href="#"><img id="coronelli-stars-white" class="catcoro coro-star" src="star_white.png"></a>
<a href="#"><img id="coronelli-stars-yellow" class="catcoro coro-star" src="star_yellow.png"></a><br>
<a href="#"><img id="coronelli-stars-red" class="catcoro coro-star" src="star_red.png"></a>
<a href="#"><img id="coronelli-stars-blue" class="catcoro coro-star" src="star_blue.png"></a>
</div>
<br><br>
<b>Navigation</b>&nbsp;&nbsp;<br><button id="stop">Stop</button>
@@ -99,6 +105,14 @@
<a class="pure-button nav-button nav-goto" href="#">Halley</a><br>
&nbsp;&nbsp;<a class="pure-button nav-button nav-flyto" href="#">Move</a>
</div>
<div id="coo_halley">
<a class="pure-button nav-button nav-goto" href="#">Halley</a><br>
&nbsp;&nbsp;<a class="pure-button nav-button nav-flyto" href="#">Move</a>
</div>
<div id="coo_halley">
<a class="pure-button nav-button nav-goto" href="#">Halley</a><br>
&nbsp;&nbsp;<a class="pure-button nav-button nav-flyto" href="#">Move</a>
</div>
</div>
<style type="text/css"> .aladin-reticleColor { color: rgb(178, 50, 178); font-weight:bold;} </style>
@@ -231,11 +245,10 @@
import {Utils} from '../src/js/Utils';
A.init.then(() => {
var hipsDir="http://alasky.u-strasbg.fr/CDS_P_Coronelli";
aladin = A.aladin("#aladin-lite-div", {showSimbadPointerControl: true, expandLayersControl: true, realFullscreen: true, fov: 100, allowFullZoomout: true, showReticle: false });
aladin.createImageSurvey('Coronelli', 'Coronelli', hipsDir, 'equatorial', 4, {imgFormat: 'jpg'});
aladin.setImageSurvey('Coronelli');
var hipsDir="http://alasky.cds.unistra.fr/CDS_P_Coronelli";
aladin = A.aladin("#aladin-lite-div", {showSimbadPointerControl: true, lockNorthUp: true, reverseLongitude: true, realFullscreen: true, fov: 100, allowFullZoomout: true, showReticle: false });
aladin.createImageSurvey('Coronelli', 'Coronelli', hipsDir, 'equatorial', 4, {imgFormat: 'jpg', minOrder: 3});
aladin.setImageSurvey('Coronelli')
$('#layersControlLeft').show();
$('#layersCL2').show();
$('#layersControlRight').show();
@@ -344,14 +357,14 @@
// listen click on navigation buttons
$('.nav-button').click(function() {
var cooTarget = $(this).parent().attr('id');
var cooTarget = $(this).parent().attr('id');
if ($(this).hasClass("nav-goto")) {
aladin.gotoRaDec(cooNav[cooTarget].ra, cooNav[cooTarget].dec);
}
else if ($(this).hasClass("nav-flyto")) {
aladin.animateToRaDec(cooNav[cooTarget].ra, cooNav[cooTarget].dec, cooNav[cooTarget].time);
}
if ($(this).hasClass("nav-goto")) {
aladin.gotoRaDec(cooNav[cooTarget].ra, cooNav[cooTarget].dec);
}
else if ($(this).hasClass("nav-flyto")) {
aladin.animateToRaDec(cooNav[cooTarget].ra, cooNav[cooTarget].dec, cooNav[cooTarget].time);
}
});
// stop animations

View File

@@ -0,0 +1,22 @@
<!doctype html>
<html>
<head>
<meta name="viewport" content="width=device-width, height=device-height, maximum-scale=1.0, initial-scale=1.0, user-scalable=no">
</head>
<body>
<div id="aladin-lite-div" style="width: 500px; height: 500px"></div>
<script type="text/javascript" src="./../dist/aladin.umd.cjs" charset="utf-8"></script>
<script type="text/javascript">
var aladin;
A.init.then(() => {
aladin = A.aladin('#aladin-lite-div', {fullScreen: true, cooFrame: "ICRSd", showSimbadPointerControl: true, showShareControl: true, showShareControl: true, survey: 'https://alasky.cds.unistra.fr/DSS/DSSColor/', fov: 1.0, target: 'M 20', showContextMenu: true});
// customize share URL function
aladin.customizeShareURLFunction(() => {return 'https://sky.esa.int/esasky/?target=' + aladin.getRaDec()[0] + '%20' + aladin.getRaDec()[1] + '&fov=' + aladin.getFoV()[0]})
});
</script>
</body>
</html>

View File

@@ -10,12 +10,12 @@
import A from '../src/js/A.js';
var aladin;
A.init.then(() => {
aladin = A.aladin('#aladin-lite-div', {projection: 'AIT', cooFrame: 'galactic', fov: 200, target: 'galactic center'});
aladin = A.aladin('#aladin-lite-div', {projection: 'AIT', cooFrame: 'galactic', fov: 200, target: 'galactic center', showSettingsControl: true, showCooGridControl: true});
let dss = aladin.createImageSurvey("DSS blue band", "Color DSS blue HiPS", "http://alasky.cds.unistra.fr/DSS/DSS2-blue-XJ-S/", "equatorial", 9, {imgFormat: 'fits'})
aladin.setBaseImageLayer(dss);
dss.setCuts(2, 10000);
dss.setCuts(2, 100, 'jpeg');
});

View File

@@ -11,11 +11,12 @@
import A from '../src/js/A.js';
let aladin;
A.init.then(() => {
aladin = A.aladin('#aladin-lite-div', {cooFrame: "icrs", log: false, backgroundColor: 'red'});
aladin = A.aladin('#aladin-lite-div', {cooFrame: "icrs", log: false, backgroundColor: 'rgba(0, 0, 0, 255)'});
aladin.displayFITS(
//'https://fits.gsfc.nasa.gov/samples/FOCx38i0101t_c0f.fits', // url of the fits file
'data/fits/panstarrs-g-m61.fits',
//'https://almascience.eso.org/dataPortal/member.uid___A001_X88f_X297.calibrated_final_cont_Sgr_B1off.pbcor.fits',
{
name: 'm61',
colormap: 'viridis'

View File

@@ -39,7 +39,7 @@ Image Opacity: <br/> <input id="slider" type="range" value=1 min=0 max=1 step=0.
//let fits = aladin.displayFITS('http://goldmine.mib.infn.it/data//B/fits/A04_VC1316_ooooog.fits', 'overlay');
let jpg = aladin.displayJPG(
// the JPG to transform to HiPS
'https://noirlab.edu/public/media/archives/images/large/noirlab1912a.jpg',
'https://owncloud.tuebingen.mpg.de/index.php/s/sdxfNgcEaaXoBp7/download/nightskycam3_2025_08_07_05_17_30_healpix1024_red.fits',
// no options
{
transparency: 1.0,

View File

@@ -68,8 +68,8 @@
console.log(pos)
});
aladin.on('layerChanged', function(imageLayer, layer, state){
console.log(imageLayer, layer, state)
aladin.on('stackChanged', function(state) {
console.log(state)
});
cat.sources[0].actionClicked();

View File

@@ -12,7 +12,7 @@
A.init.then(() => {
// Start up Aladin Lite
aladin = A.aladin('#aladin-lite-div', {target: 'M 1', fov: 0.2, showContextMenu: true, fullScreen: true});
var overlay = A.graphicOverlay({color: '#ee2345', lineWidth: 3, lineDash: [2, 2]});
var overlay = A.graphicOverlay({color: 'purple', lineWidth: 3, lineDash: [2, 2]});
aladin.addOverlay(overlay);
overlay.addFootprints([
A.polygon([[83.64287, 22.01713], [83.59872, 22.01692], [83.59852, 21.97629], [83.64295, 21.97629]], {hoverColor: 'green'}),

62
examples/al-hips-3D.html Normal file
View File

@@ -0,0 +1,62 @@
<!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: 8.0, // initial field of view in degrees
target: '10.6875598 +41.1402170', // initial target
cooFrame: 'icrs', // set galactic frame
reticleColor: '#ff89ff', // change reticle color
showContextMenu: true,
showFrame: true,
showZoomControl:true,
showSettingsControl:true,
fullScreen: true,
samp: true,
}
);
hips = aladin.newImageSurvey("https://alasky.cds.unistra.fr/HIPS3D/LGLBSHI-test-compression/", {
successCallback: (hips) => {
//hips.setFrequency({value: 6.374279333565797E-7, unit: "m"}) // GALFA
}
});
// compressed https://alasky.cds.unistra.fr/test-compression-cubes/DHIGLS/
//hips = aladin.newImageSurvey("http://alasky.cds.unistra.fr/DHIGLS");
//hips = aladin.newImageSurvey("https://alasky.cds.unistra.fr/MUSE3D");
// http://alasky.cds.unistra.fr/LGLBSHI
aladin.setImageLayer(hips)
//hips.setFrequency({value: emMin + delta * i, unit: "m"})
//hips.setFrequency({value: 6.374279333565797E-7, unit: "m"}) // MUSE
//hips.setFrequency({value: 0.21101690259115785, unit: "m"}) // DGHILG
/*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>

View File

@@ -30,9 +30,14 @@
}
);
hips = aladin.newImageSurvey("https://alasky.cds.unistra.fr/GALFAHI/GALFAHI-Narrow-DR2/");
hips = aladin.newImageSurvey("https://alasky.cds.unistra.fr/GALFAHI/GALFAHI-Narrow-DR2");
aladin.setImageLayer(hips)
setTimeout(() => {
hips.setSliceNumber(100)
}, 1000)
/*let id;
aladin.on("zoomChanged", () => {
if (id)

View File

@@ -11,7 +11,7 @@
let aladin;
A.init.then(() => {
aladin = A.aladin('#aladin-lite-div', {survey: "data/hips/CDS_P_DSS2_color", target: "05 40 59.12 -02 27 04.1", fov: 2, log: false});
aladin = A.aladin('#aladin-lite-div', {survey: "./data/hips/CDS_P_DSS2_color", target: "05 40 59.12 -02 27 04.1", fov: 2, log: false});
});
</script>

View File

@@ -7,31 +7,55 @@
<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, showSettingsControl: true, showContextMenu:true});
let aladin = A.aladin('#aladin-lite-div', {fov: 30, target: "286.411023328 -37.3460065319", projection: "AIT", showShareControl:true, showSettingsControl: true, showContextMenu:true});
aladin.setOverlayImageLayer(A.image(
"https://nova.astrometry.net/image/25038473?filename=M61.jpg",
"data/img/m82.png",
{
name: "M61",
name: "M82",
wcs: {
NAXIS: 2, // Minimal header
CTYPE1: 'RA---TAN', // TAN (gnomic) projection
CTYPE2: 'DEC--TAN', // TAN (gnomic) projection
NAXIS: 2, // number of axes
NAXIS1: 3000, // image width
NAXIS2: 1918, // image height
CTYPE3: "RGB", // Tell Aladin this is RGB
WCSAXES: 2, // no comment
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.
CRVAL1: 286.411023328, // RA of reference point
CRVAL2: -37.3460065319, // DEC of reference point
CRPIX1: 2264.1858724, // X reference pixel
CRPIX2: 583.14634196, // Y reference pixel
CUNIT1: "deg", // X pixel scale units
CUNIT2: "deg", // Y pixel scale units
CD1_1: -0.00284225200648, // Transformation matrix
CD1_2: 0.00145908284254, // no comment
CD2_1: -0.00145832184852, // no comment
CD2_2: -0.0028440175499, // no comment
A_ORDER: 2, // Polynomial order, axis 1
A_0_0: 0, A_0_1: 0, A_0_2: 1.97760279295e-7,
A_1_0: 0, A_1_1: 5.32298396638e-7,
A_2_0: -2.16045473726e-6,
B_ORDER: 2, // Polynomial order, axis 2
B_0_0: 0, B_0_1: 0, B_0_2: 3.97377848239e-7,
B_1_0: 0, B_1_1: -2.25823401545e-6,
B_2_0: -1.47800507759e-7,
AP_ORDER: 2, // Inv polynomial order, axis 1
AP_0_0: 0.00617616810622,
AP_0_1: -1.68315582233e-6,
AP_0_2: -1.96504899588e-7,
AP_1_0: -5.8320637913e-6,
AP_1_1: -5.26081207663e-7,
AP_2_0: 2.13760782681e-6,
BP_ORDER: 2, // Inv polynomial order, axis 2
BP_0_0: -0.000681183014773,
BP_0_1: -2.15389849968e-7,
BP_0_2: -3.94508397022e-7,
BP_1_0: 4.51837961352e-6,
BP_1_1: 2.24050293101e-6,
BP_2_0: 1.49195269783e-7
},
successCallback: (ra, dec, fov, image) => {
aladin.gotoRaDec(ra, dec);

View File

@@ -13,6 +13,9 @@
aladin = A.aladin(
'#aladin-lite-div',
{
toolbar: {
vertical: false,
},
showSimbadPointerControl: true,
survey: 'https://skies.esac.esa.int/AKARI/color/', // set initial image survey
projection: 'AIT', // set a projection
@@ -23,6 +26,8 @@
reticleSize: 64, // change reticle size
showContextMenu: true,
showShareControl: true,
showCooGridControl: true,
showColorPickerControl: true,
showFrame: true,
showZoomControl:true,
showSettingsControl:true,

View File

@@ -8,7 +8,7 @@
<script type="module">
import A from '../src/js/A.js';
A.init.then(() => {
aladin = A.aladin('#aladin-lite-div', {projection: 'MOL', fullScreen: true, fov: 360, survey: ['P/DM/vizMine', 'P/HST/GOODS/color', 'P/MATLAS/g'], target: '0 0', showProjectionControl: false, showSettingsControl: false, showLayersControl: true, showCooGrid: false, showFrame: false, showCooLocation: false});
aladin = A.aladin('#aladin-lite-div', {projection: 'MOL', lockNorthUp: true, fullScreen: true, showSettingsControl: true, fov: 360, survey: ['P/DM/vizMine', 'P/HST/GOODS/color', 'P/MATLAS/g'], target: '0 0', showProjectionControl: false, showSettingsControl: true, showLayersControl: true, showCooGrid: true, showFrame: false, showCooLocation: false});
});
</script>

View File

@@ -17,6 +17,8 @@
});
aladin.addCatalog(A.catalogFromVizieR("B/assocdata/obscore", "0 +0", 20, {onClick: 'showTable', hoverColor: 'yellow', limit: 1000}))
aladin.addCatalog(A.catalogFromSKAORucio("0 +0", 70, {onClick: 'showTable', hoverColor: 'yellow', limit: 1000}))
});
</script>
</body>

View File

@@ -13,9 +13,15 @@
A.init.then(() => {
aladin = A.aladin('#aladin-lite-div', {target: 'Gamma Cas', fov: 10, cooFrame: 'icrs'});
var overlay = A.graphicOverlay({lineWidth: 2});
var overlay = A.graphicOverlay({color: 'green', lineWidth: 2});
aladin.addOverlay(overlay);
overlay.add(A.polyline([ [2.29452158, 59.14978110], [10.12683778, 56.53733116], [14.1772154, 60.7167403], [21.45396446, 60.23528403], [28.59885697, 63.67010079] ], {color: 'green'}));
overlay.add(A.polyline([ [2.29452158, 59.14978110], [10.12683778, 56.53733116], [14.1772154, 60.7167403], [21.45396446, 60.23528403], [28.59885697, 63.67010079] ], {
opacity: 0.7
}));
aladin.on('rotationChanged', (rot) => {
aladin.setRotation(rot)
})
});
</script>
</body>

View File

@@ -77,7 +77,7 @@
let bValues = [];
let i = 0;
for(var [r, g, b] of base.probe({type: 'line', x1: p.a.x, y1: p.a.y, x2: p.b.x, y2: p.b.y})) {
for(var [r, g, b] of base.probePixels({type: 'line', x1: p.a.x, y1: p.a.y, x2: p.b.x, y2: p.b.y})) {
xValues.push(i)
rValues.push(r)
gValues.push(g)

View File

@@ -10,7 +10,7 @@
<script type="text/javascript">
var aladin;
A.init.then(() => {
aladin = A.aladin('#aladin-lite-div', {fullScreen: true, cooFrame: "ICRSd", showSimbadPointerControl: true, showShareControl: true, showShareControl: true, survey: 'https://alasky.cds.unistra.fr/DSS/DSSColor/', fov: 180, showContextMenu: true});
aladin = A.aladin('#aladin-lite-div', {fullScreen: true, cooFrame: "ICRSd", showSimbadPointerControl: true, showShareControl: true, showShareControl: true, fov: 180, showContextMenu: true});
// manage URL parameters
const searchParams = new URL(document.location).searchParams;
if (searchParams.has('baseImageLayer')) {

View File

@@ -1,8 +1,8 @@
{
"homepage": "https://aladin.u-strasbg.fr/",
"homepage": "https://aladin.cds.unistra.fr/",
"name": "aladin-lite",
"type": "module",
"version": "3.7.0-beta",
"version": "3.8.0-beta",
"description": "An astronomical HiPS visualizer in the browser",
"author": "Thomas Boch and Matthieu Baumann",
"license": "GPL-3",
@@ -30,13 +30,17 @@
"HiPS"
],
"scripts": {
"wasm": "wasm-pack build ./src/core --target web --release --out-name core -- --features webgl2",
"wasm:npm": "wasm-pack build ./src/core --target web --release --out-name core -- --features webgl2",
"wasm:prod": "wasm-pack build ./src/core --target web --release --out-name core -- --features \"webgl2 minify_shaders\" && wasm-opt -Oz --strip-debug --strip-producers --dce -o src/core/pkg/core_bg.wasm src/core/pkg/core_bg.wasm",
"wasm:dev": "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",
"predeploy": "npm run build:prod && rm -rf aladin-lite*.tgz && npm pack",
"deploy": "python3 deploy/deploy.py",
"build": "npm run wasm && vite build",
"build:npm": "npm run wasm:npm && vite build",
"build:prod": "npm run wasm:prod && vite build",
"build:dev": "npm run wasm:dev && vite build",
"build:dbg": "npm run wasm:dbg && vite build",
"dev": "npm run build && vite",
"dev": "npm run build:dev && vite",
"dev:dbg": "npm run build:dbg && vite",
"serve": "npm run dev",
"serve:dbg": "npm run dev:dbg",
@@ -45,14 +49,15 @@
"test:playwright": "npx playwright test",
"test:update-snapshots": "npx playwright test --update-snapshots",
"doc": "jsdoc -c jsdoc.json src/js src/js/shapes src/js/libs/astro && cp aladin-logo.png docs/ && cp jsdoc-custom-style.css docs/ && cp jsdoc-make-responsive.js docs/",
"doc:dev": "npm run doc && open docs/index.html"
"doc:dev": "npm run doc && open docs/index.html",
"analyze": "vite build --mode analyze"
},
"devDependencies": {
"@playwright/test": "^1.47.0",
"docdash": "^2.0.2",
"jsdoc": "^4.0.2",
"rollup-plugin-visualizer": "^6.0.3",
"vite": "^4.3.8",
"vite-plugin-glsl": "^1.1.2",
"vite-plugin-top-level-await": "^1.4.1",
"vite-plugin-wasm": "^3.2.2",
"vite-plugin-wasm-pack": "^0.1.12"

View File

@@ -3,7 +3,7 @@ name = "aladin-lite"
description = "Aladin Lite v3 introduces a new graphical engine written in Rust with the use of WebGL"
license = "BSD-3-Clause"
repository = "https://github.com/cds-astro/aladin-lite"
version = "3.7.0"
version = "3.8.0-beta"
authors = [ "baumannmatthieu0@gmail.com", "matthieu.baumann@astro.unistra.fr",]
edition = "2018"
@@ -18,21 +18,20 @@ futures = "0.3.12"
js-sys = "0.3.47"
wasm-bindgen-futures = "0.4.20"
cgmath = "*"
url-lite = "0.1.0"
serde_json = "1.0.104"
serde-wasm-bindgen = "0.5"
enum_dispatch = "0.3.8"
wasm-bindgen = "=0.2.92"
wasm-streams = "0.3.0"
async-channel = "1.8.0"
mapproj = "0.3.0"
fitsrs = "0.3.4"
colorgrad = "0.6.2"
fitsrs = "0.4.1"
[features]
webgl1 = [ "al-core/webgl1", "al-api/webgl1", "web-sys/WebGlRenderingContext", "web-sys/AngleInstancedArrays", "web-sys/ExtSRgb", "web-sys/OesTextureFloat",]
webgl2 = [ "al-core/webgl2", "al-api/webgl2", "web-sys/WebGl2RenderingContext", "web-sys/WebGlVertexArrayObject", "web-sys/ExtColorBufferFloat",]
dbg = [ "dep:console_error_panic_hook",]
minify_shaders = []
[dev-dependencies]
rand = "0.8"
@@ -50,7 +49,8 @@ version = "0.7.3"
[dependencies.moclib]
package = "moc"
version = "0.17.0"
git = "https://github.com/cds-astro/cds-moc-rust"
branch = "main"
[dependencies.serde]
version = "^1.0.183"
@@ -64,7 +64,7 @@ path = "./al-api"
[dependencies.web-sys]
version = "0.3.56"
features = [ "console", "CssStyleDeclaration", "Document", "Element", "HtmlCollection", "HtmlElement", "HtmlImageElement", "HtmlCanvasElement", "Blob", "ImageBitmap", "ImageData", "CanvasRenderingContext2d", "WebGlBuffer", "WebGlContextAttributes", "WebGlFramebuffer", "WebGlProgram", "WebGlShader", "WebGlUniformLocation", "WebGlTexture", "WebGlActiveInfo", "Headers", "Window", "Request", "RequestInit", "RequestMode", "RequestCredentials", "Response", "XmlHttpRequest", "XmlHttpRequestResponseType", "PerformanceTiming", "Performance", "Url", "ReadableStream", "File", "FileList",]
features = [ "console", "CssStyleDeclaration", "Document", "Element", "HtmlCollection", "CustomEvent", "CustomEventInit", "HtmlElement", "HtmlImageElement", "HtmlCanvasElement", "Blob", "ImageBitmap", "ImageData", "CanvasRenderingContext2d", "WebGlBuffer", "WebGlContextAttributes", "WebGlFramebuffer", "WebGlProgram", "WebGlShader", "WebGlUniformLocation", "WebGlTexture", "WebGlActiveInfo", "Headers", "Window", "Request", "RequestInit", "RequestMode", "RequestCredentials", "Response", "XmlHttpRequest", "XmlHttpRequestResponseType", "PerformanceTiming", "Performance", "Url", "ReadableStream", "File", "FileList",]
[dev-dependencies.image-decoder]
package = "image"
@@ -83,7 +83,7 @@ overflow-checks = false
lto = true
panic = "abort"
incremental = false
codegen-units = 16
codegen-units = 1
rpath = false
[package.metadata.wasm-pack.profile.release]

View File

@@ -1,6 +1,6 @@
[package]
name = "al-api"
version = "3.7.0"
version = "3.8.0"
authors = ["baumannmatthieu0@gmail.com", "matthieu.baumann@astro.unistra.fr"]
edition = "2018"

View File

@@ -48,14 +48,26 @@ pub struct HiPSProperties {
hips_initial_fov: Option<f64>,
hips_initial_ra: Option<f64>,
hips_initial_dec: Option<f64>,
// HiPS cube
hips_cube_depth: Option<u32>,
// HiPS 3D keywords
hips_order_freq: Option<u8>,
hips_tile_depth: Option<u8>,
/// Start of spectral coordinates (in meters)
em_min: Option<f32>,
/// End of spectral coordinates (in meters)
em_max: Option<f32>,
// Parametrable by the user
#[allow(unused)]
min_cutout: Option<f32>,
#[allow(unused)]
max_cutout: Option<f32>,
dataproduct_type: Option<DataproductType>,
creator_did: String,
request_credentials: String,
@@ -63,6 +75,20 @@ pub struct HiPSProperties {
}
impl HiPSProperties {
#[inline(always)]
pub fn get_hips_order_freq(&self) -> Option<u8> {
self.hips_order_freq
}
#[inline(always)]
pub fn get_hips_tile_depth(&self) -> Option<u8> {
self.hips_tile_depth
}
#[inline(always)]
pub fn get_dataproduct_type(&self) -> Option<DataproductType> {
self.dataproduct_type
}
#[inline(always)]
pub fn get_url(&self) -> &str {
&self.url
@@ -137,6 +163,16 @@ impl HiPSProperties {
pub fn get_request_mode(&self) -> &str {
&self.request_mode
}
#[inline(always)]
pub fn get_em_min(&self) -> Option<f32> {
self.em_min
}
#[inline(always)]
pub fn get_em_max(&self) -> Option<f32> {
self.em_max
}
}
#[derive(Deserialize, Debug, Clone, Copy, PartialEq, Eq, Hash)]
@@ -147,11 +183,24 @@ pub enum ImageExt {
Jpeg,
Png,
Webp,
#[serde(alias = "fits.fz")]
FitsFz,
}
#[derive(Deserialize, Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[wasm_bindgen]
#[serde(rename_all = "camelCase")]
pub enum DataproductType {
#[serde(rename = "spectral-cube")]
SpectralCube,
Image,
Cube,
}
impl std::fmt::Display for ImageExt {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
match self {
ImageExt::FitsFz => write!(f, "fits.fz"),
ImageExt::Fits => write!(f, "fits"),
ImageExt::Png => write!(f, "png"),
ImageExt::Jpeg => write!(f, "jpg"),

View File

@@ -1,20 +1,18 @@
[package]
name = "al-core"
version = "3.7.0"
version = "3.8.0"
authors = ["baumannmatthieu0@gmail.com", "matthieu.baumann@astro.unistra.fr"]
edition = "2018"
[dependencies]
js-sys = "0.3.47"
cgmath = "*"
jpeg-decoder = "0.3.0"
png = "0.17.6"
fitsrs = "0.3.4"
fitsrs = "0.4.1"
al-api = { path = "../al-api" }
serde = { version = "^1.0.59", features = ["derive"] }
serde_json = "1.0"
serde-wasm-bindgen = "0.4"
wasm-streams = "0.3.0"
# wasm-streams = "0.3.0"
futures = "0.3.25"
colorgrad = "0.6.2"
wasm-bindgen = "0.2.92"

View File

@@ -35,7 +35,7 @@ where
Ok(())
}
fn get_size(&self) -> (u32, u32) {
(self.image.width(), self.image.height())
fn get_size(&self) -> (u32, u32, u32) {
(self.image.width(), self.image.height(), 1)
}
}

View File

@@ -43,7 +43,7 @@ where
Ok(())
}
fn get_size(&self) -> (u32, u32) {
(self.canvas.width(), self.canvas.height())
fn get_size(&self) -> (u32, u32, u32) {
(self.canvas.width(), self.canvas.height(), 1)
}
}

View File

@@ -1,25 +1,29 @@
use crate::texture::format::TextureFormat;
use crate::texture::format::R8U;
use cgmath::Vector3;
use fitsrs::card::Value;
use fitsrs::hdu::header::extension::image::Image as XImage;
use fitsrs::hdu::data::bintable::data::BinaryTableData;
use fitsrs::hdu::data::bintable::tile_compressed::pixels::Pixels;
use fitsrs::hdu::header::extension::bintable::TileCompressedImage;
use fitsrs::hdu::header::Bitpix;
use fitsrs::hdu::header::Header;
use fitsrs::WCS;
use fitsrs::{Fits, HDU};
use std::borrow::Cow;
use std::fmt::Debug;
use std::io::Cursor;
use std::ops::Range;
use wasm_bindgen::JsValue;
#[derive(Debug)]
pub struct FitsImage<'a> {
// get a reference to the header
pub header: Header<XImage>,
// image size
// Margin values for HiPS3D cubic tiles
pub trim1: u32,
pub trim2: u32,
pub trim3: u32,
// Image/cube size
pub width: u32,
pub height: u32,
pub depth: u32,
// bitpix
// Bitpix
pub bitpix: Bitpix,
// 1.0 by default
pub bscale: f32,
@@ -29,8 +33,10 @@ pub struct FitsImage<'a> {
pub blank: Option<f32>,
// optional wcs
pub wcs: Option<WCS>,
// bytes offset where the data bytes are located inside the fits
pub data_byte_offset: Range<usize>,
// raw bytes of the data image (in Big-Endian)
pub raw_bytes: &'a [u8],
pub raw_bytes: Cow<'a, [u8]>,
}
impl<'a> FitsImage<'a> {
@@ -44,56 +50,124 @@ impl<'a> FitsImage<'a> {
HDU::XImage(hdu) | HDU::Primary(hdu) => {
// Prefer getting the dimension directly from NAXIS1/NAXIS2 instead of from the WCS
// because it may not exist in all HDU images
let width = hdu.get_header().get_xtension().get_naxisn(1);
let height = hdu.get_header().get_xtension().get_naxisn(2);
if let (Some(&width), Some(&height)) = (width, height) {
let depth =
*hdu.get_header().get_xtension().get_naxisn(3).unwrap_or(&1) as u32;
let naxis = hdu.get_header().get_xtension().get_naxis();
if naxis.len() >= 2 {
let width = naxis[0];
let height = naxis[1];
let depth = if naxis.len() >= 3 { naxis[2] } else { 1 };
let header = hdu.get_header();
let bscale = match header.get("BSCALE") {
Some(Value::Integer { value, .. }) => *value as f32,
Some(Value::Float { value, .. }) => *value as f32,
_ => 1.0,
};
let bscale = header.get_parsed::<f32>("BSCALE").unwrap_or(1.0);
let bzero = header.get_parsed::<f32>("BZERO").unwrap_or(0.0);
let blank = header.get_parsed::<f32>("BLANK").ok();
let bzero = match header.get("BZERO") {
Some(Value::Integer { value, .. }) => *value as f32,
Some(Value::Float { value, .. }) => *value as f32,
_ => 0.0,
};
let trim1 = header.get_parsed::<u32>("TRIM1").unwrap_or(0);
let trim2 = header.get_parsed::<u32>("TRIM2").unwrap_or(0);
let trim3 = header.get_parsed::<u32>("TRIM3").unwrap_or(0);
let blank = match header.get("BLANK") {
Some(Value::Integer { value, .. }) => Some(*value as f32),
Some(Value::Float { value, .. }) => Some(*value as f32),
_ => None,
};
let bitpix = hdu.get_header().get_xtension().get_bitpix();
let off = hdu.get_data_unit_byte_offset() as usize;
let len = hdu.get_data_unit_byte_size() as usize;
let raw_bytes = &bytes[off..(off + len)];
let bitpix = hdu.get_header().get_xtension().get_bitpix();
let data_byte_offset = off..(off + len);
let raw_bytes = Cow::Borrowed(&bytes[data_byte_offset.clone()]);
let wcs = hdu.wcs().ok();
images.push(Self {
header: hdu.get_header().clone(),
trim1,
trim2,
trim3,
width: width as u32,
height: height as u32,
depth,
depth: depth as u32,
bitpix,
bscale,
wcs,
bzero,
blank,
data_byte_offset,
raw_bytes,
});
}
}
HDU::XBinaryTable(hdu) => {
let header = hdu.get_header();
let bin_table = header.get_xtension();
if let Some(TileCompressedImage {
z_bitpix: bitpix,
z_naxisn: naxis,
..
}) = &bin_table.get_z_image()
{
if naxis.len() >= 2 {
let width = naxis[0] as u32;
let height = naxis[1] as u32;
let depth = if naxis.len() >= 3 { naxis[2] as u32 } else { 1 };
let bscale = header.get_parsed::<f32>("BSCALE").unwrap_or(1.0);
let bzero = header.get_parsed::<f32>("BZERO").unwrap_or(0.0);
let blank = header.get_parsed::<f32>("BLANK").ok();
let trim1 = header.get_parsed::<u32>("TRIM1").unwrap_or(0);
let trim2 = header.get_parsed::<u32>("TRIM2").unwrap_or(0);
let trim3 = header.get_parsed::<u32>("TRIM3").unwrap_or(0);
let wcs = hdu.wcs().ok();
let off = hdu.get_data_unit_byte_offset() as usize;
let len = hdu.get_data_unit_byte_size() as usize;
let data_byte_offset = off..(off + len);
let mut bitpix = *bitpix;
let raw_bytes = match fits.get_data(&hdu) {
BinaryTableData::TileCompressed(Pixels::U8(pixels)) => {
Some(pixels.collect::<Vec<_>>())
}
BinaryTableData::TileCompressed(Pixels::I16(pixels)) => {
Some(pixels.flat_map(|p| p.to_be_bytes()).collect::<Vec<_>>())
}
BinaryTableData::TileCompressed(Pixels::I32(pixels)) => {
Some(pixels.flat_map(|p| p.to_be_bytes()).collect::<Vec<_>>())
}
BinaryTableData::TileCompressed(Pixels::F32(pixels)) => {
Some(pixels.flat_map(|p| p.to_be_bytes()).collect::<Vec<_>>())
}
BinaryTableData::TileCompressed(Pixels::F64(pixels)) => {
bitpix = Bitpix::F32;
let raw_bytes =
pixels.flat_map(|p| p.to_be_bytes()).collect::<Vec<_>>();
Some(raw_bytes)
}
_ => None,
};
if let Some(raw_bytes) = raw_bytes {
images.push(Self {
trim1,
trim2,
trim3,
width,
height,
depth,
bitpix,
bscale,
wcs,
bzero,
blank,
data_byte_offset,
raw_bytes: Cow::Owned(raw_bytes),
});
}
}
}
}
_ => (),
}
}
@@ -107,6 +181,7 @@ impl<'a> FitsImage<'a> {
}
use crate::{image::Image, texture::Tex3D};
use std::convert::TryInto;
impl Image for FitsImage<'_> {
fn insert_into_3d_texture<T: Tex3D>(
&self,
@@ -115,11 +190,46 @@ impl Image for FitsImage<'_> {
// An offset to write the image in the texture array
offset: &Vector3<i32>,
) -> Result<(), JsValue> {
let view = unsafe { R8U::view(self.raw_bytes) };
let view = unsafe {
match self.bitpix {
Bitpix::I64 => {
// convert to i64 first
let new_bytes: Vec<_> = self
.raw_bytes
.chunks_exact(8)
.flat_map(|chunk| {
let bytes: [u8; 8] = chunk.try_into().unwrap();
let value = i64::from_be_bytes(bytes);
(value as i32).to_be_bytes()
})
.collect();
R8U::view(&new_bytes)
}
Bitpix::F64 => {
// convert to i64 first
let new_bytes: Vec<_> = self
.raw_bytes
.chunks_exact(8)
.flat_map(|chunk| {
let bytes: [u8; 8] = chunk.try_into().unwrap();
let value = f64::from_be_bytes(bytes);
(value as f32).to_be_bytes()
})
.collect();
R8U::view(&new_bytes)
}
_ => R8U::view(&self.raw_bytes),
}
};
textures.tex_sub_image_3d_with_opt_array_buffer_view(
offset.x,
offset.y,
offset.z,
offset.x + self.trim1 as i32,
offset.y + self.trim2 as i32,
offset.z + self.trim3 as i32,
self.width as i32,
self.height as i32,
self.depth as i32,
@@ -129,7 +239,8 @@ impl Image for FitsImage<'_> {
Ok(())
}
fn get_size(&self) -> (u32, u32) {
(self.width, self.height)
fn get_size(&self) -> (u32, u32, u32) {
// The true image size is given by ONAXISi keywords
(self.width, self.height, self.depth)
}
}

View File

@@ -1,7 +1,7 @@
/* ------------------------------------------------------ */
#[derive(Debug)]
pub struct HTMLImage<F> {
image: web_sys::HtmlImageElement,
pub image: web_sys::HtmlImageElement,
format: std::marker::PhantomData<F>,
}
@@ -15,6 +15,10 @@ where
format: std::marker::PhantomData,
}
}
pub fn element(&self) -> &web_sys::HtmlImageElement {
&self.image
}
}
use crate::image::Image;
@@ -43,7 +47,7 @@ where
Ok(())
}
fn get_size(&self) -> (u32, u32) {
(self.image.width(), self.image.height())
fn get_size(&self) -> (u32, u32, u32) {
(self.image.width(), self.image.height(), 1)
}
}

View File

@@ -191,7 +191,7 @@ pub trait Image {
offset: &Vector3<i32>,
) -> Result<(), JsValue>;
fn get_size(&self) -> (u32, u32);
fn get_size(&self) -> (u32, u32, u32);
}
impl<I> Image for &I
@@ -212,7 +212,7 @@ where
}
#[inline]
fn get_size(&self) -> (u32, u32) {
fn get_size(&self) -> (u32, u32, u32) {
let image = &**self;
image.get_size()
}
@@ -237,7 +237,7 @@ where
}
#[inline]
fn get_size(&self) -> (u32, u32) {
fn get_size(&self) -> (u32, u32, u32) {
let image = &**self;
image.get_size()
}
@@ -250,7 +250,7 @@ use crate::texture::Tex3D;
pub enum ImageType {
FitsRawBytes {
raw_bytes: js_sys::Uint8Array,
size: (u32, u32),
size: (u32, u32, u32),
},
Canvas {
canvas: Canvas<RGBA8U>,
@@ -311,10 +311,10 @@ impl Image for ImageType {
ImageType::Canvas { canvas } => canvas.insert_into_3d_texture(textures, offset)?,
ImageType::ImageRgba8u { image } => image.insert_into_3d_texture(textures, offset)?,
ImageType::ImageRgb8u { image } => image.insert_into_3d_texture(textures, offset)?,
ImageType::HTMLImageRgba8u { image } => {
ImageType::HTMLImageRgba8u { image, .. } => {
image.insert_into_3d_texture(textures, offset)?
}
ImageType::HTMLImageRgb8u { image } => {
ImageType::HTMLImageRgb8u { image, .. } => {
image.insert_into_3d_texture(textures, offset)?
}
ImageType::RawRgb8u { image } => image.insert_into_3d_texture(textures, offset)?,
@@ -328,7 +328,7 @@ impl Image for ImageType {
Ok(())
}
fn get_size(&self) -> (u32, u32) {
fn get_size(&self) -> (u32, u32, u32) {
match self {
ImageType::FitsRawBytes { size, .. } => *size,
ImageType::Canvas { canvas } => canvas.get_size(),

View File

@@ -8,8 +8,8 @@ pub struct ImageBuffer<T>
where
T: TextureFormat,
{
pub data: Vec<<<T as TextureFormat>::P as Pixel>::Item>,
pub size: Vector2<i32>,
pub data: Box<[<<T as TextureFormat>::P as Pixel>::Item]>,
pub size: (u32, u32, u32),
}
use crate::texture::format::Bytes;
@@ -26,21 +26,22 @@ where
T: TextureFormat,
{
pub fn new(
data: Vec<<<T as TextureFormat>::P as Pixel>::Item>,
width: i32,
height: i32,
data: Box<[<<T as TextureFormat>::P as Pixel>::Item]>,
width: u32,
height: u32,
depth: u32,
) -> Self {
let size_buf = width * height * (T::NUM_CHANNELS as i32);
debug_assert!(size_buf == data.len() as i32);
let size_buf = width * height * depth * (T::NUM_CHANNELS as u32);
debug_assert!(size_buf == data.len() as u32);
//let buf = <<T as ImageFormat>::P as Pixel>::Container::new(buf);
let size = Vector2::new(width, height);
let size = (width, height, depth);
Self { data, size }
}
pub fn from_encoded_raw_bytes(
raw_bytes: &[u8],
width: i32,
height: i32,
width: u32,
height: u32,
) -> Result<Self, JsValue> {
let mut decoded_bytes = match T::decode(raw_bytes).map_err(JsValue::from_str)? {
Bytes::Borrowed(bytes) => bytes.to_vec(),
@@ -55,29 +56,33 @@ where
std::mem::transmute::<Vec<u8>, Vec<<<T as TextureFormat>::P as Pixel>::Item>>(
decoded_bytes,
)
.into_boxed_slice()
};
Ok(Self::new(decoded_pixels, width, height))
Ok(Self::new(decoded_pixels, width, height, 1))
}
pub fn from_raw_bytes(mut raw_bytes: Vec<u8>, width: i32, height: i32) -> Self {
let size_buf = width * height * (std::mem::size_of::<T::P>() as i32);
debug_assert!(size_buf == raw_bytes.len() as i32);
pub fn from_raw_bytes(mut raw_bytes: Vec<u8>, width: u32, height: u32) -> Self {
let size_buf = width * height * (std::mem::size_of::<T::P>() as u32);
debug_assert!(size_buf == raw_bytes.len() as u32);
let decoded_pixels = unsafe {
raw_bytes.set_len(raw_bytes.len() / std::mem::size_of::<<T::P as Pixel>::Item>());
std::mem::transmute::<Vec<u8>, Vec<<T::P as Pixel>::Item>>(raw_bytes)
std::mem::transmute::<Vec<u8>, Vec<<T::P as Pixel>::Item>>(raw_bytes).into_boxed_slice()
};
Self::new(decoded_pixels, width, height)
Self::new(decoded_pixels, width, height, 1)
}
pub fn empty() -> Self {
let size = Vector2::new(0, 0);
Self { data: vec![], size }
let size = (0, 0, 0);
Self {
data: Box::new([]),
size,
}
}
pub fn allocate(pixel_fill: &T::P, width: i32, height: i32) -> ImageBuffer<T> {
pub fn allocate(pixel_fill: &T::P, width: u32, height: u32) -> ImageBuffer<T> {
let size_buf = ((width * height) as usize) * (T::NUM_CHANNELS);
let data = pixel_fill
@@ -86,9 +91,10 @@ where
.cloned()
.cycle()
.take(size_buf)
.collect::<Vec<_>>();
.collect::<Vec<_>>()
.into_boxed_slice();
ImageBuffer::<T>::new(data, width, height)
ImageBuffer::<T>::new(data, width, height, 1)
}
pub fn tex_sub(&mut self, src: &Self, s: &ImageBufferView, d: &ImageBufferView) {
@@ -97,8 +103,8 @@ where
for ix in s.x..(s.x + s.w) {
for iy in s.y..(s.y + s.h) {
let s_idx = (iy * src.width() + ix) as usize;
let d_idx = (di * self.width() + dj) as usize;
let s_idx = ((iy * src.width() as i32) + ix) as usize;
let d_idx = ((di * self.width() as i32) + dj) as usize;
for i in 0..T::NUM_CHANNELS {
let si = s_idx * T::NUM_CHANNELS + i;
@@ -124,12 +130,12 @@ where
&self.data
}
pub fn width(&self) -> i32 {
self.size.x
pub fn width(&self) -> u32 {
self.size.0
}
pub fn height(&self) -> i32 {
self.size.y
pub fn height(&self) -> u32 {
self.size.1
}
}
@@ -144,7 +150,7 @@ pub enum ImageBufferType {
}
use crate::image::{ArrayBuffer, Image};
use cgmath::{Vector2, Vector3};
use cgmath::Vector3;
impl<I> Image for ImageBuffer<I>
where
I: TextureFormat,
@@ -161,9 +167,9 @@ where
offset.x,
offset.y,
offset.z,
self.width(),
self.height(),
1,
self.width() as i32,
self.height() as i32,
self.size.2 as i32,
Some(js_array.as_ref()),
);
@@ -171,7 +177,7 @@ where
}
// The size of the image
fn get_size(&self) -> (u32, u32) {
(self.size.x as u32, self.size.y as u32)
fn get_size(&self) -> (u32, u32, u32) {
self.size
}
}

View File

@@ -1,8 +1,8 @@
extern crate futures;
extern crate jpeg_decoder as jpeg;
extern crate png;
//extern crate jpeg_decoder as jpeg;
//extern crate png;
extern crate serde_json;
extern crate wasm_streams;
//extern crate wasm_streams;
pub mod convert;
pub mod image;

View File

@@ -93,8 +93,6 @@ pub trait VertexAttribPointerType: std::marker::Sized {
}
}
use crate::webgl_ctx::WebGlRenderingCtx;
use js_sys::WebAssembly;
use wasm_bindgen::JsCast;
impl VertexAttribPointerType for u8 {
type ArrayBufferView = js_sys::Uint8Array;
@@ -308,7 +306,7 @@ impl VertexAttribPointerType for f32 {
type ArrayBufferView = Float32Array;
fn array_buffer_view<'a, B: BufferDataStorage<'a, Self>>(data: B) -> Self::ArrayBufferView {
let data = data.get_slice();
/*let data = data.get_slice();
//unsafe { Self::ArrayBufferView::view(&data) }
let memory_buffer = wasm_bindgen::memory()
.unchecked_ref::<WebAssembly::Memory>()
@@ -316,7 +314,9 @@ impl VertexAttribPointerType for f32 {
let len = data.len();
let ptr = data.as_ptr() as u32 / 4;
Float32Array::new(&memory_buffer).subarray(ptr, ptr + len as u32)
Float32Array::new(&memory_buffer).subarray(ptr, ptr + len as u32)*/
let data = data.get_slice();
unsafe { Self::ArrayBufferView::view(data) }
}
fn buffer_sub_data_with_i32_and_array_buffer_view<'a, B: BufferDataStorage<'a, Self>>(
@@ -462,6 +462,30 @@ impl ArrayBuffer {
);
}
}
/*pub fn update_from_js_array<'a, T: VertexAttribPointerType>(
&mut self,
usage: u32,
data: T::ArrayBufferView,
) {
self.bind();
if self.len >= data.len() {
T::buffer_sub_data_with_i32_and_array_buffer_view(
&self.gl,
data,
WebGlRenderingCtx::ARRAY_BUFFER,
);
} else {
self.len = data.len();
T::buffer_data_with_array_buffer_view(
&self.gl,
data,
WebGlRenderingCtx::ARRAY_BUFFER,
usage,
);
}
}*/
}
impl VertexBufferObject for ArrayBuffer {

View File

@@ -132,6 +132,20 @@ pub mod vao {
self
}
/*pub fn update_from_js_array<T: VertexAttribPointerType>(
&mut self,
attr: &'static str,
usage: u32,
js_array: T::ArrayBufferView,
) -> &mut Self {
self.vao
.array_buffer
.get_mut(attr)
.unwrap_abort()
.update_from_js_array::<T>(usage, js_array);
self
}*/
pub fn update_element_array<T: VertexAttribPointerType, B: BufferDataStorage<'a, T>>(
&mut self,
usage: u32,

View File

@@ -19,7 +19,6 @@ pub struct Texture3D {
texture: Option<WebGlTexture>,
metadata: Option<Rc<RefCell<Texture2DMeta>>>,
_depth: i32,
}
impl Texture3D {
@@ -62,7 +61,6 @@ impl Texture3D {
Ok(Texture3D {
texture,
gl: gl.clone(),
_depth: depth,
metadata,
})
}

View File

@@ -91,7 +91,7 @@ impl Texture2DArray {
// Attach the texture as the first color attachment
self.gl.framebuffer_texture_layer(
WebGlRenderingCtx::READ_FRAMEBUFFER,
WebGlRenderingCtx::FRAMEBUFFER,
WebGlRenderingCtx::COLOR_ATTACHMENT0,
self.texture.as_ref(),
0,

View File

@@ -43,13 +43,14 @@ impl TextureFormat for RGB8U {
const PIXEL_TYPE: PixelType = PixelType::RGB8U;
fn decode(raw_bytes: &[u8]) -> Result<Bytes<'_>, &'static str> {
let mut decoder = jpeg::Decoder::new(raw_bytes);
fn decode(_raw_bytes: &[u8]) -> Result<Bytes<'_>, &'static str> {
todo!()
/*let mut decoder = jpeg::Decoder::new(raw_bytes);
let bytes = decoder
.decode()
.map_err(|_| "Cannot decoder jpeg. This image may not be compressed.")?;
Ok(Bytes::Owned(bytes))
Ok(Bytes::Owned(bytes))*/
}
type ArrayBufferView = js_sys::Uint8Array;
@@ -72,13 +73,15 @@ impl TextureFormat for RGBA8U {
const PIXEL_TYPE: PixelType = PixelType::RGBA8U;
fn decode(raw_bytes: &[u8]) -> Result<Bytes<'_>, &'static str> {
let mut decoder = jpeg::Decoder::new(raw_bytes);
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))
*/
todo!()
}
type ArrayBufferView = js_sys::Uint8Array;
@@ -200,5 +203,3 @@ impl PixelType {
}
}
}
pub const NUM_CHANNELS: usize = 6;

View File

@@ -311,7 +311,7 @@ impl Texture2D {
// Attach the texture as the first color attachment
//self.attach_to_framebuffer();
self.gl.framebuffer_texture_2d(
WebGlRenderingCtx::READ_FRAMEBUFFER,
WebGlRenderingCtx::FRAMEBUFFER,
WebGlRenderingCtx::COLOR_ATTACHMENT0,
WebGlRenderingCtx::TEXTURE_2D,
self.texture.as_ref(),

View File

@@ -21,32 +21,6 @@ pub trait Pixel:
fn read_pixel(gl: &WebGlContext, x: i32, y: i32) -> Result<Self, JsValue>;
}
impl Pixel for [f32; 1] {
type Item = f32;
type Container = ArrayF32;
const BLACK: Self = [f32::NAN];
fn read_pixel(gl: &WebGlContext, x: i32, y: i32) -> Result<Self, JsValue> {
let p = js_sys::Uint8Array::new_with_length(4);
gl.read_pixels_with_opt_array_buffer_view(
x,
y,
1,
1,
WebGlRenderingCtx::RGBA,
WebGlRenderingCtx::UNSIGNED_BYTE,
Some(&p),
)?;
Ok([f32::from_le_bytes([
p.at(0).unwrap(),
p.at(1).unwrap(),
p.at(2).unwrap(),
p.at(3).unwrap(),
])])
}
}
impl Pixel for [u8; 4] {
type Item = u8;
type Container = ArrayU8;
@@ -74,13 +48,13 @@ impl Pixel for [u8; 3] {
const BLACK: Self = [0, 0, 0];
fn read_pixel(gl: &WebGlContext, x: i32, y: i32) -> Result<Self, JsValue> {
let pixels = js_sys::Uint8Array::new_with_length(3);
let pixels = js_sys::Uint8Array::new_with_length(4);
gl.read_pixels_with_opt_array_buffer_view(
x,
y,
1,
1,
WebGlRenderingCtx::RGB,
WebGlRenderingCtx::RGBA,
WebGlRenderingCtx::UNSIGNED_BYTE,
Some(&pixels),
)?;
@@ -147,7 +121,7 @@ impl Pixel for [i16; 1] {
Some(&p),
)?;
Ok([i16::from_le_bytes([p.at(0).unwrap(), p.at(1).unwrap()])])
Ok([i16::from_le_bytes([p.at(1).unwrap(), p.at(0).unwrap()])])
}
}
@@ -169,10 +143,36 @@ impl Pixel for [i32; 1] {
)?;
Ok([i32::from_le_bytes([
p.at(0).unwrap(),
p.at(1).unwrap(),
p.at(2).unwrap(),
p.at(3).unwrap(),
p.at(2).unwrap(),
p.at(1).unwrap(),
p.at(0).unwrap(),
])])
}
}
impl Pixel for [f32; 1] {
type Item = f32;
type Container = ArrayF32;
const BLACK: Self = [f32::NAN];
fn read_pixel(gl: &WebGlContext, x: i32, y: i32) -> Result<Self, JsValue> {
let p = js_sys::Uint8Array::new_with_length(4);
gl.read_pixels_with_opt_array_buffer_view(
x,
y,
1,
1,
WebGlRenderingCtx::RGBA,
WebGlRenderingCtx::UNSIGNED_BYTE,
Some(&p),
)?;
Ok([f32::from_le_bytes([
p.at(3).unwrap(),
p.at(2).unwrap(),
p.at(1).unwrap(),
p.at(0).unwrap(),
])])
}
}

View File

@@ -49,12 +49,32 @@ impl WebGlContext {
#[cfg(feature = "webgl2")]
{
/*if let Ok(r) =
get_extension::<web_sys::ExtColorBufferFloat>(&gl, "EXT_color_buffer_float")
{
let _ = r;
}*/
let ctx = WebGlContext { inner: gl };
Ok(ctx)
}
}
}
fn _get_extension<T>(context: &WebGlRenderingCtx, name: &str) -> Result<T, JsValue>
where
T: wasm_bindgen::JsCast,
{
// `unchecked_into` is used here because WebGL extensions aren't actually JS classes
// these objects are duck-type representations of the actual Rust classes
// https://github.com/rustwasm/wasm-bindgen/pull/1449
context
.get_extension(name)
.ok()
.and_then(|maybe_ext| maybe_ext.map(|ext| ext.unchecked_into::<T>()))
.ok_or_else(|| JsValue::from_str("Failed to load ext"))
}
use std::ops::Deref;
impl Deref for WebGlContext {
type Target = WebGlRenderingCtx;

View File

@@ -3,6 +3,8 @@ use walkdir::WalkDir;
extern crate walkdir;
use std::io::BufRead;
use std::process::Command;
// All my shaders reside in the 'src/shaders' directory
fn generate_shaders() -> std::result::Result<(), Box<dyn Error>> {
println!("generate shaders");
@@ -26,9 +28,48 @@ fn generate_shaders() -> std::result::Result<(), Box<dyn Error>> {
.into_owned()
.replace("/", "_")
.replace("\\", "_");
//let out_name = format!("{}/{}", OUT_PATH, out_file_name);
let src = read_shader(path)?;
let mut src = read_shader(path)?;
if std::env::var("CARGO_FEATURE_MINIFY_SHADERS").is_ok() {
println!("Feature `minify_shaders` enabled: running shader minifier");
// save to a minified path
let mut tmp_path = PathBuf::from(path);
let mut min_path = PathBuf::from(path);
let stem = path.file_stem().unwrap();
// Build new filename: stem + ".min" + extension
let tmp_file_name =
format!("{}.{}.tmp", stem.to_string_lossy(), ext.to_string_lossy());
tmp_path.set_file_name(tmp_file_name);
let min_file_name =
format!("{}.{}.min", stem.to_string_lossy(), ext.to_string_lossy());
min_path.set_file_name(min_file_name);
fs::write(tmp_path.clone(), &src)?;
Command::new("mono")
.args([
"/Users/matthieubaumann/Downloads/shader_minifier.exe",
"--format",
"text",
"--aggressive-inlining",
"--preserve-externals",
"--move-declarations",
"-o",
min_path.as_os_str().to_str().expect("Invalid UTF-8!"),
tmp_path.as_os_str().to_str().expect("Invalid UTF-8!"),
])
.status()
.expect("Failed to run shader_minifier");
src = read_shader(min_path)?;
} else {
println!("Feature `minify_shaders` not enabled: skipping");
}
shaders.insert(out_file_name, src);
println!("cargo:rerun-if-changed=src/shaders/{file_name}");
@@ -49,7 +90,7 @@ fn read_shader<P: AsRef<std::path::Path>>(path: P) -> std::io::Result<String> {
let shader_src = std::io::BufReader::new(file)
.lines()
.map_while(Result::ok)
.map(|l| {
.filter_map(|l| {
if l.starts_with("#include") {
let incl_file_names: Vec<_> = l.split_terminator(&[';', ' '][..]).collect();
let incl_file_name_rel = incl_file_names[1];
@@ -57,9 +98,12 @@ fn read_shader<P: AsRef<std::path::Path>>(path: P) -> std::io::Result<String> {
println!("{}", incl_file_name.to_string_lossy());
read_shader(incl_file_name.to_str().unwrap()).unwrap()
Some(read_shader(incl_file_name.to_str().unwrap()).unwrap())
} else if l.trim_start().starts_with("//") {
// comment
None
} else {
l
Some(l)
}
})
.collect::<Vec<_>>()

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,25 @@
use js_sys::Reflect;
use wasm_bindgen::JsValue;
use web_sys::window;
pub struct BrowserFeaturesSupport {
pub create_image_bitmap: bool,
}
impl Default for BrowserFeaturesSupport {
fn default() -> Self {
Self::new()
}
}
impl BrowserFeaturesSupport {
pub fn new() -> Self {
let window = window().expect("no global `window` exists");
let create_image_bitmap =
Reflect::has(&window, &JsValue::from_str("createImageBitmap")).unwrap_or(false);
Self {
create_image_bitmap,
}
}
}

View File

@@ -54,8 +54,8 @@ fn linspace(a: f64, b: f64, num: usize) -> Vec<f64> {
res
}
const NUM_VERTICES_WIDTH: usize = 3;
const NUM_VERTICES_HEIGHT: usize = 3;
const NUM_VERTICES_WIDTH: usize = 4;
const NUM_VERTICES_HEIGHT: usize = 4;
const NUM_VERTICES: usize = 4 + 2 * NUM_VERTICES_WIDTH + 2 * NUM_VERTICES_HEIGHT;
// This struct belongs to the CameraViewPort
pub struct FieldOfView {

View File

@@ -8,8 +8,8 @@ pub use fov::FieldOfView;
pub mod view_hpx_cells;
use crate::CooSystem;
use crate::HEALPixCoverage;
use crate::ProjectionType;
use crate::SpaceMoc;
pub fn build_fov_coverage(
depth: u8,
@@ -18,7 +18,7 @@ pub fn build_fov_coverage(
camera_frame: CooSystem,
frame: CooSystem,
proj: &ProjectionType,
) -> HEALPixCoverage {
) -> SpaceMoc {
if let Some(vertices) = fov.get_vertices() {
// The vertices coming from the camera are in a specific coo sys
// but cdshealpix accepts them to be given in ICRS coo sys
@@ -44,20 +44,20 @@ pub fn build_fov_coverage(
::healpix::nested::hash(depth, lon.to_radians(), lat.to_radians())
});
HEALPixCoverage::from_fixed_hpx_cells(depth, hpx_idxs_iter, Some(vertices.len()))
SpaceMoc::from_fixed_hpx_cells(depth, hpx_idxs_iter, Some(vertices.len()))
} else {
// The polygon is not too small for the depth asked
let inside_vertex = crate::coosys::apply_coo_system(camera_frame, frame, camera_center);
// Prefer to query from_polygon with depth >= 2
HEALPixCoverage::from_3d_coos(depth, vertices_iter, &inside_vertex)
SpaceMoc::from_3d_coos(depth, vertices_iter, &inside_vertex)
}
} else {
let center_xyz = crate::coosys::apply_coo_system(camera_frame, frame, camera_center);
let biggest_fov_rad = proj.aperture_start().to_radians();
let lonlat = center_xyz.lonlat();
HEALPixCoverage::from_cone(&lonlat, biggest_fov_rad * 0.5, depth)
SpaceMoc::from_cone(&lonlat, biggest_fov_rad * 0.5, depth)
}
}

View File

@@ -3,7 +3,7 @@ use crate::healpix::cell::HEALPixCell;
use crate::math::projection::*;
use crate::HEALPixCoverage;
use crate::SpaceMoc;
use moclib::moc::{range::op::degrade::degrade, RangeMOCIterator};
@@ -84,7 +84,7 @@ impl ViewHpxCells {
self.hpx_cells[frame as usize].get_cells(depth)
}
pub(super) fn get_cov(&self, frame: CooSystem) -> &HEALPixCoverage {
pub(super) fn get_cov(&self, frame: CooSystem) -> &SpaceMoc {
self.hpx_cells[frame as usize].get_cov()
}
@@ -109,7 +109,7 @@ pub struct HpxCells {
// An index vector referring to the indices of each depth cells
//idx_rng: [Option<Range<usize>>; MAX_HPX_DEPTH as usize + 1],
// Coverage created in the frame
cov: HEALPixCoverage,
cov: SpaceMoc,
// boolean refering to if the cells in the view has changed
//new_cells: bool,
}
@@ -127,7 +127,7 @@ use super::FieldOfView;
impl HpxCells {
pub fn new(frame: CooSystem) -> Self {
//let cells = Vec::new();
let cov = HEALPixCoverage::empty(29);
let cov = SpaceMoc::empty(29);
//let idx_rng = Default::default();
@@ -203,7 +203,7 @@ impl HpxCells {
if depth == cov_depth {
self.cov
.flatten_to_fixed_depth_cells()
.map(move |idx| HEALPixCell(depth, idx))
.map(|idx| HEALPixCell(depth, idx))
.collect()
} else if depth > self.cov.depth_max() {
let cov_d = self.cov.depth_max();
@@ -212,7 +212,7 @@ impl HpxCells {
self.cov
.flatten_to_fixed_depth_cells()
.flat_map(move |idx| {
.flat_map(|idx| {
// idx is at depth_max
HEALPixCell(cov_d, idx).get_children_cells(dd)
})
@@ -221,7 +221,7 @@ impl HpxCells {
// compute the cells from the coverage
degrade((&self.cov.0).into_range_moc_iter(), depth)
.flatten_to_fixed_depth_cells()
.map(move |idx| HEALPixCell(depth, idx))
.map(|idx| HEALPixCell(depth, idx))
.collect()
}
}
@@ -257,7 +257,7 @@ impl HpxCells {
}*/
#[inline(always)]
pub fn get_cov(&self) -> &HEALPixCoverage {
pub fn get_cov(&self) -> &SpaceMoc {
&self.cov
}

View File

@@ -12,7 +12,7 @@ const ID_R: &Matrix3<f64> = &Matrix3::new(-1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.
use super::{fov::FieldOfView, view_hpx_cells::ViewHpxCells};
use crate::healpix::cell::HEALPixCell;
use crate::healpix::coverage::HEALPixCoverage;
use crate::healpix::moc::SpaceMoc;
use crate::math::angle::ToAngle;
use crate::math::{projection::coo_space::XYZModel, projection::domain::sdf::ProjDef};
use cgmath::{InnerSpace, Vector3};
@@ -216,7 +216,7 @@ impl CameraViewPort {
self.view_hpx_cells.has_changed()
}*/
pub fn get_cov(&self, frame: CooSystem) -> &HEALPixCoverage {
pub fn get_cov(&self, frame: CooSystem) -> &SpaceMoc {
self.view_hpx_cells.get_cov(frame)
}
@@ -224,6 +224,8 @@ impl CameraViewPort {
self.view_hpx_cells.get_cells(depth, frame)
}
// This method has the role to determine the render mode based on the fov
// For large FoV, raytracing drawing mode, rasterizer otherwise
pub fn is_raytracing(&self, proj: &ProjectionType) -> bool {
// Check whether the tile depth is 0 for square projection
// definition domains i.e. Mercator
@@ -240,6 +242,7 @@ impl CameraViewPort {
ProjectionType::Ait(_) => self.aperture >= 100.0_f64.to_radians(),
ProjectionType::Mol(_) => self.aperture >= 100.0_f64.to_radians(),
ProjectionType::Zea(_) => self.aperture >= 140.0_f64.to_radians(),
_ => self.aperture >= 140.0_f64.to_radians(),
}
}
@@ -315,11 +318,7 @@ impl CameraViewPort {
}
pub fn compute_ndc_to_clip_factor(&mut self, proj: &ProjectionType) {
self.ndc_to_clip = if self.height < self.width {
Vector2::new(1.0, (self.height as f64) / (self.width as f64))
} else {
Vector2::new((self.width as f64) / (self.height as f64), 1.0)
};
self.ndc_to_clip = Vector2::new(1.0, (self.height as f64) / (self.width as f64));
let bounds_size_ratio = proj.bounds_size_ratio();
self.ndc_to_clip.y *= bounds_size_ratio;
@@ -570,42 +569,48 @@ impl CameraViewPort {
}
fn compute_texture_depth(&mut self) {
/*// Compute a depth from a number of pixels on screen
let width = self.width;
let aperture = self.aperture.0 as f32;
// Compute a depth from a number of pixels on screen
/*let width = self.width;
let aperture = self.aperture as f32;
let angle_per_pixel = aperture / width;
let angle_per_pixel = aperture / width;
let two_power_two_times_depth_pixel =
std::f32::consts::PI / (3.0 * angle_per_pixel * angle_per_pixel);
let depth_pixel = (two_power_two_times_depth_pixel.log2() / 2.0).floor() as u32;
let two_power_two_times_depth_pixel =
std::f32::consts::PI / (3.0 * angle_per_pixel * angle_per_pixel);
let depth_pixel = (two_power_two_times_depth_pixel.log2() / 2.0).ceil() as u32;
//let survey_max_depth = conf.get_max_depth();
// The depth of the texture
// A texture of 512x512 pixels will have a depth of 9
const DEPTH_OFFSET_TEXTURE: u32 = 9;
// The depth of the texture corresponds to the depth of a pixel
// minus the offset depth of the texture
self.texture_depth = if DEPTH_OFFSET_TEXTURE > depth_pixel {
0_u8
} else {
(depth_pixel - DEPTH_OFFSET_TEXTURE) as u8
};*/
//let survey_max_depth = conf.get_max_depth();
// The depth of the texture
// A texture of 512x512 pixels will have a depth of 9
const DEPTH_OFFSET_TEXTURE: u32 = 9;
// The depth of the texture corresponds to the depth of a pixel
// minus the offset depth of the texture
self.texture_depth = if DEPTH_OFFSET_TEXTURE > depth_pixel {
0_u8
} else {
(depth_pixel - DEPTH_OFFSET_TEXTURE) as u8
};
*/
let w_screen_device_px = self.width as f64 / (self.dpi as f64);
//let depth_pixel = 29_usize;
let w_screen_px = self.width as f64;
let smallest_cell_size_px = self.dpi as f64;
let mut depth_pixel = 29_usize;
let pixel_angle_rad = self.get_aperture() / w_screen_device_px;
let hpx_cell_size_rad = (smallest_cell_size_px / w_screen_px) * self.get_aperture();
while depth_pixel > 0 {
if crate::healpix::utils::MEAN_HPX_CELL_RES[depth_pixel] > hpx_cell_size_rad {
break;
// Find the smallest depth such that MEAN_HPX_CELL_RES[depth] > pixel_angle_rad
let depth_pixel = match crate::healpix::utils::MEAN_HPX_CELL_RES.binary_search_by(|&res| {
if res < pixel_angle_rad {
std::cmp::Ordering::Greater
} else if res > pixel_angle_rad {
std::cmp::Ordering::Less
} else {
std::cmp::Ordering::Equal
}
}) {
Ok(idx) => idx, // exact match
Err(idx) => idx,
};
depth_pixel -= 1;
}
depth_pixel += 1;
//al_core::log(&format!("{:?}", depth_pixel));
const DEPTH_OFFSET_TEXTURE: usize = 9;
self.texture_depth = if DEPTH_OFFSET_TEXTURE > depth_pixel {
0_u8

View File

@@ -10,13 +10,13 @@ pub struct Downloader {
requests: Vec<RequestType>,
queried_list: HashSet<QueryId>,
cache: Cache<QueryId, Resource>,
cache: Cache<QueryId, RequestType>,
}
use crate::fifo_cache::Cache;
use query::Query;
use request::{RequestType, Resource};
use request::RequestType;
impl Default for Downloader {
fn default() -> Self {
@@ -62,26 +62,23 @@ impl Downloader {
}
}
pub fn get_received_resources(&mut self) -> Vec<Resource> {
pub fn get_received_resources(&mut self) -> Vec<RequestType> {
let mut rscs = vec![];
let mut not_finished_requests = vec![];
let mut finished_query_list = vec![];
self.requests = self
.requests
.drain(..)
.filter(|request| {
// If the request resolves into a resource
if let Some(rsc) = request.into() {
rscs.push(rsc);
finished_query_list.push(request.id().clone());
false
// The request is not resolved, we keep it
} else {
true
}
})
.collect();
while let Some(request) = self.requests.pop() {
if request.is_resolved() {
finished_query_list.push(request.id().clone());
rscs.push(request);
// The request is not resolved, we keep it
} else {
not_finished_requests.push(request);
}
}
self.requests = not_finished_requests;
for query_id in finished_query_list.into_iter() {
self.queried_list.remove(&query_id);
@@ -98,18 +95,8 @@ impl Downloader {
self.queried_list.contains(id)
}
pub fn delay(&mut self, r: Resource) {
match r {
Resource::Tile(tile) => {
let k = format!(
"{:?}{:?}/{:?}",
tile.get_hips_cdid(),
tile.cell.depth(),
tile.cell.idx()
);
self.cache.insert(k, Resource::Tile(tile));
}
_ => unimplemented!(),
}
pub fn delay(&mut self, r: RequestType) {
let id = r.id().to_owned();
self.cache.insert(id, r);
}
}

View File

@@ -6,32 +6,87 @@ pub trait Query: Sized {
fn id(&self) -> &QueryId;
}
pub type QueryId = String;
use crate::browser_support::BrowserFeaturesSupport;
use crate::healpix::cell::HEALPixFreqCell;
use al_api::hips::DataproductType;
use al_core::image::format::ImageFormatType;
/// Description of a cell to query
#[derive(Clone, PartialEq, Eq)]
pub enum CellDesc {
HiPS2D {
// A description of the tile in space
cell: HEALPixCell,
// Size of the tile requested
tile_size: u32,
},
HiPS3D {
// A description of the tile in space and frequency
cell: HEALPixFreqCell,
// Size of the tile requested
tile_size: u32,
// Depth of the cubic tile
tile_depth: u32,
},
HiPSCube {
// A description of the tile in space
cell: HEALPixCell,
// size of the tile requested
tile_size: u32,
// The channel number to query
channel: u32,
},
}
impl CellDesc {
/*fn get_size(&self) -> (u32, u32, u32) {
match self {
Self::HiPS2D { tile_size, .. } => (*tile_size, *tile_size, 1),
Self::HiPSCube { tile_size, .. } => (*tile_size, *tile_size, 1),
Self::HiPS3D {
tile_size,
tile_depth,
..
} => (*tile_size, *tile_size, *tile_depth),
}
}*/
pub fn get_hpx(&self) -> &HEALPixCell {
match self {
Self::HiPS2D { cell, .. } => cell,
Self::HiPS3D { cell, .. } => &cell.hpx,
Self::HiPSCube { cell, .. } => cell,
}
}
}
#[derive(Eq, PartialEq, Clone)]
pub struct Tile {
pub cell: HEALPixCell,
pub cell: CellDesc,
pub format: ImageFormatType,
// The root url of the HiPS
pub hips_cdid: CreatorDid,
// The total url of the query
pub url: Url,
pub size: u32, // size of the tile requested
pub credentials: RequestCredentials,
pub mode: RequestMode,
pub id: QueryId,
pub channel: Option<u32>,
pub create_bitmap_support: bool,
}
use crate::healpix::cell::HEALPixCell;
use crate::renderable::hips::config::HiPSConfig;
use crate::renderable::CreatorDid;
use crate::tile_fetcher::HiPSLocalFiles;
use web_sys::{RequestCredentials, RequestMode};
impl Tile {
pub fn new(cell: &HEALPixCell, channel: Option<u32>, cfg: &HiPSConfig) -> Self {
pub fn new(
cell: &HEALPixCell,
cfg: &HiPSConfig,
browser_support: &BrowserFeaturesSupport,
) -> Self {
let hips_cdid = cfg.get_creator_did();
let hips_url = cfg.get_root_url();
let format = cfg.get_format();
@@ -44,38 +99,108 @@ impl Tile {
let dir_idx = (idx / 10000) * 10000;
let mut url = format!("{hips_url}/Norder{depth}/Dir{dir_idx}/Npix{idx}");
let url = format!("{hips_url}/Norder{depth}/Dir{dir_idx}/Npix{idx}.{ext}");
// handle cube case
if let Some(channel) = channel {
if channel > 0 {
url.push_str(&format!("_{channel:?}"));
}
}
let id = format!("{}_{}_{}_{}", hips_cdid, depth, idx, ext);
// add the tile format
url.push_str(&format!(".{ext}"));
let id = format!(
"{}{}{}{}{}",
hips_cdid,
depth,
idx,
channel.unwrap_or(0),
ext
);
let size = cfg.get_tile_size();
let tile_size = cfg.get_tile_size() as u32;
Tile {
hips_cdid: hips_cdid.to_string(),
url,
cell: *cell,
cell: CellDesc::HiPS2D {
cell: *cell,
tile_size,
},
format,
credentials,
mode,
id,
channel,
size: size as u32,
create_bitmap_support: browser_support.create_image_bitmap,
}
}
pub fn new_with_channel(
cell: &HEALPixCell,
channel: u32,
cfg: &HiPSConfig,
browser_support: &BrowserFeaturesSupport,
) -> Self {
let hips_cdid = cfg.get_creator_did();
let hips_url = cfg.get_root_url();
let format = cfg.get_format();
let credentials = cfg.get_request_credentials();
let mode = cfg.get_request_mode();
let ext = format.get_ext_file();
let HEALPixCell(depth, idx) = *cell;
let dir_idx = (idx / 10000) * 10000;
let url = format!("{hips_url}/Norder{depth}/Dir{dir_idx}/Npix{idx}_{channel:?}.{ext}");
let id = format!("{}_{}_{}_{}_{}", hips_cdid, depth, idx, channel, ext);
let tile_size = cfg.get_tile_size() as u32;
Tile {
hips_cdid: hips_cdid.to_string(),
url,
cell: CellDesc::HiPSCube {
cell: *cell,
tile_size,
channel,
},
format,
credentials,
mode,
id,
create_bitmap_support: browser_support.create_image_bitmap,
}
}
pub fn new_cubic(
hpx_f_cell: &HEALPixFreqCell,
cfg: &HiPSConfig,
browser_support: &BrowserFeaturesSupport,
) -> Self {
let hips_cdid = cfg.get_creator_did();
let hips_url = cfg.get_root_url();
let format = cfg.get_format();
let credentials = cfg.get_request_credentials();
let mode = cfg.get_request_mode();
let ext = format.get_ext_file();
// f hash at order_f
let HEALPixFreqCell {
hpx: HEALPixCell(k, n),
f_hash: m,
f_depth: l,
} = *hpx_f_cell;
let d = (n / 10000) * 10000;
let e = (m / 10) * 10;
let url = format!("{hips_url}/Norder{k}_{l}/Dir{d}_{e}/Npix{n}_{m}.{ext}");
let id = format!("{hips_cdid}_{k}_{l}_{n}_{m}_{ext}");
let tile_size = cfg.get_tile_size() as u32;
let tile_depth = cfg.tile_depth.unwrap_or(1) as u32;
Tile {
hips_cdid: hips_cdid.to_string(),
url,
cell: CellDesc::HiPS3D {
cell: hpx_f_cell.clone(),
tile_size,
tile_depth,
},
format,
credentials,
mode,
id,
create_bitmap_support: browser_support.create_image_bitmap,
}
}
}
@@ -168,21 +293,41 @@ pub struct Moc {
pub credentials: RequestCredentials,
pub params: MOCOptions,
pub hips_cdid: CreatorDid,
pub dataproduct_type: DataproductType,
}
use std::collections::HashMap;
impl Moc {
pub fn new(
url: String,
mode: RequestMode,
credentials: RequestCredentials,
hips_cdid: CreatorDid,
cfg: &HiPSConfig,
hips_local_files: &HashMap<String, HiPSLocalFiles>,
params: MOCOptions,
) -> Self {
// Try to fetch the MOC
let hips_cdid = cfg.get_creator_did();
let url = if let Some(local_hips) = hips_local_files.get(hips_cdid) {
if let Ok(url) =
web_sys::Url::create_object_url_with_blob(local_hips.get_moc().as_ref())
{
url
} else {
format!("{}/Moc.fits", cfg.get_root_url())
}
} else {
format!("{}/Moc.fits", cfg.get_root_url())
};
let mode = cfg.get_request_mode();
let credentials = cfg.get_request_credentials();
let hips_cdid = cfg.get_creator_did().to_string();
let dataproduct_type = cfg.dataproduct_type;
Moc {
url,
params,
hips_cdid,
mode,
credentials,
dataproduct_type,
}
}
}

View File

@@ -14,7 +14,13 @@ pub struct AllskyRequest {
pub id: QueryId,
pub channel: Option<u32>,
request: Request<Vec<ImageType>>,
pub request: Request<Vec<ImageType>>,
}
impl AllskyRequest {
pub fn missing(&self) -> bool {
self.request.data.borrow().is_none()
}
}
impl From<AllskyRequest> for RequestType {
@@ -57,7 +63,7 @@ async fn query_allsky(
let raw_bytes = image_data.data();
Ok(ImageBuffer::from_raw_bytes(raw_bytes.0, w as i32, h as i32))
Ok(ImageBuffer::from_raw_bytes(raw_bytes.0, w, h))
}
impl From<query::Allsky> for AllskyRequest {
@@ -89,12 +95,18 @@ impl From<query::Allsky> for AllskyRequest {
.map(|image| {
let ImageBuffer { data, size } = image;
let data = data
.into_iter()
.iter()
.enumerate()
.filter(|&(i, _)| i % 4 != 3)
.map(|(_, v)| v)
.collect();
let image = ImageBuffer::new(data, size.x, size.y);
.map(|(_, v)| *v)
.collect::<Vec<_>>();
let image = ImageBuffer::new(
data.into_boxed_slice(),
size.0,
size.1,
size.2,
);
ImageType::RawRgb8u { image }
})
@@ -135,7 +147,7 @@ impl From<query::Allsky> for AllskyRequest {
let FitsImage {
raw_bytes, bitpix, ..
} = FitsImage::from_raw_bytes(raw_bytes.as_slice())?[0];
} = &FitsImage::from_raw_bytes(raw_bytes.as_slice())?[0];
match bitpix {
Bitpix::U8 => {
Ok(handle_allsky_fits(raw_bytes, tile_size, allsky_tile_size)?
@@ -201,7 +213,6 @@ impl From<query::Allsky> for AllskyRequest {
Self {
id,
hips_cdid,
//depth_tile,
url,
request,
channel: slice,
@@ -220,8 +231,11 @@ fn handle_allsky_file<F: TextureFormat>(
let mut src_idx = 0;
let tiles = (0..12).map(move |_| {
let mut base_tile =
ImageBuffer::<F>::allocate(&F::P::BLACK, allsky_tile_size, allsky_tile_size);
let mut base_tile = ImageBuffer::<F>::allocate(
&F::P::BLACK,
allsky_tile_size as u32,
allsky_tile_size as u32,
);
for idx_tile in 0..64 {
let (x, y) = crate::utils::unmortonize(idx_tile as u64);
let dx = x * (d3_tile_allsky_size as u32);
@@ -268,8 +282,14 @@ fn handle_allsky_fits<F: TextureFormat>(
.rev()
.flatten()
.copied()
.collect::<Vec<_>>();
let image = ImageBuffer::<F>::new(reversed_rows_data, width_allsky_px, height_allsky_px);
.collect::<Vec<_>>()
.into_boxed_slice();
let image = ImageBuffer::<F>::new(
reversed_rows_data,
width_allsky_px as u32,
height_allsky_px as u32,
1,
);
let allsky_tiles_iter =
handle_allsky_file::<F>(image, allsky_tile_size, tile_size)?.map(move |image| {
@@ -286,7 +306,12 @@ fn handle_allsky_fits<F: TextureFormat>(
.cloned()
.collect();
ImageBuffer::<F>::new(new_image_data, allsky_tile_size, allsky_tile_size)
ImageBuffer::<F>::new(
new_image_data,
allsky_tile_size as u32,
allsky_tile_size as u32,
1,
)
});
Ok(allsky_tiles_iter)
@@ -294,59 +319,4 @@ fn handle_allsky_fits<F: TextureFormat>(
use al_core::texture::format::RGBA8U;
use crate::time::Time;
use std::cell::RefCell;
use std::rc::Rc;
pub struct Allsky {
pub image: Rc<RefCell<Option<Vec<ImageType>>>>,
pub time_req: Time,
//pub depth_tile: u8,
pub hips_cdid: CreatorDid,
url: Url,
pub channel: Option<u32>,
}
use crate::Abort;
impl Allsky {
pub fn missing(&self) -> bool {
self.image.borrow().is_none()
}
pub fn get_hips_cdid(&self) -> &CreatorDid {
&self.hips_cdid
}
pub fn get_url(&self) -> &Url {
&self.url
}
}
impl<'a> From<&'a AllskyRequest> for Option<Allsky> {
fn from(request: &'a AllskyRequest) -> Self {
let AllskyRequest {
request,
hips_cdid,
//depth_tile,
url,
channel,
..
} = request;
if request.is_resolved() {
let Request::<Vec<ImageType>> {
time_request, data, ..
} = request;
Some(Allsky {
time_req: *time_request,
// This is a clone on a Arc, it is supposed to be fast
image: data.clone(),
hips_cdid: hips_cdid.clone(),
url: url.clone(),
//depth_tile: *depth_tile,
channel: *channel,
})
} else {
None
}
}
}

View File

@@ -3,15 +3,15 @@ use crate::renderable::CreatorDid;
use super::{Request, RequestType};
use crate::healpix::coverage::Smoc;
use moclib::deser::fits::MocType;
use moclib::qty::Hpx;
use crate::healpix::moc::Moc;
use crate::healpix::moc::{FreqSpaceMoc, SpaceMoc};
use al_api::hips::DataproductType;
pub struct MOCRequest {
//pub id: QueryId,
pub hips_cdid: CreatorDid,
pub params: MOCOptions,
request: Request<HEALPixCoverage>,
pub request: Request<Moc>,
}
impl From<MOCRequest> for RequestType {
@@ -19,35 +19,14 @@ impl From<MOCRequest> for RequestType {
RequestType::Moc(request)
}
}
use super::Url;
use moclib::deser::fits;
use wasm_bindgen::JsCast;
use wasm_bindgen_futures::JsFuture;
use web_sys::{RequestInit, Response};
use moclib::moc::range::op::convert::convert_to_u64;
/// Convenient type for Space-MOCs
pub fn from_fits_hpx<T: Idx>(moc: MocType<T, Hpx<T>, Cursor<&[u8]>>) -> Smoc {
match moc {
MocType::Ranges(moc) => convert_to_u64::<T, Hpx<T>, _, Hpx<u64>>(moc).into_range_moc(),
MocType::Cells(moc) => {
convert_to_u64::<T, Hpx<T>, _, Hpx<u64>>(moc.into_cell_moc_iter().ranges())
.into_range_moc()
}
}
}
use crate::healpix::coverage::HEALPixCoverage;
use crate::Abort;
use al_api::moc::MOCOptions;
use moclib::deser::fits::MocIdxType;
use moclib::deser::fits::MocQtyType;
use moclib::idx::Idx;
use moclib::moc::{CellMOCIntoIterator, CellMOCIterator, RangeMOCIterator};
use std::io::Cursor;
use wasm_bindgen::JsValue;
impl From<query::Moc> for MOCRequest {
// Create a tile request associated to a HiPS
fn from(query: query::Moc) -> Self {
@@ -57,6 +36,7 @@ impl From<query::Moc> for MOCRequest {
hips_cdid,
credentials,
mode,
dataproduct_type,
} = query;
let url_clone = url.clone();
@@ -75,22 +55,20 @@ impl From<query::Moc> for MOCRequest {
let resp: Response = resp_value.dyn_into()?;
let array_buffer = JsFuture::from(resp.array_buffer()?).await?;
let bytes_buf = js_sys::Uint8Array::new(&array_buffer);
let num_bytes = bytes_buf.length() as usize;
let mut bytes = vec![0; num_bytes];
bytes_buf.copy_to(&mut bytes[..]);
let buf = js_sys::Uint8Array::new(&array_buffer);
let bytes = buf.to_vec();
// Coosys is permissive because we load a moc
let smoc = match fits::from_fits_ivoa_custom(Cursor::new(&bytes[..]), true)
.map_err(|e| JsValue::from_str(&e.to_string()))?
{
MocIdxType::U16(MocQtyType::<u16, _>::Hpx(moc)) => Ok(from_fits_hpx(moc)),
MocIdxType::U32(MocQtyType::<u32, _>::Hpx(moc)) => Ok(from_fits_hpx(moc)),
MocIdxType::U64(MocQtyType::<u64, _>::Hpx(moc)) => Ok(from_fits_hpx(moc)),
_ => Err(JsValue::from_str("MOC not supported. Must be a HPX MOC")),
}?;
Ok(HEALPixCoverage(smoc))
Ok(match dataproduct_type {
DataproductType::SpectralCube => {
Moc::FreqSpace(FreqSpaceMoc::from_fits_raw_bytes(&bytes)?)
}
DataproductType::Cube => {
let moc = SpaceMoc::from_fits_raw_bytes(&bytes)?;
Moc::FreqSpace(FreqSpaceMoc::from_space_moc(moc))
}
_ => Moc::Space(SpaceMoc::from_fits_raw_bytes(&bytes)?),
})
});
Self {
@@ -102,39 +80,3 @@ impl From<query::Moc> for MOCRequest {
}
}
}
use std::cell::RefCell;
use std::rc::Rc;
pub struct Moc {
pub moc: Rc<RefCell<Option<HEALPixCoverage>>>,
pub params: MOCOptions,
pub hips_cdid: Url,
}
impl Moc {
pub fn get_hips_cdid(&self) -> &Url {
&self.hips_cdid
}
}
impl<'a> From<&'a MOCRequest> for Option<Moc> {
fn from(request: &'a MOCRequest) -> Self {
let MOCRequest {
request,
hips_cdid,
params,
..
} = request;
if request.is_resolved() {
let Request::<HEALPixCoverage> { data, .. } = request;
Some(Moc {
// This is a clone on a Arc, it is supposed to be fast
moc: data.clone(),
hips_cdid: hips_cdid.clone(),
params: params.clone(),
})
} else {
None
}
}
}

View File

@@ -11,8 +11,8 @@ use std::cell::{Cell, RefCell};
use std::rc::Rc;
pub type Url = String;
pub struct Request<R> {
data: Rc<RefCell<Option<R>>>,
time_request: Time,
pub data: Rc<RefCell<Option<R>>>,
pub time_request: Time,
// Flag telling if the tile has been copied so that
// the HtmlImageElement can be reused to download another tile
//ready: bool,
@@ -75,6 +75,10 @@ where
pub fn resolve_status(&self) -> ResolvedStatus {
self.resolved.get()
}
pub fn get_data(&self) -> Rc<RefCell<Option<R>>> {
self.data.clone()
}
}
use allsky::AllskyRequest;
@@ -83,7 +87,7 @@ use tile::TileRequest;
pub enum RequestType {
Tile(TileRequest),
Allsky(AllskyRequest),
Moc(MOCRequest), //..
Moc(MOCRequest),
}
use crate::downloader::QueryId;
@@ -95,29 +99,30 @@ impl RequestType {
RequestType::Moc(request) => &request.hips_cdid,
}
}
}
impl<'a> From<&'a RequestType> for Option<Resource> {
fn from(request: &'a RequestType) -> Self {
match request {
RequestType::Tile(request) => Option::<Tile>::from(request).map(Resource::Tile),
RequestType::Allsky(request) => Option::<Allsky>::from(request).map(Resource::Allsky),
RequestType::Moc(request) => Option::<Moc>::from(request).map(Resource::Moc),
pub fn is_resolved(&self) -> bool {
match self {
RequestType::Tile(request) => request.request.is_resolved(),
RequestType::Allsky(request) => request.request.is_resolved(),
RequestType::Moc(request) => request.request.is_resolved(),
}
}
}
use crate::Abort;
use allsky::Allsky;
use moc::Moc;
use tile::Tile;
pub enum Resource {
Tile(Tile),
Allsky(Allsky),
Moc(Moc),
}
/*
impl From<RequestType> for Option<Resource> {
fn from(request: RequestType) -> Self {
match request {
RequestType::Tile(request) => Option::<Tile>::from(request).map(Resource::Tile),
RequestType::Allsky(request) => Option::<Allsky>::from(request).map(Resource::Allsky),
RequestType::Moc(request) => Option::<FetchedMoc>::from(request).map(Resource::Moc),
}
}
}*/
use crate::Abort;
use web_sys::RequestCredentials;
async fn query_html_image(
url: &str,
credentials: RequestCredentials,
@@ -128,8 +133,9 @@ async fn query_html_image(
// Set the CORS and credentials options for the image
let cors_value = match credentials {
RequestCredentials::Include => Some("use-credentials"),
RequestCredentials::SameOrigin => Some("anonymous"),
_ => Some(""),
RequestCredentials::Omit => Some("anonymous"),
RequestCredentials::SameOrigin => Some(""),
_ => None,
};
let promise = js_sys::Promise::new(
@@ -146,3 +152,39 @@ async fn query_html_image(
Ok(image)
}
use wasm_bindgen::JsCast;
use web_sys::RequestInit;
use web_sys::RequestMode;
use web_sys::Response;
async fn query_bitmap_from_blob(
url: &str,
mode: RequestMode,
credentials: RequestCredentials,
) -> Result<web_sys::ImageBitmap, JsValue> {
let window = web_sys::window().unwrap_abort();
let mut opts = RequestInit::new();
opts.method("GET");
opts.mode(mode);
opts.credentials(credentials);
let request = web_sys::Request::new_with_str_and_init(url, &opts).unwrap_abort();
let resp_value = JsFuture::from(window.fetch_with_request(&request)).await?;
// `resp_value` is a `Response` object.
debug_assert!(resp_value.is_instance_of::<Response>());
let resp: Response = resp_value.dyn_into()?;
if resp.ok() {
let blob = JsFuture::from(resp.blob()?)
.await?
.dyn_into::<web_sys::Blob>()?;
let image_bitmap = JsFuture::from(window.create_image_bitmap_with_blob(&blob)?).await?;
Ok(image_bitmap.into())
} else {
Err(JsValue::from_str(
"Response status code not between 200-299.",
))
}
}

View File

@@ -1,24 +1,24 @@
use crate::healpix::cell::HEALPixCell;
use crate::renderable::CreatorDid;
use al_core::image::format::ImageFormatType;
use al_core::texture::format::{PixelType, RGB8U, RGBA8U};
use al_core::texture::format::PixelType;
use crate::downloader::query;
use al_core::image::ImageType;
use super::super::query::CellDesc;
use super::Url;
use super::{Request, RequestType};
use crate::downloader::request::query_html_image;
use crate::downloader::QueryId;
pub struct TileRequest {
request: Request<ImageType>,
pub request: Request<ImageType>,
pub id: QueryId,
cell: HEALPixCell,
hips_cdid: CreatorDid,
url: Url,
format: ImageFormatType,
channel: Option<u32>,
pub cell: CellDesc,
pub hips_cdid: CreatorDid,
pub url: Url,
pub format: ImageFormatType,
}
impl From<TileRequest> for RequestType {
@@ -27,11 +27,14 @@ impl From<TileRequest> for RequestType {
}
}
use crate::downloader::request::query_bitmap_from_blob;
use al_core::image::bitmap::Bitmap;
use al_core::image::html::HTMLImage;
use wasm_bindgen::JsCast;
use wasm_bindgen::JsValue;
use wasm_bindgen_futures::JsFuture;
use web_sys::{RequestInit, Response};
impl From<query::Tile> for TileRequest {
// Create a tile request associated to a HiPS
fn from(query: query::Tile) -> Self {
@@ -43,33 +46,62 @@ impl From<query::Tile> for TileRequest {
credentials,
mode,
id,
channel: slice,
size,
create_bitmap_support,
} = query;
let url_clone = url.clone();
let channel = format.get_pixel_format();
let pixel_format = format.get_pixel_format();
let window = web_sys::window().unwrap_abort();
let request = match channel {
let size = match cell {
CellDesc::HiPS2D { tile_size, .. } | CellDesc::HiPSCube { tile_size, .. } => {
(tile_size, tile_size, 1)
}
CellDesc::HiPS3D {
tile_size,
tile_depth,
..
} => (tile_size, tile_size, tile_depth),
};
let request = match pixel_format {
PixelType::RGB8U => Request::new(async move {
// HTMLImageElement
let image = query_html_image(&url_clone, credentials).await?;
// The image has been resolved
Ok(ImageType::HTMLImageRgb8u {
image: HTMLImage::<RGB8U>::new(image),
})
if create_bitmap_support {
// optimized download of tile for GPU (using Blob + Bitmap) without creating any DOM structure
let image_bitmap =
query_bitmap_from_blob(&url_clone, mode, credentials).await?;
Ok(ImageType::ImageRgb8u {
image: Bitmap::new(image_bitmap),
})
} else {
// HTMLImageElement
let image = query_html_image(&url_clone, credentials).await?;
// The image has been resolved
Ok(ImageType::HTMLImageRgb8u {
image: HTMLImage::new(image),
})
}
}),
PixelType::RGBA8U => Request::new(async move {
// HTMLImageElement
let image = query_html_image(&url_clone, credentials).await?;
// The image has been resolved
Ok(ImageType::HTMLImageRgba8u {
image: HTMLImage::<RGBA8U>::new(image),
})
if create_bitmap_support {
// optimized download of tile for GPU (using Blob + Bitmap) without creating any DOM structure
let image_bitmap =
query_bitmap_from_blob(&url_clone, mode, credentials).await?;
Ok(ImageType::ImageRgba8u {
image: Bitmap::new(image_bitmap),
})
} else {
// HTMLImageElement
let image = query_html_image(&url_clone, credentials).await?;
// The image has been resolved
Ok(ImageType::HTMLImageRgba8u {
image: HTMLImage::new(image),
})
}
}),
PixelType::R32F | PixelType::R32I | PixelType::R16I | PixelType::R8U => {
Request::new(async move {
let window = web_sys::window().unwrap_abort();
let mut opts = RequestInit::new();
opts.method("GET");
opts.mode(mode);
@@ -93,10 +125,7 @@ impl From<query::Tile> for TileRequest {
let array_buffer = JsFuture::from(resp.array_buffer()?).await?;
let raw_bytes = js_sys::Uint8Array::new(&array_buffer);
Ok(ImageType::FitsRawBytes {
raw_bytes,
size: (size, size),
})
Ok(ImageType::FitsRawBytes { raw_bytes, size })
} else {
Err(JsValue::from_str(
"Response status code not between 200-299.",
@@ -113,74 +142,8 @@ impl From<query::Tile> for TileRequest {
hips_cdid,
url,
request,
channel: slice,
}
}
}
use crate::time::Time;
use std::cell::RefCell;
use std::rc::Rc;
pub struct Tile {
pub image: Rc<RefCell<Option<ImageType>>>,
pub time_req: Time,
pub cell: HEALPixCell,
pub format: ImageFormatType,
pub channel: Option<u32>,
hips_cdid: CreatorDid,
url: Url,
}
use crate::Abort;
impl Tile {
#[inline(always)]
pub fn missing(&self) -> bool {
self.image.borrow().is_none()
}
#[inline(always)]
pub fn get_hips_cdid(&self) -> &CreatorDid {
&self.hips_cdid
}
#[inline(always)]
pub fn get_url(&self) -> &Url {
&self.url
}
#[inline(always)]
pub fn cell(&self) -> &HEALPixCell {
&self.cell
}
}
impl<'a> From<&'a TileRequest> for Option<Tile> {
fn from(request: &'a TileRequest) -> Self {
let TileRequest {
cell,
request,
hips_cdid,
url,
format,
channel,
..
} = request;
if request.is_resolved() {
let Request::<ImageType> {
time_request, data, ..
} = request;
Some(Tile {
cell: *cell,
time_req: *time_request,
// This is a clone on a Arc, it is supposed to be fast
image: data.clone(),
hips_cdid: hips_cdid.clone(),
url: url.clone(),
format: *format,
channel: *channel,
})
} else {
None
}
}
}

18
src/core/src/event.rs Normal file
View File

@@ -0,0 +1,18 @@
use wasm_bindgen::prelude::*;
use web_sys::{window, CustomEvent, CustomEventInit};
pub(crate) fn send_custom_event(name: &str, value: JsValue) {
// Create event details (optional)
let mut event_init = CustomEventInit::new();
event_init.detail(&value);
// Create the event
let event = CustomEvent::new_with_event_init_dict(name, &event_init)
.expect("Failed to create custom event");
// Dispatch the event on the window or any target element
window()
.expect("no global `window` exists")
.dispatch_event(&event)
.expect("failed to dispatch event");
}

View File

@@ -15,6 +15,7 @@ use healpix::compass_point::MainWind;
use healpix::compass_point::Ordinal;
use healpix::compass_point::OrdinalMap;
use crate::math::lonlat::LonLatT;
use crate::utils;
impl HEALPixCell {
@@ -95,6 +96,13 @@ impl HEALPixCell {
self.depth() == 0
}
#[inline(always)]
pub fn hash_with_dxdy(depth: u8, lon: f64, lat: f64) -> (Self, f64, f64) {
let (hash, dx, dy) = healpix::nested::hash_with_dxdy(depth, lon, lat);
(HEALPixCell(depth, hash), dx, dy)
}
// Find the smallest HEALPix cell containing self and another cells
// Returns None if the 2 HEALPix cell are not located in the same base HEALPix cell
#[inline]
@@ -483,6 +491,83 @@ impl Ord for HEALPixCell {
}
}
/// A simple object describing a cubic tile of a HiPS3D
#[derive(Eq, Hash, PartialEq, Clone, Debug)]
pub struct HEALPixFreqCell {
pub hpx: HEALPixCell,
pub f_hash: u64,
pub f_depth: u8,
}
use crate::math::spectra::Freq;
use crate::math::spectra::SpectralUnit;
impl HEALPixFreqCell {
pub fn from_lonlat(lonlat: LonLatT<f64>, freq: Freq, s_depth: u8, f_depth: u8) -> Self {
let hpx = HEALPixCell::new(
s_depth,
lonlat.lon().to_radians(),
lonlat.lat().to_radians(),
);
let f_hash = freq.hash(f_depth);
Self {
hpx,
f_hash,
f_depth,
}
}
pub fn new(hpx: HEALPixCell, f_hash: u64, f_depth: u8) -> Self {
Self {
hpx,
f_hash,
f_depth,
}
}
pub fn hpx_parent(&self) -> Self {
Self {
hpx: self.hpx.parent(),
f_hash: self.f_hash,
f_depth: self.f_depth,
}
}
pub fn parent(&self) -> Self {
Self {
hpx: self.hpx.parent(),
f_hash: self.f_hash >> 1,
f_depth: self.f_depth - 1,
}
}
pub fn is_hpx_root(&self) -> bool {
self.hpx.is_root()
}
pub fn freq_range(&self) -> Range<Freq> {
let f0 = Freq::from_hash_with_order(self.f_hash, self.f_depth);
let f1 = Freq::from_hash_with_order(
(self.f_hash + 1).min(Freq::num_max_cells(self.f_depth) as u64),
self.f_depth,
);
f0..f1
}
pub fn pixel_frequencies(&self, num_pixels: usize) -> impl Iterator<Item = f32> {
let delta_depth = num_pixels.trailing_zeros();
let pixel_depth = self.f_depth + delta_depth as u8;
let h0 = self.f_hash << delta_depth;
let h1 = (self.f_hash + 1) << delta_depth;
(h0..h1).map(move |hash| Freq::from_hash_with_order(hash, pixel_depth).0 as f32)
}
}
// Utils
#[inline(always)]
pub fn nside2depth(nside: u32) -> u8 {

View File

@@ -0,0 +1,127 @@
use crate::healpix::cell::HEALPixFreqCell;
use moclib::hpxranges2d::HpxRanges2D;
use moclib::ranges::ranges2d::Ranges2D;
use moclib::qty::{Frequency, MocQty};
#[derive(Debug)]
pub struct FreqSpaceMoc(pub moclib::hpxranges2d::FreqSpaceMoc<u64, u64>);
impl Clone for FreqSpaceMoc {
fn clone(&self) -> Self {
let HpxRanges2D(Moc2DRanges {
ranges2d: Ranges2D { x, y },
..
}) = &**self;
Self(HpxRanges2D(Moc2DRanges::new(x.clone(), y.clone())))
}
}
use wasm_bindgen::JsValue;
use moclib::deser::fits;
use moclib::deser::fits::MocIdxType;
use moclib::deser::fits::MocQtyType;
use moclib::mocranges2d::Moc2DRanges;
use std::io::Cursor;
impl FreqSpaceMoc {
/// Create a FreqSpaceMoc from a
pub fn from_space_moc(moc: SpaceMoc) -> Self {
let moc_2d = Moc2DRanges::new(vec![0..u64::MAX; 1], vec![moc.0.into_moc_ranges().0]);
FreqSpaceMoc(HpxRanges2D(moc_2d))
}
pub fn from_fits_raw_bytes(bytes: &[u8]) -> Result<Self, JsValue> {
let sfmoc = match fits::from_fits_ivoa_custom(Cursor::new(bytes), true)
.map_err(|e| JsValue::from_str(&e.to_string()))?
{
//MocIdxType::U16(MocQtyType::<u16, _>::FreqHpx(moc)) => Ok(from_fits_hpx(moc)),
//MocIdxType::U32(MocQtyType::<u32, _>::FreqHpx(moc)) => Ok(from_fits_hpx(moc)),
MocIdxType::U64(MocQtyType::<u64, _>::FreqHpx(ranges_iter)) => {
/*al_core::log(&format!(
"ranges moc 2D iter from fits {:?}",
));*/
let moc_2d_ranges = Moc2DRanges::from_ranges_it(ranges_iter);
let inner = moclib::hpxranges2d::HpxRanges2D(moc_2d_ranges);
Ok(inner)
}
_ => Err(JsValue::from_str(
"MOC not supported. Must be a FREQ|HPX 2DMOC coded on U64 only",
)),
}?;
Ok(Self(sfmoc))
}
/*pub fn from_fixed_hpx_cells(
depth: u8,
hpx_idx: impl Iterator<Item = u64>,
cap: Option<usize>,
) -> Self {
let moc = RangeMOC::from_fixed_depth_cells(depth, hpx_idx, cap);
SpaceMoc(moc)
}
pub fn from_hpx_cells<'a>(
depth: u8,
hpx_cell_it: impl Iterator<Item = &'a HEALPixCell>,
cap: Option<usize>,
) -> Self {
let cells_it = hpx_cell_it.map(|HEALPixCell(depth, idx)| (*depth, *idx));
let moc = RangeMOC::from_cells(depth, cells_it, cap);
SpaceMoc(moc)
}*/
pub fn f_max_depth(&self) -> u8 {
self.0.compute_min_depth().0
}
pub fn s_max_depth(&self) -> u8 {
self.0.compute_min_depth().1
}
pub fn sky_fraction(&self) -> f64 {
todo!()
}
pub fn intersects_cell(&self, cell: &HEALPixFreqCell) -> bool {
let HEALPixFreqCell {
hpx,
f_hash,
f_depth,
} = *cell;
let f_hash_0 = f_hash << (Frequency::<u64>::MAX_DEPTH - f_depth);
let f_hash_1 = (f_hash + 1) << (Frequency::<u64>::MAX_DEPTH - f_depth);
let hpx_ranges_2d = HpxRanges2D::create_from_freq_ranges_positions(
vec![f_hash_0..f_hash_1; 1],
vec![hpx.idx()],
Frequency::<u64>::MAX_DEPTH,
hpx.depth(),
);
!self.0.intersection(&hpx_ranges_2d).is_empty()
}
/*/// provide the list of (hash hpx, hash freq) of the cells contained in the sfmoc
pub fn cells(&self) -> impl Iterator<Item = (u64, u64)> {
todo!()
}*/
}
use core::ops::Deref;
use super::SpaceMoc;
impl Deref for FreqSpaceMoc {
type Target = moclib::hpxranges2d::FreqSpaceMoc<u64, u64>;
fn deref(&'_ self) -> &'_ Self::Target {
&self.0
}
}

View File

@@ -0,0 +1,10 @@
mod freq_space;
mod space;
pub use freq_space::FreqSpaceMoc;
pub use space::SpaceMoc;
pub enum Moc {
FreqSpace(FreqSpaceMoc),
Space(SpaceMoc),
}

View File

@@ -1,8 +1,8 @@
use crate::math::lonlat::LonLat;
use crate::math::lonlat::LonLatT;
use crate::math::PI;
use crate::math::{self, lonlat::LonLat};
use cgmath::Vector3;
use moclib::moc::RangeMOCIntoIterator;
use moclib::{
moc::range::{CellSelection, RangeMOC},
qty::Hpx,
@@ -12,9 +12,63 @@ pub type Smoc = RangeMOC<u64, Hpx<u64>>;
use crate::healpix::cell::HEALPixCell;
#[derive(Clone, Debug)]
pub struct HEALPixCoverage(pub Smoc);
pub struct SpaceMoc(pub Smoc);
use wasm_bindgen::JsValue;
use moclib::deser::fits;
use moclib::deser::fits::MocIdxType;
use moclib::deser::fits::MocQtyType;
use moclib::idx::Idx;
use moclib::moc::range::op::convert::convert_to_u64;
use moclib::moc::{CellMOCIntoIterator, CellMOCIterator, RangeMOCIterator};
/// Convenient type for Space-MOCs
pub fn from_fits_hpx<T: Idx>(moc: MocType<T, Hpx<T>, Cursor<&[u8]>>) -> Smoc {
match moc {
MocType::Ranges(moc) => convert_to_u64::<T, Hpx<T>, _, Hpx<u64>>(moc).into_range_moc(),
MocType::Cells(moc) => {
convert_to_u64::<T, Hpx<T>, _, Hpx<u64>>(moc.into_cell_moc_iter().ranges())
.into_range_moc()
}
}
}
use moclib::deser::fits::MocType;
use std::io::Cursor;
impl SpaceMoc {
pub fn from_fits_raw_bytes(bytes: &[u8]) -> Result<Self, JsValue> {
let smoc = match fits::from_fits_ivoa_custom(Cursor::new(bytes), true)
.map_err(|e| JsValue::from_str(&e.to_string()))?
{
MocIdxType::U16(MocQtyType::<u16, _>::Hpx(moc)) => Ok(from_fits_hpx(moc)),
MocIdxType::U32(MocQtyType::<u32, _>::Hpx(moc)) => Ok(from_fits_hpx(moc)),
MocIdxType::U64(MocQtyType::<u64, _>::Hpx(moc)) => Ok(from_fits_hpx(moc)),
_ => Err(JsValue::from_str("MOC not supported. Must be a HPX MOC")),
}?;
Ok(Self(smoc))
}
pub fn from_json(s: &str) -> Result<Self, JsValue> {
let moc = moclib::deser::json::from_json_aladin::<u64, Hpx<u64>>(s)
.map_err(|e| JsValue::from(js_sys::Error::new(&e.to_string())))?
.into_cell_moc_iter()
.ranges()
.into_range_moc();
Ok(Self(moc))
}
pub fn serialize_to_json(&self) -> Result<String, JsValue> {
let mut buf: Vec<u8> = Default::default();
(&self.0)
.into_range_moc_iter()
.cells()
.to_json_aladin(None, &mut buf)
.map(|()| unsafe { String::from_utf8_unchecked(buf) })
.map_err(|err| JsValue::from_str(&format!("{err:?}")))
}
impl HEALPixCoverage {
pub fn from_3d_coos<T: LonLat<f64>>(
// The depth of the smallest HEALPix cells contained in it
depth: u8,
@@ -38,7 +92,7 @@ impl HEALPixCoverage {
depth,
CellSelection::All,
);
HEALPixCoverage(moc)
SpaceMoc(moc)
}
pub fn from_fixed_hpx_cells(
@@ -47,7 +101,7 @@ impl HEALPixCoverage {
cap: Option<usize>,
) -> Self {
let moc = RangeMOC::from_fixed_depth_cells(depth, hpx_idx, cap);
HEALPixCoverage(moc)
SpaceMoc(moc)
}
pub fn from_hpx_cells<'a>(
@@ -58,14 +112,14 @@ impl HEALPixCoverage {
let cells_it = hpx_cell_it.map(|HEALPixCell(depth, idx)| (*depth, *idx));
let moc = RangeMOC::from_cells(depth, cells_it, cap);
HEALPixCoverage(moc)
SpaceMoc(moc)
}
pub fn from_cone(lonlat: &LonLatT<f64>, rad: f64, depth: u8) -> Self {
if rad >= PI {
Self::allsky(depth)
} else {
HEALPixCoverage(RangeMOC::from_cone(
SpaceMoc(RangeMOC::from_cone(
lonlat.lon().to_radians(),
lonlat.lat().to_radians(),
rad,
@@ -78,12 +132,7 @@ impl HEALPixCoverage {
pub fn allsky(depth_max: u8) -> Self {
let moc = RangeMOC::new_full_domain(depth_max);
HEALPixCoverage(moc)
}
pub fn contains_coo(&self, coo: &Vector3<f64>) -> bool {
let (lon, lat) = math::lonlat::xyz_to_radec(coo);
self.0.is_in(lon.to_radians(), lat.to_radians())
SpaceMoc(moc)
}
pub fn contains_lonlat(&self, lonlat: &LonLatT<f64>) -> bool {
@@ -98,9 +147,9 @@ impl HEALPixCoverage {
self.0.moc_ranges().intersects_range(&z29_rng)
}
pub fn is_intersecting(&self, other: &Self) -> bool {
/*pub fn is_intersecting(&self, other: &Self) -> bool {
!self.0.intersection(&other.0).is_empty()
}
}*/
pub fn depth(&self) -> u8 {
self.0.depth_max()
@@ -111,16 +160,16 @@ impl HEALPixCoverage {
}
pub fn not(&self) -> Self {
HEALPixCoverage(self.0.not())
SpaceMoc(self.0.not())
}
pub fn empty(depth: u8) -> Self {
HEALPixCoverage(RangeMOC::new_empty(depth))
SpaceMoc(RangeMOC::new_empty(depth))
}
}
use core::ops::Deref;
impl Deref for HEALPixCoverage {
impl Deref for SpaceMoc {
type Target = Smoc;
fn deref(&'_ self) -> &'_ Self::Target {

View File

@@ -1,4 +1,4 @@
pub mod cell;
pub mod coverage;
pub mod index_vector;
pub mod moc;
pub mod utils;

View File

@@ -3,7 +3,6 @@ use cgmath::Vector3;
use crate::camera::CameraViewPort;
use crate::math::angle::ToAngle;
use crate::math::projection::ProjectionType;
use crate::time::{DeltaTime, Time};
/// State for inertia
pub struct Inertia {
// Initial angular distance
@@ -12,21 +11,20 @@ pub struct Inertia {
// Vector of rotation
axis: Vector3<f64>,
// The time when the inertia begins
time_start: Time,
north_up: bool,
}
impl Inertia {
pub fn new(ampl: f64, axis: Vector3<f64>, north_up: bool) -> Self {
Inertia {
time_start: Time::now(),
ampl,
speed: ampl,
speed: (ampl * 0.5).min(0.1),
axis,
north_up,
}
}
/*
pub fn apply(&mut self, camera: &mut CameraViewPort, proj: &ProjectionType, _dt: DeltaTime) {
let t = ((Time::now() - self.time_start).as_millis() / 1000.0) as f64;
// Undamped angular frequency of the oscillator
@@ -46,6 +44,27 @@ impl Inertia {
let fov = start_fov * (1_f32 - alpha) + goal_fov * alpha;*/
camera.apply_axis_rotation(&self.axis, self.speed.to_angle(), proj);
if self.north_up {
camera.set_position_angle(0.0.to_angle(), proj);
}
}*/
pub fn apply(&mut self, camera: &mut CameraViewPort, proj: &ProjectionType, dt: f64) {
// Initial angular velocity
//let v0 = self.ampl * 0.5;
// Friction coefficient (tweak this)
const DAMPING_FACTOR: f64 = 5e-3;
self.speed *= (-DAMPING_FACTOR * dt).exp();
let delta_angle = self.speed * dt;
// Exponential decay of angular velocity
// self.speed = (v0 * (-damping * t).exp()).min(3.0);
//camera.apply_axis_rotation(&self.axis, self.speed.to_angle(), proj);
camera.apply_axis_rotation(&self.axis, delta_angle.to_angle(), proj);
if self.north_up {
camera.set_position_angle(0.0.to_angle(), proj);
}

View File

@@ -17,6 +17,7 @@
//extern crate num;
//extern crate num_traits;
//use crate::time::Time;
#[cfg(feature = "dbg")]
use std::panic;
@@ -39,7 +40,7 @@ pub trait Abort {
impl<T> Abort for Option<T> {
type Item = T;
#[inline]
#[inline(always)]
fn unwrap_abort(self) -> Self::Item {
use std::process;
match self {
@@ -51,7 +52,7 @@ impl<T> Abort for Option<T> {
impl<T, E> Abort for Result<T, E> {
type Item = T;
#[inline]
#[inline(always)]
fn unwrap_abort(self) -> Self::Item {
use std::process;
match self {
@@ -65,7 +66,7 @@ extern crate serde_json;
#[macro_use]
extern crate enum_dispatch;
#[inline]
#[inline(always)]
pub fn unwrap_abort<T>(o: Option<T>) -> T {
use std::process;
match o {
@@ -85,7 +86,6 @@ mod utils;
use math::projection::*;
use moclib::moc::RangeMOCIntoIterator;
//use votable::votable::VOTableWrapper;
use crate::tile_fetcher::HiPSLocalFiles;
use al_api::moc::MOCOptions;
@@ -101,8 +101,10 @@ pub mod async_task;
mod camera;
mod shaders;
mod browser_support;
mod coosys;
mod downloader;
mod event;
mod fifo_cache;
mod healpix;
mod inertia;
@@ -112,16 +114,9 @@ mod shader;
mod tile_fetcher;
mod time;
use crate::downloader::request::moc::from_fits_hpx;
use crate::{
camera::CameraViewPort, healpix::coverage::HEALPixCoverage, math::lonlat::LonLatT,
shader::ShaderManager, time::DeltaTime,
camera::CameraViewPort, healpix::moc::SpaceMoc, math::lonlat::LonLatT, shader::ShaderManager,
};
use moclib::deser::fits;
use moclib::deser::fits::MocIdxType;
use moclib::deser::fits::MocQtyType;
use std::io::Cursor;
use al_api::color::{Color, ColorRGBA};
use al_api::coo_system::CooSystem;
@@ -136,19 +131,11 @@ use cgmath::{Vector2, Vector3};
use crate::healpix::cell::HEALPixCell;
use math::angle::ArcDeg;
use moclib::{
moc::{CellMOCIntoIterator, CellMOCIterator, RangeMOCIterator},
qty::Hpx,
};
#[wasm_bindgen]
pub struct WebClient {
// The app
app: App,
// The time between the previous and the current
// frame
dt: DeltaTime,
}
use al_api::hips::ImageMetadata;
@@ -175,9 +162,7 @@ impl WebClient {
let app = App::new(&gl, aladin_div, shaders, resources)?;
let dt = DeltaTime::zero();
let webclient = WebClient { app, dt };
let webclient = WebClient { app };
Ok(webclient)
}
@@ -202,15 +187,15 @@ impl WebClient {
///
/// # Return
/// Whether the view is moving or not
pub fn update(&mut self, dt: f32) -> Result<bool, JsValue> {
pub fn update(&mut self, dt: f64) -> Result<bool, JsValue> {
// dt refers to the time taking (in ms) rendering the previous frame
self.dt = DeltaTime::from_millis(dt);
//self.dt = DeltaTime::from_millis(dt as f32);
// Update the application and get back the
// world coordinates of the center of projection in (ra, dec)
self.app.update(
// Time of the previous frame rendering
self.dt,
dt,
)
}
@@ -246,7 +231,7 @@ impl WebClient {
"ZEA" => self
.app
.set_projection(ProjectionType::Zea(mapproj::zenithal::zea::Zea::new())), /* Equal-area */
/*"FEYE" => self
"FEYE" => self
.app
.set_projection(ProjectionType::Feye(mapproj::zenithal::feye::Feye::new())),
"AIR" => {
@@ -254,19 +239,19 @@ impl WebClient {
//air_proj.set_n_iter(10);
//air_proj.set_eps(1e-12);
self.app.set_projection(ProjectionType::Air(air_proj))
}*/
}
//"AZP",
/*"ARC" => self
"ARC" => self
.app
.set_projection(ProjectionType::Arc(mapproj::zenithal::arc::Arc::new())),
"NCP" => self
.app
.set_projection(ProjectionType::Ncp(mapproj::zenithal::ncp::Ncp::new())),*/
.set_projection(ProjectionType::Ncp(mapproj::zenithal::ncp::Ncp::new())),
// Cylindrical
"MER" => self
.app
.set_projection(ProjectionType::Mer(mapproj::cylindrical::mer::Mer::new())),
/*"CAR" => self
"CAR" => self
.app
.set_projection(ProjectionType::Car(mapproj::cylindrical::car::Car::new())),
"CEA" => self
@@ -274,17 +259,17 @@ impl WebClient {
.set_projection(ProjectionType::Cea(mapproj::cylindrical::cea::Cea::new())),
"CYP" => self
.app
.set_projection(ProjectionType::Cyp(mapproj::cylindrical::cyp::Cyp::new())),*/
.set_projection(ProjectionType::Cyp(mapproj::cylindrical::cyp::Cyp::new())),
// Pseudo-cylindrical
"AIT" => self
.app
.set_projection(ProjectionType::Ait(mapproj::pseudocyl::ait::Ait::new())),
/*"PAR" => self
"PAR" => self
.app
.set_projection(ProjectionType::Par(mapproj::pseudocyl::par::Par::new())),
"SFL" => self
.app
.set_projection(ProjectionType::Sfl(mapproj::pseudocyl::sfl::Sfl::new())),*/
.set_projection(ProjectionType::Sfl(mapproj::pseudocyl::sfl::Sfl::new())),
"MOL" => {
let mut mol_proj = mapproj::pseudocyl::mol::Mol::new();
mol_proj.set_n_iter(10);
@@ -292,13 +277,13 @@ impl WebClient {
self.app.set_projection(ProjectionType::Mol(mol_proj))
} // Conic
/*"COD" => self
"COD" => self
.app
.set_projection(ProjectionType::Cod(mapproj::conic::cod::Cod::new())),
// Hybrid
"HPX" => self
.app
.set_projection(ProjectionType::Hpx(mapproj::hybrid::hpx::Hpx::new())),*/
.set_projection(ProjectionType::Hpx(mapproj::hybrid::hpx::Hpx::new())),
_ => Err(JsValue::from_str(
"Not a valid projection name. AIT, ZEA, SIN, STG, TAN, MOL and MER are accepted",
)),
@@ -387,12 +372,6 @@ impl WebClient {
Ok(())
}
#[wasm_bindgen(js_name = renameLayer)]
pub fn rename_layer(&mut self, layer: String, new_layer: String) -> Result<(), JsValue> {
// Deserialize the hips objects that compose the hips
self.app.rename_layer(&layer, &new_layer)
}
#[wasm_bindgen(js_name = swapLayers)]
pub fn swap_layers(
&mut self,
@@ -421,9 +400,24 @@ impl WebClient {
self.app.set_image_hips_color_cfg(layer, meta)
}
#[wasm_bindgen(js_name = setSliceNumber)]
pub fn set_hips_slice_number(&mut self, layer: String, slice: u32) -> Result<(), JsValue> {
self.app.set_hips_slice_number(&layer, slice)
#[wasm_bindgen(js_name = setFreq)]
pub fn set_hips_frequency(&mut self, layer: String, frequency: f32) -> Result<(), JsValue> {
self.app.set_hips_frequency(&layer, frequency)
}
#[wasm_bindgen(js_name = getFreq)]
pub fn get_hips_frequency(&mut self, layer: String) -> Result<f32, JsValue> {
self.app.get_hips_frequency(&layer)
}
#[wasm_bindgen(js_name = freq2hash)]
pub fn get_freq_hash(&mut self, layer: String, freq: f64) -> Result<u64, JsValue> {
self.app.get_freq_hash(&layer, freq)
}
#[wasm_bindgen(js_name = hash2freq)]
pub fn get_freq_from_hash(&mut self, layer: String, hash: u64) -> Result<f64, JsValue> {
self.app.get_freq_from_hash(&layer, hash)
}
#[wasm_bindgen(js_name = setBackgroundColor)]
@@ -1062,13 +1056,8 @@ impl WebClient {
pub fn add_json_moc(&mut self, options: MOCOptions, data: &JsValue) -> Result<(), JsValue> {
let str: String = js_sys::JSON::stringify(data)?.into();
let moc = moclib::deser::json::from_json_aladin::<u64, Hpx<u64>>(&str)
.map_err(|e| JsValue::from(js_sys::Error::new(&e.to_string())))?
.into_cell_moc_iter()
.ranges()
.into_range_moc();
self.app.add_moc(HEALPixCoverage(moc), options)?;
let smoc = SpaceMoc::from_json(&str)?;
self.app.add_moc(smoc, options)?;
Ok(())
}
@@ -1076,18 +1065,8 @@ impl WebClient {
#[wasm_bindgen(js_name = addFITSMOC)]
pub fn add_fits_moc(&mut self, options: MOCOptions, data: &[u8]) -> Result<(), JsValue> {
//let bytes = js_sys::Uint8Array::new(array_buffer).to_vec();
let moc = match fits::from_fits_ivoa_custom(Cursor::new(data), false)
.map_err(|e| JsValue::from_str(&e.to_string()))?
{
MocIdxType::U16(MocQtyType::<u16, _>::Hpx(moc)) => {
Ok(crate::downloader::request::moc::from_fits_hpx(moc))
}
MocIdxType::U32(MocQtyType::<u32, _>::Hpx(moc)) => Ok(from_fits_hpx(moc)),
MocIdxType::U64(MocQtyType::<u64, _>::Hpx(moc)) => Ok(from_fits_hpx(moc)),
_ => Err(JsValue::from_str("MOC not supported. Must be a HPX MOC")),
}?;
self.app.add_moc(HEALPixCoverage(moc), options)?;
let smoc = SpaceMoc::from_fits_raw_bytes(data)?;
self.app.add_moc(smoc, options)?;
Ok(())
}
@@ -1102,7 +1081,7 @@ impl WebClient {
) -> Result<(), JsValue> {
let tile_d = self.app.get_norder();
let pixel_d = tile_d + 9;
let moc = HEALPixCoverage::from_cone(
let moc = SpaceMoc::from_cone(
&LonLatT::new(
ra_deg.to_radians().to_angle(),
dec_deg.to_radians().to_angle(),
@@ -1136,7 +1115,7 @@ impl WebClient {
let v_in = &Vector3::new(1.0, 0.0, 0.0);
let mut moc = HEALPixCoverage::from_3d_coos(pixel_d as u8 - 1, vertex_it, v_in);
let mut moc = SpaceMoc::from_3d_coos(pixel_d as u8 - 1, vertex_it, v_in);
if moc.sky_fraction() > 0.5 {
moc = moc.not();
}
@@ -1182,13 +1161,7 @@ impl WebClient {
.get_moc(&moc_uuid)
.ok_or_else(|| JsValue::from(js_sys::Error::new("MOC not found")))?;
let mut buf: Vec<u8> = Default::default();
let json = (&moc.0)
.into_range_moc_iter()
.cells()
.to_json_aladin(None, &mut buf)
.map(|()| unsafe { String::from_utf8_unchecked(buf) })
.map_err(|err| JsValue::from_str(&format!("{err:?}")))?;
let json = moc.serialize_to_json()?;
serde_wasm_bindgen::to_value(&json).map_err(|err| JsValue::from_str(&format!("{err:?}")))
}

View File

@@ -55,6 +55,15 @@ impl From<fitsrs::wcs::LonLat> for LonLatT<f64> {
}
}
impl<S: BaseFloat> From<&'_ Vector3<S>> for LonLatT<S> {
fn from(v: &'_ Vector3<S>) -> Self {
let lon = Rad(v.x.atan2(v.z));
let lat = Rad(v.y.atan2((v.x * v.x + v.z * v.z).sqrt()));
LonLatT::new(Angle::new(lon), Angle::new(lat))
}
}
impl<S> LonLat<S> for LonLatT<S>
where
S: BaseFloat,
@@ -98,10 +107,7 @@ where
#[inline]
fn lonlat(&self) -> LonLatT<S> {
let lon = Rad(self.x.atan2(self.z));
let lat = Rad(self.y.atan2((self.x * self.x + self.z * self.z).sqrt()));
LonLatT::new(Angle::new(lon), Angle::new(lat))
self.into()
}
#[inline]

View File

@@ -9,6 +9,8 @@ pub const SQRT_TWO: f64 = std::f64::consts::SQRT_2;
pub const ZERO: f64 = 0.0;
pub mod spectra;
pub mod angle;
pub mod lonlat;
pub mod projection;

View File

@@ -9,6 +9,7 @@
// World space
use crate::camera::CameraViewPort;
use crate::domain::sdf::ProjDefType;
use crate::math::rotation::Rotation;
use coo_space::XYZModel;
//use crate::num_traits::FloatConst;
@@ -22,7 +23,7 @@ pub mod domain;
use crate::math::angle::ToAngle;
use crate::math::angle::Angle;
use domain::{basic, full::FullScreen};
use domain::{basic, cod::Cod, full::FullScreen, hpx::Hpx, par::Par};
/* S <-> NDC space conversion methods */
pub fn screen_to_ndc_space(
pos_screen_space: &XYScreen<f64>,
@@ -114,15 +115,15 @@ pub enum ProjectionType {
/* ZEA, Equal-area */
Zea(mapproj::zenithal::zea::Zea),
/* FEYE, Fish-eyes */
//Feye(mapproj::zenithal::feye::Feye),
Feye(mapproj::zenithal::feye::Feye),
/* AIR, */
//Air(mapproj::zenithal::air::Air),
Air(mapproj::zenithal::air::Air),
//AZP: {fov: 180},
//Azp(mapproj::zenithal::azp::Azp),
/* ARC, */
//Arc(mapproj::zenithal::arc::Arc),
Arc(mapproj::zenithal::arc::Arc),
/* NCP, */
//Ncp(mapproj::zenithal::ncp::Ncp),
Ncp(mapproj::zenithal::ncp::Ncp),
// Pseudo-cylindrical projections
/* AIT, Aitoff */
@@ -130,26 +131,26 @@ pub enum ProjectionType {
// MOL, Mollweide */
Mol(mapproj::pseudocyl::mol::Mol),
// PAR, */
//Par(mapproj::pseudocyl::par::Par),
Par(mapproj::pseudocyl::par::Par),
// SFL, */
//Sfl(mapproj::pseudocyl::sfl::Sfl),
Sfl(mapproj::pseudocyl::sfl::Sfl),
// Cylindrical projections
// MER, Mercator */
Mer(mapproj::cylindrical::mer::Mer),
// CAR, */
//Car(mapproj::cylindrical::car::Car),
Car(mapproj::cylindrical::car::Car),
// CEA, */
//Cea(mapproj::cylindrical::cea::Cea),
Cea(mapproj::cylindrical::cea::Cea),
// CYP, */
//Cyp(mapproj::cylindrical::cyp::Cyp),
Cyp(mapproj::cylindrical::cyp::Cyp),
// Conic projections
// COD, */
//Cod(mapproj::conic::cod::Cod),
Cod(mapproj::conic::cod::Cod),
// HEALPix hybrid projection
//Hpx(mapproj::hybrid::hpx::Hpx),
Hpx(mapproj::hybrid::hpx::Hpx),
}
use crate::math::lonlat::LonLat;
@@ -305,38 +306,38 @@ impl ProjectionType {
/* ZEA, Equal-area */
ProjectionType::Zea(_) => 1.0,
/* FEYE, Fish-eyes */
//ProjectionType::Feye(_) => 1.0,
ProjectionType::Feye(_) => 1.0,
/* AIR, */
//ProjectionType::Air(_) => 1.0,
ProjectionType::Air(_) => 1.0,
//AZP: {fov: 180},
//Azp(mapproj::zenithal::azp::Azp),
/* ARC, */
//ProjectionType::Arc(_) => 1.0,
ProjectionType::Arc(_) => 1.0,
/* NCP, */
//ProjectionType::Ncp(_) => 1.0,
ProjectionType::Ncp(_) => 1.0,
// Pseudo-cylindrical projections
/* AIT, Aitoff */
ProjectionType::Ait(_) => 2.0,
// MOL, Mollweide */
ProjectionType::Mol(_) => 2.0,
// PAR, */
//ProjectionType::Par(_) => 2.0,
ProjectionType::Par(_) => 2.0,
// SFL, */
//ProjectionType::Sfl(_) => 2.0,
ProjectionType::Sfl(_) => 2.0,
// Cylindrical projections
// MER, Mercator */
ProjectionType::Mer(_) => 1.0,
// CAR, */
//ProjectionType::Car(_) => 1.0,
ProjectionType::Car(_) => 1.0,
// CEA, */
//ProjectionType::Cea(_) => 1.0,
ProjectionType::Cea(_) => 1.0,
// CYP, */
//ProjectionType::Cyp(_) => 1.0,
ProjectionType::Cyp(_) => 1.0,
// Conic projections
// COD, */
//ProjectionType::Cod(_) => 1.0,
ProjectionType::Cod(_) => 1.0,
// HEALPix hybrid projection
//ProjectionType::Hpx(_) => 2.0,
ProjectionType::Hpx(_) => 2.0,
}
}
@@ -352,15 +353,15 @@ impl ProjectionType {
/* ZEA, Equal-area */
ProjectionType::Zea(_) => 359.9_f64.to_radians().to_angle(),
/* FEYE, Fish-eyes */
//ProjectionType::Feye(_) => 190.0,
ProjectionType::Feye(_) => 190.0_f64.to_radians().to_angle(),
/* AIR, */
//ProjectionType::Air(_) => 360.0,
ProjectionType::Air(_) => 360.0_f64.to_radians().to_angle(),
//AZP: {fov: 180},
//Azp(mapproj::zenithal::azp::Azp),
//ProjectionType::Azp(mapproj::zenithal::azp::Azp),
/* ARC, */
//ProjectionType::Arc(_) => 360.0,
ProjectionType::Arc(_) => 360.0_f64.to_radians().to_angle(),
/* NCP, */
//ProjectionType::Ncp(_) => 180.0,
ProjectionType::Ncp(_) => 180.0_f64.to_radians().to_angle(),
// Pseudo-cylindrical projections
/* AIT, Aitoff */
@@ -368,26 +369,26 @@ impl ProjectionType {
// MOL, Mollweide */
ProjectionType::Mol(_) => 360.0_f64.to_radians().to_angle(),
// PAR, */
//ProjectionType::Par(_) => 360.0,
ProjectionType::Par(_) => 360.0_f64.to_radians().to_angle(),
// SFL, */
//ProjectionType::Sfl(_) => 360.0,
ProjectionType::Sfl(_) => 360.0_f64.to_radians().to_angle(),
// Cylindrical projections
// MER, Mercator */
ProjectionType::Mer(_) => 360.0_f64.to_radians().to_angle(),
// CAR, */
//ProjectionType::Car(_) => 360.0,
ProjectionType::Car(_) => 360.0_f64.to_radians().to_angle(),
// CEA, */
//ProjectionType::Cea(_) => 360.0,
ProjectionType::Cea(_) => 360.0_f64.to_radians().to_angle(),
// CYP, */
//ProjectionType::Cyp(_) => 360.0,
ProjectionType::Cyp(_) => 360.0_f64.to_radians().to_angle(),
// Conic projections
// COD, */
//ProjectionType::Cod(_) => 330.0,
ProjectionType::Cod(_) => 330.0_f64.to_radians().to_angle(),
// HEALPix hybrid projection
//ProjectionType::Hpx(_) => 360.0,
ProjectionType::Hpx(_) => 360.0_f64.to_radians().to_angle(),
}
}
@@ -415,27 +416,27 @@ impl ProjectionType {
&DISK
}
/* FEYE, Fish-eyes */
/*ProjectionType::Feye(_) => {
ProjectionType::Feye(_) => {
const DISK: ProjDefType = ProjDefType::Disk(basic::disk::Disk { radius: 1.0 });
&DISK
}*/
}
/* AIR, */
/*ProjectionType::Air(_) => {
ProjectionType::Air(_) => {
const DISK: ProjDefType = ProjDefType::FullScreen(FullScreen);
&DISK
}*/
}
//AZP: {fov: 180},
//Azp(mapproj::zenithal::azp::Azp),
/* ARC, */
/*ProjectionType::Arc(_) => {
ProjectionType::Arc(_) => {
const DISK: ProjDefType = ProjDefType::Disk(basic::disk::Disk { radius: 1.0 });
&DISK
}*/
}
/* NCP, */
/*ProjectionType::Ncp(_) => {
ProjectionType::Ncp(_) => {
const DISK: ProjDefType = ProjDefType::Disk(basic::disk::Disk { radius: 1.0 });
&DISK
}*/
}
// Pseudo-cylindrical projections
/* AIT, Aitoff */
@@ -449,15 +450,15 @@ impl ProjectionType {
&ELLIPSE
}
// PAR, */
/*ProjectionType::Par(_) => {
ProjectionType::Par(_) => {
const PAR: ProjDefType = ProjDefType::Par(Par);
&PAR
}*/
}
// SFL, */
/*ProjectionType::Sfl(_) => {
ProjectionType::Sfl(_) => {
const PAR: ProjDefType = ProjDefType::Par(Par);
&PAR
}*/
}
// Cylindrical projections
// MER, Mercator */
@@ -465,32 +466,32 @@ impl ProjectionType {
const FULL_SCREEN: ProjDefType = ProjDefType::FullScreen(FullScreen);
&FULL_SCREEN
} // CAR, */
/*ProjectionType::Car(_) => {
const FULL_SCREEN: ProjDefType = ProjDefType::FullScreen(FullScreen);
&FULL_SCREEN
}*/
// CEA, */
/*ProjectionType::Cea(_) => {
const FULL_SCREEN: ProjDefType = ProjDefType::FullScreen(FullScreen);
&FULL_SCREEN
}*/
// CYP, */
/*ProjectionType::Cyp(_) => {
const FULL_SCREEN: ProjDefType = ProjDefType::FullScreen(FullScreen);
&FULL_SCREEN
}*/
ProjectionType::Car(_) => {
const FULL_SCREEN: ProjDefType = ProjDefType::FullScreen(FullScreen);
&FULL_SCREEN
}
// CEA, */
ProjectionType::Cea(_) => {
const FULL_SCREEN: ProjDefType = ProjDefType::FullScreen(FullScreen);
&FULL_SCREEN
}
// CYP, */
ProjectionType::Cyp(_) => {
const FULL_SCREEN: ProjDefType = ProjDefType::FullScreen(FullScreen);
&FULL_SCREEN
}
// Conic projections
// COD, */
/*ProjectionType::Cod(_) => {
const CONIC: ProjDefType = ProjDefType::Cod(Cod::new());
&CONIC
}*/
// HEALPix hybrid projection
/*ProjectionType::Hpx(_) => {
const HPX_DEF_REG: ProjDefType = ProjDefType::Hpx(Hpx);
&HPX_DEF_REG
}*/
// Conic projections
// COD, */
ProjectionType::Cod(_) => {
const CONIC: ProjDefType = ProjDefType::Cod(Cod::new());
&CONIC
}
// HEALPix hybrid projection
ProjectionType::Hpx(_) => {
const HPX_DEF_REG: ProjDefType = ProjDefType::Hpx(Hpx);
&HPX_DEF_REG
}
}
}
}
@@ -509,15 +510,15 @@ impl Projection for ProjectionType {
/* ZEA, Equal-area */
ProjectionType::Zea(zea) => zea.clip_to_world_space(xy),
/* FEYE, Fish-eyes */
//ProjectionType::Feye(feye) => feye.clip_to_world_space(xy),
ProjectionType::Feye(feye) => feye.clip_to_world_space(xy),
/* AIR, */
//ProjectionType::Air(air) => air.clip_to_world_space(xy),
ProjectionType::Air(air) => air.clip_to_world_space(xy),
//AZP: {fov: 180},
//Azp(mapproj::zenithal::azp::Azp),
/* ARC, */
//ProjectionType::Arc(arc) => arc.clip_to_world_space(xy),
ProjectionType::Arc(arc) => arc.clip_to_world_space(xy),
/* NCP, */
//ProjectionType::Ncp(ncp) => ncp.clip_to_world_space(xy),
ProjectionType::Ncp(ncp) => ncp.clip_to_world_space(xy),
// Pseudo-cylindrical projections
/* AIT, Aitoff */
@@ -525,30 +526,34 @@ impl Projection for ProjectionType {
// MOL, Mollweide */
ProjectionType::Mol(mol) => mol.clip_to_world_space(xy),
// PAR, */
//ProjectionType::Par(par) => par.clip_to_world_space(xy),
ProjectionType::Par(par) => par.clip_to_world_space(xy),
// SFL, */
//ProjectionType::Sfl(sfl) => sfl.clip_to_world_space(xy),
ProjectionType::Sfl(sfl) => sfl.clip_to_world_space(xy),
// Cylindrical projections
// MER, Mercator */
ProjectionType::Mer(mer) => mer.clip_to_world_space(xy),
// CAR, */
//ProjectionType::Car(car) => car.clip_to_world_space(xy),
ProjectionType::Car(car) => car.clip_to_world_space(xy),
// CEA, */
//ProjectionType::Cea(cea) => cea.clip_to_world_space(xy),
ProjectionType::Cea(cea) => cea.clip_to_world_space(xy),
// CYP, */
//ProjectionType::Cyp(cyp) => cyp.clip_to_world_space(xy),
ProjectionType::Cyp(cyp) => cyp.clip_to_world_space(xy),
// Conic projections
// COD, */
/*ProjectionType::Cod(cod) => cod.clip_to_world_space(xy).map(|xyz| {
ProjectionType::Cod(cod) => cod.clip_to_world_space(xy).map(|xyz| {
let rot = Rotation::from_sky_position(
&LonLatT::new(0.0_f64.to_angle(), (HALF_PI * 0.5).to_angle()).vector(),
&LonLatT::new(
0.0_f64.to_angle(),
(mapproj::math::HALF_PI * 0.5).to_angle(),
)
.vector(),
);
rot.inv_rotate(&xyz)
}),*/
}),
// HEALPix hybrid projection
//ProjectionType::Hpx(hpx) => hpx.clip_to_world_space(xy),
ProjectionType::Hpx(hpx) => hpx.clip_to_world_space(xy),
}
}
@@ -565,15 +570,15 @@ impl Projection for ProjectionType {
/* ZEA, Equal-area */
ProjectionType::Zea(zea) => zea.world_to_clip_space(xyz),
/* FEYE, Fish-eyes */
//ProjectionType::Feye(feye) => feye.world_to_clip_space(xyz),
ProjectionType::Feye(feye) => feye.world_to_clip_space(xyz),
/* AIR, */
//ProjectionType::Air(air) => air.world_to_clip_space(xyz),
ProjectionType::Air(air) => air.world_to_clip_space(xyz),
//AZP: {fov: 180},
//Azp(mapproj::zenithal::azp::Azp),
/* ARC, */
//ProjectionType::Arc(arc) => arc.world_to_clip_space(xyz),
ProjectionType::Arc(arc) => arc.world_to_clip_space(xyz),
/* NCP, */
//ProjectionType::Ncp(ncp) => ncp.world_to_clip_space(xyz),
ProjectionType::Ncp(ncp) => ncp.world_to_clip_space(xyz),
// Pseudo-cylindrical projections
/* AIT, Aitoff */
@@ -581,30 +586,34 @@ impl Projection for ProjectionType {
// MOL, Mollweide */
ProjectionType::Mol(mol) => mol.world_to_clip_space(xyz),
// PAR, */
//ProjectionType::Par(par) => par.world_to_clip_space(xyz),
ProjectionType::Par(par) => par.world_to_clip_space(xyz),
// SFL, */
//ProjectionType::Sfl(sfl) => sfl.world_to_clip_space(xyz),
ProjectionType::Sfl(sfl) => sfl.world_to_clip_space(xyz),
// Cylindrical projections
// MER, Mercator */
ProjectionType::Mer(mer) => mer.world_to_clip_space(xyz),
// CAR, */
//ProjectionType::Car(car) => car.world_to_clip_space(xyz),
ProjectionType::Car(car) => car.world_to_clip_space(xyz),
// CEA, */
//ProjectionType::Cea(cea) => cea.world_to_clip_space(xyz),
ProjectionType::Cea(cea) => cea.world_to_clip_space(xyz),
// CYP, */
//ProjectionType::Cyp(cyp) => cyp.world_to_clip_space(xyz),
ProjectionType::Cyp(cyp) => cyp.world_to_clip_space(xyz),
// Conic projections
// COD, */
/*ProjectionType::Cod(cod) => {
ProjectionType::Cod(cod) => {
// The Cod projection is centered on (0, 45 deg)
let rot = Rotation::from_sky_position(
&LonLatT::new(0.0_f64.to_angle(), (HALF_PI * 0.5).to_angle()).vector(),
&LonLatT::new(
0.0_f64.to_angle(),
(mapproj::math::HALF_PI * 0.5).to_angle(),
)
.vector(),
);
cod.world_to_clip_space(&rot.rotate(&xyz))
}*/
cod.world_to_clip_space(&rot.rotate(xyz))
}
// HEALPix hybrid projection
//ProjectionType::Hpx(hpx) => hpx.world_to_clip_space(xyz),
ProjectionType::Hpx(hpx) => hpx.world_to_clip_space(xyz),
}
}
}
@@ -634,6 +643,7 @@ impl UniformType for ProjectionType {
// Cylindrical projections
// MER, Mercator */
ProjectionType::Mer(_) => gl.uniform1i(location, 6),
_ => gl.uniform1i(location, 6),
}
}
}
@@ -808,7 +818,7 @@ mod tests {
"./../img/zea.jpg",
ProjectionType::Zea(mapproj::zenithal::zea::Zea),
);
/*generate_projection_map(
generate_projection_map(
"./../img/feye.png",
ProjectionType::Feye(mapproj::zenithal::feye::Feye),
);
@@ -823,14 +833,14 @@ mod tests {
generate_projection_map(
"./../img/air.png",
ProjectionType::Air(mapproj::zenithal::air::Air::new()),
);*/
);
// Cylindrical
generate_projection_map(
"./../img/mer.jpg",
ProjectionType::Mer(mapproj::cylindrical::mer::Mer),
);
/*generate_projection_map(
generate_projection_map(
"./../img/car.png",
ProjectionType::Car(mapproj::cylindrical::car::Car),
);
@@ -841,26 +851,26 @@ mod tests {
generate_projection_map(
"./../img/cyp.png",
ProjectionType::Cyp(mapproj::cylindrical::cyp::Cyp::new()),
);*/
);
// Pseudo-cylindrical
generate_projection_map(
"./../img/ait.jpg",
ProjectionType::Ait(mapproj::pseudocyl::ait::Ait),
);
/*generate_projection_map(
generate_projection_map(
"./../img/car.png",
ProjectionType::Par(mapproj::pseudocyl::par::Par),
);
generate_projection_map(
"./../img/cea.png",
ProjectionType::Sfl(mapproj::pseudocyl::sfl::Sfl),
);*/
);
generate_projection_map(
"./../img/mol.jpg",
ProjectionType::Mol(mapproj::pseudocyl::mol::Mol::new()),
);
// Conic
/*generate_projection_map(
generate_projection_map(
"./../img/cod.png",
ProjectionType::Cod(mapproj::conic::cod::Cod::new()),
);
@@ -868,6 +878,6 @@ mod tests {
generate_projection_map(
"./../img/hpx.png",
ProjectionType::Hpx(mapproj::hybrid::hpx::Hpx),
);*/
);
}
}

View File

@@ -111,27 +111,50 @@ where
// Define a rotation from an axis and a angle
pub fn from_axis_angle(axis: &Vector3<S>, angle: Angle<S>) -> Rotation<S> {
let angle: Rad<S> = angle.into();
let mat = Matrix3::from_axis_angle(axis.normalize(), angle);
(&mat).into()
let half = angle.0 * S::from(0.5).unwrap();
let (s, c) = half.sin_cos();
let axis = axis.normalize();
let q = Quaternion::new(c, axis.x * s, axis.y * s, axis.z * s);
Rotation(q)
}
// Define a rotation from a normalized vector
pub fn from_sky_position(pos: &Vector3<S>) -> Rotation<S> {
let (lon, lat) = math::lonlat::xyz_to_radec(pos);
let qy = Self::from_axis_angle(&Vector3::unit_y(), lon);
let qx = Self::from_axis_angle(&Vector3::unit_x(), -lat);
qy * qx
}
/*pub fn from_sky_position(pos: &Vector3<S>) -> Rotation<S> {
let (lon, lat) = math::lonlat::xyz_to_radec(pos);
let rot_y = Matrix3::from_angle_y(lon);
let rot_x = Matrix3::from_angle_x(-lat);
let mat = rot_y * rot_x;
(&(mat)).into()
}
}*/
// Apply a rotation to a position
pub fn rotate(&self, pos_world_space: &Vector3<S>) -> Vector3<S> {
let w2m: &Matrix3<S> = &self.into();
pub fn rotate(&self, v: &Vector3<S>) -> Vector3<S> {
/*let w2m: &Matrix3<S> = &self.into();
w2m * v*/
let qvec = self.0.v; // vector part of the quaternion
w2m * pos_world_space
// uv = qvec × v
let uv = qvec.cross(*v);
// uuv = qvec × uv
let uuv = qvec.cross(uv);
// v' = v + 2 * (uv * q.w + uuv)
*v + ((uv * self.0.s) + uuv) * (S::from(2.0).unwrap())
}
pub fn inv_rotate(&self, pos_model_space: &Vector3<S>) -> Vector3<S> {
let w2m: &Matrix3<S> = &self.into();
let m2w = w2m.transpose();

View File

@@ -0,0 +1,104 @@
pub trait SpectralUnit: Into<Freq> + Clone + Copy {
fn hash(&self, depth: u8) -> u64 {
let f: Freq = (*self).into();
let f_hash_max_order = Frequency::<u64>::freq2hash(f.0);
f_hash_max_order >> (Frequency::<u64>::MAX_DEPTH - depth)
}
}
use moclib::qty::{Frequency, MocQty};
pub const FREQ_MAX: Freq = Freq(5.846_006_549_323_611e48);
pub const FREQ_MIN: Freq = Freq(5.048_709_793_414_476e-29);
/// Frequency in Hz unit
#[derive(Clone, Copy, Debug, PartialEq, PartialOrd)]
pub struct Freq(pub f64);
impl Freq {
pub fn from_hash(hash: u64) -> Self {
let f = Frequency::hash2freq(hash);
Freq(f)
}
pub fn from_hash_with_order(hash: u64, order: u8) -> Self {
let hash_max_order = hash << (Frequency::<u64>::MAX_DEPTH - order);
let f = Frequency::hash2freq(hash_max_order);
Freq(f)
}
pub fn max(&self, other: Self) -> Self {
Freq(self.0.max(other.0))
}
pub fn min(&self, other: Self) -> Self {
Freq(self.0.min(other.0))
}
pub fn num_max_cells(order: u8) -> usize {
(Frequency::<u64>::n_cells_max() >> (Frequency::<u64>::MAX_DEPTH - order)) as usize
}
}
use std::ops::Sub;
impl Sub for Freq {
type Output = Self;
fn sub(self, other: Self) -> Self::Output {
Self(self.0 - other.0)
}
}
use std::ops::Add;
impl Add for Freq {
type Output = Self;
fn add(self, other: Self) -> Self::Output {
Self(self.0 + other.0)
}
}
/// Wavelength in meter unit
#[derive(Clone, Copy)]
pub struct Wavelength(pub f64);
/// Velocity in meter/sec unit
#[derive(Clone, Copy)]
pub struct Velocity {
/// A rest frequency to compute the velocity from
/// given by the obs_restfreq HiPS property
rest_freq: Freq,
/// The velocity in m/s
velocity: f64,
}
const SPEED_OF_LIGHT: f64 = 299792458.0;
impl From<Velocity> for Freq {
fn from(v: Velocity) -> Self {
let Velocity {
rest_freq,
velocity,
} = v;
// v = c * (of - f) / of
// v * of = c * (of - f)
// c * f = c * of - v * of = of * (c - v)
// f = of * (c - v) / c = of * (1 - v / c)
Freq(rest_freq.0 * (1.0 - velocity / SPEED_OF_LIGHT))
}
}
impl From<Wavelength> for Freq {
fn from(lambda: Wavelength) -> Self {
Freq(SPEED_OF_LIGHT / lambda.0)
}
}
impl SpectralUnit for Freq {}
impl SpectralUnit for Wavelength {}
impl SpectralUnit for Velocity {}

View File

@@ -1,39 +1,52 @@
use al_api::hips::ImageExt;
use al_api::hips::{DataproductType, ImageExt};
use crate::math::spectra::Freq;
use al_core::image::format::ImageFormatType;
use al_core::texture::format::PixelType;
use web_sys::{RequestCredentials, RequestMode};
#[derive(Debug)]
pub struct HiPSConfig {
pub root_url: String,
// HiPS image format
// TODO: Make that independant of the HiPS but of the ImageFormat
// The size of the texture images
tile_size: i32,
// Size of the tiles
pub tile_size: i32,
// Number of slices for HiPS cubes
pub cube_depth: Option<u32>,
/// Max depth of the current HiPS tiles
pub max_depth_tile: u8,
/// Min depth of the current HiPS tiles
min_depth_tile: u8,
// the number of slices for cubes
cube_depth: Option<u32>,
/// Max depth in the frequency axis (HiPS3D only)
pub max_depth_freq: Option<u8>,
// Max depth of the current HiPS tiles
max_depth_tile: u8,
/// Start of spectral coordinates (in meters)
pub em_min: Option<Freq>,
/// End of spectral coordinates (in meters)
pub em_max: Option<Freq>,
// For HiPS3D
pub tile_depth: Option<u8>,
pub is_allsky: bool,
pub frame: CooSystem,
// For FITS HiPSes
pub bitpix: Option<i32>,
format: ImageFormatType,
//dataproduct_subtype: Option<Vec<String>>,
//colored: bool,
pub dataproduct_type: DataproductType,
pub creator_did: String,
pub request_credentials: RequestCredentials,
pub request_mode: RequestMode,
}
use crate::HiPSProperties;
use crate::{math::spectra::Wavelength, HiPSProperties};
use al_api::coo_system::CooSystem;
use wasm_bindgen::JsValue;
@@ -64,7 +77,7 @@ impl HiPSConfig {
}
let format = match img_ext {
ImageExt::Fits => {
ImageExt::Fits | ImageExt::FitsFz => {
// Check the bitpix to determine the internal format of the tiles
if let Some(bitpix) = bitpix {
let fmt = (match bitpix {
@@ -73,6 +86,7 @@ impl HiPSConfig {
32 => Ok(PixelType::R32I),
-32 => Ok(PixelType::R32F),
-64 => Ok(PixelType::R32F),
64 => Ok(PixelType::R32I),
_ => Err(JsValue::from_str(
"Fits tiles exists but the BITPIX is not correct in the property file",
)),
@@ -116,6 +130,19 @@ impl HiPSConfig {
_ => RequestMode::Cors,
};
let dataproduct_type = properties.get_dataproduct_type().ok_or(JsValue::from_str(
"dataproduct_type keyword is required in the HiPS properties file",
))?;
let max_depth_freq = properties.get_hips_order_freq();
let tile_depth = properties.get_hips_tile_depth();
let em_min: Option<Freq> = properties
.get_em_max()
.map(|lambda| Wavelength(lambda as f64).into());
let em_max: Option<Freq> = properties
.get_em_min()
.map(|lambda| Wavelength(lambda as f64).into());
let hips_config = HiPSConfig {
creator_did,
// HiPS name
@@ -125,15 +152,23 @@ impl HiPSConfig {
is_allsky,
// the number of slices in a cube
// HiPSCube
cube_depth,
em_min,
em_max,
// HiPS3D
tile_depth,
max_depth_freq,
frame,
bitpix,
format,
tile_size,
request_credentials,
request_mode,
dataproduct_type,
};
Ok(hips_config)
@@ -141,13 +176,14 @@ impl HiPSConfig {
pub fn set_image_ext(&mut self, ext: ImageExt) -> Result<(), JsValue> {
let format = match ext {
ImageExt::Fits => {
ImageExt::Fits | ImageExt::FitsFz => {
// Check the bitpix to determine the internal format of the tiles
if let Some(bitpix) = self.bitpix {
let fmt = (match bitpix {
8 => Ok(PixelType::R8U),
16 => Ok(PixelType::R16I),
32 => Ok(PixelType::R32I),
64 => Ok(PixelType::R32I),
-32 => Ok(PixelType::R32F),
-64 => Ok(PixelType::R32F),
_ => Err(JsValue::from_str(
@@ -187,6 +223,7 @@ impl HiPSConfig {
self.root_url = root_url;
}
#[inline(always)]
pub fn get_cube_depth(&self) -> Option<u32> {
self.cube_depth
}

View File

@@ -1,10 +1,9 @@
use std::cmp::Ordering;
use std::collections::BinaryHeap;
use crate::renderable::hips::d2::texture::HpxTex;
use std::collections::HashMap;
use al_core::texture::format::PixelType;
use crate::renderable::hips::HpxTile;
use crate::downloader::request::allsky::AllskyRequest;
use cgmath::Vector3;
use al_api::hips::ImageExt;
@@ -16,9 +15,8 @@ use al_core::texture::format::{R16I, R32F, R32I, R8U, RGB8U, RGBA8U};
use al_core::Texture2DArray;
use al_core::WebGlContext;
use super::texture::{HpxTexture2D, HpxTexture2DUniforms};
use super::texture::HpxTexUniforms;
use crate::downloader::request::allsky::Allsky;
use crate::healpix::cell::HEALPixCell;
use crate::healpix::cell::NUM_HPX_TILES_DEPTH_ZERO;
use crate::renderable::hips::config::HiPSConfig;
@@ -26,116 +24,19 @@ use crate::time::Time;
use crate::Abort;
use crate::JsValue;
#[derive(Clone, Debug)]
pub struct TextureCellItem {
cell: HEALPixCell,
time_request: Time,
}
impl TextureCellItem {
fn is_root(&self) -> bool {
self.cell.is_root()
}
}
impl PartialEq for TextureCellItem {
fn eq(&self, other: &Self) -> bool {
self.cell == other.cell
}
}
impl Eq for TextureCellItem {}
// Ordering based on the time the tile has been requested
impl PartialOrd for TextureCellItem {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
Some(self.cmp(other))
}
}
impl Ord for TextureCellItem {
fn cmp(&self, other: &Self) -> Ordering {
other
.time_request
.partial_cmp(&self.time_request)
.unwrap_abort()
}
}
impl From<HpxTexture2D> for TextureCellItem {
fn from(texture: HpxTexture2D) -> Self {
let time_request = texture.time_request();
let cell = *texture.cell();
Self { cell, time_request }
}
}
impl From<&HpxTexture2D> for TextureCellItem {
fn from(texture: &HpxTexture2D) -> Self {
let time_request = texture.time_request();
let cell = *texture.cell();
Self { cell, time_request }
}
}
impl From<&mut HpxTexture2D> for TextureCellItem {
fn from(texture: &mut HpxTexture2D) -> Self {
let time_request = texture.time_request();
let cell = *texture.cell();
Self { cell, time_request }
}
}
struct HEALPixCellHeap(BinaryHeap<TextureCellItem>);
impl HEALPixCellHeap {
fn with_capacity(cap: usize) -> Self {
Self(BinaryHeap::with_capacity(cap))
}
fn push<E: Into<TextureCellItem>>(&mut self, item: E) {
let item = item.into();
self.0.push(item);
}
fn update_entry<E: Into<TextureCellItem>>(&mut self, item: E) {
let item = item.into();
self.0 = self
.0
.drain()
// Remove the cell
.filter(|texture_node| texture_node.cell != item.cell)
// Collect to a new binary heap that does not have cell anymore
.collect::<BinaryHeap<_>>();
self.push(item);
}
fn clear(&mut self) {
self.0.clear();
}
fn pop(&mut self) -> Option<TextureCellItem> {
self.0.pop()
}
fn len(&self) -> usize {
self.0.len()
}
}
use super::super::tile_heap::{Tile, TileHeap};
use crate::renderable::hips::HpxTileBuffer;
// Fixed sized binary heap
pub struct HiPS2DBuffer {
// Some information about the HiPS
config: HiPSConfig,
heap: HEALPixCellHeap,
heap: TileHeap<HEALPixCell>,
textures: HashMap<HEALPixCell, HpxTex>,
num_root_textures_available: u8,
size: usize,
textures: HashMap<HEALPixCell, HpxTexture2D>,
base_textures: [HpxTexture2D; NUM_HPX_TILES_DEPTH_ZERO],
base_textures: [HpxTex; NUM_HPX_TILES_DEPTH_ZERO],
// Array of 2D textures
tile_pixels: Texture2DArray,
@@ -176,34 +77,37 @@ fn create_hpx_texture_storage(
WebGlRenderingCtx::TEXTURE_WRAP_T,
WebGlRenderingCtx::CLAMP_TO_EDGE,
),
// Prevents r-coordinate wrapping (repeating)
(
WebGlRenderingCtx::TEXTURE_WRAP_R,
WebGlRenderingCtx::CLAMP_TO_EDGE,
),
];
match channel {
PixelType::RGBA8U => Texture2DArray::create_empty::<RGBA8U>(
gl, tile_size, tile_size,
// 256 is a consensus for targetting the maximum GPU architectures. We create a 128 slices to optimize performance
num_tiles, tex_params,
),
PixelType::RGB8U => Texture2DArray::create_empty::<RGB8U>(
gl, tile_size, tile_size,
// 256 is a consensus for targetting the maximum GPU architectures. We create a 128 slices to optimize performance
num_tiles, tex_params,
),
PixelType::RGBA8U => {
Texture2DArray::create_empty::<RGBA8U>(
gl, tile_size, tile_size,
// 256 is a consensus for targetting the maximum GPU architectures. We create a 128 slices to optimize performance
num_tiles, tex_params,
)
}
PixelType::RGB8U => {
Texture2DArray::create_empty::<RGB8U>(
gl, tile_size, tile_size,
// 256 is a consensus for targetting the maximum GPU architectures. We create a 128 slices to optimize performance
num_tiles, tex_params,
)
}
PixelType::R32F => Texture2DArray::create_empty::<R32F>(
gl, tile_size, tile_size,
// 256 is a consensus for targetting the maximum GPU architectures. We create a 128 slices to optimize performance
num_tiles, tex_params,
),
PixelType::R8U => Texture2DArray::create_empty::<R8U>(
gl, tile_size, tile_size,
// 256 is a consensus for targetting the maximum GPU architectures. We create a 128 slices to optimize performance
num_tiles, tex_params,
),
PixelType::R16I => Texture2DArray::create_empty::<R16I>(
gl, tile_size, tile_size,
// 256 is a consensus for targetting the maximum GPU architectures. We create a 128 slices to optimize performance
@@ -218,16 +122,14 @@ fn create_hpx_texture_storage(
}
impl HiPS2DBuffer {
pub fn push_allsky(&mut self, allsky: Allsky) -> Result<(), JsValue> {
let Allsky {
image, time_req, ..
} = allsky;
pub fn push_allsky(&mut self, allsky: AllskyRequest) -> Result<(), JsValue> {
let AllskyRequest { request, .. } = allsky;
{
let mutex_locked = image.borrow();
let mutex_locked = request.data.borrow();
let images = mutex_locked.as_ref().unwrap_abort();
for (idx, image) in images.iter().enumerate() {
self.push(&HEALPixCell(0, idx as u64), image, time_req)?;
self.push(&HEALPixCell(0, idx as u64), image, request.time_request)?;
}
}
@@ -250,14 +152,6 @@ impl HiPS2DBuffer {
}
}
fn is_heap_full(&self) -> bool {
// Check that there are no more than num_textures
// textures in the buffer
let num_textures_heap = self.heap.len();
num_textures_heap == self.size
}
// Update the priority of the texture containing the tile
// It must be ensured that the tile is already contained in the buffer
pub fn update_priority(&mut self, cell: &HEALPixCell /*, new_fov_cell: bool*/) {
@@ -270,7 +164,7 @@ impl HiPS2DBuffer {
let texture = self
.textures
.get_mut(cell)
.get(cell)
.expect("Texture cell has not been found while the buffer contains one of its tile!");
// Reset the time the tile has been received if it is a new cell present in the fov
//if new_fov_cell {
@@ -283,8 +177,8 @@ impl HiPS2DBuffer {
// But other textures can be removed thanks to the heap
// data-structure. We have to update the time_request of the texture
// and push it again in the heap to update its position.
let mut tex_cell_item: TextureCellItem = texture.into();
tex_cell_item.time_request = Time::now();
let mut tex_cell_item: Tile<HEALPixCell> = texture.into();
tex_cell_item.reset_time();
self.heap.update_entry(tex_cell_item);
}
@@ -320,9 +214,9 @@ impl HiPS2DBuffer {
)?;
self.num_root_textures_available += 1;
if self.num_root_textures_available == 12 {
/*if self.num_root_textures_available == 12 {
self.allsky_pixels.generate_mipmap()
}
}*/
}
self.available_tiles_during_frame = true;
@@ -331,14 +225,14 @@ impl HiPS2DBuffer {
if !self.contains_tile(cell) {
// The texture is not among the essential ones
// (i.e. is not a root texture)
let mut texture = if self.is_heap_full() {
let mut texture = if self.heap.is_full() {
// Pop the oldest requested texture
let oldest_texture = self.heap.pop().unwrap_abort();
// Ensure this is not a base texture
debug_assert!(!oldest_texture.is_root());
// Remove it from the textures HashMap
let mut texture = self.textures.remove(&oldest_texture.cell).expect(
let mut texture = self.textures.remove(oldest_texture.cell()).expect(
"Texture (oldest one) has not been found in the buffer of textures",
);
texture.replace(cell, time_request);
@@ -347,7 +241,7 @@ impl HiPS2DBuffer {
} else {
let idx = NUM_HPX_TILES_DEPTH_ZERO + self.heap.len();
HpxTexture2D::new(cell, idx as i32, time_request)
HpxTex::new(cell, idx as i32, time_request)
};
texture.copy_to_gpu(
@@ -394,7 +288,7 @@ impl HiPS2DBuffer {
.tile_pixels
.read_pixel(pos_tex.x, pos_tex.y, pos_tex.z)?,
_ => {
let uvy = 1.0 - (pos_tex.y as f32 / tile_size);
let uvy = 1.0 - (dx as f32);
pos_tex.y = (uvy * tile_size) as i32;
let f64_v = self
@@ -421,10 +315,26 @@ impl HiPS2DBuffer {
pub fn render_allsky(&mut self, flag: bool) {
self.allsky_rendering = flag;
}
// Get the nearest parent tile found in the CPU buffer
pub fn get_nearest_parent(&self, cell: &HEALPixCell) -> Option<HEALPixCell> {
let mut parent_cell = cell.parent();
while !self.contains(&parent_cell) && !parent_cell.is_root() {
parent_cell = parent_cell.parent();
}
if self.contains(&parent_cell) {
Some(parent_cell)
} else {
None
}
}
}
impl HpxTileBuffer for HiPS2DBuffer {
type T = HpxTexture2D;
type T = HpxTex;
type C = HEALPixCell;
fn new(gl: &WebGlContext, config: HiPSConfig) -> Result<Self, JsValue> {
let size = 128 - NUM_HPX_TILES_DEPTH_ZERO;
@@ -432,24 +342,25 @@ impl HpxTileBuffer for HiPS2DBuffer {
// Ensures there is at least space for the 12
// root textures
//debug_assert!(size >= NUM_HPX_TILES_DEPTH_ZERO);
let heap = HEALPixCellHeap::with_capacity(size);
let heap = TileHeap::with_capacity(size);
let textures = HashMap::with_capacity(size);
let now = Time::now();
let base_textures = [
HpxTexture2D::new(&HEALPixCell(0, 0), 0, now),
HpxTexture2D::new(&HEALPixCell(0, 1), 1, now),
HpxTexture2D::new(&HEALPixCell(0, 2), 2, now),
HpxTexture2D::new(&HEALPixCell(0, 3), 3, now),
HpxTexture2D::new(&HEALPixCell(0, 4), 4, now),
HpxTexture2D::new(&HEALPixCell(0, 5), 5, now),
HpxTexture2D::new(&HEALPixCell(0, 6), 6, now),
HpxTexture2D::new(&HEALPixCell(0, 7), 7, now),
HpxTexture2D::new(&HEALPixCell(0, 8), 8, now),
HpxTexture2D::new(&HEALPixCell(0, 9), 9, now),
HpxTexture2D::new(&HEALPixCell(0, 10), 10, now),
HpxTexture2D::new(&HEALPixCell(0, 11), 11, now),
HpxTex::new(&HEALPixCell(0, 0), 0, now),
HpxTex::new(&HEALPixCell(0, 1), 1, now),
HpxTex::new(&HEALPixCell(0, 2), 2, now),
HpxTex::new(&HEALPixCell(0, 3), 3, now),
HpxTex::new(&HEALPixCell(0, 4), 4, now),
HpxTex::new(&HEALPixCell(0, 5), 5, now),
HpxTex::new(&HEALPixCell(0, 6), 6, now),
HpxTex::new(&HEALPixCell(0, 7), 7, now),
HpxTex::new(&HEALPixCell(0, 8), 8, now),
HpxTex::new(&HEALPixCell(0, 9), 9, now),
HpxTex::new(&HEALPixCell(0, 10), 10, now),
HpxTex::new(&HEALPixCell(0, 11), 11, now),
];
let channel = config.get_format().get_pixel_format();
let tile_size = config.get_tile_size();
let tile_pixels = create_hpx_texture_storage(gl, channel, 128, tile_size)?;
@@ -467,7 +378,6 @@ impl HpxTileBuffer for HiPS2DBuffer {
config,
heap,
size,
num_root_textures_available,
textures,
base_textures,
@@ -484,6 +394,7 @@ impl HpxTileBuffer for HiPS2DBuffer {
self.config.set_image_ext(ext)?;
let channel = self.config.get_format().get_pixel_format();
let tile_size = self.config.get_tile_size();
self.tile_pixels = create_hpx_texture_storage(gl, channel, 128, tile_size)?;
@@ -492,18 +403,18 @@ impl HpxTileBuffer for HiPS2DBuffer {
let now = Time::now();
self.base_textures = [
HpxTexture2D::new(&HEALPixCell(0, 0), 0, now),
HpxTexture2D::new(&HEALPixCell(0, 1), 1, now),
HpxTexture2D::new(&HEALPixCell(0, 2), 2, now),
HpxTexture2D::new(&HEALPixCell(0, 3), 3, now),
HpxTexture2D::new(&HEALPixCell(0, 4), 4, now),
HpxTexture2D::new(&HEALPixCell(0, 5), 5, now),
HpxTexture2D::new(&HEALPixCell(0, 6), 6, now),
HpxTexture2D::new(&HEALPixCell(0, 7), 7, now),
HpxTexture2D::new(&HEALPixCell(0, 8), 8, now),
HpxTexture2D::new(&HEALPixCell(0, 9), 9, now),
HpxTexture2D::new(&HEALPixCell(0, 10), 10, now),
HpxTexture2D::new(&HEALPixCell(0, 11), 11, now),
HpxTex::new(&HEALPixCell(0, 0), 0, now),
HpxTex::new(&HEALPixCell(0, 1), 1, now),
HpxTex::new(&HEALPixCell(0, 2), 2, now),
HpxTex::new(&HEALPixCell(0, 3), 3, now),
HpxTex::new(&HEALPixCell(0, 4), 4, now),
HpxTex::new(&HEALPixCell(0, 5), 5, now),
HpxTex::new(&HEALPixCell(0, 6), 6, now),
HpxTex::new(&HEALPixCell(0, 7), 7, now),
HpxTex::new(&HEALPixCell(0, 8), 8, now),
HpxTex::new(&HEALPixCell(0, 9), 9, now),
HpxTex::new(&HEALPixCell(0, 10), 10, now),
HpxTex::new(&HEALPixCell(0, 11), 11, now),
];
self.heap.clear();
@@ -527,7 +438,7 @@ impl HpxTileBuffer for HiPS2DBuffer {
// Tell if a texture is available meaning all its sub tiles
// must have been written for the GPU
fn contains(&self, cell: &HEALPixCell) -> bool {
fn contains(&self, cell: &Self::C) -> bool {
if let Some(t) = self.get(cell) {
t.is_on_gpu()
} else {
@@ -536,7 +447,7 @@ impl HpxTileBuffer for HiPS2DBuffer {
}
/// Accessors
fn get(&self, cell: &HEALPixCell) -> Option<&Self::T> {
fn get(&self, cell: &Self::C) -> Option<&Self::T> {
if cell.is_root() {
let HEALPixCell(_, idx) = cell;
Some(&self.base_textures[*idx as usize])
@@ -570,7 +481,7 @@ impl SendUniforms for HiPS2DBuffer {
let cell = HEALPixCell(0, idx as u64);
let texture = self.get(&cell).unwrap();
let texture_uniforms = HpxTexture2DUniforms::new(texture, idx as i32);
let texture_uniforms = HpxTexUniforms::new(texture, idx as i32);
shader.attach_uniforms_from(&texture_uniforms);
}

View File

@@ -2,9 +2,12 @@ pub mod buffer;
pub mod texture;
use crate::app::BLENDING_ANIM_DURATION;
use crate::browser_support::BrowserFeaturesSupport;
use crate::downloader::query;
use crate::downloader::query::CellDesc;
use crate::downloader::request::allsky::AllskyRequest;
use crate::math::angle::ToAngle;
use crate::renderable::hips::HpxTile;
use crate::tile_fetcher::TileFetcherQueue;
use al_api::hips::ImageExt;
use al_api::hips::ImageMetadata;
use al_core::colormap::Colormap;
@@ -32,8 +35,7 @@ use crate::camera::CameraViewPort;
use crate::shader::ShaderManager;
use crate::utils;
use crate::downloader::request::allsky::Allsky;
use crate::healpix::{cell::HEALPixCell, coverage::HEALPixCoverage};
use crate::healpix::{cell::HEALPixCell, moc::SpaceMoc};
use crate::time::Time;
use super::config::HiPSConfig;
@@ -44,7 +46,7 @@ use std::collections::HashSet;
// to not be too much skewed
use buffer::HiPS2DBuffer;
use texture::HpxTexture2D;
use texture::HpxTex;
use super::raytracing::RayTracer;
use super::uv::{TileCorner, TileUVW};
@@ -63,13 +65,21 @@ pub struct HpxDrawData<'a> {
impl<'a> HpxDrawData<'a> {
fn from_texture(
starting_texture: &HpxTexture2D,
ending_texture: &HpxTexture2D,
starting_texture: &HpxTex,
ending_texture: &HpxTex,
cell: &'a HEALPixCell,
) -> Self {
let uv_0 = TileUVW::new(cell, starting_texture);
let uv_1 = TileUVW::new(cell, ending_texture);
let start_time = ending_texture.start_time().as_millis();
let uv_0 = TileUVW::new(
cell,
&Some(starting_texture.cell),
starting_texture.idx() as f32,
);
let uv_1 = TileUVW::new(
cell,
&Some(ending_texture.cell),
ending_texture.idx() as f32,
);
let start_time = ending_texture.start_time.unwrap_or(Time::now()).as_millis();
Self {
uv_0,
@@ -209,6 +219,9 @@ pub struct HiPS2D {
//#[cfg(feature = "webgl1")]
// layout (location = 0) in vec3 position;
position: Vec<f32>,
//js_position: Float32Array,
//cap: usize,
//ptr: usize,
//#[cfg(feature = "webgl1")]
// layout (location = 1) in vec3 uv_start;
uv_start: Vec<f32>,
@@ -225,8 +238,7 @@ pub struct HiPS2D {
vao: VertexArrayObject,
gl: WebGlContext,
footprint_moc: Option<HEALPixCoverage>,
moc: Option<SpaceMoc>,
// A buffer storing the cells in the view
hpx_cells_in_view: Vec<HEALPixCell>,
@@ -292,8 +304,9 @@ impl HiPS2D {
let buffer = HiPS2DBuffer::new(gl, config)?;
let gl = gl.clone();
let footprint_moc = None;
let moc = None;
let hpx_cells_in_view = vec![];
// request the allsky texture
Ok(Self {
// The image survey texture buffer
@@ -313,15 +326,17 @@ impl HiPS2D {
idx_vertices,
footprint_moc,
moc,
hpx_cells_in_view,
})
}
pub fn look_for_new_tiles<'a>(
&'a mut self,
camera: &'a CameraViewPort,
) -> Option<impl Iterator<Item = HEALPixCell> + 'a> {
pub fn look_for_new_tiles(
&mut self,
tile_fetcher: &mut TileFetcherQueue,
camera: &CameraViewPort,
browser_features_support: &BrowserFeaturesSupport,
) {
// do not add tiles if the view is already at depth 0
let cfg = self.get_config();
let depth_tile = camera
@@ -330,37 +345,66 @@ impl HiPS2D {
.max(cfg.get_min_depth_tile());
let survey_frame = cfg.get_frame();
let mut already_considered_tiles = HashSet::new();
let min_tile_depth = cfg.get_min_depth_tile();
let tile_cells_iter = camera
let tile_queries_iter = camera
.get_hpx_cells(depth_tile, survey_frame)
.into_iter()
.filter(move |tile_cell| {
if already_considered_tiles.contains(tile_cell) {
return false;
}
already_considered_tiles.insert(*tile_cell);
if let Some(moc) = self.footprint_moc.as_ref() {
moc.intersects_cell(tile_cell) && !self.update_priority_tile(tile_cell)
.filter_map(|tile_cell| {
let make_query = if let Some(moc) = self.moc.as_ref() {
moc.intersects_cell(&tile_cell) && !self.update_priority_tile(&tile_cell)
} else {
!self.update_priority_tile(tile_cell)
!self.update_priority_tile(&tile_cell)
};
if make_query {
Some(query::Tile::new(
&tile_cell,
self.get_config(),
browser_features_support,
))
} else {
None
}
});
Some(tile_cells_iter)
let mut ancestors = HashSet::new();
for tile_query in tile_queries_iter {
match tile_query.cell {
CellDesc::HiPS2D { cell, .. } => {
let tile_cell = cell;
tile_fetcher.append(tile_query);
// check if we are starting aladin lite or not.
// If so we want to retrieve only the tiles in the view and access them
// directly i.e. without blending them with less precised tiles
if tile_fetcher.get_num_tile_fetched() > 0
&& tile_cell.depth() >= min_tile_depth + 3
{
let ancestor_tile_cell = tile_cell.ancestor(3);
ancestors.insert(ancestor_tile_cell);
}
}
_ => unreachable!(),
}
}
for ancestor in ancestors {
if !self.update_priority_tile(&ancestor) {
tile_fetcher.append(query::Tile::new(
&ancestor,
self.get_config(),
browser_features_support,
));
}
}
}
pub fn contains_tile(&self, cell: &HEALPixCell) -> bool {
self.buffer.contains_tile(cell)
}
pub fn get_tile_query(&self, cell: &HEALPixCell) -> query::Tile {
let cfg = self.get_config();
query::Tile::new(cell, None, cfg)
}
pub fn update(&mut self, camera: &mut CameraViewPort, projection: &ProjectionType) {
let raytracing = camera.is_raytracing(projection);
@@ -401,13 +445,13 @@ impl HiPS2D {
}
#[inline]
pub fn set_moc(&mut self, moc: HEALPixCoverage) {
self.footprint_moc = Some(moc);
pub fn set_moc(&mut self, moc: SpaceMoc) {
self.moc = Some(moc);
}
#[inline]
pub fn get_moc(&self) -> Option<&HEALPixCoverage> {
self.footprint_moc.as_ref()
pub fn get_moc(&self) -> Option<&SpaceMoc> {
self.moc.as_ref()
}
pub fn set_image_ext(&mut self, ext: ImageExt) -> Result<(), JsValue> {
@@ -453,6 +497,7 @@ impl HiPS2D {
}
fn recompute_vertices(&mut self, camera: &mut CameraViewPort, projection: &ProjectionType) {
//al_core::log(&format!("num position: {:?}", self.position.len()));
self.position.clear();
self.uv_start.clear();
self.uv_end.clear();
@@ -479,7 +524,7 @@ impl HiPS2D {
// super::subdivide::num_hpx_subdivision(&self.hpx_cells_in_view[0], camera, projection);
for cell in &self.hpx_cells_in_view {
// filter textures that are not in the moc
let cell_in_cov = if let Some(moc) = self.footprint_moc.as_ref() {
let cell_in_cov = if let Some(moc) = self.moc.as_ref() {
if moc.intersects_cell(cell) {
// Rasterizer does not render tiles that are not in the MOC
// This is not a problem for transparency rendered HiPses (FITS or PNG)
@@ -696,7 +741,7 @@ impl HiPS2D {
}
}
pub fn add_tile<I: Image>(
pub fn push_tile<I: Image>(
&mut self,
cell: &HEALPixCell,
image: I,
@@ -705,7 +750,7 @@ impl HiPS2D {
self.buffer.push(cell, image, time_request)
}
pub fn add_allsky(&mut self, allsky: Allsky) -> Result<(), JsValue> {
pub fn add_allsky(&mut self, allsky: AllskyRequest) -> Result<(), JsValue> {
self.buffer.push_allsky(allsky)
}

View File

@@ -4,8 +4,8 @@ use al_core::image::Image;
use al_core::Texture2DArray;
use wasm_bindgen::JsValue;
pub struct HpxTexture2D {
tile_cell: HEALPixCell,
pub struct HpxTex {
pub cell: HEALPixCell,
// Precomputed uniq number
uniq: i32,
// Position of the texture in the buffer
@@ -13,7 +13,7 @@ pub struct HpxTexture2D {
// The time the texture has been received
// If the texture contains multiple tiles, then the receiving time
// is set when all the tiles have been copied to the buffer
start_time: Option<Time>,
pub start_time: Option<Time>,
// The time request of the texture is the time request
// of the first tile being inserted in it
// It is then only given in the constructor of Texture
@@ -22,23 +22,21 @@ pub struct HpxTexture2D {
// texture. But this is too expensive because at each tile inserted
// in the buffer, one should reevalute the priority of the texture
// in the buffer's binary heap.
time_request: Time,
pub time_request: Time,
// Full flag telling the texture has been filled
copied_to_gpu: bool,
}
use crate::renderable::hips::HpxTile;
impl HpxTexture2D {
impl HpxTex {
pub fn new(cell: &HEALPixCell, idx: i32, time_request: Time) -> Self {
let start_time = None;
let copied_to_gpu = false;
let tile_cell = *cell;
let cell = *cell;
let uniq = cell.uniq();
Self {
tile_cell,
cell,
uniq,
time_request,
idx,
@@ -56,13 +54,13 @@ impl HpxTexture2D {
}
// Setter
pub fn replace(&mut self, tile_cell: &HEALPixCell, time_request: Time) {
pub fn replace(&mut self, cell: &HEALPixCell, time_request: Time) {
// Cancel the tasks copying the tiles contained in the texture
// which have not yet been completed.
//self.clear_tasks_in_progress(config, exec);
self.tile_cell = *tile_cell;
self.uniq = tile_cell.uniq();
self.cell = *cell;
self.uniq = cell.uniq();
self.copied_to_gpu = false;
self.start_time = None;
self.time_request = time_request;
@@ -77,8 +75,7 @@ impl HpxTexture2D {
image: &I,
gpu_texture: &Texture2DArray,
) -> Result<(), JsValue> {
debug_assert!(*cell == self.tile_cell);
debug_assert!(!self.copied_to_gpu);
debug_assert!(*cell == self.cell);
self.copied_to_gpu = true;
self.start_time = Some(Time::now());
@@ -87,7 +84,8 @@ impl HpxTexture2D {
}
}
impl HpxTile for HpxTexture2D {
/*
impl HpxTile for HpxTex {
// Getter
// Returns the current time if the texture is not full
fn start_time(&self) -> Time {
@@ -103,44 +101,43 @@ impl HpxTile for HpxTexture2D {
}
fn cell(&self) -> &HEALPixCell {
&self.tile_cell
&self.cell
}
}
}*/
use std::cmp::Ordering;
impl PartialOrd for HpxTexture2D {
impl PartialOrd for HpxTex {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
Some(self.cmp(other))
}
}
use crate::Abort;
impl Ord for HpxTexture2D {
impl Ord for HpxTex {
fn cmp(&self, other: &Self) -> Ordering {
self.uniq.cmp(&other.uniq)
}
}
impl PartialEq for HpxTexture2D {
impl PartialEq for HpxTex {
fn eq(&self, other: &Self) -> bool {
self.uniq == other.uniq
}
}
impl Eq for HpxTexture2D {}
impl Eq for HpxTex {}
pub struct HpxTexture2DUniforms<'a> {
texture: &'a HpxTexture2D,
pub struct HpxTexUniforms<'a> {
texture: &'a HpxTex,
name: String,
}
impl<'a> HpxTexture2DUniforms<'a> {
pub fn new(texture: &'a HpxTexture2D, idx_texture: i32) -> Self {
impl<'a> HpxTexUniforms<'a> {
pub fn new(texture: &'a HpxTex, idx_texture: i32) -> Self {
let name = format!("textures_tiles[{idx_texture}].");
HpxTexture2DUniforms { texture, name }
HpxTexUniforms { texture, name }
}
}
use al_core::shader::{SendUniforms, ShaderBound};
impl SendUniforms for HpxTexture2DUniforms<'_> {
impl SendUniforms for HpxTexUniforms<'_> {
// Info: These uniforms are used for raytracing drawing mode only
fn attach_uniforms<'b>(&self, shader: &'b ShaderBound<'b>) -> &'b ShaderBound<'b> {
shader
@@ -160,7 +157,7 @@ impl SendUniforms for HpxTexture2DUniforms<'_> {
)
.attach_uniform(
&format!("{}{}", self.name, "start_time"),
&self.texture.start_time(),
&self.texture.start_time.unwrap_or(Time::now()),
);
shader

View File

@@ -1,197 +0,0 @@
use std::collections::HashMap;
use al_core::image::Image;
use al_core::WebGlContext;
use super::texture::HpxTexture3D;
use crate::downloader::request::allsky::Allsky;
use crate::healpix::cell::HEALPixCell;
use crate::renderable::hips::config::HiPSConfig;
use crate::renderable::hips::HpxTileBuffer;
use crate::time::Time;
use crate::Abort;
use crate::JsValue;
use al_api::hips::ImageExt;
// Fixed sized binary heap
pub struct HiPS3DBuffer {
// Some information about the HiPS
textures: HashMap<HEALPixCell, HpxTexture3D>,
config: HiPSConfig,
available_tiles_during_frame: bool,
gl: WebGlContext,
}
impl HiPS3DBuffer {
pub fn new(gl: &WebGlContext, config: HiPSConfig) -> Result<Self, JsValue> {
let textures = HashMap::new();
let available_tiles_during_frame = false;
let gl = gl.clone();
Ok(Self {
config,
textures,
available_tiles_during_frame,
gl,
})
}
pub fn push_allsky(&mut self, allsky: Allsky) -> Result<(), JsValue> {
let Allsky {
image,
time_req,
//depth_tile,
channel,
..
} = allsky;
{
let mutex_locked = image.borrow();
let images = mutex_locked.as_ref().unwrap_abort();
for (idx, image) in images.iter().enumerate() {
self.push(
&HEALPixCell(0, idx as u64),
image,
time_req,
channel.map(|c| c as u16).unwrap_or(0),
)?;
}
}
Ok(())
}
pub fn find_nearest_slice(&self, cell: &HEALPixCell, slice: u16) -> Option<u16> {
self.get(cell).and_then(|t| t.find_nearest_slice(slice))
}
// This method pushes a new downloaded tile into the buffer
// It must be ensured that the tile is not already contained into the buffer
pub fn push<I: Image>(
&mut self,
cell: &HEALPixCell,
image: I,
time_request: Time,
slice_idx: u16,
) -> Result<(), JsValue> {
let tex = if let Some(tex) = self.textures.get_mut(cell) {
tex
} else {
self.textures
.insert(*cell, HpxTexture3D::new(*cell, time_request));
self.textures.get_mut(cell).unwrap()
};
// copy to the 3D textured block
tex.append(image, slice_idx, &self.config, &self.gl)?;
self.available_tiles_during_frame = true;
Ok(())
}
// Return if tiles did become available
pub fn reset_available_tiles(&mut self) -> bool {
let available_tiles_during_frame = self.available_tiles_during_frame;
self.available_tiles_during_frame = false;
available_tiles_during_frame
}
// Tell if a texture is available meaning all its sub tiles
// must have been written for the GPU
pub fn contains_tile(&self, texture_cell: &HEALPixCell, slice: u16) -> bool {
self.get(texture_cell)
.is_some_and(|t| t.contains_slice(slice))
}
/// Accessors
pub fn get(&self, cell: &HEALPixCell) -> Option<&HpxTexture3D> {
self.textures.get(cell)
}
pub fn config(&self) -> &HiPSConfig {
&self.config
}
pub fn config_mut(&mut self) -> &mut HiPSConfig {
&mut self.config
}
}
impl HpxTileBuffer for HiPS3DBuffer {
type T = HpxTexture3D;
fn new(gl: &WebGlContext, config: HiPSConfig) -> Result<Self, JsValue> {
let textures = HashMap::new();
let available_tiles_during_frame = false;
let gl = gl.clone();
Ok(Self {
config,
textures,
available_tiles_during_frame,
gl,
})
}
// Return if tiles did become available
fn reset_available_tiles(&mut self) -> bool {
let available_tiles_during_frame = self.available_tiles_during_frame;
self.available_tiles_during_frame = false;
available_tiles_during_frame
}
fn set_image_ext(&mut self, _gl: &WebGlContext, ext: ImageExt) -> Result<(), JsValue> {
self.config.set_image_ext(ext)?;
self.textures.clear();
//self.ready = false;
self.available_tiles_during_frame = true;
Ok(())
}
// Tell if a texture is available meaning all its sub tiles
// must have been written for the GPU
fn contains(&self, cell: &HEALPixCell) -> bool {
self.get(cell).is_some()
}
/// Accessors
fn get(&self, cell: &HEALPixCell) -> Option<&HpxTexture3D> {
self.textures.get(cell)
}
fn config(&self) -> &HiPSConfig {
&self.config
}
fn config_mut(&mut self) -> &mut HiPSConfig {
&mut self.config
}
}
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> {
shader.attach_uniforms_from(&self.config)
}
}
impl Drop for HiPS3DBuffer {
fn drop(&mut self) {
// drop all the 3D block textures
self.textures.clear();
}
}

View File

@@ -0,0 +1,264 @@
use std::collections::HashMap;
use al_core::image::Image;
use al_core::WebGlContext;
use super::super::tile_heap::TileHeap;
use super::texture::HpxFreqTex;
use crate::healpix::cell::HEALPixFreqCell;
use crate::renderable::hips::config::HiPSConfig;
use crate::renderable::hips::HpxTileBuffer;
use crate::time::Time;
use crate::Abort;
use crate::JsValue;
use al_api::hips::ImageExt;
// Fixed sized binary heap
pub struct HiPS3DBuffer {
// Some information about the HiPS
textures: HashMap<HEALPixFreqCell, HpxFreqTex>,
heap: TileHeap<HEALPixFreqCell>,
config: HiPSConfig,
available_tiles_during_frame: bool,
gl: WebGlContext,
}
impl HiPS3DBuffer {
/*pub fn push_allsky(&mut self, allsky: AllskyRequest) -> Result<(), JsValue> {
let AllskyRequest {
request,
//depth_tile,
channel,
..
} = allsky;
{
let mutex_locked = request.data.borrow();
let images = mutex_locked.as_ref().unwrap_abort();
for (idx, image) in images.iter().enumerate() {
self.push(
&HEALPixCell(0, idx as u64),
image,
request.time_request,
channel.map(|c| c as u16).unwrap_or(0),
)?;
}
}
Ok(())
}*/
/*pub fn find_nearest_slice(&self, cell: &HEALPixCell, slice: u16) -> Option<u16> {
self.get(cell).and_then(|t| t.find_nearest_slice(slice))
}*/
fn push_cell(&mut self, cell: &HEALPixFreqCell, time_request: Time) -> Result<(), JsValue> {
// Check if the cell is not yet contain in the buffer
if !self.contains(cell) {
// If not, add create it and add it to the buffer
if self.heap.is_full() {
// Pop the oldest requested texture
let oldest_texture = self.heap.pop().unwrap_abort();
// Remove it from the textures HashMap
self.textures
.remove(oldest_texture.cell())
.expect("Texture (oldest one) has not been found in the buffer of textures");
}
let texture = HpxFreqTex::new(
cell.clone(),
time_request,
self.config.tile_size as u16,
self.config.tile_depth.unwrap_or(32) as u16,
self.config.get_format().get_pixel_format(),
&self.gl,
)?;
// Push it to the buffer
self.heap.push(&texture);
self.textures.insert(cell.clone(), texture);
};
Ok(())
}
// Push a image slice into the buffer
pub fn push_tile_slice<I: Image>(
&mut self,
cell: &HEALPixFreqCell,
image: I,
time_request: Time,
// this slice index inside the cubic cell
slice_idx: u16,
) -> Result<(), JsValue> {
self.push_cell(cell, time_request)?;
let texture = self.textures.get_mut(cell).unwrap_abort();
// And copy the image in that cubic tile
texture.append_tile_slice(image, slice_idx)?;
self.available_tiles_during_frame = true;
Ok(())
}
pub fn push_tile_from_fits(
&mut self,
cell: &HEALPixFreqCell,
raw_bytes: js_sys::Uint8Array,
size: (u32, u32, u32),
time_request: Time,
) -> Result<(), JsValue> {
self.push_cell(cell, time_request)?;
let texture = self.textures.get_mut(cell).unwrap_abort();
// And copy the image in that cubic tile
texture.set_data_from_fits(raw_bytes, size)?;
self.available_tiles_during_frame = true;
Ok(())
}
pub fn push_tile_from_jpeg(
&mut self,
cell: &HEALPixFreqCell,
decoded_bytes: Box<[u8]>,
size: (u32, u32, u32),
time_request: Time,
) -> Result<(), JsValue> {
self.push_cell(cell, time_request)?;
let texture = self.textures.get_mut(cell).unwrap_abort();
// And copy the image in that cubic tile
texture.set_data_from_jpeg(decoded_bytes, size)?;
self.available_tiles_during_frame = true;
Ok(())
}
pub fn push_tile_from_png(
&mut self,
cell: &HEALPixFreqCell,
decoded_bytes: Box<[u8]>,
size: (u32, u32, u32),
time_request: Time,
) -> Result<(), JsValue> {
self.push_cell(cell, time_request)?;
let texture = self.textures.get_mut(cell).unwrap_abort();
// And copy the image in that cubic tile
texture.set_data_from_png(decoded_bytes, size)?;
self.available_tiles_during_frame = true;
Ok(())
}
// Tell if a texture is available meaning all its sub tiles
// must have been written for the GPU
pub fn contains_slice(
&self,
// the cell to check
cell: &HEALPixFreqCell,
// the idx of one slice inside the cube, has to be in [0; 2^(f_order) - 1]
idx_slice: u16,
) -> bool {
self.get(cell).is_some_and(|t| t.contains_slice(idx_slice))
}
// Get the nearest spatial parent found in the buffer
pub fn get_nearest_parent(&self, cell: &HEALPixFreqCell) -> Option<HEALPixFreqCell> {
let mut parent_cell = cell.parent();
while !self.contains(&parent_cell) && !parent_cell.is_hpx_root() {
parent_cell = parent_cell.parent();
}
if self.contains(&parent_cell) {
Some(parent_cell)
} else {
None
}
}
}
impl HpxTileBuffer for HiPS3DBuffer {
type T = HpxFreqTex;
type C = HEALPixFreqCell;
fn new(gl: &WebGlContext, config: HiPSConfig) -> Result<Self, JsValue> {
let textures = HashMap::new();
// Limit the number of cached cubes to 256 so approx 256 MB
let heap = TileHeap::with_capacity(1024);
let available_tiles_during_frame = false;
let gl = gl.clone();
Ok(Self {
config,
textures,
heap,
available_tiles_during_frame,
gl,
})
}
// Return if tiles did become available
fn reset_available_tiles(&mut self) -> bool {
let available_tiles_during_frame = self.available_tiles_during_frame;
self.available_tiles_during_frame = false;
available_tiles_during_frame
}
fn set_image_ext(&mut self, _gl: &WebGlContext, ext: ImageExt) -> Result<(), JsValue> {
self.config.set_image_ext(ext)?;
self.textures.clear();
self.heap.clear();
self.available_tiles_during_frame = true;
Ok(())
}
/// Accessors
fn get(&self, cell: &Self::C) -> Option<&HpxFreqTex> {
self.textures.get(cell)
}
fn contains(&self, cell: &Self::C) -> bool {
self.get(cell).is_some()
}
fn config(&self) -> &HiPSConfig {
&self.config
}
fn config_mut(&mut self) -> &mut HiPSConfig {
&mut self.config
}
}
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> {
shader.attach_uniforms_from(&self.config)
}
}
impl Drop for HiPS3DBuffer {
fn drop(&mut self) {
// drop all the 3D block textures
self.textures.clear();
self.heap.clear();
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -1,21 +1,140 @@
use crate::renderable::hips::d2::texture::HpxTexture2D;
use crate::{healpix::cell::HEALPixCell, time::Time};
use crate::time::Time;
use crate::renderable::hips::d3::Freq;
use crate::Abort;
use crate::WebGlContext;
use al_core::image::fits::FitsImage;
use al_core::image::raw::ImageBuffer;
use al_core::image::Image;
use al_core::texture::format::{PixelType, R16I, R32F, R32I, R8U, RGB8U, RGBA8U};
use al_core::texture::format::{PixelType, R16I, R32F, R32I, R8U};
use al_core::texture::Texture3D;
use al_core::webgl_ctx::WebGlRenderingCtx;
use cgmath::Vector3;
use fitsrs::hdu::header::Bitpix;
use std::borrow::Cow;
use std::cmp::Ordering;
use std::ops::Range;
use wasm_bindgen::JsValue;
pub struct HpxTexture3D {
tile_cell: HEALPixCell,
// Precomputed uniq number
uniq: i32,
pub enum HpxFreqData {
Fits {
// The raw bytes of the whole cubic FITS file, data big endian
raw_bytes: Box<[u8]>,
// Offset to the data bytes of the cubic tile
data_byte_offset: Range<usize>,
// Number of bytes per pixel (deduced from the bitpix)
bitpix: Bitpix,
// Triming offset indices when reading the data
trim: (u32, u32, u32),
// Naxis
naxis: (u32, u32, u32),
// Scaling value
bscale: f32,
// Offset value
bzero: f32,
// The real size of the cube
size: (u32, u32, u32),
},
Jpeg {
data: Box<[u8]>,
size: (u32, u32, u32),
},
Png {
data: Box<[u8]>,
size: (u32, u32, u32),
},
}
pub enum Pixel {
F32(f32),
I32(i32),
I16(i16),
U8(u8),
}
impl Pixel {
pub fn to_f32(&self) -> f32 {
match *self {
Pixel::F32(v) => v,
Pixel::I16(v) => v as f32,
Pixel::I32(v) => v as f32,
Pixel::U8(v) => v as f32,
}
}
}
impl HpxFreqData {
pub fn read_pixel(&self, x: u32, y: u32, z: u32) -> Option<f32> {
match self {
HpxFreqData::Fits {
raw_bytes,
data_byte_offset,
bitpix,
trim,
naxis,
bscale,
bzero,
size,
} => {
// Do not remember the origin in fits image data is left-down corner
let y = size.1 - y;
let x_in_data = (trim.0..(trim.0 + naxis.0)).contains(&x);
let y_in_data = (trim.1..(trim.1 + naxis.1)).contains(&y);
let z_in_data = (trim.2..(trim.2 + naxis.2)).contains(&z);
if !x_in_data || !y_in_data || !z_in_data {
None
} else {
let x = x - trim.0;
let y = y - trim.1;
let z = z - trim.2;
let data_raw_bytes = &raw_bytes[data_byte_offset.clone()];
let bytes_per_pixel = bitpix.byte_size();
let pixel_bytes_off =
bytes_per_pixel * (x + y * naxis.0 + z * (naxis.0 * naxis.1)) as usize;
let p = &data_raw_bytes[pixel_bytes_off..(pixel_bytes_off + bytes_per_pixel)];
let pixel = match bitpix {
Bitpix::U8 => Pixel::U8(p[0]),
Bitpix::I16 => Pixel::I16(i16::from_be_bytes([p[0], p[1]])),
Bitpix::I32 => Pixel::I32(i32::from_be_bytes([p[0], p[1], p[2], p[3]])),
Bitpix::F32 => Pixel::F32(f32::from_be_bytes([p[0], p[1], p[2], p[3]])),
Bitpix::F64 => Pixel::F32(f64::from_be_bytes([
p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7],
]) as f32),
Bitpix::I64 => Pixel::I32(i64::from_be_bytes([
p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7],
]) as i32),
};
Some(pixel.to_f32() * (*bscale) + (*bzero))
}
}
HpxFreqData::Jpeg { data, size } => {
let pixel_bytes_off = (x + y * size.0 + z * (size.0 * size.1)) as usize;
let p = data[pixel_bytes_off];
Some(p as f32)
}
HpxFreqData::Png { data, size } => {
let pixel_bytes_off = (x + y * size.0 + z * (size.0 * size.1)) as usize;
let p = data[2 * pixel_bytes_off];
Some(p as f32)
}
}
}
}
pub struct HpxFreqTex {
pub cell: HEALPixFreqCell,
// The time the texture has been received
// If the texture contains multiple tiles, then the receiving time
// is set when all the tiles have been copied to the buffer
start_time: Option<Time>,
pub start_time: Option<Time>,
// The time request of the texture is the time request
// of the first tile being inserted in it
// It is then only given in the constructor of Texture
@@ -24,272 +143,277 @@ pub struct HpxTexture3D {
// texture. But this is too expensive because at each tile inserted
// in the buffer, one should reevalute the priority of the texture
// in the buffer's binary heap.
time_request: Time,
pub time_request: Time,
// OLD CODE
// We autorize 512 cubic tiles of size 32 each which allows to store max 16384 slices
textures: Vec<Option<Texture3D>>,
//textures: Vec<Option<Texture3D>>,
// A set of already inserted slices. Each cubic tiles can have 32 slices. The occupancy of the
// slices inside a cubic tile is done with a u32 mask. Limited to 16384 slices
blocks: [u32; 512],
//blocks: [u32; 512],
// sorted index list of 32-length blocks that are not empty
block_indices: Vec<usize>,
//block_indices: Vec<usize>,
/// The webgl2 3D texture of the cubic tile
pub texture: Texture3D,
data: Option<HpxFreqData>,
// The real image data for accessing the pixel values
//data: ImageType,
/// A bitvector keeping track of the slices that have been inserted into the 3D texture
/// It is limited to a cube depth of 256 (~ to the max texture size).
slice_idx: [u32; 8],
/// Depth of the tile
num_slices: u16,
/// Number of slices copied (concerns only HiPSCube)
num_stored_slices: u16,
}
use crate::renderable::hips::config::HiPSConfig;
use crate::WebGlContext;
const TEX_PARAMS: &[(u32, u32)] = &[
(
WebGlRenderingCtx::TEXTURE_MIN_FILTER,
WebGlRenderingCtx::NEAREST,
),
(
WebGlRenderingCtx::TEXTURE_MAG_FILTER,
WebGlRenderingCtx::NEAREST,
),
// Prevents s-coordinate wrapping (repeating)
(
WebGlRenderingCtx::TEXTURE_WRAP_S,
WebGlRenderingCtx::CLAMP_TO_EDGE,
),
// Prevents t-coordinate wrapping (repeating)
(
WebGlRenderingCtx::TEXTURE_WRAP_T,
WebGlRenderingCtx::CLAMP_TO_EDGE,
),
// Prevents r-coordinate wrapping (repeating)
(
WebGlRenderingCtx::TEXTURE_WRAP_R,
WebGlRenderingCtx::CLAMP_TO_EDGE,
),
];
use crate::renderable::hips::HpxTile;
impl HpxTexture3D {
pub fn new(tile_cell: HEALPixCell, time_request: Time) -> Self {
use crate::healpix::cell::HEALPixFreqCell;
impl HpxFreqTex {
pub fn new(
// The cubic tile definition to locate the cube in the sky + spectral axis
cell: HEALPixFreqCell,
// The time the request has been made, i.e. when the tile was needed
time_request: Time,
// The size of the cubis tile
tile_size: u16,
// The depth of the cubic tile. Must be a power of two
num_slices: u16,
// pixel format
pixel_format: PixelType,
// The Gl context
gl: &WebGlContext,
) -> Result<Self, JsValue> {
let start_time = None;
let uniq = tile_cell.uniq();
let textures = std::iter::repeat_n(None, 512).collect();
let blocks = [0; 512];
let block_indices = Vec::new();
Self {
tile_cell,
uniq,
let texture = match pixel_format {
// alpha transparency
PixelType::RGBA8U => Texture3D::create_empty::<R16I>(
gl,
tile_size as i32,
tile_size as i32,
num_slices as i32,
TEX_PARAMS,
),
PixelType::RGB8U => Texture3D::create_empty::<R8U>(
gl,
tile_size as i32,
tile_size as i32,
num_slices as i32,
TEX_PARAMS,
),
PixelType::R8U => Texture3D::create_empty::<R8U>(
gl,
tile_size as i32,
tile_size as i32,
num_slices as i32,
TEX_PARAMS,
),
PixelType::R32F => Texture3D::create_empty::<R32F>(
gl,
tile_size as i32,
tile_size as i32,
num_slices as i32,
TEX_PARAMS,
),
PixelType::R16I => Texture3D::create_empty::<R16I>(
gl,
tile_size as i32,
tile_size as i32,
num_slices as i32,
TEX_PARAMS,
),
PixelType::R32I => Texture3D::create_empty::<R32I>(
gl,
tile_size as i32,
tile_size as i32,
num_slices as i32,
TEX_PARAMS,
),
}?;
let data = None;
let num_stored_slices = 0;
let slice_idx = [0x0; 8];
Ok(Self {
cell,
slice_idx,
time_request,
start_time,
textures,
blocks,
block_indices,
}
data,
texture,
num_slices,
num_stored_slices,
})
}
pub fn find_nearest_slice(&self, slice: u16) -> Option<u16> {
let block_idx = (slice >> 5) as usize;
pub fn set_data_from_fits(
&mut self,
// the tile image of the whole cubic tile
raw_bytes: js_sys::Uint8Array,
// size of the cube
size: (u32, u32, u32),
) -> Result<(), JsValue> {
let raw_bytes = raw_bytes.to_vec().into_boxed_slice();
match self.block_indices.binary_search(&block_idx) {
Ok(_) => {
if self.contains_slice(slice) {
Some(slice)
} else {
// the slice is not present but we know there is one in the block
let block = self.blocks[block_idx];
self.data = {
let image = FitsImage::from_raw_bytes(&raw_bytes[..])?.pop().unwrap();
image.insert_into_3d_texture(&self.texture, &Vector3::<i32>::new(0, 0, 0))?;
let slice_idx = (slice & 0x1f) as u32;
let bitpix = image.bitpix;
let trim = (image.trim1, image.trim2, image.trim3);
let naxis = (image.width, image.height, image.depth);
let bscale = image.bscale;
let bzero = image.bzero;
let m2 = if slice_idx == 31 {
0
} else {
0xffffffff >> (slice_idx + 1)
};
let m1 = (!m2) & !(1 << (31 - slice_idx));
if let Cow::Owned(uncompressed_bytes) = image.raw_bytes {
Some(HpxFreqData::Fits {
data_byte_offset: 0..uncompressed_bytes.len(),
raw_bytes: uncompressed_bytes.into_boxed_slice(),
bitpix,
trim,
naxis,
bscale,
bzero,
size,
})
} else {
let data_byte_offset = image.data_byte_offset.clone();
let lb = (block & m1) >> (32 - slice_idx);
let rb = block & m2;
std::mem::drop(image);
let lb_trailing_zeros = (lb.trailing_zeros() as u16).min(slice_idx as u16);
let rb_leading_zeros = (rb.leading_zeros() - slice_idx - 1) as u16;
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;
match (no_more_left_bits, no_more_right_bits) {
(false, false) => {
if lb_trailing_zeros <= rb_leading_zeros {
Some(slice - lb_trailing_zeros - 1)
} else {
Some(slice + rb_leading_zeros + 1)
}
}
(false, true) => {
if lb_trailing_zeros <= rb_leading_zeros {
Some(slice - lb_trailing_zeros - 1)
} else {
// explore next block
if block_idx == self.blocks.len() - 1 {
// no after block
Some(slice - lb_trailing_zeros - 1)
} else {
// get the next block
let next_block = self.blocks[block_idx + 1];
let num_bits_to_next_block =
next_block.leading_zeros() as u16 + rb_leading_zeros;
if num_bits_to_next_block < lb_trailing_zeros {
Some(slice + num_bits_to_next_block + 1)
} else {
Some(slice - lb_trailing_zeros - 1)
}
}
}
}
(true, false) => {
if rb_leading_zeros <= lb_trailing_zeros {
Some(slice + rb_leading_zeros + 1)
} else {
// explore previous block
if block_idx == 0 {
// no after block
Some(slice + rb_leading_zeros + 1)
} else {
// get the next block
let prev_block = self.blocks[block_idx - 1];
let num_bits_from_prev_block =
prev_block.trailing_zeros() as u16 + lb_trailing_zeros;
if num_bits_from_prev_block < rb_leading_zeros {
Some(slice - num_bits_from_prev_block - 1)
} else {
Some(slice + rb_leading_zeros + 1)
}
}
}
}
(true, true) => unreachable!(),
}
}
Some(HpxFreqData::Fits {
raw_bytes,
data_byte_offset,
bitpix,
trim,
naxis,
bscale,
bzero,
size,
})
}
Err(i) => {
let prev_block = if i > 0 {
self.block_indices.get(i - 1)
} else {
None
};
};
let cur_block = self.block_indices.get(i);
match (prev_block, cur_block) {
(Some(b_idx_1), Some(b_idx_2)) => {
let b1 = self.blocks[*b_idx_1];
let b2 = self.blocks[*b_idx_2];
self.num_stored_slices = self.num_slices;
self.start_time = Some(Time::now());
let b1_tz = b1.trailing_zeros() as usize;
let b2_lz = b2.leading_zeros() as usize;
let slice_b1 = ((*b_idx_1 << 5) + 32 - b1_tz - 1) as u16;
let slice_b2 = ((*b_idx_2 << 5) + b2_lz) as u16;
if slice - slice_b1 <= slice_b2 - slice {
// the nearest slice is in b1
Some(slice_b1)
} else {
// the nearest slice is in b2
Some(slice_b2)
}
}
(None, Some(b_idx_2)) => {
let b2 = self.blocks[*b_idx_2];
let b2_lz = b2.leading_zeros() as usize;
Some(((*b_idx_2 << 5) + b2_lz) as u16)
}
(Some(b_idx_1), None) => {
let b1 = self.blocks[*b_idx_1];
let b1_tz = b1.trailing_zeros() as usize;
Some(((*b_idx_1 << 5) + 32 - b1_tz - 1) as u16)
}
(None, None) => None,
}
}
}
Ok(())
}
pub fn get_3d_block_from_slice(&self, slice: u16) -> Option<&Texture3D> {
let block_idx = (slice >> 5) as usize;
self.textures[block_idx].as_ref()
}
pub fn extract_2d_slice_texture(&self, slice: u16) -> Option<HpxTexture2D> {
// Find the good sub cube containing the slice
let block_idx = (slice >> 5) as usize;
let slice_idx = (slice & 0x1f) as u8;
// check the texture is there
if self.blocks[block_idx] & (1 << (31 - slice_idx)) != 0 {
Some(HpxTexture2D::new(
&self.tile_cell,
slice_idx as i32,
self.time_request,
))
pub fn read_pixel(&self, x: u32, y: u32, z: u32) -> Option<f32> {
if let Some(data) = &self.data {
data.read_pixel(x, y, z)
} else {
None
}
}
pub fn frequencies(&self) -> Vec<f32> {
let delta_depth = self.num_slices.trailing_zeros();
let pixel_depth = self.cell.f_depth + delta_depth as u8;
let h0 = self.cell.f_hash << delta_depth;
let h1 = (self.cell.f_hash + 1) << delta_depth;
(h0..h1)
.map(|hash| Freq::from_hash_with_order(hash, pixel_depth).0 as f32)
.collect()
}
pub fn set_data_from_jpeg(
&mut self,
// the tile image of the whole cubic tile
decoded_bytes: Box<[u8]>,
// size of the cube
size: (u32, u32, u32),
) -> Result<(), JsValue> {
let cubic_tile = ImageBuffer::<R8U>::new(decoded_bytes, size.0, size.1, size.2);
cubic_tile.insert_into_3d_texture(&self.texture, &Vector3::<i32>::new(0, 0, 0))?;
self.data = Some(HpxFreqData::Jpeg {
data: cubic_tile.data,
size,
});
self.num_stored_slices = self.num_slices;
self.start_time = Some(Time::now());
Ok(())
}
pub fn set_data_from_png(
&mut self,
// the tile image of the whole cubic tile
decoded_bytes: Box<[u8]>,
// size of the cube
size: (u32, u32, u32),
) -> Result<(), JsValue> {
let cubic_tile = ImageBuffer::<R16I>::new(decoded_bytes, size.0, size.1, size.2);
cubic_tile.insert_into_3d_texture(&self.texture, &Vector3::<i32>::new(0, 0, 0))?;
self.data = Some(HpxFreqData::Png {
data: cubic_tile.data,
size,
});
self.num_stored_slices = self.num_slices;
self.start_time = Some(Time::now());
Ok(())
}
// Panic if cell is not contained in the texture
// Do nothing if the texture is full
// Return true if the tile is newly added
pub fn append<I: Image>(
// Used by HiPS Cubes
pub fn append_tile_slice<I: Image>(
&mut self,
// the tile image of 1 slice
image: I,
slice: u16,
cfg: &HiPSConfig,
gl: &WebGlContext,
// the slice offset in the cubic tile
offset: u16,
) -> Result<(), JsValue> {
let block_idx = (slice >> 5) as usize;
// If there is already something, do not tex sub
let block_idx = (offset >> 5) as usize;
let slice_idx = (offset & 0x1f) as u8;
let texture = if let Some(texture) = self.textures[block_idx].as_ref() {
texture
} else {
let tile_size = cfg.get_tile_size();
let params = &[
(
WebGlRenderingCtx::TEXTURE_MIN_FILTER,
WebGlRenderingCtx::NEAREST,
),
(
WebGlRenderingCtx::TEXTURE_MAG_FILTER,
WebGlRenderingCtx::NEAREST,
),
// Prevents s-coordinate wrapping (repeating)
(
WebGlRenderingCtx::TEXTURE_WRAP_S,
WebGlRenderingCtx::CLAMP_TO_EDGE,
),
// Prevents t-coordinate wrapping (repeating)
(
WebGlRenderingCtx::TEXTURE_WRAP_T,
WebGlRenderingCtx::CLAMP_TO_EDGE,
),
// Prevents r-coordinate wrapping (repeating)
(
WebGlRenderingCtx::TEXTURE_WRAP_R,
WebGlRenderingCtx::CLAMP_TO_EDGE,
),
];
if self.slice_idx[block_idx] & (1 << (31 - slice_idx)) == 0 {
image.insert_into_3d_texture(
&self.texture,
&Vector3::<i32>::new(0, 0, slice_idx as i32),
)?;
let texture = match cfg.get_format().get_pixel_format() {
PixelType::RGBA8U => {
Texture3D::create_empty::<RGBA8U>(gl, tile_size, tile_size, 32, params)
}
PixelType::RGB8U => {
Texture3D::create_empty::<RGB8U>(gl, tile_size, tile_size, 32, params)
}
PixelType::R32F => {
Texture3D::create_empty::<R32F>(gl, tile_size, tile_size, 32, params)
}
PixelType::R8U => {
Texture3D::create_empty::<R8U>(gl, tile_size, tile_size, 32, params)
}
PixelType::R16I => {
Texture3D::create_empty::<R16I>(gl, tile_size, tile_size, 32, params)
}
PixelType::R32I => {
Texture3D::create_empty::<R32I>(gl, tile_size, tile_size, 32, params)
}
};
self.textures[block_idx] = Some(texture?);
self.textures[block_idx].as_ref().unwrap()
};
let slice_idx = slice & 0x1f;
// if there is already something, do not tex sub
if self.blocks[block_idx] & (1 << (31 - slice_idx)) == 0 {
image.insert_into_3d_texture(texture, &Vector3::<i32>::new(0, 0, slice_idx as i32))?;
match self.block_indices.binary_search(&block_idx) {
Ok(_) => {} // element already in vector @ `pos`
Err(i) => self.block_indices.insert(i, block_idx),
}
self.blocks[block_idx] |= 1 << (31 - slice_idx);
self.slice_idx[block_idx] |= 1 << (31 - slice_idx);
self.num_stored_slices += 1;
}
self.start_time = Some(Time::now());
@@ -298,50 +422,29 @@ impl HpxTexture3D {
}
// Cell must be contained in the texture
pub fn contains_slice(&self, slice: u16) -> bool {
let block_idx = (slice >> 5) as usize;
let idx_in_block = slice & 0x1f;
pub fn contains_slice(&self, offset: u16) -> bool {
let block_idx = (offset >> 5) as usize;
let slice_idx = offset & 0x1f;
(self.blocks[block_idx] >> (31 - idx_in_block)) & 0x1 == 1
(self.slice_idx[block_idx] >> (31 - slice_idx)) & 0x1 == 1
}
}
impl HpxTile for HpxTexture3D {
// Getter
// Returns the current time if the texture is not full
fn start_time(&self) -> Time {
if let Some(t) = self.start_time {
t
} else {
Time::now()
}
}
fn time_request(&self) -> Time {
self.time_request
}
fn cell(&self) -> &HEALPixCell {
&self.tile_cell
}
}
use std::cmp::Ordering;
impl PartialOrd for HpxTexture3D {
impl PartialOrd for HpxFreqTex {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
Some(self.cmp(other))
}
}
use crate::Abort;
impl Ord for HpxTexture3D {
impl Ord for HpxFreqTex {
fn cmp(&self, other: &Self) -> Ordering {
self.partial_cmp(other).unwrap_abort()
}
}
impl PartialEq for HpxTexture3D {
impl PartialEq for HpxFreqTex {
fn eq(&self, other: &Self) -> bool {
self.uniq == other.uniq
self.cell == other.cell
}
}
impl Eq for HpxTexture3D {}
impl Eq for HpxFreqTex {}

View File

@@ -3,23 +3,23 @@ pub mod config;
pub mod d2;
pub mod d3;
pub mod raytracing;
pub mod tile_heap;
mod triangulation;
pub mod uv;
pub use d2::HiPS2D;
use crate::downloader::request::allsky::Allsky;
use crate::browser_support::BrowserFeaturesSupport;
use crate::renderable::HiPSConfig;
use crate::time::Time;
use crate::tile_fetcher::TileFetcherQueue;
use crate::CameraViewPort;
use crate::HEALPixCell;
use crate::HEALPixCoverage;
use crate::WebGlContext;
use al_api::hips::ImageExt;
use wasm_bindgen::JsValue;
mod subdivide;
/*
pub(crate) trait HpxTile {
// Getter
// Returns the current time if the texture is not full
@@ -28,10 +28,11 @@ pub(crate) trait HpxTile {
fn time_request(&self) -> Time;
fn cell(&self) -> &HEALPixCell;
}
}*/
pub(crate) trait HpxTileBuffer {
type T: HpxTile;
type T;
type C;
fn new(gl: &WebGlContext, config: HiPSConfig) -> Result<Self, JsValue>
where
@@ -43,35 +44,14 @@ pub(crate) trait HpxTileBuffer {
fn reset_available_tiles(&mut self) -> bool;
/// Accessors
fn get(&self, cell: &HEALPixCell) -> Option<&Self::T>;
fn get(&self, cell: &Self::C) -> Option<&Self::T>;
fn contains(&self, cell: &HEALPixCell) -> bool;
// Get the nearest parent tile found in the CPU buffer
fn get_nearest_parent(&self, cell: &HEALPixCell) -> Option<HEALPixCell> {
/*if cell.is_root() {
// Root cells are in the buffer by definition
Some(*cell)
} else {*/
let mut parent_cell = cell.parent();
while !self.contains(&parent_cell) && !parent_cell.is_root() {
parent_cell = parent_cell.parent();
}
if self.contains(&parent_cell) {
Some(parent_cell)
} else {
None
}
//}
}
fn contains(&self, cell: &Self::C) -> bool;
fn config_mut(&mut self) -> &mut HiPSConfig;
fn config(&self) -> &HiPSConfig;
}
use crate::downloader::query;
use crate::renderable::hips::HiPS::{D2, D3};
use crate::renderable::HiPS3D;
use crate::ProjectionType;
@@ -83,10 +63,15 @@ pub enum HiPS {
}
impl HiPS {
pub fn look_for_new_tiles(&mut self, camera: &CameraViewPort) -> Option<Vec<HEALPixCell>> {
pub fn look_for_new_tiles(
&mut self,
tile_fetcher: &mut TileFetcherQueue,
camera: &CameraViewPort,
browser_features_support: &BrowserFeaturesSupport,
) {
match self {
D2(hips) => hips.look_for_new_tiles(camera).map(|it| it.collect()),
D3(hips) => hips.look_for_new_tiles(camera).map(|it| it.collect()),
D2(hips) => hips.look_for_new_tiles(tile_fetcher, camera, browser_features_support),
D3(hips) => hips.look_for_new_tiles(tile_fetcher, camera, browser_features_support),
}
}
@@ -114,10 +99,10 @@ impl HiPS {
}
#[inline]
pub fn get_config_mut(&mut self) -> &mut HiPSConfig {
pub fn set_root_url(&mut self, root_url: String) {
match self {
D2(hips) => hips.get_config_mut(),
D3(hips) => hips.get_config_mut(),
D2(hips) => hips.get_config_mut().set_root_url(root_url),
D3(hips) => hips.get_config_mut().set_root_url(root_url),
}
}
@@ -128,30 +113,6 @@ impl HiPS {
}
}
#[inline]
pub fn set_moc(&mut self, moc: HEALPixCoverage) {
match self {
D2(hips) => hips.set_moc(moc),
D3(hips) => hips.set_moc(moc),
}
}
#[inline]
pub fn get_tile_query(&self, cell: &HEALPixCell) -> query::Tile {
match self {
HiPS::D2(hips) => hips.get_tile_query(cell),
HiPS::D3(hips) => hips.get_tile_query(cell),
}
}
#[inline]
pub fn add_allsky(&mut self, allsky: Allsky) -> Result<(), JsValue> {
match self {
HiPS::D2(hips) => hips.add_allsky(allsky),
HiPS::D3(hips) => hips.add_allsky(allsky),
}
}
pub fn is_allsky(&self) -> bool {
self.get_config().is_allsky
}

View File

@@ -0,0 +1,139 @@
use crate::renderable::hips::d2::texture::HpxTex;
use crate::renderable::hips::d3::texture::HpxFreqTex;
use crate::time::Time;
use crate::Abort;
use crate::HEALPixCell;
use std::cmp::Ordering;
use std::collections::BinaryHeap;
#[derive(Clone, Debug)]
pub struct Tile<C> {
cell: C,
time_request: Time,
}
impl<C> Tile<C> {
pub fn reset_time(&mut self) {
self.time_request = Time::now();
}
#[inline(always)]
pub fn cell(&self) -> &C {
&self.cell
}
}
impl Tile<HEALPixCell> {
pub fn is_root(&self) -> bool {
self.cell.is_root()
}
}
impl<C> PartialEq for Tile<C>
where
C: PartialEq,
{
fn eq(&self, other: &Self) -> bool {
self.cell == other.cell
}
}
impl<C> Eq for Tile<C> where C: PartialEq {}
// Ordering based on the time the tile has been requested
impl<C> PartialOrd for Tile<C>
where
C: PartialEq,
{
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
Some(self.cmp(other))
}
}
impl<C> Ord for Tile<C>
where
C: PartialEq,
{
fn cmp(&self, other: &Self) -> Ordering {
other
.time_request
.partial_cmp(&self.time_request)
.unwrap_abort()
}
}
impl From<&HpxTex> for Tile<HEALPixCell> {
fn from(tex: &HpxTex) -> Self {
let time_request = tex.time_request;
let cell = tex.cell;
Self { cell, time_request }
}
}
use crate::healpix::cell::HEALPixFreqCell;
impl From<&HpxFreqTex> for Tile<HEALPixFreqCell> {
fn from(tex: &HpxFreqTex) -> Self {
let time_request = tex.time_request;
let cell = tex.cell.clone();
Self { cell, time_request }
}
}
pub struct TileHeap<C> {
heap: BinaryHeap<Tile<C>>,
size: usize,
}
impl<C> TileHeap<C> {
pub fn clear(&mut self) {
self.heap.clear();
}
pub fn len(&self) -> usize {
self.heap.len()
}
pub fn is_empty(&self) -> bool {
self.len() == 0
}
}
impl<C> TileHeap<C>
where
C: PartialEq,
{
pub fn with_capacity(cap: usize) -> Self {
Self {
heap: BinaryHeap::with_capacity(cap),
size: cap,
}
}
// Check if the heap is full
pub fn is_full(&self) -> bool {
self.heap.len() >= self.size
}
pub fn update_entry<T: Into<Tile<C>>>(&mut self, item: T) {
let item = item.into();
self.heap = self
.heap
.drain()
// Remove the cell
.filter(|texture_node| texture_node.cell != item.cell)
// Collect to a new binary heap that does not have cell anymore
.collect::<BinaryHeap<_>>();
self.push(item);
}
pub fn push<T: Into<Tile<C>>>(&mut self, item: T) {
let item = item.into();
self.heap.push(item);
}
pub fn pop(&mut self) -> Option<Tile<C>> {
self.heap.pop()
}
}

View File

@@ -12,26 +12,35 @@ impl<T> Deref for UV<T> {
}
}
use super::d2::texture::HpxTexture2D;
use crate::healpix::cell::HEALPixCell;
use crate::renderable::hips::HpxTile;
pub struct TileUVW(pub [Vector3<f32>; 4]);
impl TileUVW {
// The texture cell passed must be a child of texture
pub fn new(cell: &HEALPixCell, texture: &HpxTexture2D) -> TileUVW {
pub fn new(cell: &HEALPixCell, parent_cell: &Option<HEALPixCell>, w: f32) -> TileUVW {
// Index of the texture in the total set of textures
let texture_idx = texture.idx();
//let texture_idx = texture.idx();
// Row and column indexes of the tile in its texture
let (idx_col_in_tex, idx_row_in_tex) = cell.offset_in_parent(texture.cell());
let (u, v, ds) = if let Some(parent) = parent_cell {
let (idx_col_in_tex, idx_row_in_tex) = cell.offset_in_parent(parent);
let nside = (1 << (cell.depth() - texture.cell().depth())) as f32;
let u = (idx_row_in_tex as f32) / nside;
let v = (idx_col_in_tex as f32) / nside;
let nside = (1 << (cell.depth() - parent.depth())) as f32;
let ds = 1_f32 / nside;
let ds = 1_f32 / nside;
let u = (idx_row_in_tex as f32) / nside;
let v = (idx_col_in_tex as f32) / nside;
let w = texture_idx as f32;
(u, v, ds)
} else {
(0.0, 0.0, 1.0)
};
//let u = 0.0;
//let v = 0.0;
//let ds = 1.0;
// let w = texture_idx as f32;
TileUVW([
Vector3::new(u, v, w),
Vector3::new(u + ds, v, w),

View File

@@ -98,7 +98,7 @@ fn get_coord_uv_it(
)
.chain(std::iter::once((
xmax,
if xmax % max_tex_size == 0 {
if xmax.is_multiple_of(max_tex_size) {
1.0
} else {
get_uv_in_tex_chunk(xmax)
@@ -129,7 +129,7 @@ fn get_coord_uv_it(
})
.chain(std::iter::once((
xmax,
if xmax % max_tex_size == 0 {
if xmax.is_multiple_of(max_tex_size) {
1.0
} else {
get_uv_in_tex_chunk(xmax)
@@ -199,7 +199,9 @@ pub fn vertices(
};
x_it.clone().map(move |(x, uvx)| {
let ndc = if let Some(xyz) = wcs.unproj_xyz(&ImgXY::new(x as f64, y as f64)) {
let ndc = if let Some(xyz) =
wcs.unproj_xyz(&ImgXY::new(x as f64 + 0.5, y as f64 + 0.5))
{
let xyz = crate::coosys::apply_coo_system(
CooSystem::ICRS,
camera.get_coo_system(),

View File

@@ -162,7 +162,10 @@ impl Image {
// Compute the fov
let center = wcs
.unproj_lonlat(&ImgXY::new(width as f64 / 2.0, height as f64 / 2.0))
.unproj_lonlat(&ImgXY::new(
(width as f64 / 2.0) + 0.5,
(height as f64 / 2.0) + 0.5,
))
.ok_or(JsValue::from_str("(w / 2, h / 2) px cannot be unprojected"))?;
let center_xyz = center.to_xyz();
let inside = crate::coosys::apply_coo_system(
@@ -172,13 +175,13 @@ impl Image {
);
let vertices = [
wcs.unproj_lonlat(&ImgXY::new(0.0, 0.0))
wcs.unproj_lonlat(&ImgXY::new(0.5, 0.5))
.ok_or(JsValue::from_str("(0, 0) does not lie in the sky"))?,
wcs.unproj_lonlat(&ImgXY::new(width as f64 - 1.0, 0.0))
wcs.unproj_lonlat(&ImgXY::new(width as f64 - 0.5, 0.5))
.ok_or(JsValue::from_str("(w - 1, 0) does not lie in the sky"))?,
wcs.unproj_lonlat(&ImgXY::new(width as f64 - 1.0, height as f64 - 1.0))
wcs.unproj_lonlat(&ImgXY::new(width as f64 - 0.5, height as f64 - 0.5))
.ok_or(JsValue::from_str("(w - 1, h - 1) does not lie in the sky"))?,
wcs.unproj_lonlat(&ImgXY::new(0.0, height as f64 - 1.0))
wcs.unproj_lonlat(&ImgXY::new(0.5, height as f64 - 0.5))
.ok_or(JsValue::from_str("(0, h - 1) does not lie in the sky"))?,
]
.iter()
@@ -669,7 +672,10 @@ impl Image {
// let's redefine the region
let center = self
.wcs
.unproj_lonlat(&ImgXY::new(width as f64 / 2.0, height as f64 / 2.0))
.unproj_lonlat(&ImgXY::new(
(width as f64 / 2.0) + 0.5,
(height as f64 / 2.0) + 0.5,
))
.ok_or(JsValue::from_str("(w / 2, h / 2) px cannot be unprojected"))?;
let center_xyz = center.to_xyz();
let inside = crate::coosys::apply_coo_system(
@@ -680,16 +686,16 @@ impl Image {
let vertices = [
self.wcs
.unproj_lonlat(&ImgXY::new(0.0, 0.0))
.unproj_lonlat(&ImgXY::new(0.5, 0.5))
.ok_or(JsValue::from_str("(0, 0) does not lie in the sky"))?,
self.wcs
.unproj_lonlat(&ImgXY::new(width as f64 - 1.0, 0.0))
.unproj_lonlat(&ImgXY::new(width as f64 - 0.5, 0.5))
.ok_or(JsValue::from_str("(w - 1, 0) does not lie in the sky"))?,
self.wcs
.unproj_lonlat(&ImgXY::new(width as f64 - 1.0, height as f64 - 1.0))
.unproj_lonlat(&ImgXY::new(width as f64 - 0.5, height as f64 - 0.5))
.ok_or(JsValue::from_str("(w - 1, h - 1) does not lie in the sky"))?,
self.wcs
.unproj_lonlat(&ImgXY::new(0.0, height as f64 - 1.0))
.unproj_lonlat(&ImgXY::new(0.5, height as f64 - 0.5))
.ok_or(JsValue::from_str("(0, h - 1) does not lie in the sky"))?,
]
.iter()

View File

@@ -88,7 +88,7 @@ where
pixels_written += num_pixels_to_read;
if F::PIXEL_TYPE.num_channels() == 1 && y % step_cut == 0 {
if F::PIXEL_TYPE.num_channels() == 1 && y.is_multiple_of(step_cut) {
// on a good line
let bytes_line = &buf[id_tx][off_bytes_dst..(off_bytes_dst + num_bytes_to_read)];
for x_in_patch in (0..w_patch).step_by(step_cut) {
@@ -153,7 +153,7 @@ where
}
}
if (((dy + 1) % (max_tex_size as usize) == 0) && id_tx == buf.len() - 1)
if ((dy + 1).is_multiple_of(max_tex_size as usize) && id_tx == buf.len() - 1)
|| pixels_written >= num_pixels
{
// we can create new textures of size max_tex_size

View File

@@ -1,5 +1,5 @@
use super::MOC;
use crate::{camera::CameraViewPort, HEALPixCoverage};
use crate::{camera::CameraViewPort, SpaceMoc};
use al_api::moc::MOCOptions;
pub struct MOCHierarchy {
@@ -12,19 +12,13 @@ use al_core::WebGlContext;
impl MOCHierarchy {
pub fn from_full_res_moc(
gl: WebGlContext,
full_res_moc: HEALPixCoverage,
full_res_moc: SpaceMoc,
options: &MOCOptions,
) -> Self {
let full_res_depth = full_res_moc.depth();
let mut mocs: Vec<_> = (0..full_res_depth)
.map(|d| {
MOC::new(
gl.clone(),
HEALPixCoverage(full_res_moc.degraded(d)),
options,
)
})
.map(|d| MOC::new(gl.clone(), SpaceMoc(full_res_moc.degraded(d)), options))
.collect();
mocs.push(MOC::new(gl.clone(), full_res_moc, options));
@@ -80,7 +74,7 @@ impl MOCHierarchy {
&mut self.mocs[d]
}
pub fn get_full_moc(&self) -> &HEALPixCoverage {
pub fn get_full_moc(&self) -> &SpaceMoc {
&self.mocs.last().unwrap().moc
}

View File

@@ -3,7 +3,7 @@ pub mod renderer;
pub use renderer::MOCRenderer;
use crate::camera::CameraViewPort;
use crate::healpix::coverage::HEALPixCoverage;
use crate::healpix::moc::SpaceMoc;
use crate::math::projection::ProjectionType;
use crate::renderable::WebGl2RenderingContext;
use crate::shader::ShaderManager;
@@ -32,11 +32,11 @@ pub struct MOC {
inner: [Option<MOCIntern>; 3],
pub moc: HEALPixCoverage,
pub moc: SpaceMoc,
}
impl MOC {
pub(super) fn new(gl: WebGlContext, moc: HEALPixCoverage, cfg: &MOCOptions) -> Self {
pub(super) fn new(gl: WebGlContext, moc: SpaceMoc, cfg: &MOCOptions) -> Self {
let sky_fraction = moc.sky_fraction() as f32;
let max_order = moc.depth_max();
@@ -228,7 +228,7 @@ impl MOCIntern {
fn vertices_in_view<'a>(
&self,
moc: &'a HEALPixCoverage,
moc: &'a SpaceMoc,
camera: &'a mut CameraViewPort,
) -> impl Iterator<Item = [(f64, f64); 4]> + 'a {
let view_moc = camera.get_cov(CooSystem::ICRS);
@@ -250,7 +250,7 @@ impl MOCIntern {
fn draw(
&mut self,
moc: &HEALPixCoverage,
moc: &SpaceMoc,
camera: &mut CameraViewPort,
proj: &ProjectionType,
shaders: &mut ShaderManager,
@@ -457,7 +457,7 @@ impl MOCIntern {
fn compute_edge_paths_iter<'a>(
&self,
moc: &'a HEALPixCoverage,
moc: &'a SpaceMoc,
camera: &'a mut CameraViewPort,
) -> impl Iterator<Item = f32> + 'a {
self.vertices_in_view(moc, camera).flat_map(|v| {

View File

@@ -1,4 +1,4 @@
use crate::{healpix::coverage::HEALPixCoverage, CameraViewPort, ShaderManager};
use crate::{healpix::moc::SpaceMoc, CameraViewPort, ShaderManager};
use al_core::WebGlContext;
use wasm_bindgen::JsValue;
@@ -67,7 +67,7 @@ impl MOCRenderer {
pub fn push_back(
&mut self,
moc: HEALPixCoverage,
moc: SpaceMoc,
cfg: MOCOptions,
camera: &mut CameraViewPort,
proj: &ProjectionType,
@@ -80,7 +80,7 @@ impl MOCRenderer {
//self.layers.push(key);
}
pub fn get_hpx_coverage(&self, moc_uuid: &str) -> Option<&HEALPixCoverage> {
pub fn get_hpx_coverage(&self, moc_uuid: &str) -> Option<&SpaceMoc> {
if let Some(idx) = self.cfgs.iter().position(|cfg| cfg.get_uuid() == moc_uuid) {
Some(self.mocs[idx].get_full_moc())
} else {

Some files were not shown because too many files have changed in this diff Show More