feat: Bbox drawing
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
use crate::*;
|
use crate::{roi::RoiMut, *};
|
||||||
pub use color::Rgba8;
|
pub use color::Rgba8;
|
||||||
|
|
||||||
use ndarray::{Array1, Array3, ArrayViewMut3};
|
use ndarray::{Array1, Array3, ArrayViewMut3};
|
||||||
@@ -27,6 +27,8 @@ impl Drawable<ArrayViewMut3<'_, u8>> for Aabb2<usize> {
|
|||||||
self.corners()
|
self.corners()
|
||||||
.iter()
|
.iter()
|
||||||
.zip(self.padding(thickness).corners())
|
.zip(self.padding(thickness).corners())
|
||||||
|
.cycle()
|
||||||
|
.take(5)
|
||||||
.tuple_windows()
|
.tuple_windows()
|
||||||
.for_each(|((a, b), (c, d))| {
|
.for_each(|((a, b), (c, d))| {
|
||||||
let bbox = Aabb2::from_vertices([*a, b, *c, d]).expect("Invalid bounding box");
|
let bbox = Aabb2::from_vertices([*a, b, *c, d]).expect("Invalid bounding box");
|
||||||
@@ -49,5 +51,15 @@ impl Drawable<Array3<u8>> for Aabb2<usize> {
|
|||||||
let pixel_size = canvas.dim().2;
|
let pixel_size = canvas.dim().2;
|
||||||
let color = color.slice(ndarray::s![..pixel_size]);
|
let color = color.slice(ndarray::s![..pixel_size]);
|
||||||
let [x1y1, x2y1, x1y2, x2y2] = self.corners();
|
let [x1y1, x2y1, x1y2, x2y2] = self.corners();
|
||||||
|
let right = Aabb2::from_x1y1x2y2(x1y1.x, x1y1.y, x2y1.x, x2y1.y + thickness);
|
||||||
|
dbg!(right);
|
||||||
|
canvas
|
||||||
|
.roi_mut(right)
|
||||||
|
.expect("Failed to get ROI")
|
||||||
|
.lanes_mut(ndarray::Axis(2))
|
||||||
|
.into_iter()
|
||||||
|
.for_each(|mut pixel| {
|
||||||
|
pixel.assign(&color);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -108,7 +108,8 @@ impl<T: Num, const D: usize> AxisAlignedBoundingBox<T, D> {
|
|||||||
let min = self.min_vertex();
|
let min = self.min_vertex();
|
||||||
let max = self.max_vertex();
|
let max = self.max_vertex();
|
||||||
|
|
||||||
*point > min && *point < max
|
// *point > min && *point < max
|
||||||
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn scale(self, vector: SVector<T, D>) -> Self
|
pub fn scale(self, vector: SVector<T, D>) -> Self
|
||||||
@@ -140,6 +141,18 @@ impl<T: Num, const D: usize> AxisAlignedBoundingBox<T, D> {
|
|||||||
other_min >= self_min && other_max <= self_max
|
other_min >= self_min && other_max <= self_max
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn clamp(&self, other: &Self) -> Self
|
||||||
|
where
|
||||||
|
T: core::ops::AddAssign,
|
||||||
|
T: core::ops::SubAssign,
|
||||||
|
T: PartialOrd,
|
||||||
|
{
|
||||||
|
if self.contains_bbox(other) {
|
||||||
|
return *other;
|
||||||
|
}
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
|
|
||||||
pub fn union(&self, other: &Self) -> Self
|
pub fn union(&self, other: &Self) -> Self
|
||||||
where
|
where
|
||||||
T: core::ops::AddAssign,
|
T: core::ops::AddAssign,
|
||||||
|
|||||||
@@ -43,7 +43,6 @@ pub fn main() -> Result<()> {
|
|||||||
.cast()
|
.cast()
|
||||||
.ok_or(errors::Error)
|
.ok_or(errors::Error)
|
||||||
.attach_printable("Failed to cast f32 to usize")?;
|
.attach_printable("Failed to cast f32 to usize")?;
|
||||||
dbg!(bbox);
|
|
||||||
array.draw(bbox, color::palette::css::GREEN_YELLOW.to_rgba8(), 20);
|
array.draw(bbox, color::palette::css::GREEN_YELLOW.to_rgba8(), 20);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user