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 {
00093 class QVComponentTree
00094 {
00095 public:
00109 QVComponentTree(const QVImage<uChar,1> &image, bool inverseTree= false, bool useAlternative = false);
00110
00111 ~QVComponentTree();
00112
00115 bool isInverseTree() const { return inverseTree; }
00116
00123 uInt & rootNode() { return rootNodeID; }
00124
00134 uInt & seedX(uInt index) { return nodes[index].seedX; }
00135
00145 uInt & seedY(uInt index) { return nodes[index].seedY; }
00146
00153 uChar & firstThreshold(uInt index) { return nodes[index].firstThreshold; }
00154
00161 uChar & lastThreshold(uInt index) { return nodes[index].lastThreshold; }
00162
00166 uInt & numChilds(uInt index) { return nodes[index].numChilds; }
00167
00171 uInt & firstChild(uInt index) { return nodes[index].child; }
00172
00176 uInt & nextSibling(uInt index) { return nodes[index].sibling; }
00177
00195 uInt *area(uInt index) { return nodes[index].area; }
00196
00200 bool & validNode(uInt index) { return nodes[index].inited; }
00201
00204 uInt getNumNodes() const { return numNodes; }
00205
00208 uInt getLeafNodes() const { return leafNodes; }
00209
00214 uInt getTotalPoints() const { return totalPoints; }
00215
00216 private:
00217 void getComponentTree(const QVImage<uChar> &image);
00218 void getComponentTree2(const QVImage<uChar> &image);
00219
00220 uInt numNodes, freePoints, totalPoints, leafNodes, rootNodeID, maxNodes;
00221 bool inverseTree;
00222
00223 uInt newNode(uInt SeedX, uInt SeedY, uChar Threshold)
00224 {
00225 uInt newNodeID = this->numNodes++;
00226 if (nodes.size() <= this->numNodes)
00227 nodes.resize(2*nodes.size());
00228
00229 seedX(newNodeID) = SeedX;
00230 seedY(newNodeID) = SeedY;
00231 firstThreshold(newNodeID) = lastThreshold(newNodeID) = Threshold;
00232 firstChild(newNodeID) = nextSibling(newNodeID) = NULL_NODE;
00233 numChilds(newNodeID) = 0;
00234 area(newNodeID)[Threshold] = 0;
00235 validNode(newNodeID) = false;
00236
00237 return newNodeID;
00238 }
00239
00240 void addChild(uInt ParentNodeID, uInt ChildNodeID)
00241 {
00242 nextSibling(ChildNodeID) = firstChild(ParentNodeID);
00243 firstChild(ParentNodeID) = ChildNodeID;
00244 numChilds(ParentNodeID)++;
00245 }
00246
00247 class QVComponentTreeNode
00248 {
00249 public:
00250 uInt seedX, seedY;
00251 uInt child, sibling, numChilds;
00252 uChar firstThreshold, lastThreshold;
00253 uInt area[256];
00254 bool inited;
00255 };
00256
00257 QVector<QVComponentTreeNode> nodes;
00258 };
00259
00260 void FilterComponentTreeSmallRegions(QVImage<uChar> &image, QVComponentTree &componentTree, uInt area);
00261
00262 }