OpenWalnut  1.5.0dev
WMVoxelizer.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 WMVOXELIZER_H
26 #define WMVOXELIZER_H
27 
28 #include <memory>
29 #include <string>
30 #include <utility>
31 
32 #include <osg/Geode>
33 
34 #include "core/kernel/WModule.h"
35 
36 class WBresenhamDBL;
37 class WDataSetScalar;
38 class WDataSetFibers;
39 class WFiberCluster;
40 class WRasterAlgorithm;
42 template< class T > class WModuleInputData;
43 
44 /**
45  * Traces a given set of deterministic tracts as given by a dataset of deterministic tracts (optionally only a subset may be
46  * processed) in a voxel-wise manner.
47  * Every voxel which is hit by one or more tracts or tract-segments is marked with a scalar and stored in a dataset scalar.
48  * \ingroup modules
49  */
50 class WMVoxelizer : public WModule
51 {
52 /**
53 * Only UnitTests may be friends.
54 */
55 friend class WMVoxelizerTest;
56 public:
57  /**
58  * Default Constructor.
59  */
60  WMVoxelizer();
61 
62  /**
63  * Default Destructor.
64  */
65  virtual ~WMVoxelizer();
66 
67  /**
68  * Gives back the name of this module.
69  * \return the module's name.
70  */
71  virtual const std::string getName() const;
72 
73  /**
74  * Gives back a description of this module.
75  * \return Description to module.
76  */
77  virtual const std::string getDescription() const;
78 
79  /**
80  * Due to the prototype design pattern used to build modules, this method
81  * returns a new instance of this method. NOTE: it should never be
82  * initialized or modified in some other way. A simple new instance is
83  * required.
84  *
85  * \return The prototype used to create every module in OpenWalnut.
86  */
87  virtual std::shared_ptr< WModule > factory() const;
88 
89 protected:
90  /**
91  * Entry point after loading the module. Runs in separate thread.
92  */
93  virtual void moduleMain();
94 
95  /**
96  * Initialize the connectors this module is using.
97  */
98  virtual void connectors();
99 
100  /**
101  * Initialize the properties for this module.
102  */
103  virtual void properties();
104 
105  /**
106  * Generates a intensity dataset where each tract is rasterized into. If additionally the (optional) cluster is given as
107  * subselection only tracts with IDs inside this dataset are considered. If additionally a parameterization was selected
108  * also a corresponding dataset will be generated and returned.
109  *
110  * \param tracts Dataset of deterministic tracts.
111  * \param cluster Optional selection of a subset of tracts.
112  *
113  * \return Two references to datasets where the intensity field is always the first and should be always present, but not when
114  * an error has occured. Since parameterization is optional, the second dataset will only be generated when a parameterization
115  * algo has been selected first.
116  */
117  boost::array< std::shared_ptr< WDataSetScalar >, 2 > generateDatasets(
118  std::shared_ptr< const WDataSetFibers > tracts,
119  std::shared_ptr< const WFiberCluster > cluster ) const;
120 
121  /**
122  * Removes or inserts geode for the center line of the current cluster into this modules group node.
123  */
125 
126  /**
127  * Builds an OSG geode where all voxels inside the dataSet which are not
128  * zero are drawn as cuboids.
129  *
130  * \param dataset The dataset which should be drawn
131  *
132  * \return OSG node with the voxels as cuboids.
133  */
134  osg::ref_ptr< osg::Node > genDataSetGeode( std::shared_ptr< WDataSetScalar > dataset ) const;
135 
136  /**
137  * Performs rasterization with the given algorithm on either all tracts or only a subset if given.
138  *
139  * \param algo The algorithm which actually rasters every fiber.
140  * \param tracts Dataset of tracts.
141  * \param cluster A subset of tracts.
142  */
143  void raster( std::shared_ptr< WRasterAlgorithm > algo, std::shared_ptr< const WDataSetFibers > tracts,
144  std::shared_ptr< const WFiberCluster > cluster ) const;
145 
146  /**
147  * Creates two vertices describing the bounding box of a cluster.
148  *
149  * \param cluster With its fibers
150  *
151  * \return The axis aligned bounding box.
152  */
154 
155  /**
156  * Constructs a grid out of the current tract dataset or out of a subset (selection) of this dataset.
157  *
158  * \param tracts Dataset of deterministic tracts.
159  * \param cluster Optional subselection of tracts.
160  *
161  * \return A WGridRegular3D reference wherein the voxels may be marked.
162  */
163  std::shared_ptr< WGridRegular3D > constructGrid( std::shared_ptr< const WDataSetFibers > tracts,
164  std::shared_ptr< const WFiberCluster > cluster ) const;
165 
166  /**
167  * Finds and returns a copy of the longest line (in term of \#points) in the dataset, or in a subset of it specified by the
168  * given cluster. If the cluster is empty all tracts are considered.
169  *
170  * \param tracts The dataset of tracts.
171  * \param cluster A subset of tracts.
172  *
173  * \note This involves heavy computational time, including dataset convertion to WDataSetFiberVector, since I didn't had the
174  * time to use the crappy index lists of the original WDataSetFibers.
175  *
176  * \return A reference of a copy of the longest line.
177  */
178  std::shared_ptr< WFiber > longestLine( std::shared_ptr< const WDataSetFibers > tracts,
179  std::shared_ptr< const WFiberCluster > cluster = std::shared_ptr< const WFiberCluster >() ) const;
180 
181  /**
182  * Finds and returns a copy of the center line in the dataset, or in a subset of it specified by the given cluster. If the
183  * cluster is empty all tracts are considered.
184  *
185  * \param tracts The dataset of tracts.
186  * \param cluster A subset of tracts.
187  *
188  * \note This involves heavy computational time, including dataset convertion to WDataSetFiberVector, since I didn't had the
189  * time to use the crappy index lists of the original WDataSetFibers.
190  *
191  * \return A reference of a copy of the center line.
192  */
193  std::shared_ptr< WFiber > centerLine( std::shared_ptr< const WDataSetFibers > tracts,
194  std::shared_ptr< const WFiberCluster > cluster = std::shared_ptr< const WFiberCluster >() ) const;
195 
196 private:
197  /**
198  * Input connector for a fiber dataset.
199  */
200  std::shared_ptr< WModuleInputData< const WDataSetFibers > > m_tractIC;
201 
202  /**
203  * Input connector for an optional selection of some fibers in the fiber dataset via a cluster.
204  */
205  std::shared_ptr< WModuleInputData< const WFiberCluster > > m_clusterIC;
206 
207  /**
208  * Output connector for a voxelized cluster.
209  */
210  std::shared_ptr< WModuleOutputData< WDataSetScalar > > m_voxelizedOC;
211 
212  /**
213  * Output providing parameterization to other algorithms. It provides a scalar field which gets filled with the parameterization of the
214  * fibers, i.e. current integrated length.
215  */
216  std::shared_ptr< WModuleOutputData< WDataSetScalar > > m_paramOC;
217 
218  /**
219  * Reference to the fiber dataset.
220  */
221  std::shared_ptr< const WDataSetFibers > m_tracts;
222 
223  /**
224  * OSG root node for this module
225  */
226  osg::ref_ptr< WGEManagedGroupNode > m_rootNode;
227 
228  /**
229  * module is performing an expensive update
230  */
231  std::shared_ptr< WCondition > m_fullUpdate;
232 
233  WPropBool m_antialiased; //!< Enable/disable anti-aliased rasterization of voxels
234  WPropBool m_renderingActive; //!< Enable/disable rendering of voxels.
235 
236  /**
237  * List for selecting the rasterization method.
238  *
239  * \note At the moment there is only Bresenham, but this might change.
240  */
241  WPropSelection m_rasterAlgo;
242 
243  /**
244  * The number of voxels per unit in the coordinate system
245  */
246  WPropDouble m_voxelsPerUnit;
247 
248  /**
249  * The available parameterization algorithms.
250  */
251  std::shared_ptr< WItemSelection > m_paramAlgoSelections;
252 
253  /**
254  * The actually selected parameterization algorithm.
255  */
256  WPropSelection m_parameterAlgo;
257 
258  /**
259  * add colormapping
260  */
261  WPropBool m_colorMapping;
262 
263  /**
264  * Add lighting to the scene
265  */
266  WPropBool m_phongShading;
267 };
268 
269 inline const std::string WMVoxelizer::getName() const
270 {
271  return std::string( "Voxelizer" );
272 }
273 
274 inline const std::string WMVoxelizer::getDescription() const
275 {
276  return std::string( "Rasterize or voxelize a dataset with the given tracts." );
277 }
278 
279 #endif // WMVOXELIZER_H
This is a modified version the Bresenham algorithm.
Definition: WBresenhamDBL.h:40
Represents a simple set of WFibers.
This data set type contains scalars as values.
Represents a cluster of indices of a WDataSetFiberVector.
Definition: WFiberCluster.h:45
This class adds some convenience methods to WGEGroupNode.
Traces a given set of deterministic tracts as given by a dataset of deterministic tracts (optionally ...
Definition: WMVoxelizer.h:51
virtual std::shared_ptr< WModule > factory() const
Due to the prototype design pattern used to build modules, this method returns a new instance of this...
Definition: WMVoxelizer.cpp:78
void updateCenterLine()
Removes or inserts geode for the center line of the current cluster into this modules group node.
WPropBool m_antialiased
Enable/disable anti-aliased rasterization of voxels.
Definition: WMVoxelizer.h:233
WPropBool m_colorMapping
add colormapping
Definition: WMVoxelizer.h:261
WMVoxelizer()
Default Constructor.
Definition: WMVoxelizer.cpp:68
WPropDouble m_voxelsPerUnit
The number of voxels per unit in the coordinate system.
Definition: WMVoxelizer.h:246
WPropBool m_phongShading
Add lighting to the scene.
Definition: WMVoxelizer.h:266
WPropSelection m_rasterAlgo
List for selecting the rasterization method.
Definition: WMVoxelizer.h:241
void raster(std::shared_ptr< WRasterAlgorithm > algo, std::shared_ptr< const WDataSetFibers > tracts, std::shared_ptr< const WFiberCluster > cluster) const
Performs rasterization with the given algorithm on either all tracts or only a subset if given.
std::shared_ptr< WModuleInputData< const WFiberCluster > > m_clusterIC
Input connector for an optional selection of some fibers in the fiber dataset via a cluster.
Definition: WMVoxelizer.h:205
WPropSelection m_parameterAlgo
The actually selected parameterization algorithm.
Definition: WMVoxelizer.h:256
WBoundingBox createBoundingBox(const WFiberCluster &cluster) const
Creates two vertices describing the bounding box of a cluster.
std::shared_ptr< WFiber > longestLine(std::shared_ptr< const WDataSetFibers > tracts, std::shared_ptr< const WFiberCluster > cluster=std::shared_ptr< const WFiberCluster >()) const
Finds and returns a copy of the longest line (in term of #points) in the dataset, or in a subset of i...
std::shared_ptr< WModuleOutputData< WDataSetScalar > > m_paramOC
Output providing parameterization to other algorithms.
Definition: WMVoxelizer.h:216
std::shared_ptr< WGridRegular3D > constructGrid(std::shared_ptr< const WDataSetFibers > tracts, std::shared_ptr< const WFiberCluster > cluster) const
Constructs a grid out of the current tract dataset or out of a subset (selection) of this dataset.
osg::ref_ptr< WGEManagedGroupNode > m_rootNode
OSG root node for this module.
Definition: WMVoxelizer.h:226
std::shared_ptr< WItemSelection > m_paramAlgoSelections
The available parameterization algorithms.
Definition: WMVoxelizer.h:251
osg::ref_ptr< osg::Node > genDataSetGeode(std::shared_ptr< WDataSetScalar > dataset) const
Builds an OSG geode where all voxels inside the dataSet which are not zero are drawn as cuboids.
virtual const std::string getName() const
Gives back the name of this module.
Definition: WMVoxelizer.h:269
std::shared_ptr< WModuleOutputData< WDataSetScalar > > m_voxelizedOC
Output connector for a voxelized cluster.
Definition: WMVoxelizer.h:210
std::shared_ptr< const WDataSetFibers > m_tracts
Reference to the fiber dataset.
Definition: WMVoxelizer.h:221
WPropBool m_renderingActive
Enable/disable rendering of voxels.
Definition: WMVoxelizer.h:234
virtual ~WMVoxelizer()
Default Destructor.
Definition: WMVoxelizer.cpp:74
virtual void properties()
Initialize the properties for this module.
Definition: WMVoxelizer.cpp:83
std::shared_ptr< WCondition > m_fullUpdate
module is performing an expensive update
Definition: WMVoxelizer.h:231
virtual void connectors()
Initialize the connectors this module is using.
virtual void moduleMain()
Entry point after loading the module.
std::shared_ptr< WFiber > centerLine(std::shared_ptr< const WDataSetFibers > tracts, std::shared_ptr< const WFiberCluster > cluster=std::shared_ptr< const WFiberCluster >()) const
Finds and returns a copy of the center line in the dataset, or in a subset of it specified by the giv...
friend class WMVoxelizerTest
Only UnitTests may be friends.
Definition: WMVoxelizer.h:55
boost::array< std::shared_ptr< WDataSetScalar >, 2 > generateDatasets(std::shared_ptr< const WDataSetFibers > tracts, std::shared_ptr< const WFiberCluster > cluster) const
Generates a intensity dataset where each tract is rasterized into.
virtual const std::string getDescription() const
Gives back a description of this module.
Definition: WMVoxelizer.h:274
std::shared_ptr< WModuleInputData< const WDataSetFibers > > m_tractIC
Input connector for a fiber dataset.
Definition: WMVoxelizer.h:200
Class offering an instantiate-able data connection between modules.
Class representing a single module of OpenWalnut.
Definition: WModule.h:72
Base class for all rasterization algorithms.