src/qvdta/qvcomponenttree.h

Go to the documentation of this file.
00001 /*
00002  *      Copyright (C) 2007. PARP Research Group.
00003  *      <http://perception.inf.um.es>
00004  *      University of Murcia, Spain.
00005  *
00006  *      This file is part of the QVision library.
00007  *
00008  *      QVision is free software: you can redistribute it and/or modify
00009  *      it under the terms of the GNU Lesser General Public License as
00010  *      published by the Free Software Foundation, version 3 of the License.
00011  *
00012  *      QVision is distributed in the hope that it will be useful,
00013  *      but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  *      GNU Lesser General Public License for more details.
00016  *
00017  *      You should have received a copy of the GNU Lesser General Public
00018  *      License along with QVision. If not, see <http://www.gnu.org/licenses/>.
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 }

Generated on Wed Jan 16 18:41:28 2008 for QVision by  doxygen 1.5.3