OpenWalnut  1.5.0dev
WMPointConnector.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 WMPOINTCONNECTOR_H
26 #define WMPOINTCONNECTOR_H
27 
28 #include <cmath>
29 #include <memory>
30 #include <string>
31 #include <vector>
32 
33 #include <osg/Geode>
34 
35 #include "core/dataHandler/WDataSetFibers.h"
36 #include "core/dataHandler/WDataSetPoints.h"
37 #include "core/graphicsEngine/onscreenSelection/WOnscreenSelection.h"
38 #include "core/kernel/WKernel.h"
39 #include "core/kernel/WModule.h"
40 #include "core/kernel/WModuleContainer.h"
41 #include "core/kernel/WModuleInputData.h"
42 #include "core/kernel/WModuleOutputData.h"
43 
44 #include "../fiberDisplay/WMFiberDisplay.h"
45 #include "../pointRenderer/WMPointRenderer.h"
46 
47 class WClickHandler;
48 class WConnectorData;
49 class WFiberHandler;
50 class WKeyboardHandler;
51 
52 /**
53  * This module connects the points in a point dataset.
54  *
55  * \ingroup modules
56  */
58 {
59  /**
60  * Test is your best ... friend
61  */
62  friend class WMPointConnectorTest;
63 
64 public:
65  /**
66  * represents a std::shared_ptr to a vector containing a vector of floats.
67  */
68  typedef std::shared_ptr< std::vector< float > > SPFloatVector;
69 
70  /**
71  * represents a std::shared_ptr to a vector containing a vector of size_t.
72  */
73  typedef std::shared_ptr< std::vector< size_t > > SPSizeVector;
74 
75  /**
76  * A shared_ptr to this class.
77  */
78  typedef std::shared_ptr< WMPointConnector > SPtr;
79 
80  /**
81  * Constructor. Creates the module skeleton.
82  */
84 
85  /**
86  * Destructor.
87  */
88  virtual ~WMPointConnector();
89 
90  /**
91  * Gives back the name of this module.
92  * \return the module's name.
93  */
94  virtual const std::string getName() const;
95 
96  /**
97  * Gives back a description of this module.
98  * \return description to module.
99  */
100  virtual const std::string getDescription() const;
101 
102  /**
103  * Due to the prototype design pattern used to build modules, this method returns a new instance of this method. NOTE: it
104  * should never be initialized or modified in some other way. A simple new instance is required.
105  *
106  * \return the prototype used to create every module in OpenWalnut.
107  */
108  virtual std::shared_ptr< WModule > factory() const;
109 
110  /**
111  * Get the icon for this module in XPM format.
112  * \return The icon.
113  */
114  virtual const char** getXPMIcon() const;
115 
116  /**
117  * Handles a click on the drawing area.
118  * It checks all vertices and whether they are clicked.
119  * \param cameraPosition The position of the camera.
120  * \param direction The direction of the click.
121  * \param isLeftClick Whether this click is a left or a right click.
122  */
123  void handleClick( osg::Vec3 cameraPosition, osg::Vec3 direction, bool isLeftClick );
124 
125  /**
126  * Redraws the current vertices with their colors.
127  */
128  void updatePoints();
129 
130  /**
131  * Updates the fiber output
132  */
133  void updateOutput();
134 
135  /**
136  * Updates all
137  */
138  void updateAll();
139 
140  /**
141  * \return std::shared_ptr< WConnectorData > The WConnectorData of this module.
142  */
143  std::shared_ptr< WConnectorData > getConnectorData();
144 
145  /**
146  *
147  * \return std::shared_ptr< WFiberHandler > The WFiberHandler of this module.
148  */
149  std::shared_ptr< WFiberHandler > getFiberHandler();
150 
151  /**
152  *
153  * \return shared_ptr< WOnscreenSelection > The WOnscreenSelection of this module.
154  */
155  std::shared_ptr< WOnscreenSelection > getOnscreenSelection();
156 
157  /**
158  *
159  * \return WPropPosition The scaling of this module.
160  */
161  WPropPosition getScaling();
162 
163  /**
164  * Pushes a function to the selection queue
165  * \param func The function
166  */
167  void pushEventQueue( std::function< void() > func );
168 
169  /**
170  * Accepts the current prediction.
171  */
172  void acceptPrediction();
173 
174 protected:
175  /**
176  * Entry point after loading the module. Runs in separate thread.
177  */
178  virtual void moduleMain();
179 
180  /**
181  * Initialize the connectors this module is using.
182  */
183  virtual void connectors();
184 
185  /**
186  * Initialize the properties for this module.
187  */
188  virtual void properties();
189 
190  /**
191  * Deactivates or activates the inner modules when active changes.
192  */
193  virtual void activate();
194 
195 private:
196  /**
197  * Checks if a vertex with a certain radius is hit by a ray.
198  * \param rayStart The starting point of the ray.
199  * \param rayDir The direction of the ray.
200  * \param vertex The vertex to be checked.
201  * \param radius The radius of the vertex.
202  * \return < 0 if ray does not intersect. == 0 if ray is a tangent. > 0 if ray intersects.
203  */
204  float hitVertex( osg::Vec3 rayStart, osg::Vec3 rayDir, osg::Vec3 vertex, float radius );
205 
206  /**
207  * Creates the WMPointRenderer and runs it.
208  */
209  void createPointRenderer();
210 
211  /**
212  * Creates the WMFiberDisplay and runs it.
213  */
214  void createFiberDisplay();
215 
216  /**
217  * Creates the WKeyboardHandler and registers them.
218  */
219  void createHandler();
220 
221  /**
222  * Handles the input of this module.
223  */
224  void handleInput();
225 
226  /**
227  * Finds the point that was clicked and writes it into hitIdx,
228  * while return whether a point was hit.
229  * \param cameraPosition The position of the camera.
230  * \param direction The direction to check.
231  * \param hitIdx A pointer to a variable where the index of the clicked point is written.
232  * \return true A point was clicked.
233  * \return false A point was not clicked.
234  */
235  bool findClickedPoint( osg::Vec3 cameraPosition, osg::Vec3 direction, size_t* hitIdx );
236 
237  /**
238  * Toggles the activation of a module.
239  * \param mod THe module to change the activation of.
240  */
242 
243  /**
244  * The end callback of m_onscreenSelection.
245  * \param type The type of the selection.
246  * \param x The x position of the selection.
247  * \param y The y position of the selection.
248  */
249  void selectionEnd( WOnscreenSelection::WSelectionType type, float x, float y );
250 
251  /**
252  * Checks whether a vertex is adaptively hidden.
253  * \param vertex The vertex to check.
254  * \param from Optional parameter for vertex to check from.
255  * \return true The vertex is hidden.
256  * \return false The vertex is visible.
257  */
258  bool isAdaptivelyHidden( osg::Vec3 vertex, osg::Vec3* from = NULL );
259 
260  /**
261  * Handles a selection with only one click
262  * \param clickType The type of click (true -> left, false -> right).
263  * \param x The x position.
264  * \param y The y position.
265  */
266  void handleClickSelection( bool clickType, double x, double y );
267 
268  /**
269  * Handles the selection of a left click.
270  * \param positions The positions in the selection.
271  */
272  void handleLeftSelection( std::vector< WPosition > positions );
273 
274  /**
275  * Handles the selection of a right click.
276  * \param positions The positions in the selection.
277  */
278  void handleRightSelection( std::vector< WPosition > positions );
279 
280  /**
281  * Creates a track continuation prediction.
282  */
283  void createPrediction();
284 
285  /**
286  * The WMPointRenderer associated with this module.
287  */
289 
290  /**
291  * The WMFiberDisplay associated with this module.
292  */
294 
295  /**
296  * The data of this module.
297  */
298  std::shared_ptr< WConnectorData > m_connectorData;
299 
300  /**
301  * The WFiberHandler of this module.
302  */
303  std::shared_ptr< WFiberHandler > m_fiberHandler;
304 
305  /**
306  * An input connector used to get points from other modules.
307  */
308  std::shared_ptr< WModuleInputData< WDataSetPoints > > m_pointInput;
309 
310  /**
311  * An output connector used to provide fibers to other modules.
312  */
313  std::shared_ptr< WModuleOutputData< WDataSetFibers > > m_fiberOutput;
314 
315  /**
316  * The internal pointOutput to pass data to the WMPointRenderer
317  */
318  std::shared_ptr< WModuleOutputData< WDataSetPoints > > m_pointOutput;
319 
320  /**
321  * Enables possibility for multiselection of points.
322  */
323  std::shared_ptr< WOnscreenSelection > m_onscreenSelection;
324 
325  /**
326  * A vector for the events.
327  */
328  std::vector< std::function< void() > > m_eventQueue;
329 
330  /**
331  * A mutex for the vector to make it thread-safe.
332  */
333  std::mutex m_eventMutex;
334 
335  /**
336  * The current prediction.
337  */
338  std::vector< WPosition > m_prediction;
339 
340  /**
341  * A condition notifying when something was added to the event queue.
342  */
344 
345  /**
346  * The keyboard handler for this point connector.
347  */
348  osg::ref_ptr< WKeyboardHandler > m_keyboardHandler;
349 
350  /**
351  * Property to enable the adjusted dijkstra.
352  */
353  WPropBool m_enableSAPT;
354 
355  /**
356  * Property to enable adaptive visibility.
357  */
359 
360  /**
361  * Enables the prediction.
362  */
364 
365  /**
366  * Property to set the angle for the adaptive visibility.
367  */
369 
370  /**
371  * Property to set the opacity of the hidden points.
372  */
373  WPropDouble m_hiddenOpacity;
374 
375  /**
376  * Property for the scaling as Vector.
377  */
378  WPropPosition m_scaling;
379 
380  /**
381  * Property to enable the sizes.
382  */
383  WPropBool m_enableSizes;
384 };
385 
386 #endif // WMPOINTCONNECTOR_H
std::shared_ptr< WCondition > SPtr
Shared pointer type for WCondition.
Definition: WCondition.h:48
Holds the data of the WMPointConnector.
Handles the fibers of the WMPointsConnector.
Definition: WFiberHandler.h:48
The keyboard handler for the keyboard events of WMPointConnector.
Test functionality of WMPointConnector class.
This module connects the points in a point dataset.
WModule::SPtr m_fiberDisplay
The WMFiberDisplay associated with this module.
std::shared_ptr< std::vector< size_t > > SPSizeVector
represents a std::shared_ptr to a vector containing a vector of size_t.
virtual void activate()
Deactivates or activates the inner modules when active changes.
WPropDouble m_adaptiveVisibilityAngle
Property to set the angle for the adaptive visibility.
bool isAdaptivelyHidden(osg::Vec3 vertex, osg::Vec3 *from=NULL)
Checks whether a vertex is adaptively hidden.
virtual void properties()
Initialize the properties for this module.
std::shared_ptr< WConnectorData > m_connectorData
The data of this module.
void updateAll()
Updates all.
WPropDouble m_hiddenOpacity
Property to set the opacity of the hidden points.
WPropPosition m_scaling
Property for the scaling as Vector.
WMPointConnector()
Constructor.
std::vector< std::function< void() > > m_eventQueue
A vector for the events.
virtual ~WMPointConnector()
Destructor.
std::shared_ptr< WOnscreenSelection > getOnscreenSelection()
float hitVertex(osg::Vec3 rayStart, osg::Vec3 rayDir, osg::Vec3 vertex, float radius)
Checks if a vertex with a certain radius is hit by a ray.
WPropBool m_enableAdaptiveVisibility
Property to enable adaptive visibility.
WPropPosition getScaling()
void handleInput()
Handles the input of this module.
bool findClickedPoint(osg::Vec3 cameraPosition, osg::Vec3 direction, size_t *hitIdx)
Finds the point that was clicked and writes it into hitIdx, while return whether a point was hit.
void pushEventQueue(std::function< void() > func)
Pushes a function to the selection queue.
void createHandler()
Creates the WKeyboardHandler and registers them.
std::shared_ptr< WModuleOutputData< WDataSetFibers > > m_fiberOutput
An output connector used to provide fibers to other modules.
void handleRightSelection(std::vector< WPosition > positions)
Handles the selection of a right click.
std::mutex m_eventMutex
A mutex for the vector to make it thread-safe.
std::shared_ptr< WMPointConnector > SPtr
A shared_ptr to this class.
virtual void connectors()
Initialize the connectors this module is using.
std::shared_ptr< WFiberHandler > getFiberHandler()
WModule::SPtr m_pointRenderer
The WMPointRenderer associated with this module.
void acceptPrediction()
Accepts the current prediction.
std::shared_ptr< WConnectorData > getConnectorData()
WPropBool m_enableSizes
Property to enable the sizes.
virtual void moduleMain()
Entry point after loading the module.
osg::ref_ptr< WKeyboardHandler > m_keyboardHandler
The keyboard handler for this point connector.
virtual const std::string getDescription() const
Gives back a description of this module.
std::shared_ptr< std::vector< float > > SPFloatVector
represents a std::shared_ptr to a vector containing a vector of floats.
std::vector< WPosition > m_prediction
The current prediction.
std::shared_ptr< WModuleInputData< WDataSetPoints > > m_pointInput
An input connector used to get points from other modules.
void createPrediction()
Creates a track continuation prediction.
void toggleActivationOfModule(WModule::SPtr mod)
Toggles the activation of a module.
void handleClickSelection(bool clickType, double x, double y)
Handles a selection with only one click.
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 selectionEnd(WOnscreenSelection::WSelectionType type, float x, float y)
The end callback of m_onscreenSelection.
virtual const char ** getXPMIcon() const
Get the icon for this module in XPM format.
void createFiberDisplay()
Creates the WMFiberDisplay and runs it.
void updateOutput()
Updates the fiber output.
std::shared_ptr< WModuleOutputData< WDataSetPoints > > m_pointOutput
The internal pointOutput to pass data to the WMPointRenderer.
std::shared_ptr< WFiberHandler > m_fiberHandler
The WFiberHandler of this module.
WCondition::SPtr m_eventCondition
A condition notifying when something was added to the event queue.
void updatePoints()
Redraws the current vertices with their colors.
WPropBool m_enableSAPT
Property to enable the adjusted dijkstra.
void handleLeftSelection(std::vector< WPosition > positions)
Handles the selection of a left click.
virtual const std::string getName() const
Gives back the name of this module.
void handleClick(osg::Vec3 cameraPosition, osg::Vec3 direction, bool isLeftClick)
Handles a click on the drawing area.
void createPointRenderer()
Creates the WMPointRenderer and runs it.
std::shared_ptr< WOnscreenSelection > m_onscreenSelection
Enables possibility for multiselection of points.
WPropBool m_enablePrediction
Enables the prediction.
Class able to contain other modules.
std::shared_ptr< WModule > SPtr
Shared pointer to a WModule.
Definition: WModule.h:106
WSelectionType
The different types of selection.