OpenWalnut  1.4.0
WJoinContourTree.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 WJOINCONTOURTREE_H
26 #define WJOINCONTOURTREE_H
27 
28 #include <set>
29 #include <string>
30 #include <vector>
31 
32 #ifndef Q_MOC_RUN
33 #include <boost/shared_ptr.hpp>
34 #endif
35 
36 #include "../../common/WTransferable.h"
37 #include "../WDataSetSingle.h"
38 
39 
40 /**
41  * Processes a dataset for join tree computation. This is a part of those famous contur trees.
42  *
43  * Every leaf in that tree represents a local maximum. A branch is a collection of vertices belonging to the
44  * same component and nodes joining branches represent a data point which melds multiple (at least two)
45  * branches.
46  *
47  * With the Split tree then you may compute the contour tree, but for that you may need to fullfil at least two
48  * conditions:
49  * - You operate on a simplicial mesh (WGridRegular3D is not simplicial!!!)
50  * - All data points are pairwise disjoint
51  *
52  * \note You may use this join tree also for finding the vertices belonging to the volume enclosed by the
53  * biggest isosurface for a given isovalue. Then you don't need "simulation of simplicity" to make the
54  * data points disjoint also you don't need simplicial meshes.
55  */
56 class WJoinContourTree : public WTransferable // NOLINT
57 {
58 friend class WJoinContourTreeTest;
59 public:
60  /**
61  * Initialize this with a data set for which the join tree should be computed.
62  *
63  * \throw WNotImplemented If the dataset is not a scalar double field
64  *
65  * \param dataset Reference to the dataset.
66  */
67  explicit WJoinContourTree( boost::shared_ptr< WDataSetSingle > dataset );
68 
70 
71  /**
72  * Build the join tree.
73  */
74  void buildJoinTree();
75 
76  /**
77  * For a given isovalue all the voxel which are enclosed by the biggest isosurface are computed.
78  *
79  * \param isoValue The isovalue
80  *
81  * \return Set of voxel indices
82  */
83  boost::shared_ptr< std::set< size_t > > getVolumeVoxelsEnclosedByIsoSurface( const double isoValue ) const;
84 
85  /**
86  * Gets the name of this prototype.
87  *
88  * \return the name.
89  */
90  virtual const std::string getName() const;
91 
92  /**
93  * Gets the description for this prototype.
94  *
95  * \return the description
96  */
97  virtual const std::string getDescription() const;
98 
99  /**
100  * Returns a prototype instantiated with the true type of the deriving class.
101  *
102  * \return the prototype.
103  */
104  static boost::shared_ptr< WPrototyped > getPrototype();
105 
106 protected:
107  /**
108  * Sort the indices on their element value of the value set in descending order.
109  */
110  void sortIndexArray();
111 
112  static boost::shared_ptr< WPrototyped > m_prototype; //!< The prototype as singleton.
113 
114 private:
115  boost::shared_ptr< WGridRegular3D > m_grid; //!< Stores the reference to the grid of the given dataset to get the neighbours of a voxel
116  boost::shared_ptr< WValueSet< double > > m_valueSet; //!< Stores reference to the isovalues, so we may sort them indirect on their value
117 
118  std::vector< size_t > m_elementIndices; //!< Stores the component number for the i'th vertex in the value set
119  std::vector< size_t > m_joinTree; //!< For each index stores which node it is connected to
120  std::vector< size_t > m_lowestVoxel; //!< Stores the index of lowest element for the i'th component
121 
122  /**
123  * Comperator for indirect sort so the value set is not modified.
124  */
126  {
127  public: // NOLINT
128  /**
129  * Since we must have access to the value set we need a reference to it.
130  *
131  * \param valueSet Value set on which the comparision is done.
132  */
133  explicit IndirectCompare( boost::shared_ptr< WValueSet< double > > valueSet );
134 
135  /**
136  * Compares the isovalue of the elments with index i and j.
137  *
138  * \param i The index of the first element
139  * \param j The index of the other element
140  *
141  * \return True if the element in the value set at position i is
142  * greater than the the element at position j
143  */
144  bool operator()( size_t i, size_t j );
145 
146  private: // NOLINT
147  boost::shared_ptr< WValueSet < double > > m_valueSet; //!< Reference to the isovalues
148  };
149 };
150 
151 inline const std::string WJoinContourTree::getName() const
152 {
153  return "JoinContourTree";
154 }
155 
156 inline const std::string WJoinContourTree::getDescription() const
157 {
158  return "Computes the Join-Tree out of a given dataset.";
159 }
160 
161 #endif // WJOINCONTOURTREE_H
boost::shared_ptr< WValueSet< double > > m_valueSet
Stores reference to the isovalues, so we may sort them indirect on their value.
boost::shared_ptr< WValueSet< double > > m_valueSet
Reference to the isovalues.
bool operator()(size_t i, size_t j)
Compares the isovalue of the elments with index i and j.
void buildJoinTree()
Build the join tree.
static boost::shared_ptr< WPrototyped > m_prototype
The prototype as singleton.
Unit tests the Join Tree of the Contour Tree!
std::vector< size_t > m_lowestVoxel
Stores the index of lowest element for the i'th component.
std::vector< size_t > m_joinTree
For each index stores which node it is connected to.
Class building the interface for classes that might be transferred using WModuleConnector.
Definition: WTransferable.h:37
Comperator for indirect sort so the value set is not modified.
boost::shared_ptr< std::set< size_t > > getVolumeVoxelsEnclosedByIsoSurface(const double isoValue) const
For a given isovalue all the voxel which are enclosed by the biggest isosurface are computed...
boost::shared_ptr< WGridRegular3D > m_grid
Stores the reference to the grid of the given dataset to get the neighbours of a voxel.
void sortIndexArray()
Sort the indices on their element value of the value set in descending order.
Processes a dataset for join tree computation.
Base Class for all value set types.
Definition: WValueSet.h:48
virtual const std::string getDescription() const
Gets the description for this prototype.
std::vector< size_t > m_elementIndices
Stores the component number for the i'th vertex in the value set.
virtual const std::string getName() const
Gets the name of this prototype.
IndirectCompare(boost::shared_ptr< WValueSet< double > > valueSet)
Since we must have access to the value set we need a reference to it.
static boost::shared_ptr< WPrototyped > getPrototype()
Returns a prototype instantiated with the true type of the deriving class.