mirror of
https://github.com/mii443/usls.git
synced 2025-08-22 15:45:41 +00:00
impl Drawable for slice (#99)
This commit is contained in:
@ -31,7 +31,10 @@ impl Default for Annotator {
|
||||
}
|
||||
|
||||
impl Annotator {
|
||||
pub fn annotate<T: Drawable>(&self, image: &Image, drawable: &T) -> Result<Image> {
|
||||
pub fn annotate<T>(&self, image: &Image, drawable: &T) -> Result<Image>
|
||||
where
|
||||
T: Drawable + ?Sized,
|
||||
{
|
||||
let ctx = DrawContext {
|
||||
text_renderer: &self.text_renderer,
|
||||
prob_style: self.prob_style.as_ref(),
|
||||
|
@ -4,7 +4,7 @@ use image::{Rgba, RgbaImage};
|
||||
|
||||
use crate::{DrawContext, Hbb, Style, TextLoc};
|
||||
|
||||
impl Drawable for Vec<Hbb> {
|
||||
impl Drawable for [Hbb] {
|
||||
fn draw(&self, ctx: &DrawContext, canvas: &mut RgbaImage) -> Result<()> {
|
||||
self.iter().try_for_each(|x| x.draw(ctx, canvas))
|
||||
}
|
||||
|
@ -91,7 +91,7 @@ impl Drawable for Keypoint {
|
||||
}
|
||||
}
|
||||
|
||||
impl Drawable for Vec<Keypoint> {
|
||||
impl Drawable for [Keypoint] {
|
||||
fn draw(&self, ctx: &DrawContext, canvas: &mut RgbaImage) -> Result<()> {
|
||||
let nk = self.len();
|
||||
if nk > 0 {
|
||||
@ -137,7 +137,7 @@ impl Drawable for Vec<Keypoint> {
|
||||
}
|
||||
}
|
||||
|
||||
impl Drawable for Vec<Vec<Keypoint>> {
|
||||
impl Drawable for [Vec<Keypoint>] {
|
||||
fn draw(&self, ctx: &DrawContext, canvas: &mut RgbaImage) -> Result<()> {
|
||||
self.iter().try_for_each(|x| x.draw(ctx, canvas))
|
||||
}
|
||||
|
@ -70,7 +70,7 @@ fn draw_masks(
|
||||
Ok(())
|
||||
}
|
||||
|
||||
impl Drawable for Vec<Mask> {
|
||||
impl Drawable for [Mask] {
|
||||
fn get_global_style<'a>(&self, ctx: &'a DrawContext) -> Option<&'a Style> {
|
||||
ctx.mask_style
|
||||
}
|
||||
|
@ -86,6 +86,45 @@ impl Drawable for Y {
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Drawable for Vec<T>
|
||||
where
|
||||
[T]: Drawable,
|
||||
{
|
||||
fn get_local_style(&self) -> Option<&Style> {
|
||||
self.as_slice().get_local_style()
|
||||
}
|
||||
|
||||
fn get_global_style<'a>(&self, ctx: &'a DrawContext) -> Option<&'a Style> {
|
||||
self.as_slice().get_global_style(ctx)
|
||||
}
|
||||
|
||||
fn get_id(&self) -> Option<usize> {
|
||||
self.as_slice().get_id()
|
||||
}
|
||||
|
||||
fn draw_shapes_with_style(
|
||||
&self,
|
||||
ctx: &DrawContext,
|
||||
canvas: &mut image::RgbaImage,
|
||||
style: &Style,
|
||||
) -> anyhow::Result<()> {
|
||||
self.as_slice().draw_shapes_with_style(ctx, canvas, style)
|
||||
}
|
||||
|
||||
fn draw_texts_with_style(
|
||||
&self,
|
||||
ctx: &DrawContext,
|
||||
canvas: &mut image::RgbaImage,
|
||||
style: &Style,
|
||||
) -> anyhow::Result<()> {
|
||||
self.as_slice().draw_texts_with_style(ctx, canvas, style)
|
||||
}
|
||||
|
||||
fn draw(&self, ctx: &DrawContext, canvas: &mut image::RgbaImage) -> anyhow::Result<()> {
|
||||
self.as_slice().draw(ctx, canvas)
|
||||
}
|
||||
}
|
||||
|
||||
// impl<T: Drawable> Drawable for Vec<T> {
|
||||
// fn draw_shapes(&self, ctx: &DrawContext, canvas: &mut image::RgbaImage) -> anyhow::Result<()> {
|
||||
// self.iter().try_for_each(|x| x.draw_shapes(ctx, canvas))
|
||||
|
@ -4,7 +4,7 @@ use image::{Rgba, RgbaImage};
|
||||
|
||||
use crate::{DrawContext, Obb, Style, TextLoc};
|
||||
|
||||
impl Drawable for Vec<Obb> {
|
||||
impl Drawable for [Obb] {
|
||||
fn draw(&self, ctx: &DrawContext, canvas: &mut RgbaImage) -> Result<()> {
|
||||
self.iter().try_for_each(|x| x.draw(ctx, canvas))
|
||||
}
|
||||
|
@ -4,7 +4,7 @@ use image::{Rgba, RgbaImage};
|
||||
|
||||
use crate::{DrawContext, Polygon, Style, TextLoc};
|
||||
|
||||
impl Drawable for Vec<Polygon> {
|
||||
impl Drawable for [Polygon] {
|
||||
fn draw(&self, ctx: &DrawContext, canvas: &mut RgbaImage) -> Result<()> {
|
||||
self.iter().try_for_each(|x| x.draw(ctx, canvas))
|
||||
}
|
||||
|
@ -4,7 +4,7 @@ use image::RgbaImage;
|
||||
|
||||
use crate::{DrawContext, Prob, Style, TextLoc};
|
||||
|
||||
impl Drawable for Vec<Prob> {
|
||||
impl Drawable for [Prob] {
|
||||
fn draw_texts_with_style(
|
||||
&self,
|
||||
ctx: &DrawContext,
|
||||
|
Reference in New Issue
Block a user