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