00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00024
00025 #include <qvdta/qvdta.h>
00026
00027 #define NULL_NODE 256*256*256
00028
00029 namespace qvdta
00030 {
00071 class QVComponentTree
00072 {
00073 public:
00074
00080 QVComponentTree(const QVImage<uChar,1> &image, bool inverseTree= false);
00081
00082 ~QVComponentTree();
00083
00084 bool isInverseTree() const { return inverseTree; }
00085 uInt rootNode() const { return rootNodeID; }
00086 uInt seedX(uInt node) const { return nodes[node].seedX; }
00087 uInt seedY(uInt node) const { return nodes[node].seedY; }
00088 uChar firstThreshold(uInt node) const { return nodes[node].firstThreshold; }
00089 uChar lastThreshold(uInt node) const { return nodes[node].lastThreshold; }
00090 uInt numChilds(uInt node) const { return nodes[node].numChilds; }
00091 uInt firstChild(uInt node) const { return nodes[node].child; }
00092 uInt nextSibling(uInt node) const { return nodes[node].sibling; }
00093 uInt *area(uInt node) const { return nodes[node].area; }
00094 bool validNode(uInt node) const { return nodes[node].inited; }
00095
00096 uInt & rootNode() { return rootNodeID; }
00097 uInt & seedX(uInt node) { return nodes[node].seedX; }
00098 uInt & seedY(uInt node) { return nodes[node].seedY; }
00099 uChar & firstThreshold(uInt node) { return nodes[node].firstThreshold; }
00100 uChar & lastThreshold(uInt node) { return nodes[node].lastThreshold; }
00101 uInt & numChilds(uInt node) { return nodes[node].numChilds; }
00102 uInt & firstChild(uInt node) { return nodes[node].child; }
00103 uInt & nextSibling(uInt node) { return nodes[node].sibling; }
00104 uInt *area(uInt node) { return nodes[node].area; }
00105 bool & validNode(uInt node) { return nodes[node].inited; }
00106
00107 uInt getNumNodes() const { return numNodes; }
00108 uInt getTotalPoints() const { return totalPoints; }
00109 uInt getLeafNodes() const { return leafNodes; }
00110
00111 private:
00112 void getComponentTree(const QVImage<uChar> &image);
00113 uInt numNodes, freePoints, totalPoints, leafNodes, rootNodeID, maxNodes;
00114 bool inverseTree;
00115
00116 uInt newNode(uInt SeedX, uInt SeedY, uChar Threshold)
00117 {
00118 uInt newNodeID = this->numNodes++;
00119 seedX(newNodeID) = SeedX;
00120 seedY(newNodeID) = SeedY;
00121 firstThreshold(newNodeID) = lastThreshold(newNodeID) = Threshold;
00122 firstChild(newNodeID) = nextSibling(newNodeID) = NULL_NODE;
00123 numChilds(newNodeID) = 0;
00124 area(newNodeID)[Threshold] = 0;
00125 validNode(newNodeID) = false;
00126
00127 return newNodeID;
00128 }
00129
00130 void addChild(uInt ParentNodeID, uInt ChildNodeID)
00131 {
00132 nextSibling(ChildNodeID) = firstChild(ParentNodeID);
00133 firstChild(ParentNodeID) = ChildNodeID;
00134 numChilds(ParentNodeID)++;
00135 }
00136
00137 class QVComponentTreeNode
00138 {
00139 public:
00140 uInt seedX, seedY;
00141 uInt child, sibling, numChilds;
00142 uChar firstThreshold, lastThreshold;
00143 uInt area[256];
00144 bool inited;
00145 } *nodes;
00146 };
00147
00148
00149 void FilterComponentTreeSmallRegions(QVImage<uChar> &image, QVComponentTree &componentTree, uInt area);
00150
00151 }