OpenWalnut  1.5.0dev
WMPickingDVR.h
1 //---------------------------------------------------------------------------
2 //
3 // Project: OpenWalnut ( http://www.openwalnut.org )
4 //
5 // Copyright 2015-2017 A. Betz, D. Gerlicher, OpenWalnut Community
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 WMPICKINGDVR_H
26 #define WMPICKINGDVR_H
27 
28 #include <memory>
29 #include <string>
30 #include <utility>
31 #include <vector>
32 
33 #include "WVisiTrace.h"
34 #include "core/kernel/WModule.h"
35 
36 // forward declarations to reduce compile dependencies
37 template< class T > class WModuleInputData;
38 class WDataSetScalar;
39 class WSinglePosition;
41 class WPickInfo;
42 
43 /**
44  * Allows to select a 3D position in a DVR by selecting a 2D location on the screen.
45  * \ingroup modules
46  */
47 class WMPickingDVR: public WModule
48 {
49 public:
50  /**
51  * Creates the module for drawing contour lines.
52  */
53  WMPickingDVR();
54 
55  /**
56  * Destroys this module.
57  */
58  virtual ~WMPickingDVR();
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 protected:
81  /**
82  * Entry point after loading the module. Runs in separate thread.
83  */
84  virtual void moduleMain();
85 
86  /**
87  * Initialize the connectors this module is using.
88  */
89  virtual void connectors();
90 
91  /**
92  * Initialize the properties for this module.
93  */
94  virtual void properties();
95 
96  /**
97  * Initialize requirements for this module.
98  */
99  virtual void requirements();
100 
101 private:
102  /**
103  * Handles picking and calculates ray start/end-position
104  *
105  * \param pickInfo class summarizing all important facts about the pick
106  */
107  void pickHandler( WPickInfo pickInfo );
108 
109  /**
110  * Check if a \ref WSinglePosition is connected and dis/connects pick signal from clicking accordingly.
111  */
112  void setPickPositionSource();
113 
114  /**
115  * Set the current pick position to the \ref WSinglePosition from the connector.
116  */
118 
119  /**
120  * Shows and hide relevant properties according to chosen picking mode.
121  *
122  * \param pickingMode The type of picking criterion used
123  */
124  void updateModuleGUI( std::string pickingMode );
125 
126  /**
127  * Calculates which interval is the most visible according
128  * to WYSIWYP (http://dx.doi.org/10.1109/TVCG.2012.292)
129  *
130  * \param vecAlphaAcc The accumulated alpha values at the samples along the viewing ray
131  *
132  * \result lower and upper bounds of the determined interval
133  */
134  std::pair<int, int> getWYSIWYPBounds( const std::vector<double>& vecAlphaAcc );
135 
136  /**
137  * Calculates the object intervals according
138  * to WYSIWYP (http://dx.doi.org/10.1109/TVCG.2012.292)
139  *
140  * \param vecAlphaAcc The accumulated alpha values at the samples along the viewing ray
141  * \param vecIndicesLowerBounds Returns the lower bounds of all intervals.
142  * \param vecIndicesUpperBounds Returns the upper bounds of all intervals.
143  */
144  void calculateIntervalsWYSIWYP( const std::vector<double>& vecAlphaAcc,
145  std::vector<int>& vecIndicesLowerBounds,
146  std::vector<int>& vecIndicesUpperBounds );
147 
148  /**
149  * Set the new position of the graphical representation
150  * of the picked position.
151  *
152  * \param position The position where the indicator should appear.
153  */
154  void updatePositionIndicator( osg::Vec3f position );
155 
156 
157  /**
158  * Samples the scalar data set along the viewing ray.
159  *
160  * \return vector of scalar values at sample positions
161  */
162  std::vector< std::pair< double, WPosition > > sampleIntensityAlongRay();
163 
164  /**
165  * Evaluate transfer function.
166  *
167  * \param scalar Evaluate transfer function for this value.
168  *
169  * \return Opacity obtained from transfer function.
170  */
171  double getTFAlpha( const double scalar ) const;
172 
173  /**
174  * Perform front to back compositing.
175  *
176  * \param accAlpha Opacity accumulated until this step.
177  * \param currentAlpha Opacity obtained from data value at this step.
178  *
179  * \return New accumulated opacity.
180  */
181  double compositingStep( const double accAlpha, double currentAlpha );
182 
183  /**
184  * Get the Visitrace candidates
185  *
186  * \return Candidates as pairs of opacity jump and location.
187  */
188  std::vector< std::pair< double, WPosition > > computeVisiTraceCandidates();
189 
190  /**
191  * Compute the position picked in the DVR
192  *
193  * \param pickingMode Which mode for picking is chosen.
194  * \param pickingSuccess Variable will be set to whether a position in the DVR has been determined or not.
195  *
196  * \return The picked position.
197  */
198  WPosition getPickedDVRPosition( std::string pickingMode, bool* pickingSuccess );
199 
200  /**
201  * Create the line rendering of the VisiTrace line.
202  */
203  void updateCurveRendering();
204 
205  std::shared_ptr< WModuleInputData< WDataSetScalar > > m_scalarIC; //!< Input connector for scalar data.
206 
207  std::shared_ptr< WModuleInputData< WDataSetSingle > > m_transferFunction; //!< The transfer function as an input data set
208 
209  std::shared_ptr< WModuleInputData< WSinglePosition > > m_externalScreenPos; //!< External screen position for picking instead of by clicking.
210 
211  osg::ref_ptr< WGEManagedGroupNode > m_rootNode; //!< All other geodes or OSG nodes of this module will be attached on this node.
212 
213  osg::ref_ptr< osg::Geode > m_geode; //!< The geometry rendered by this module.
214 
215  std::shared_ptr< WCondition > m_propCondition; //!< Needed for recreating the geometry, incase when resolution changes.
216 
217  WPropBool m_triggerCalculation; //!< Trigger Property, will be triggered by the pickhandle
218 
219  WPropBool m_continuousDrawing; //!< Should line be shown during drawing acrion?
220 
221  WPropSelection m_selectionType; //!< Property determining what type of structure will be selected
222 
223  std::shared_ptr< WItemSelection > m_selectionTypesList; //!< List of selection types for \ref m_selectionType
224 
225  WPropColor m_lineColor; //!< Color of line/s indicating selected position/s
226 
227  WPropInt m_sampleSteps; //!< Number of samples along the ray
228 
229  /**
230  * If active, the opacity of the classified fragment gets scaled according to sample count to ensure relative opacities even if sampling
231  * number changes (\ref m_sampleSteps)
232  */
234 
235  WPropDouble m_alphaThreshold; //!< Alpha value and alpha percentage
236 
237  WPropDouble m_lineThickness; //!< Thinkness of line/s indicating selected position/s
238 
239  WPropDouble m_crossSize; //!< Picking crosshair length of lines
240 
241  WPropSelection m_pickingCriteriaCur; //!< Current picking method
242 
243  std::shared_ptr< WItemSelection > m_pickingCriteriaList; //!< Possible picking criteria for \ref m_pickingCriteriaCur
244 
245  WPropSelection m_wysiwypPositionType; //!< Selecting the type of position obtained by WYSIWYP
246 
247  std::shared_ptr< WItemSelection > m_wysiwypPositionTypesList; //!< Possible position types for WYSIWYP
248 
249  osg::Vec3f m_posStart; //!< Intersection position start
250 
251  osg::Vec3f m_posEnd; //!< Intersection position end
252 
253  bool m_intersected; //!< Indicates if intersected positions are valid
254 
255  bool m_pickInProgress; //!< Indicates whether continouos picking is still in progress.
256 
257  std::vector<WPosition> m_curve3D; //!< Positions representing the from VisiTrace selection mode.
258 
259  WVisiTrace m_visiTrace; //!< Class providing VisiTrace optimization.
260 
261  WPosition m_oldRayStart; //!< Used to check if position of picking has changed
262 
263  bool m_pickHandlerConnected; //!< Is the signal from the pick handler connected?
264 };
265 
266 #endif // WMPICKINGDVR_H
This data set type contains scalars as values.
This class adds some convenience methods to WGEGroupNode.
Allows to select a 3D position in a DVR by selecting a 2D location on the screen.
Definition: WMPickingDVR.h:48
std::vector< WPosition > m_curve3D
Positions representing the from VisiTrace selection mode.
Definition: WMPickingDVR.h:257
WPropColor m_lineColor
Color of line/s indicating selected position/s.
Definition: WMPickingDVR.h:225
WPropBool m_continuousDrawing
Should line be shown during drawing acrion?
Definition: WMPickingDVR.h:219
virtual void moduleMain()
Entry point after loading the module.
void setPickPositionFromConnector()
Set the current pick position to the WSinglePosition from the connector.
osg::ref_ptr< osg::Geode > m_geode
The geometry rendered by this module.
Definition: WMPickingDVR.h:213
bool m_pickHandlerConnected
Is the signal from the pick handler connected?
Definition: WMPickingDVR.h:263
double getTFAlpha(const double scalar) const
Evaluate transfer function.
WPropSelection m_wysiwypPositionType
Selecting the type of position obtained by WYSIWYP.
Definition: WMPickingDVR.h:245
WPropSelection m_pickingCriteriaCur
Current picking method.
Definition: WMPickingDVR.h:241
bool m_intersected
Indicates if intersected positions are valid.
Definition: WMPickingDVR.h:253
virtual const std::string getDescription() const
Gives back a description of this module.
virtual void properties()
Initialize the properties for this module.
osg::Vec3f m_posStart
Intersection position start.
Definition: WMPickingDVR.h:249
WPropDouble m_crossSize
Picking crosshair length of lines.
Definition: WMPickingDVR.h:239
void setPickPositionSource()
Check if a WSinglePosition is connected and dis/connects pick signal from clicking accordingly.
osg::ref_ptr< WGEManagedGroupNode > m_rootNode
All other geodes or OSG nodes of this module will be attached on this node.
Definition: WMPickingDVR.h:211
std::shared_ptr< WItemSelection > m_pickingCriteriaList
Possible picking criteria for m_pickingCriteriaCur.
Definition: WMPickingDVR.h:243
std::pair< int, int > getWYSIWYPBounds(const std::vector< double > &vecAlphaAcc)
Calculates which interval is the most visible according to WYSIWYP (http://dx.doi....
std::vector< std::pair< double, WPosition > > sampleIntensityAlongRay()
Samples the scalar data set along the viewing ray.
WPosition getPickedDVRPosition(std::string pickingMode, bool *pickingSuccess)
Compute the position picked in the DVR.
virtual void requirements()
Initialize requirements for this module.
std::shared_ptr< WItemSelection > m_selectionTypesList
List of selection types for m_selectionType.
Definition: WMPickingDVR.h:223
virtual ~WMPickingDVR()
Destroys this module.
WPropBool m_opacityCorrectionEnabled
If active, the opacity of the classified fragment gets scaled according to sample count to ensure rel...
Definition: WMPickingDVR.h:233
WPropDouble m_lineThickness
Thinkness of line/s indicating selected position/s.
Definition: WMPickingDVR.h:237
WPropSelection m_selectionType
Property determining what type of structure will be selected.
Definition: WMPickingDVR.h:221
WPropDouble m_alphaThreshold
Alpha value and alpha percentage.
Definition: WMPickingDVR.h:235
WPropBool m_triggerCalculation
Trigger Property, will be triggered by the pickhandle.
Definition: WMPickingDVR.h:217
virtual void connectors()
Initialize the connectors this module is using.
virtual const std::string getName() const
Gives back the name of this module.
std::shared_ptr< WModuleInputData< WDataSetSingle > > m_transferFunction
The transfer function as an input data set.
Definition: WMPickingDVR.h:207
osg::Vec3f m_posEnd
Intersection position end.
Definition: WMPickingDVR.h:251
std::vector< std::pair< double, WPosition > > computeVisiTraceCandidates()
Get the Visitrace candidates.
WMPickingDVR()
Creates the module for drawing contour lines.
void updatePositionIndicator(osg::Vec3f position)
Set the new position of the graphical representation of the picked position.
void pickHandler(WPickInfo pickInfo)
Handles picking and calculates ray start/end-position.
WVisiTrace m_visiTrace
Class providing VisiTrace optimization.
Definition: WMPickingDVR.h:259
std::shared_ptr< WItemSelection > m_wysiwypPositionTypesList
Possible position types for WYSIWYP.
Definition: WMPickingDVR.h:247
std::shared_ptr< WModuleInputData< WSinglePosition > > m_externalScreenPos
External screen position for picking instead of by clicking.
Definition: WMPickingDVR.h:209
void updateModuleGUI(std::string pickingMode)
Shows and hide relevant properties according to chosen picking mode.
WPosition m_oldRayStart
Used to check if position of picking has changed.
Definition: WMPickingDVR.h:261
void calculateIntervalsWYSIWYP(const std::vector< double > &vecAlphaAcc, std::vector< int > &vecIndicesLowerBounds, std::vector< int > &vecIndicesUpperBounds)
Calculates the object intervals according to WYSIWYP (http://dx.doi.org/10.1109/TVCG....
double compositingStep(const double accAlpha, double currentAlpha)
Perform front to back compositing.
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...
std::shared_ptr< WModuleInputData< WDataSetScalar > > m_scalarIC
Input connector for scalar data.
Definition: WMPickingDVR.h:205
WPropInt m_sampleSteps
Number of samples along the ray.
Definition: WMPickingDVR.h:227
void updateCurveRendering()
Create the line rendering of the VisiTrace line.
bool m_pickInProgress
Indicates whether continouos picking is still in progress.
Definition: WMPickingDVR.h:255
std::shared_ptr< WCondition > m_propCondition
Needed for recreating the geometry, incase when resolution changes.
Definition: WMPickingDVR.h:215
Class offering an instantiate-able data connection between modules.
Class representing a single module of OpenWalnut.
Definition: WModule.h:72
Encapsulates info for pick action.
Definition: WPickInfo.h:42
This only is a 3d double vector.
Represents a single position that is transferable between modules by connectors.
Class performing graph computations for VisiTrace algorithm.
Definition: WVisiTrace.h:42