1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
//! Plugin for labels and metadata

use super::*;
use crate::covertree::node::CoverNode;
use crate::covertree::CoverTreeReader;
//use pointcloud::*;
use std::sync::Arc;

/// Wrapper around the summary found in the point cloud
#[derive(Debug, Default)]
pub struct NodeLabelSummary<T: Summary + Clone> {
    /// The summary object, refenced counted to eliminate duplicates
    pub summary: Arc<SummaryCounter<T>>,
}

impl<T: Summary + Clone> Clone for NodeLabelSummary<T> {
    fn clone(&self) -> Self {
        NodeLabelSummary {
            summary: Arc::clone(&self.summary),
        }
    }
}

impl<D: PointCloud> NodePlugin<D> for NodeLabelSummary<D::LabelSummary> {}

/// Plug in that allows for summaries of labels to be attached to
#[derive(Debug, Clone, Default)]
pub struct LabelSummaryPlugin {}

impl<D: PointCloud> GokoPlugin<D> for LabelSummaryPlugin {
    type NodeComponent = NodeLabelSummary<D::LabelSummary>;
    fn node_component(
        _parameters: &Self,
        my_node: &CoverNode<D>,
        my_tree: &CoverTreeReader<D>,
    ) -> Option<Self::NodeComponent> {
        let mut bucket = my_tree
            .parameters()
            .point_cloud
            .label_summary(my_node.singletons())
            .unwrap();
        // If we're a routing node then grab the childen's values
        if let Some((nested_scale, child_addresses)) = my_node.children() {
            my_tree.get_node_plugin_and::<Self::NodeComponent, _, _>(
                (nested_scale, *my_node.center_index()),
                |p| bucket.combine(p.summary.as_ref()),
            );

            for ca in child_addresses {
                my_tree.get_node_plugin_and::<Self::NodeComponent, _, _>(*ca, |p| {
                    bucket.combine(p.summary.as_ref())
                });
            }
        } else {
            bucket.add(
                my_tree
                    .parameters()
                    .point_cloud
                    .label(*my_node.center_index()),
            );
        }
        Some(NodeLabelSummary {
            summary: Arc::new(bucket),
        })
    }
}

/// Wrapper around the summary found in the point cloud
#[derive(Debug, Default)]
pub struct NodeMetaSummary<T: Summary + Clone> {
    /// The summary object, refenced counted to eliminate duplicates
    pub summary: Arc<SummaryCounter<T>>,
}

impl<T: Summary + Clone> Clone for NodeMetaSummary<T> {
    fn clone(&self) -> Self {
        NodeMetaSummary {
            summary: Arc::clone(&self.summary),
        }
    }
}

impl<D: PointCloud> NodePlugin<D> for NodeMetaSummary<D::MetaSummary> {}

/// Plug in that allows for summaries of Metas to be attached to
#[derive(Debug, Clone, Default)]
pub struct MetaSummaryPlugin {}

impl<D: PointCloud> GokoPlugin<D> for MetaSummaryPlugin {
    type NodeComponent = NodeMetaSummary<D::MetaSummary>;
    fn node_component(
        _parameters: &Self,
        my_node: &CoverNode<D>,
        my_tree: &CoverTreeReader<D>,
    ) -> Option<Self::NodeComponent> {
        let mut bucket = my_tree
            .parameters()
            .point_cloud
            .metasummary(my_node.singletons())
            .unwrap();
        // If we're a routing node then grab the childen's values
        if let Some((nested_scale, child_addresses)) = my_node.children() {
            my_tree.get_node_plugin_and::<Self::NodeComponent, _, _>(
                (nested_scale, *my_node.center_index()),
                |p| bucket.combine(p.summary.as_ref()),
            );

            for ca in child_addresses {
                my_tree.get_node_plugin_and::<Self::NodeComponent, _, _>(*ca, |p| {
                    bucket.combine(p.summary.as_ref())
                });
            }
        } else {
            bucket.add(
                my_tree
                    .parameters()
                    .point_cloud
                    .metadata(*my_node.center_index()),
            );
        }
        Some(NodeMetaSummary {
            summary: Arc::new(bucket),
        })
    }
}