Tree.C
Go to the documentation of this file.00001
00002
00003
00004
00005
00006 #include "Landmark/Tree.H"
00007
00008 #include "Image/DrawOps.H"
00009 #include "Image/Pixels.H"
00010
00011 Tree::Tree(Point2D<int> loc, double height)
00012 {
00013 node = new Node;
00014
00015 node->parent = NULL;
00016 node->loc = loc;
00017 node->height = height;
00018
00019
00020 }
00021
00022
00023
00024 void Tree::insert(Point2D<int> loc, double height)
00025 {
00026 Tree child(loc, height);
00027 node->children.push_back(child.node);
00028
00029 }
00030
00031
00032
00033 void Tree:: mergeTrees(std::vector<Tree* > trees)
00034 {
00035 std::vector<Node* > nodes;
00036 for(uint i = 0; i < trees.size(); i++)
00037 nodes.push_back(trees[i]->node);
00038
00039 mergeNodes(nodes);
00040 }
00041
00042
00043
00044 void Tree::mergeNodes(std::vector<Node* > nodes)
00045 {
00046 for(uint i = 0; i < nodes.size(); i++)
00047 node->children.push_back(nodes[i]);
00048
00049 }
00050
00051
00052
00053 void Tree::traverse(Image<float>& input, Image<PixRGB<byte> >& output)
00054 {
00055
00056 drawCircle(output, node->loc, 2, PixRGB<byte>(255, 255, 0), 3);
00057 int idx = 0;
00058 bfs(node, input, output, idx);
00059 }
00060
00061
00062
00063 void Tree::bfs(Node* q, Image<float>& input, Image<PixRGB<byte> >& output,
00064 int& idx)
00065 {
00066 PixRGB<byte> col,
00067 red(255, 0, 0),
00068 blue(0, 0, 255),
00069 green(0, 255, 0),
00070 yellow(255, 255, 0);
00071 switch(idx % 3)
00072 {
00073 case 0:
00074 col = red;
00075 break;
00076 case 1:
00077 col = green;
00078 break;
00079 case 2:
00080 col = blue;
00081 break;
00082 }
00083 idx++;
00084
00085
00086 int count = q->children.size();
00087 for (int i = 0; i < count; i++)
00088 {
00089
00090
00091 drawCircle(output, q->children[i]->loc, 2, col, 1);
00092 }
00093
00094
00095 for (int j = 0; j < count; j++)
00096 {
00097 drawCircle(output, node->loc, 3, yellow, 3);
00098 bfs(q->children[j], input, output, idx);
00099 }
00100 }
00101
00102