OpenWalnut  1.5.0dev
WMPaintTexture.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 WMPAINTTEXTURE_H
26 #define WMPAINTTEXTURE_H
27 
28 #include <memory>
29 #include <queue>
30 #include <string>
31 #include <vector>
32 
33 #include <osg/Geode>
34 
35 #include "core/dataHandler/WDataSetScalar.h"
36 #include "core/dataHandler/WValueSet.h"
37 #include "core/graphicsEngine/WGETexture.h"
38 #include "core/graphicsEngine/WPickInfo.h"
39 #include "core/kernel/WModule.h"
40 #include "core/kernel/WModuleInputData.h"
41 #include "core/kernel/WModuleOutputData.h"
42 
43 
44 /**
45  * Forward declaration of WPickInfo.
46  */
47 //class WPickInfo;
48 
49 /**
50  * This module allows mark areas in a 3D texture by "painting"
51  * on pickable surfaces.
52  *
53  * \ingroup modules
54  */
55 class WMPaintTexture: public WModule
56 {
57 public:
58  /**
59  *
60  */
62 
63  /**
64  *
65  */
66  virtual ~WMPaintTexture();
67 
68  /**
69  * Gives back the name of this module.
70  * \return the module's name.
71  */
72  virtual const std::string getName() const;
73 
74  /**
75  * Gives back a description of this module.
76  * \return description to module.
77  */
78  virtual const std::string getDescription() const;
79 
80  /**
81  * Due to the prototype design pattern used to build modules, this method returns a new instance of this method. NOTE: it
82  * should never be initialized or modified in some other way. A simple new instance is required.
83  *
84  * \return the prototype used to create every module in OpenWalnut.
85  */
86  virtual std::shared_ptr< WModule > factory() const;
87 
88  /**
89  * Get the icon for this module in XPM format.
90  * \return The icon.
91  */
92  virtual const char** getXPMIcon() const;
93 
94 protected:
95  /**
96  * Entry point after loading the module. Runs in separate thread.
97  */
98  virtual void moduleMain();
99 
100  /**
101  * Initialize the connectors this module is using.
102  */
103  virtual void connectors();
104 
105  /**
106  * Initialize the properties for this module.
107  */
108  virtual void properties();
109 
110  /**
111  * Callback for m_active.
112  */
113  virtual void activate();
114 
115 
116 private:
117  /**
118  * this function listens to the pick handler, if the paint flag is true it will write into the out texture
119  */
120  void doPaint();
121 
122  /**
123  * this function listens to the pick handler, if the paint flag is true it will add the paint position to the
124  * paint queue
125  *
126  * \param pickInfo the pickInfo object fromt he current pick
127  */
128  void queuePaint( WPickInfo pickInfo );
129 
130  /**
131  * creates a new texture
132  */
133  void createTexture();
134 
135  /**
136  * updates the output connector
137  */
138  void updateOutDataset();
139 
140  /**
141  * copies data from the input dataset into the paint texture
142  */
143  void copyFromInput();
144 
145  /**
146  * creates a ROI from the currently selected paint value
147  */
148  void createROI();
149 
150  /**
151  * get the paint index at the picked voexel fromt he out texture and sets m_paintIndex accordingly
152  *
153  * \param pickInfo the pickInfo object for the pick
154  */
155  void setColorFromPick( WPickInfo pickInfo );
156 
157  /**
158  * Interpolation?
159  */
160  WPropBool m_painting;
161 
162  /**
163  * A list of pencil sizes and shapes
164  */
165  std::shared_ptr< WItemSelection > m_pencilSelectionsList;
166 
167  /**
168  * Selection property for pencil size and shape
169  */
170  WPropSelection m_pencilSelection;
171 
172  /**
173  * specifies the value we paint into the output texture
174  */
175  WPropInt m_paintIndex;
176 
177  /**
178  * A list of color map selection types
179  */
180  std::shared_ptr< WItemSelection > m_colorMapSelectionsList;
181 
182  /**
183  * Selection property for color map
184  */
185  WPropSelection m_colorMapSelection;
186 
187  /**
188  * true when a new paint coordinate is added to the queue
189  */
190  WPropBool m_queueAdded;
191 
192  /**
193  * new paint coordinates get added here
194  */
195  std::queue< WPickInfo >m_paintQueue;
196 
197  /**
198  * An input connector that accepts order 1 datasets.
199  */
200  std::shared_ptr< WModuleInputData< WDataSetSingle > > m_input;
201 
202  /**
203  * An output connector for the output scalar dsataset.
204  */
205  std::shared_ptr< WModuleOutputData< WDataSetScalar > > m_output;
206 
207  /**
208  * This is a pointer to the dataset the module is currently working on.
209  */
210  std::shared_ptr< WDataSetSingle > m_dataSet;
211 
212  /**
213  * Point to the out dataset once it is invalid. Used to deregister from the datahandler
214  */
215  std::shared_ptr< WDataSetScalar > m_outDataOld;
216 
217  /**
218  * This is a pointer to the current output.
219  */
220  std::shared_ptr< WDataSetScalar > m_outData;
221 
222  /**
223  * stores a pointer to the texture we paint in
224  */
225  osg::ref_ptr< WGETexture3D > m_texture;
226 
227  /**
228  * stores a pointer to the grid we use;
229  */
230  std::shared_ptr< WGridRegular3D > m_grid;
231 
232  /**
233  * A condition used to notify about changes in several properties.
234  */
235  std::shared_ptr< WCondition > m_propCondition;
236 
237  /**
238  * copies the input dataset into the paint texture, this allows one to continue work
239  */
240  WPropTrigger m_buttonCopyFromInput;
241 
242  /**
243  * updates the output connector on demand, as we don't want to do this every paint command
244  */
245  WPropTrigger m_buttonUpdateOutput;
246 
247  /**
248  * updates the output connector on demand, as we don't want to do this every paint command
249  */
250  WPropTrigger m_buttonCreateRoi;
251 };
252 
253 #endif // WMPAINTTEXTURE_H
Forward declaration of WPickInfo.
virtual void moduleMain()
Entry point after loading the module.
WPropSelection m_colorMapSelection
Selection property for color map.
WPropTrigger m_buttonCreateRoi
updates the output connector on demand, as we don't want to do this every paint command
void copyFromInput()
copies data from the input dataset into the paint texture
void doPaint()
this function listens to the pick handler, if the paint flag is true it will write into the out textu...
WPropBool m_painting
Interpolation?
std::shared_ptr< WDataSetSingle > m_dataSet
This is a pointer to the dataset the module is currently working on.
void setColorFromPick(WPickInfo pickInfo)
get the paint index at the picked voexel fromt he out texture and sets m_paintIndex accordingly
WPropSelection m_pencilSelection
Selection property for pencil size and shape.
WPropTrigger m_buttonCopyFromInput
copies the input dataset into the paint texture, this allows one to continue work
std::shared_ptr< WDataSetScalar > m_outData
This is a pointer to the current output.
std::shared_ptr< WGridRegular3D > m_grid
stores a pointer to the grid we use;
std::shared_ptr< WCondition > m_propCondition
A condition used to notify about changes in several properties.
virtual void connectors()
Initialize the connectors this module is using.
WPropTrigger m_buttonUpdateOutput
updates the output connector on demand, as we don't want to do this every paint command
WPropInt m_paintIndex
specifies the value we paint into the output texture
void createROI()
creates a ROI from the currently selected paint value
virtual const char ** getXPMIcon() const
Get the icon for this module in XPM format.
void updateOutDataset()
updates the output connector
std::shared_ptr< WDataSetScalar > m_outDataOld
Point to the out dataset once it is invalid.
virtual const std::string getDescription() const
Gives back a description of this module.
std::shared_ptr< WModuleOutputData< WDataSetScalar > > m_output
An output connector for the output scalar dsataset.
osg::ref_ptr< WGETexture3D > m_texture
stores a pointer to the texture we paint in
std::shared_ptr< WItemSelection > m_pencilSelectionsList
A list of pencil sizes and shapes.
std::queue< WPickInfo > m_paintQueue
new paint coordinates get added here
virtual void properties()
Initialize the properties for this module.
std::shared_ptr< WItemSelection > m_colorMapSelectionsList
A list of color map selection types.
virtual void activate()
Callback for m_active.
std::shared_ptr< WModuleInputData< WDataSetSingle > > m_input
An input connector that accepts order 1 datasets.
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...
void createTexture()
creates a new texture
WPropBool m_queueAdded
true when a new paint coordinate is added to the queue
void queuePaint(WPickInfo pickInfo)
this function listens to the pick handler, if the paint flag is true it will add the paint position t...
virtual const std::string getName() const
Gives back the name of this module.
Class representing a single module of OpenWalnut.
Definition: WModule.h:72
Encapsulates info for pick action.
Definition: WPickInfo.h:42