OpenWalnut  1.2.5
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
WHierarchicalTreeFibers.h
1 //---------------------------------------------------------------------------
2 //
3 // Project: OpenWalnut ( http://www.openwalnut.org )
4 //
5 // Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
6 // For more information see http://www.openwalnut.org/copying
7 //
8 // This file is part of OpenWalnut.
9 //
10 // OpenWalnut is free software: you can redistribute it and/or modify
11 // it under the terms of the GNU Lesser General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // OpenWalnut is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public License
21 // along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
22 //
23 //---------------------------------------------------------------------------
24 
25 #ifndef WHIERARCHICALTREEFIBERS_H
26 #define WHIERARCHICALTREEFIBERS_H
27 
28 #include <utility>
29 #include <vector>
30 #include <queue>
31 #include <list>
32 
33 #include <boost/shared_ptr.hpp>
34 
35 #include "WColor.h"
36 
37 #include "WHierarchicalTree.h"
38 #include "WExportCommon.h"
39 
40 /**
41  * Class implements a hierarchical tree and provides helper functions for selection and navigation
42  */
43 class OWCOMMON_EXPORT WHierarchicalTreeFibers : public WHierarchicalTree
44 {
45 public:
46  /**
47  * standard constructor
48  */
50 
51  /**
52  * destructor
53  */
55 
56  /**
57  * A leaf is at the very bottom of the tree, it represents a single fiber or voxel, for several purposes
58  * a leaf also counts as a cluster
59  */
60  void addLeaf();
61 
62  /**
63  * adds a cluster to the set, it combines 2 already existing clusters
64  *
65  * \param cluster1 first cluster to add
66  * \param cluster2 second cluster to add
67  * \param level level of the new cluster
68  * \param leafes vector of leafes the new cluster contains
69  * \param customData some arbitrary data stored with the cluster
70  */
71  void addCluster( size_t cluster1, size_t cluster2, size_t level, std::vector<size_t> leafes, float customData );
72 
73  /**
74  * generates a bitfield where for every leaf in the selected cluster the value is true, false otherwise
75  *
76  * \param cluster
77  * \return shared pointer to the bitfield
78  */
79  boost::shared_ptr< std::vector<bool> >getOutputBitfield( size_t cluster );
80 
81  /**
82  * generates a bitfield where for every leaf in the selected cluster the value is true, false otherwise
83  *
84  * \param clusters
85  * \return shared pointer to the bitfield
86  */
87  boost::shared_ptr< std::vector<bool> >getOutputBitfield( std::vector<size_t>clusters );
88 
89  /**
90  * finds clusters that match a given ROI up to a certain percentage
91  *
92  * \param ratio value of [0,1] of how many leafs have to be in the ROI to activate the cluster
93  * \param number number of clusters to select, if more than given number matches the ratio criterion only the
94  * biggest clusters are returned
95  *
96  * \return The indices of the chosen clusters.
97  */
98  std::vector<size_t> getBestClustersFittingRoi( float ratio = 0.9, size_t number = 1 );
99 
100  /**
101  * calculates the ratio of fibers in the roi for a given cluster
102  * \param cluster
103  * \return ratio
104  */
105  float getRatio( size_t cluster );
106 
107  /**
108  * setter
109  * \param bitfield
110  */
111  void setRoiBitField( boost::shared_ptr< std::vector<bool> > bitfield );
112 
113 protected:
114 private:
115  /**
116  * stores a pointer to the bitfield by the current roi setting
117  */
118  boost::shared_ptr< std::vector<bool> > m_roiSelection;
119 };
120 
121 
122 inline void WHierarchicalTreeFibers::setRoiBitField( boost::shared_ptr< std::vector<bool> > bitfield )
123 {
124  m_roiSelection = bitfield;
125 }
126 
127 #endif // WHIERARCHICALTREEFIBERS_H