forked from larrylindsey/imageprocessing
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathComponentTreeDownSampler.cpp
More file actions
46 lines (32 loc) · 1.27 KB
/
Copy pathComponentTreeDownSampler.cpp
File metadata and controls
46 lines (32 loc) · 1.27 KB
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
#include <util/foreach.h>
#include <util/Logger.h>
#include "ComponentTreeDownSampler.h"
static logger::LogChannel componenttreedownsamplerlog("componenttreedownsamplerlog", "[ComponentTreeDownSampler] ");
ComponentTreeDownSampler::ComponentTreeDownSampler() {
registerInput(_componentTree, "component tree");
registerOutput(_downsampled, "component tree");
}
void
ComponentTreeDownSampler::updateOutputs() {
downsample();
}
void
ComponentTreeDownSampler::downsample() {
// copy and downsample on-the-fly, starting with the root node
_downsampled->setRoot(downsample(_componentTree->getRoot()));
}
boost::shared_ptr<ComponentTree::Node>
ComponentTreeDownSampler::downsample(boost::shared_ptr<ComponentTree::Node> node) {
// create a clone of the node
boost::shared_ptr<ComponentTree::Node> nodeClone = boost::make_shared<ComponentTree::Node>(node->getComponent());
// skip over all single children
while (node->getChildren().size() == 1)
node = node->getChildren().front();
// downsample the trees under every child and add them to the clone
foreach (boost::shared_ptr<ComponentTree::Node> child, node->getChildren()) {
boost::shared_ptr<ComponentTree::Node> childClone = downsample(child);
nodeClone->addChild(childClone);
}
// return the clone
return nodeClone;
}