OpenWalnut  1.3.1
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 class WGEViewer;
37 
38 #include "WROI.h"
39 
40 
41 /**
42  * A box representing a region of interest.
43  */
44 class WROIBox : public WROI
45 {
46 public:
47  /**
48  * Yields box with desired extremal points minPos and maxPos
49  * \param minPos Left, lower, front corner. Minimal x, y and z coordinates.
50  * \param maxPos Right, upper, back corner. Maximal x, y and z coordinates.
51  */
52  WROIBox( WPosition minPos, WPosition maxPos );
53 
54  virtual ~WROIBox();
55 
56  /**
57  * Get the corner of the box that has minimal x, y and z values
58  *
59  * \return the corner position
60  */
61  WPosition getMinPos() const;
62 
63  /**
64  * Get the corner of the box that has maximal x, y and z values
65  *
66  * \return the corner position
67  */
68  WPosition getMaxPos() const;
69 
70  /**
71  * Setter for standard color
72  * \param color The new color.
73  */
74  void setColor( osg::Vec4 color );
75 
76  /**
77  * Setter for color in negated state
78  * \param color The new color.
79  */
80  void setNotColor( osg::Vec4 color );
81 
82 protected:
83 private:
84  static size_t maxBoxId; //!< Current maximum boxId over all boxes.
85  size_t boxId; //!< Id of the current box.
86 
87  WPosition m_minPos; //!< The minimum position of the box
88  WPosition m_maxPos; //!< The maximum position of the box
89  bool m_isPicked; //!< Indicates whether the box is currently picked or not.
90  WPosition m_pickedPosition; //!< Caches the old picked position to a allow for cmoparison
91  WVector3d m_pickNormal; //!< Store the normal that occured when the pick action was started.
92  WVector2d m_oldPixelPosition; //!< Caches the old picked position to a allow for cmoparison
93  int16_t m_oldScrollWheel; //!< caches scroll wheel value
94  boost::shared_mutex m_updateLock; //!< Lock to prevent concurrent threads trying to update the osg node
95  osg::ref_ptr< osg::Geometry > m_surfaceGeometry; //!< store this pointer for use in updates
96 
97  WPickInfo m_pickInfo; //!< Stores the pick information for potential redraw
98 
99  boost::shared_ptr< WGEViewer > m_viewer; //!< makes viewer available all over this class.
100 
101  osg::Vec4 m_color; //!< the color of the box
102 
103  osg::Vec4 m_notColor; //!< the color of the box when negated
104 
105  /**
106  * note that there was a pick
107  * \param pickInfo info from pick
108  */
109  void registerRedrawRequest( WPickInfo pickInfo );
110 
111  /**
112  * updates the graphics
113  */
114  virtual void updateGFX();
115 
116  /**
117  * Node callback to handle updates properly
118  */
119  class ROIBoxNodeCallback : public osg::NodeCallback
120  {
121  public: // NOLINT
122  /**
123  * operator ()
124  *
125  * \param node the osg node
126  * \param nv the node visitor
127  */
128  virtual void operator()( osg::Node* node, osg::NodeVisitor* nv )
129  {
130  osg::ref_ptr< WROIBox > module = static_cast< WROIBox* > ( node->getUserData() );
131  if( module )
132  {
133  module->updateGFX();
134  }
135  traverse( node, nv );
136  }
137  };
138 };
139 
140 #endif // WROIBOX_H