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