OpenWalnut  1.5.0dev
WMData.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 WMDATA_H
26 #define WMDATA_H
27 
28 #include <memory>
29 #include <string>
30 #include <vector>
31 
32 #include <boost/thread.hpp>
33 
34 #include "core/kernel/WDataModule.h"
35 
36 // forward declarations
37 class WDataSet;
38 class WDataSetSingle;
39 class WModuleConnector;
40 template< class T > class WModuleOutputData;
41 
42 /**
43  * Module for encapsulating WDataSets. It can encapsulate almost everything, but is intended to be used with WDataSets and its
44  * inherited classes. This class builds a "source" in OpenWalnut's DataFlow Network.
45  * \ingroup modules
46  */
47 class WMData: public WDataModule
48 {
49 public:
50  /**
51  * Default constructor.
52  */
53  WMData();
54 
55  /**
56  * Destructor.
57  */
58  virtual ~WMData();
59 
60  /**
61  * Gives back the name of this module.
62  * \return the module's name.
63  */
64  virtual const std::string getName() const;
65 
66  /**
67  * Gives back a description of this module.
68  * \return description to module.
69  */
70  virtual const std::string getDescription() const;
71 
72  /**
73  * Due to the prototype design pattern used to build modules, this method returns a new instance of this method. NOTE: it
74  * should never be initialized or modified in some other way. A simple new instance is required.
75  *
76  * \return the prototype used to create every module in OpenWalnut.
77  */
78  virtual std::shared_ptr< WModule > factory() const;
79 
80  /**
81  * Get the icon for this module in XPM format.
82  * \return The icon.
83  */
84  virtual const char** getXPMIcon() const;
85 
86  /**
87  * Define a list of file filters we support.
88  *
89  * \return the list of filters
90  */
91  virtual std::vector< WDataModuleInputFilter::ConstSPtr > getInputFilter() const;
92 
93 protected:
94  /**
95  * \par Description
96  * Entry point after loading the module. Runs in separate thread.
97  */
98  virtual void moduleMain();
99 
100  /**
101  * Initialize connectors in this function. This function must not be called multiple times for one module instance.
102  * The module container manages calling those functions -> so just implement it.
103  */
104  virtual void connectors();
105 
106  /**
107  * Initialize properties in this function. This function must not be called multiple times for one module instance.
108  * The module container manages calling those functions -> so just implement it. Once initialized the number and type
109  * of all properties should be set.
110  */
111  virtual void properties();
112 
113  /**
114  * The name of the dataset. Usually the filename.
115  */
116  WPropString m_dataName;
117 
118  /**
119  * The basic type of data used in this data set (e.g. float, double, ...)
120  */
121  WPropString m_dataType;
122 
123  /**
124  * The name of the dataset type created from the data (e.g. WDataSetScalar, WDataSetVector ...)
125  */
126  WPropString m_dataSetType;
127 
128  /**
129  * A list of color map selection types
130  */
131  std::shared_ptr< WItemSelection > m_matrixSelectionsList;
132 
133  /**
134  * Selection property for color map
135  */
136  WPropSelection m_matrixSelection;
137 
138  bool m_isTexture; //!< Indicates whether the loaded dataSet will be available as texture.
139 
140  /**
141  * Called whenever a property changes.
142  *
143  * \param property the property that has been changed
144  */
145  void propertyChanged( std::shared_ptr< WPropertyBase > property );
146 
147  // in case of a nifti file, there may be several transforms specified in the file
148  //! a standard transform (should be an identity transform)
150 
151  //! a standard transform (should be an identity transform)
153 
154  //! a standard transform (should be an identity transform)
156 
157  /**
158  * Do the loading.
159  */
160  void load();
161 
162  /**
163  * Handle a newly set input. Implement this method to load the newly set input. You can get the input using the \ref getInput and \ref getInputAs
164  * methods. Please remember that it is possible to get a NULL pointer here.
165  * This happens when the user explicitly sets no input. In this case, you should clean up and reset your output connectors.
166  *
167  * \note it is very important to NOT load the data inside of this method. It is usually called in the GUI thread. This would block the whole GUI.
168  * Instead, use this method for firing a condition, which then wakes your module thread.
169  */
170  virtual void handleInputChange();
171 
172  /**
173  * Clean up. Remove props and colormap.
174  */
175  void cleanUp();
176 private:
177  /**
178  * Returns info property group with the three availabe transformation matrixes
179  *
180  * \return info property group with the three availabe transformation matrixes
181  */
182  std::shared_ptr< WProperties > getTransformationProperties() const;
183 
184  //! a condition for the matrix selection
185  std::shared_ptr< WCondition > m_propCondition;
186 
187  /**
188  * Get a string for the datatype of the given dataset.
189  *
190  * \param dss the data set whose name should be returned.
191  *
192  * \return the type name of the specified dataset
193  */
194  std::string getDataTypeString( std::shared_ptr< WDataSetSingle > dss );
195 
196  /**
197  * The associated dataset.
198  */
199  std::shared_ptr< WDataSet > m_dataSet;
200 
201  /**
202  * The only output of this data module.
203  */
204  std::shared_ptr< WModuleOutputData< WDataSet > > m_output;
205 
206  /**
207  * As single. Can be NULL.
208  */
210 
211  /**
212  * Keep track of registered colormaps.
213  */
214  osg::ref_ptr< WDataTexture3D > m_oldColormap;
215 
216  /**
217  * Keep track of the old dataset
218  */
219  std::shared_ptr< WDataSet > m_oldDataSet;
220 
221  /**
222  * Add the colormapping.
223  *
224  * \param dataSet the dataset to add
225  */
226  void updateColorMap( std::shared_ptr< WDataSet > dataSet );
227 
228  /**
229  * Update matrix.
230  */
231  void matrixUpdate();
232 
233  /**
234  * True if the load function needs to be called. Usually set by handleInputChange or the reload trigger
235  */
236  bool m_reload;
237 };
238 
239 #endif // WMDATA_H
Base for all data loader modules.
Definition: WDataModule.h:47
A data set consisting of a set of values based on a grid.
std::shared_ptr< WDataSetSingle > SPtr
Convenience typedef for a std::shared_ptr.
Base class for all data set types.
Definition: WDataSet.h:50
Module for encapsulating WDataSets.
Definition: WMData.h:48
virtual void properties()
Initialize properties in this function.
Definition: WMData.cpp:134
std::shared_ptr< WDataSet > m_oldDataSet
Keep track of the old dataset.
Definition: WMData.h:219
void load()
Do the loading.
Definition: WMData.cpp:439
osg::ref_ptr< WDataTexture3D > m_oldColormap
Keep track of registered colormaps.
Definition: WMData.h:214
virtual const char ** getXPMIcon() const
Get the icon for this module in XPM format.
Definition: WMData.cpp:86
void updateColorMap(std::shared_ptr< WDataSet > dataSet)
Add the colormapping.
Definition: WMData.cpp:390
std::shared_ptr< WItemSelection > m_matrixSelectionsList
A list of color map selection types.
Definition: WMData.h:131
WPropSelection m_matrixSelection
Selection property for color map.
Definition: WMData.h:136
void cleanUp()
Clean up.
Definition: WMData.cpp:418
virtual std::vector< WDataModuleInputFilter::ConstSPtr > getInputFilter() const
Define a list of file filters we support.
Definition: WMData.cpp:101
std::shared_ptr< WProperties > getTransformationProperties() const
Returns info property group with the three availabe transformation matrixes.
Definition: WMData.cpp:373
WMatrix< double > m_transformQForm
a standard transform (should be an identity transform)
Definition: WMData.h:155
void propertyChanged(std::shared_ptr< WPropertyBase > property)
Called whenever a property changes.
Definition: WMData.cpp:159
WMatrix< double > m_transformSForm
a standard transform (should be an identity transform)
Definition: WMData.h:152
WDataSetSingle::SPtr m_dataSetAsSingle
As single.
Definition: WMData.h:209
virtual void connectors()
Initialize connectors in this function.
Definition: WMData.cpp:120
virtual void handleInputChange()
Handle a newly set input.
Definition: WMData.cpp:185
WPropString m_dataName
The name of the dataset.
Definition: WMData.h:116
virtual const std::string getDescription() const
Gives back a description of this module.
Definition: WMData.cpp:96
std::shared_ptr< WModuleOutputData< WDataSet > > m_output
The only output of this data module.
Definition: WMData.h:204
std::string getDataTypeString(std::shared_ptr< WDataSetSingle > dss)
Get a string for the datatype of the given dataset.
Definition: WMData.cpp:226
WMatrix< double > m_transformNoMatrix
a standard transform (should be an identity transform)
Definition: WMData.h:149
WMData()
Default constructor.
Definition: WMData.cpp:66
std::shared_ptr< WCondition > m_propCondition
a condition for the matrix selection
Definition: WMData.h:185
bool m_isTexture
Indicates whether the loaded dataSet will be available as texture.
Definition: WMData.h:138
virtual ~WMData()
Destructor.
Definition: WMData.cpp:76
bool m_reload
True if the load function needs to be called.
Definition: WMData.h:236
virtual const std::string getName() const
Gives back the name of this module.
Definition: WMData.cpp:91
std::shared_ptr< WDataSet > m_dataSet
The associated dataset.
Definition: WMData.h:199
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: WMData.cpp:81
virtual void moduleMain()
Definition: WMData.cpp:192
void matrixUpdate()
Update matrix.
Definition: WMData.cpp:313
WPropString m_dataType
The basic type of data used in this data set (e.g.
Definition: WMData.h:121
WPropString m_dataSetType
The name of the dataset type created from the data (e.g.
Definition: WMData.h:126
Base class for modelling connections between kernel modules.
Class offering an instantiate-able data connection between modules.