Implement the Gaussian Blur node (#933)

This commit is contained in:
Dennis Kobert
2022-12-31 21:12:02 +01:00
committed by Keavon Chambers
parent 74bfd630a9
commit a9601ab164
11 changed files with 578 additions and 51 deletions

View File

@@ -2,35 +2,32 @@ use graphene_core::{Cache, Node};
use once_cell::sync::OnceCell;
/// Caches the output of a given Node and acts as a proxy
pub struct CacheNode<CachedNode: Node<I>, I> {
node: CachedNode,
cache: OnceCell<CachedNode::Output>,
pub struct CacheNode<T> {
cache: OnceCell<T>,
}
impl<'n, CashedNode: Node<I> + Copy, I> Node<I> for &'n CacheNode<CashedNode, I> {
type Output = &'n CashedNode::Output;
fn eval(self, input: I) -> Self::Output {
impl<'n, T> Node<T> for &'n CacheNode<T> {
type Output = &'n T;
fn eval(self, input: T) -> Self::Output {
self.cache.get_or_init(|| {
trace!("Creating new cache node");
self.node.eval(input)
input
})
}
}
impl<'n, CachedNode: Node<I>, I> CacheNode<CachedNode, I> {
pub fn clear(&'n mut self) {
self.cache = OnceCell::new();
}
pub fn new(node: CachedNode) -> CacheNode<CachedNode, I> {
CacheNode { node, cache: OnceCell::new() }
impl<T> Node<T> for CacheNode<T> {
type Output = T;
fn eval(self, input: T) -> Self::Output {
input
}
}
impl<CachedNode: Node<I>, I> Cache for CacheNode<CachedNode, I> {
impl<T> CacheNode<T> {
pub fn new() -> CacheNode<T> {
CacheNode { cache: OnceCell::new() }
}
}
impl<T> Cache for CacheNode<T> {
fn clear(&mut self) {
self.cache = OnceCell::new();
}
}
/*use dyn_any::{DynAny, StaticType};
#[derive(DynAny)]
struct Boo<'a>(&'a u8);
*/