OpenWalnut  1.5.0dev
WROIBox.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 WROIBOX_H
26 #define WROIBOX_H
27 
28 #include <memory>
29 #include <shared_mutex>
30 #include <string>
31 #include <utility>
32 
33 #include <boost/thread.hpp>
34 #include <osg/Geometry>
35 
36 #include "WPickHandler.h"
37 #include "WROI.h"
38 #include "shaders/WGEShader.h"
39 
40 /**
41  * Forward declaration of WGEViewer.
42  */
43 class WGEViewer;
44 
45 /**
46  * A box representing a region of interest.
47  */
48 class WROIBox : public WROI
49 {
50 public:
51  /**
52  * Yields box with desired extremal points minPos and maxPos
53  * \param minPos Left, lower, front corner. Minimal x, y and z coordinates.
54  * \param maxPos Right, upper, back corner. Maximal x, y and z coordinates.
55  */
56  WROIBox( WPosition minPos, WPosition maxPos );
57 
58  virtual ~WROIBox();
59 
60  /**
61  * Get the corner of the box that has minimal x, y and z values
62  *
63  * \return the corner position
64  */
65  WPosition getMinPos() const;
66 
67  /**
68  * Get the corner of the box that has maximal x, y and z values
69  *
70  * \return the corner position
71  */
72  WPosition getMaxPos() const;
73 
74  /**
75  * Get the corner of the box that has minimal x, y and z values
76  *
77  * \return the corner position
78  */
79  WPropPosition getMinPosProperty();
80 
81  /**
82  * Get the corner of the box that has maximal x, y and z values
83  *
84  * \return the corner position
85  */
86  WPropPosition getMaxPosProperty();
87 
88  /**
89  * Setter for standard color
90  * \param color The new color.
91  */
92  void setColor( osg::Vec4 color );
93 
94  /**
95  * Setter for color in negated state
96  * \param color The new color.
97  */
98  void setNotColor( osg::Vec4 color );
99 
100 protected:
101 private:
102  static size_t maxBoxId; //!< Current maximum boxId over all boxes.
103  size_t boxId; //!< Id of the current box.
104 
105  /**
106  * Group for box specific props
107  */
108  WPropGroup m_propGrp;
109  WPropPosition m_minPos; //!< The minimum position of the box
110  WPropPosition m_maxPos; //!< The maximum position of the box
111 
112  /**
113  * Shader for proper lighting.
114  */
116 
117  /**
118  * If true, the box' vertex data is updated.
119  */
121  bool m_isPicked; //!< Indicates whether the box is currently picked or not.
122  WPosition m_pickedPosition; //!< Caches the old picked position to a allow for cmoparison
123  WVector3d m_pickNormal; //!< Store the normal that occured when the pick action was started.
124  WVector2d m_oldPixelPosition; //!< Caches the old picked position to a allow for cmoparison
125  int16_t m_oldScrollWheel; //!< caches scroll wheel value
126  std::shared_mutex m_updateLock; //!< Lock to prevent concurrent threads trying to update the osg node
127  osg::ref_ptr< osg::Geometry > m_surfaceGeometry; //!< store this pointer for use in updates
128 
129  WPickInfo m_pickInfo; //!< Stores the pick information for potential redraw
130 
131  std::shared_ptr< WGEViewer > m_viewer; //!< makes viewer available all over this class.
132 
133  osg::Vec4 m_color; //!< the color of the box
134 
135  osg::Vec4 m_notColor; //!< the color of the box when negated
136 
137  /**
138  * note that there was a pick
139  * \param pickInfo info from pick
140  */
141  void registerRedrawRequest( WPickInfo pickInfo );
142 
143  /**
144  * updates the graphics
145  */
146  virtual void updateGFX();
147 
148  /**
149  * Node callback to handle updates properly
150  */
151  class ROIBoxNodeCallback : public osg::NodeCallback
152  {
153  public: // NOLINT
154  /**
155  * operator ()
156  *
157  * \param node the osg node
158  * \param nv the node visitor
159  */
160  virtual void operator()( osg::Node* node, osg::NodeVisitor* nv )
161  {
162  osg::ref_ptr< WROIBox > module = static_cast< WROIBox* > ( node->getUserData() );
163  if( module )
164  {
165  module->updateGFX();
166  }
167  traverse( node, nv );
168  }
169  };
170 
171  /**
172  * Called when the specified property has changed. Used to update the ROI when modifying box properties.
173  *
174  * \param property the property
175  */
176  void boxPropertiesChanged( std::shared_ptr< WPropertyBase > property );
177 
178  /**
179  * Set new color of the box in the geometry
180  *
181  * \param color the new color
182  */
183  void updateColor( osg::Vec4 color );
184 };
185 
186 #endif // WROIBOX_H
osg::ref_ptr< WGEShader > RefPtr
Convenience typedef for an osg::ref_ptr.
Definition: WGEShader.h:53
Class for managing one view to the scene.
Definition: WGEViewer.h:71
Encapsulates info for pick action.
Definition: WPickInfo.h:42
This only is a 3d double vector.
Node callback to handle updates properly.
Definition: WROIBox.h:152
virtual void operator()(osg::Node *node, osg::NodeVisitor *nv)
operator ()
Definition: WROIBox.h:160
A box representing a region of interest.
Definition: WROIBox.h:49
static size_t maxBoxId
Current maximum boxId over all boxes.
Definition: WROIBox.h:102
void setNotColor(osg::Vec4 color)
Setter for color in negated state.
Definition: WROIBox.cpp:290
WROIBox(WPosition minPos, WPosition maxPos)
Yields box with desired extremal points minPos and maxPos.
Definition: WROIBox.cpp:43
osg::Vec4 m_notColor
the color of the box when negated
Definition: WROIBox.h:135
WPropPosition getMinPosProperty()
Get the corner of the box that has minimal x, y and z values.
Definition: WROIBox.cpp:113
std::shared_ptr< WGEViewer > m_viewer
makes viewer available all over this class.
Definition: WROIBox.h:131
WVector3d m_pickNormal
Store the normal that occured when the pick action was started.
Definition: WROIBox.h:123
void updateColor(osg::Vec4 color)
Set new color of the box in the geometry.
Definition: WROIBox.cpp:295
WPosition getMinPos() const
Get the corner of the box that has minimal x, y and z values.
Definition: WROIBox.cpp:103
WPickInfo m_pickInfo
Stores the pick information for potential redraw.
Definition: WROIBox.h:129
WVector2d m_oldPixelPosition
Caches the old picked position to a allow for cmoparison.
Definition: WROIBox.h:124
WPropPosition m_minPos
The minimum position of the box.
Definition: WROIBox.h:109
osg::Vec4 m_color
the color of the box
Definition: WROIBox.h:133
int16_t m_oldScrollWheel
caches scroll wheel value
Definition: WROIBox.h:125
WPosition m_pickedPosition
Caches the old picked position to a allow for cmoparison.
Definition: WROIBox.h:122
void registerRedrawRequest(WPickInfo pickInfo)
note that there was a pick
Definition: WROIBox.cpp:123
osg::ref_ptr< osg::Geometry > m_surfaceGeometry
store this pointer for use in updates
Definition: WROIBox.h:127
WPropPosition getMaxPosProperty()
Get the corner of the box that has maximal x, y and z values.
Definition: WROIBox.cpp:118
WPosition getMaxPos() const
Get the corner of the box that has maximal x, y and z values.
Definition: WROIBox.cpp:108
bool m_isPicked
Indicates whether the box is currently picked or not.
Definition: WROIBox.h:121
virtual void updateGFX()
updates the graphics
Definition: WROIBox.cpp:138
size_t boxId
Id of the current box.
Definition: WROIBox.h:103
WPropGroup m_propGrp
Group for box specific props.
Definition: WROIBox.h:108
WPropPosition m_maxPos
The maximum position of the box.
Definition: WROIBox.h:110
WGEShader::RefPtr m_lightShader
Shader for proper lighting.
Definition: WROIBox.h:115
bool m_needVertexUpdate
If true, the box' vertex data is updated.
Definition: WROIBox.h:120
void setColor(osg::Vec4 color)
Setter for standard color.
Definition: WROIBox.cpp:285
void boxPropertiesChanged(std::shared_ptr< WPropertyBase > property)
Called when the specified property has changed.
Definition: WROIBox.cpp:133
std::shared_mutex m_updateLock
Lock to prevent concurrent threads trying to update the osg node.
Definition: WROIBox.h:126
Superclass for different ROI (region of interest) types.
Definition: WROI.h:45