Skip to content

Commit

Permalink
WIP: polyline catalog renderer
Browse files Browse the repository at this point in the history
  • Loading branch information
bmatthieu3 committed Jul 2, 2024
1 parent 3fee4a3 commit 631b2cd
Show file tree
Hide file tree
Showing 16 changed files with 289 additions and 179 deletions.
3 changes: 1 addition & 2 deletions examples/al-init-custom-options.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@


<div id="aladin-lite-div" style="width: 768px; height: 512px"></div>

<script>let aladin;</script>
<script type="module">
import A from '../src/js/A.js';
let aladin;
A.init.then(() => {
aladin = A.aladin(
'#aladin-lite-div',
Expand Down
2 changes: 1 addition & 1 deletion src/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ mapproj = "0.3.0"
fitsrs = "0.2.9"
wcs = "0.2.8"
colorgrad = "0.6.2"
lyon = "1.0.1"
#lyon = "1.0.1"
console_error_panic_hook = {version = "0.1.7", optional = true}

[features]
Expand Down
7 changes: 1 addition & 6 deletions src/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,12 +165,7 @@ impl WebClient {

let shaders = ShaderManager::new().unwrap_abort();

// Event listeners callbacks
//let callback_position_changed = js_sys::Function::new_no_args("");
let app = App::new(
&gl, aladin_div, shaders, resources,
//callback_position_changed,
)?;
let app = App::new(&gl, aladin_div, shaders, resources)?;

let dt = DeltaTime::zero();

Expand Down
4 changes: 3 additions & 1 deletion src/core/src/math/angle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ where
}

use cgmath::{Deg, Rad};
use serde::Deserialize;
// Convert a Rad<T> to an ArcDeg<T>
impl<T> From<Rad<T>> for ArcDeg<T>
where
Expand Down Expand Up @@ -362,7 +363,8 @@ impl FormatType for HMS {
}
}

#[derive(Clone, Copy, Debug, Eq, Hash)]
#[derive(Clone, Copy, Debug, Eq, Hash, Deserialize)]
#[serde(rename_all = "camelCase")]
#[repr(C)]
pub struct Angle<S: BaseFloat>(pub S);
impl<S> Angle<S>
Expand Down
5 changes: 3 additions & 2 deletions src/core/src/math/lonlat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ pub trait LonLat<S: BaseFloat> {
fn lonlat(&self) -> LonLatT<S>;
fn from_lonlat(lonlat: &LonLatT<S>) -> Self;
}

use crate::math::angle::Angle;
#[derive(Clone, Copy, Debug)]
use serde::Deserialize;
#[derive(Clone, Copy, Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
#[repr(C)]
pub struct LonLatT<S: BaseFloat>(pub Angle<S>, pub Angle<S>);

Expand Down
32 changes: 2 additions & 30 deletions src/core/src/renderable/line/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ pub mod parallel_arc;

use crate::math::projection::ProjectionType;
use crate::shader::ShaderManager;
use crate::Abort;
use al_api::coo_system::CooSystem;
use al_core::VertexArrayObject;
use al_core::WebGlContext;
Expand All @@ -13,8 +12,6 @@ use super::Renderer;
use al_api::color::ColorRGBA;
use al_core::SliceData;

use lyon::algorithms::{math::point, path::Path};

struct Meta {
color: ColorRGBA,
thickness: f32,
Expand Down Expand Up @@ -50,33 +47,8 @@ use web_sys::WebGl2RenderingContext;

use crate::camera::CameraViewPort;

use lyon::tessellation::*;

use crate::coo_space::CooSpace;

/*impl<S: BaseFloat> GPUVertexAttribute<S> for XYZModel<S> {
const Space: CooSpace = CooSpace::Model;
fn as_ref(&self) -> &[S] {
&self[..]
}
}
impl<S: BaseFloat> GPUVertexAttribute<S> for LonLatT<S> {
const Space: CooSpace = CooSpace::LonLat;
fn as_ref(&self) -> &[S] {
let addr = self as *const LonLatT<S> as *const S;
unsafe { std::slice::from_raw_parts(addr, 2) }
}
}*/
/*
impl<S: BaseFloat> GPUVertexAttribute for XYZModel<S> {
const Space: CooSpace = CooSpace::Model;
}
impl<S: BaseFloat> GPUVertexAttribute for LonLatT<S> {
const Space: CooSpace = CooSpace::LonLat;
}*/

#[repr(C)]
pub struct PathVertices<V>
where
Expand Down Expand Up @@ -126,7 +98,7 @@ impl RasterizedLineRenderer {
})
}

pub fn add_fill_paths<V>(
/*pub fn add_fill_paths<V>(
&mut self,
paths: impl Iterator<Item = PathVertices<V>>,
color: &ColorRGBA,
Expand Down Expand Up @@ -200,7 +172,7 @@ impl RasterizedLineRenderer {
color: color.clone(),
coo_space,
});
}
}*/

fn create_instanced_vao(&mut self) {
let mut vao = VertexArrayObject::new(&self.gl);
Expand Down
137 changes: 0 additions & 137 deletions src/core/src/renderable/moc/renderer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,143 +16,6 @@ pub struct MOCRenderer {
gl: WebGlContext,
}

/*
use cgmath::Vector2;
use super::utils::triangle::Triangle;
fn is_crossing_projection(
cell: &HEALPixCell,
camera: &CameraViewPort,
projection: &ProjectionType,
) -> bool {
let vertices = cell
.vertices()
.iter()
.filter_map(|(lon, lat)| {
let xyzw = crate::math::lonlat::radec_to_xyzw(Angle(*lon), Angle(*lat));
let xyzw =
crate::coosys::apply_coo_system(CooSystem::ICRS, camera.get_coo_system(), &xyzw);
projection
.model_to_normalized_device_space(&xyzw, camera)
.map(|v| [v.x as f32, v.y as f32])
})
.collect::<Vec<_>>();
let cell_inside = vertices.len() == 4;
if cell_inside {
let c0 = &vertices[0];
let c1 = &vertices[1];
let c2 = &vertices[2];
let c3 = &vertices[3];
let t0 = Triangle::new(c0, c1, c2);
let t2 = Triangle::new(c2, c3, c0);
t0.is_invalid(camera) || t2.is_invalid(camera)
} else {
true
}
}
use al_api::cell::HEALPixCellProjeted;
fn rasterize_hpx_cell(
cell: &HEALPixCell,
n_segment_by_side: usize,
camera: &CameraViewPort,
idx_off: &mut u32,
proj: &ProjectionType,
) -> Option<(Vec<f32>, Vec<u32>)> {
let n_vertices_per_segment = n_segment_by_side + 1;
let vertices = cell
.grid(n_segment_by_side as u32)
.iter()
.filter_map(|(lon, lat)| {
let xyzw = crate::math::lonlat::radec_to_xyzw(Angle(*lon), Angle(*lat));
let xyzw =
crate::coosys::apply_coo_system(CooSystem::ICRS, camera.get_coo_system(), &xyzw);
proj.model_to_normalized_device_space(&xyzw, camera)
.map(|v| [v.x as f32, v.y as f32])
})
.flatten()
.collect::<Vec<_>>();
let cell_inside = vertices.len() == 2 * (n_segment_by_side + 1) * (n_segment_by_side + 1);
if cell_inside {
// Generate the iterator: idx_off + 1, idx_off + 1, .., idx_off + 4*n_segment - 1, idx_off + 4*n_segment - 1
let mut indices = Vec::with_capacity(n_segment_by_side * n_segment_by_side * 6);
let num_vertices = (n_segment_by_side + 1) * (n_segment_by_side + 1);
let longitude_reversed = camera.get_longitude_reversed();
let invalid_tri = |tri_ccw: bool, reversed_longitude: bool| -> bool {
(!reversed_longitude && !tri_ccw) || (reversed_longitude && tri_ccw)
};
for i in 0..n_segment_by_side {
for j in 0..n_segment_by_side {
let idx_0 = j + i * n_vertices_per_segment;
let idx_1 = j + 1 + i * n_vertices_per_segment;
let idx_2 = j + (i + 1) * n_vertices_per_segment;
let idx_3 = j + 1 + (i + 1) * n_vertices_per_segment;
let c0 = crate::math::projection::ndc_to_screen_space(
&Vector2::new(vertices[2 * idx_0] as f64, vertices[2 * idx_0 + 1] as f64),
camera,
);
let c1 = crate::math::projection::ndc_to_screen_space(
&Vector2::new(vertices[2 * idx_1] as f64, vertices[2 * idx_1 + 1] as f64),
camera,
);
let c2 = crate::math::projection::ndc_to_screen_space(
&Vector2::new(vertices[2 * idx_2] as f64, vertices[2 * idx_2 + 1] as f64),
camera,
);
let c3 = crate::math::projection::ndc_to_screen_space(
&Vector2::new(vertices[2 * idx_3] as f64, vertices[2 * idx_3 + 1] as f64),
camera,
);
let first_tri_ccw = !crate::math::vector::ccw_tri(&c0, &c1, &c2);
let second_tri_ccw = !crate::math::vector::ccw_tri(&c1, &c3, &c2);
if invalid_tri(first_tri_ccw, longitude_reversed)
|| invalid_tri(second_tri_ccw, longitude_reversed)
{
return None;
}
let vx = [c0.x, c1.x, c2.x, c3.x];
let vy = [c0.y, c1.y, c2.y, c3.y];
let projeted_cell = HEALPixCellProjeted {
ipix: cell.idx(),
vx,
vy,
};
crate::camera::view_hpx_cells::project(projeted_cell, camera, proj)?;
indices.push(*idx_off + idx_0 as u32);
indices.push(*idx_off + idx_1 as u32);
indices.push(*idx_off + idx_2 as u32);
indices.push(*idx_off + idx_1 as u32);
indices.push(*idx_off + idx_3 as u32);
indices.push(*idx_off + idx_2 as u32);
}
}
*idx_off += num_vertices as u32;
Some((vertices, indices))
} else {
None
}
}*/

use crate::ProjectionType;

impl MOCRenderer {
Expand Down
1 change: 1 addition & 0 deletions src/core/src/renderable/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ pub mod hips;
pub mod image;
pub mod line;
pub mod moc;
pub mod shape;
pub mod text;
pub mod utils;

Expand Down
1 change: 1 addition & 0 deletions src/core/src/renderable/shape/box.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Empty file.
Empty file.
Empty file.
62 changes: 62 additions & 0 deletions src/core/src/renderable/shape/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
use crate::math::{angle::Angle, lonlat::LonLatT};
use al_api::color::ColorRGBA;
use serde::Deserialize;

mod circle;
mod ellipsis;
mod image;
mod polyline;

#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub enum Shape {
Box {
/// Center of the box
c: LonLatT<f32>,
/// Size following the RA axis
ra_w: Angle<f32>,
/// Size following the Dec axis
dec_h: Angle<f32>,
/// Rotation of the box in the RA-Dec space
rot: Angle<f32>,
},
Circle {
/// Center of the circle
c: LonLatT<f32>,
/// Radius of the circle
rad: Angle<f32>,
},
PolyLine(Box<[LonLatT<f32>]>),
Ellipsis {
/// Center of the ellipsis
c: LonLatT<f32>,
/// Semi-major axis
a: Angle<f32>,
/// Semi-minor axis
b: Angle<f32>,
/// Rotation angle of the ellipsis. Origin aligns the ellipsis' major axis with the north pole. Positive angle points towards the east.
rot: Angle<f32>,
},
// TODO
Image,
}

#[derive(Debug, Deserialize)]
pub enum Style {
None,
Dashed,
Dotted,
}

#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
struct Footprint {
shapes: Vec<Shape>,
/// Some styling meta data
color: ColorRGBA,
filled: bool,
thickness: f32,
style: Style,
}

type Catalog = Footprint;
Loading

0 comments on commit 631b2cd

Please sign in to comment.