OpenWalnut  1.4.0
WHierarchicalTreeVoxels.h
00001 //---------------------------------------------------------------------------
00002 //
00003 // Project: OpenWalnut ( http://www.openwalnut.org )
00004 //
00005 // Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
00006 // For more information see http://www.openwalnut.org/copying
00007 //
00008 // This file is part of OpenWalnut.
00009 //
00010 // OpenWalnut is free software: you can redistribute it and/or modify
00011 // it under the terms of the GNU Lesser General Public License as published by
00012 // the Free Software Foundation, either version 3 of the License, or
00013 // (at your option) any later version.
00014 //
00015 // OpenWalnut is distributed in the hope that it will be useful,
00016 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018 // GNU Lesser General Public License for more details.
00019 //
00020 // You should have received a copy of the GNU Lesser General Public License
00021 // along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
00022 //
00023 //---------------------------------------------------------------------------
00024 
00025 #ifndef WHIERARCHICALTREEVOXELS_H
00026 #define WHIERARCHICALTREEVOXELS_H
00027 
00028 #include <utility>
00029 #include <vector>
00030 #include <queue>
00031 #include <list>
00032 
00033 #include <boost/shared_ptr.hpp>
00034 
00035 #include "WColor.h"
00036 
00037 #include "WHierarchicalTree.h"
00038 
00039 
00040 /**
00041  * Class implements a hierarchical tree and provides helper functions for selection and navigation
00042  */
00043 class WHierarchicalTreeVoxels : public WHierarchicalTree // NOLINT
00044 {
00045 public:
00046     /**
00047      * standard constructor
00048      */
00049     WHierarchicalTreeVoxels();
00050 
00051     /**
00052      * destructor
00053      */
00054     ~WHierarchicalTreeVoxels();
00055 
00056     /**
00057      * getter
00058      * \param cluster the cluster to work on
00059      * \return vector of voxels contained by this cluster
00060      */
00061     std::vector<size_t>getVoxelsForCluster( size_t cluster );
00062 
00063     /**
00064      * A leaf is at the very bottom of the tree, it represents a single fiber or voxel, for several purposes
00065      * a leaf also counts as a cluster
00066      * \param voxelnum the voxel id for this leaf
00067      */
00068     void addLeaf( size_t voxelnum );
00069 
00070     /**
00071      * adds a cluster to the set, it combines 2 already existing clusters
00072      *
00073      * \param cluster1 first cluster to add
00074      * \param cluster2 second cluster to add
00075      * \param customData some arbitrary data stored with the cluster
00076      */
00077     void addCluster( size_t cluster1, size_t cluster2, float customData );
00078 
00079     /**
00080      * getter
00081      * \param leaf
00082      * \return the voxel num of a leaf node in the tree
00083      */
00084     size_t getVoxelNum( size_t leaf );
00085 
00086     /**
00087      * finds the clusters for a given similarity value
00088      * \param value
00089      * \return all clusters below that value
00090      */
00091     std::vector< size_t >findClustersForValue( float value );
00092 
00093     /**
00094      * finds the clusters for a given similarity value
00095      * \param value only return clusters where the distance in energy level to its parent is large than this value
00096      * \param minSize only return clusters with a number of voxels large than minSize
00097      * \return all clusters below that value
00098      */
00099     std::vector< size_t >findClustersForBranchLength( float value, size_t minSize = 100 );
00100 
00101     /**
00102      * finds a number of clusters, the algorithm travers down the tree and will always split the cluster with the
00103      * highest energy level.
00104      * \param root the cluster to start traversing the tree from
00105      * \param number the number of cluster we want to find
00106      * \return the clusters
00107      */
00108     std::vector< size_t >findXClusters( size_t root, size_t number );
00109 
00110 protected:
00111 private:
00112     /**
00113      * A leaf is at the very bottom of the tree, it represents a single fiber or voxel, for several purposes
00114      * a leaf also counts as a cluster
00115      */
00116     void addLeaf();
00117 
00118     std::vector<size_t>m_voxelnums; //!< stores the voxel id of each leaf node
00119 };
00120 
00121 inline size_t WHierarchicalTreeVoxels::getVoxelNum( size_t leaf )
00122 {
00123     return m_voxelnums[leaf];
00124 }
00125 
00126 #endif  // WHIERARCHICALTREEVOXELS_H