PARP Research Group University of Murcia, Spain


src/qvip/qvimagefeatures/qvcomponenttree.h

Go to the documentation of this file.
00001 /*
00002  *      Copyright (C) 2007, 2008, 2009. 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 <qvip.h>
00030 
00031 #define  NULL_NODE      256*256*256
00032 
00100 class QVComponentTree
00101         {
00102         public:
00116                 QVComponentTree(const QVImage<uChar,1> &image, bool inverseTree= false, bool useAlternative = false);
00117 
00120                 bool isInverseTree()    const           { return inverseTree; }
00121 
00128                 uInt & rootNode()                       { return rootNodeID; }
00129 
00139                 uInt & seedX(uInt index)                { return nodes[index].seedX; }
00140 
00150                 uInt & seedY(uInt index)                { return nodes[index].seedY; }
00151 
00158                 uChar & firstThreshold(uInt index)      { return nodes[index].firstThreshold; }
00159 
00166                 uChar & lastThreshold(uInt index)       { return nodes[index].lastThreshold; }
00167 
00171                 uInt & numChilds(uInt index)            { return nodes[index].numChilds; }
00172 
00176                 uInt & firstChild(uInt index)           { return nodes[index].child; }
00177 
00181                 uInt & nextSibling(uInt index)          { return nodes[index].sibling; }
00182 
00200                 uInt *area(uInt index)                  { return nodes[index].area; }
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 
00219                 uInt numNodes, freePoints, totalPoints, leafNodes, rootNodeID, maxNodes;
00220                 bool inverseTree;
00221 
00223                 bool & closedNode(uInt index)           { return nodes[index].closed; }
00224 
00225                 uInt newNode(uInt SeedX, uInt SeedY, uChar Threshold)
00226                         {
00227                         uInt newNodeID = this->numNodes++;
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                         closedNode(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                 void mergeNodes(uInt actualNodeID, uInt vecinoNodeID)
00248                         {
00249                         uInt next, lastActualChildNodeID = firstChild(actualNodeID);
00250                         while ((next=nextSibling(lastActualChildNodeID)) != NULL_NODE)
00251                                 lastActualChildNodeID = next;
00252 
00253                         numChilds(actualNodeID) += numChilds(vecinoNodeID);
00254                         nextSibling(lastActualChildNodeID) = firstChild(vecinoNodeID);
00255                         }
00256 
00257                 class QVComponentTreeNode
00258                         {
00259                         public:
00260                                 uInt seedX, seedY;
00261                                 uInt child, sibling, numChilds;
00262                                 uChar firstThreshold, lastThreshold;
00263                                 uInt area[256];
00264                                 bool closed;
00265 
00266                                 /*bool operator==(const QVComponentTreeNode &other) const
00267                                         {
00268                                         if (seedX != other.seedX)
00269                                                 return false;
00270                                         if (seedY != other.seedY)
00271                                                 return false;
00272                                         //if (child != other.child)
00273                                         //      return false;
00274                                         //if (sibling != other.sibling)
00275                                         //      return false;
00276                                         if (numChilds != other.numChilds)
00277                                                 return false;
00278                                         if (firstThreshold != other.firstThreshold)
00279                                                 return false;
00280                                         if (lastThreshold != other.lastThreshold)
00281                                                 return false;
00282                                         for (int i = firstThreshold; i < lastThreshold; i++)
00283                                                 if (area[i] != other.area[i])
00284                                                         return false;
00285                                         return true;
00286                                         }*/
00287                         };
00288 
00289                 QVector<QVComponentTreeNode> nodes;
00290 
00291                 //void testComponentTree(const QVImage<uChar,1> &image, QVDisjointSet &disjointSet);
00292         };
00293 
00294 



QVision framework. PARP research group, copyright 2007, 2008.