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