src/qvip/qvimagefeatures/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 <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                         // uInt child;
00252                         // for (child = firstChild(actualNodeID); nextSibling(child) != NULL_NODE; child = nextSibling(child));
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                 //void testComponentTree(const QVImage<uChar,1> &image, QVDisjointSet &disjointSet);
00275         };
00276 
00277 

Generated on Thu Jul 17 17:23:28 2008 for QVision by  doxygen 1.5.3