OpenWalnut  1.2.5
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
WROISphere.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 WROISPHERE_H
26 #define WROISPHERE_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 
39 #include "WExportWGE.h"
40 
41 /**
42  * A sphere representing a region of interest.
43  */
44 class WGE_EXPORT WROISphere : public WROI
45 {
46 public:
47  /**
48  * Yields sphere with desired center point and radius
49  * \param position position of the center of the sphere
50  * \param radius radius of the sphere
51  */
52  WROISphere( WPosition position, float radius = 5.0 );
53 
54  /**
55  * standard destructor
56  */
57  virtual ~WROISphere();
58 
59  /**
60  * getter
61  * \return position
62  */
63  WPosition getPosition() const;
64 
65  /**
66  * setter
67  * \param position
68  */
69  void setPosition( WPosition position );
70 
71  /**
72  * setter
73  * \param x
74  * \param y
75  * \param z
76  */
77  void setPosition( float x, float y, float z );
78 
79  /**
80  * Setter for standard color
81  * \param color The new color.
82  */
83  void setColor( osg::Vec4 color );
84 
85  /**
86  * Setter for color in negated state
87  * \param color The new color.
88  */
89  void setNotColor( osg::Vec4 color );
90 
91  /**
92  * removes the old drawable from the osg geode and adds a new one at the current position and size
93  */
94  void redrawSphere();
95 
96  /**
97  * sets the flag that allows or disallows movement along the x axis
98  *
99  * \param value the flag
100  */
101  void setLockX( bool value = true );
102 
103  /**
104  * sets the flag that allows or disallows movement along the y axis
105  *
106  * \param value the flag
107  */
108  void setLockY( bool value = true );
109 
110  /**
111  * sets the flag that allows or disallows movement along the z axis
112  *
113  * \param value the flag
114  */
115  void setLockZ( bool value = true );
116 
117  /**
118  * move the sphere with a given offset
119  *
120  * \param offset the distance to move
121  */
122  void moveSphere( WVector3d offset );
123 
124  /**
125  * setter
126  * \param x sets the x component of the position of this sphere
127  */
128  void setX( float x );
129 
130  /**
131  * setter
132  * \param y sets the y component of the position of this sphere
133  */
134  void setY( float y );
135 
136  /**
137  * setter
138  * \param z sets the z component of the position of this sphere
139  */
140  void setZ( float z );
141 
142  /**
143  * setter
144  * \param vector together witht he current position this sets line in space to which the movement of the
145  * sphere is restricted
146  */
147  void setLockVector( WVector3d vector );
148 
149  /**
150  * setter
151  * \param value if the the movement of the sphere is restricted to a given vector
152  */
153  void setLockOnVector( bool value = true );
154 
155 protected:
156 
157 private:
158  static size_t maxSphereId; //!< Current maximum boxId over all spheres.
159  size_t sphereId; //!< Id of the current sphere.
160 
161  WPosition m_position; //!< The position of the sphere
162 
163  WPosition m_originalPosition; //!< The position of the sphere when created, used for locking
164 
165  float m_radius; //!< The radius of the sphere
166 
167  bool m_isPicked; //!< Indicates whether the box is currently picked or not.
168 
169  WPosition m_pickedPosition; //!< Caches the old picked position to a allow for comparison
170 
171  WVector3d m_pickNormal; //!< Store the normal that occured when the pick action was started.
172 
173  WVector2d m_oldPixelPosition; //!< Caches the old picked position to a allow for cmoparison
174 
175  WPickInfo m_pickInfo; //!< Stores the pick information for potential redraw
176 
177  boost::shared_ptr< WGEViewer > m_viewer; //!< makes viewer available all over this class.
178 
179  osg::Vec4 m_color; //!< the color of the box
180 
181  osg::Vec4 m_notColor; //!< the color of the box when negated
182 
183  WVector3d m_lockPoint; //!< stores to point of origin of the lock vector
184 
185  WVector3d m_lockVector; //!< stores the lock vector
186 
187  bool m_lockOnVector; //!< flag indicatin wether the movement of the sphere is restricted
188 
189  bool m_lockX; //!< flag indicatin wether the movement of the sphere is restricted
190  bool m_lockY; //!< flag indicatin wether the movement of the sphere is restricted
191  bool m_lockZ; //!< flag indicatin wether the movement of the sphere is restricted
192 
193 
194  /**
195  * note that there was a pick
196  * \param pickInfo info from pick
197  */
198  void registerRedrawRequest( WPickInfo pickInfo );
199 
200  /**
201  * updates the graphics
202  */
203  virtual void updateGFX();
204 };
205 
206 #endif // WROISPHERE_H