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