00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00024
00025 #include <stdio.h>
00026 #include <stdlib.h>
00027 #include <iostream>
00028
00029 #include <qvdta/qvdta.h>
00030
00031 #define NULL_NODE 256*256*256
00032
00101 class QVComponentTree
00102 {
00103 public:
00117 QVComponentTree(const QVImage<uChar,1> &image, bool inverseTree= false, bool useAlternative = false);
00118
00121 bool isInverseTree() const { return inverseTree; }
00122
00129 uInt & rootNode() { return rootNodeID; }
00130
00140 uInt & seedX(uInt index) { return nodes[index].seedX; }
00141
00151 uInt & seedY(uInt index) { return nodes[index].seedY; }
00152
00159 uChar & firstThreshold(uInt index) { return nodes[index].firstThreshold; }
00160
00167 uChar & lastThreshold(uInt index) { return nodes[index].lastThreshold; }
00168
00172 uInt & numChilds(uInt index) { return nodes[index].numChilds; }
00173
00177 uInt & firstChild(uInt index) { return nodes[index].child; }
00178
00182 uInt & nextSibling(uInt index) { return nodes[index].sibling; }
00183
00201 uInt *area(uInt index) { return nodes[index].area; }
00202
00205 uInt getNumNodes() const { return numNodes; }
00206
00209 uInt getLeafNodes() const { return leafNodes; }
00210
00215 uInt getTotalPoints() const { return totalPoints; }
00216
00217 private:
00218 void getComponentTree(const QVImage<uChar> &image);
00219 void getComponentTree2(const QVImage<uChar> &image);
00220
00221 uInt numNodes, freePoints, totalPoints, leafNodes, rootNodeID, maxNodes;
00222 bool inverseTree;
00223
00225 bool & closedNode(uInt index) { return nodes[index].closed; }
00226
00227 uInt newNode(uInt SeedX, uInt SeedY, uChar Threshold)
00228 {
00229 uInt newNodeID = this->numNodes++;
00230
00231 seedX(newNodeID) = SeedX;
00232 seedY(newNodeID) = SeedY;
00233 firstThreshold(newNodeID) = lastThreshold(newNodeID) = Threshold;
00234 firstChild(newNodeID) = nextSibling(newNodeID) = NULL_NODE;
00235 numChilds(newNodeID) = 0;
00236 area(newNodeID)[Threshold] = 0;
00237 closedNode(newNodeID) = false;
00238
00239 return newNodeID;
00240 }
00241
00242 void addChild(uInt ParentNodeID, uInt ChildNodeID)
00243 {
00244 nextSibling(ChildNodeID) = firstChild(ParentNodeID);
00245 firstChild(ParentNodeID) = ChildNodeID;
00246 numChilds(ParentNodeID)++;
00247 }
00248
00249 void mergeNodes(uInt actualNodeID, uInt vecinoNodeID)
00250 {
00251
00252
00253
00254 uInt next, lastActualChildNodeID = firstChild(actualNodeID);
00255 while ((next=nextSibling(lastActualChildNodeID)) != NULL_NODE)
00256 lastActualChildNodeID = next;
00257
00258 numChilds(actualNodeID) += numChilds(vecinoNodeID);
00259 nextSibling(lastActualChildNodeID) = firstChild(vecinoNodeID);
00260 }
00261
00262 class QVComponentTreeNode
00263 {
00264 public:
00265 uInt seedX, seedY;
00266 uInt child, sibling, numChilds;
00267 uChar firstThreshold, lastThreshold;
00268 uInt area[256];
00269 bool closed;
00270 };
00271
00272 QVector<QVComponentTreeNode> nodes;
00273
00274
00275 };
00276
00277