OpenWalnut  1.4.0
WROISphere.h
00001 //---------------------------------------------------------------------------
00002 //
00003 // Project: OpenWalnut ( http://www.openwalnut.org )
00004 //
00005 // Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
00006 // For more information see http://www.openwalnut.org/copying
00007 //
00008 // This file is part of OpenWalnut.
00009 //
00010 // OpenWalnut is free software: you can redistribute it and/or modify
00011 // it under the terms of the GNU Lesser General Public License as published by
00012 // the Free Software Foundation, either version 3 of the License, or
00013 // (at your option) any later version.
00014 //
00015 // OpenWalnut is distributed in the hope that it will be useful,
00016 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018 // GNU Lesser General Public License for more details.
00019 //
00020 // You should have received a copy of the GNU Lesser General Public License
00021 // along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
00022 //
00023 //---------------------------------------------------------------------------
00024 
00025 #ifndef WROISPHERE_H
00026 #define WROISPHERE_H
00027 
00028 #include <utility>
00029 
00030 #include <boost/thread.hpp>
00031 
00032 #include "../common/math/linearAlgebra/WPosition.h"
00033 #include "WPickHandler.h"
00034 #include "WGEViewer.h"
00035 
00036 #include "WROI.h"
00037 
00038 
00039 
00040 /**
00041  * A sphere representing a region of interest.
00042  */
00043 class WROISphere : public WROI
00044 {
00045 public:
00046     /**
00047      * Yields sphere with desired center point and radius
00048      * \param position position of the center of the sphere
00049      * \param radius radius of the sphere
00050      */
00051     WROISphere(  WPosition position, float radius = 5.0 );
00052 
00053     /**
00054      * standard destructor
00055      */
00056     virtual ~WROISphere();
00057 
00058     /**
00059      * getter
00060      * \return position
00061      */
00062     WPosition getPosition() const;
00063 
00064     /**
00065      * setter
00066      * \param position
00067      */
00068     void setPosition( WPosition position );
00069 
00070     /**
00071      * setter
00072      * \param x
00073      * \param y
00074      * \param z
00075      */
00076     void setPosition( float x, float y, float z );
00077 
00078     /**
00079      * Setter for standard color
00080      * \param color The new color.
00081      */
00082     void setColor( osg::Vec4 color );
00083 
00084     /**
00085      * Setter for color in negated state
00086      * \param color The new color.
00087      */
00088     void setNotColor( osg::Vec4 color );
00089 
00090     /**
00091      * removes the old drawable from the osg geode and adds a new one at the current position and size
00092      */
00093     void redrawSphere();
00094 
00095     /**
00096      * sets the flag that allows or disallows movement along the x axis
00097      *
00098      * \param value the flag
00099      */
00100     void setLockX( bool value = true );
00101 
00102     /**
00103      * sets the flag that allows or disallows movement along the y axis
00104      *
00105      * \param value the flag
00106      */
00107     void setLockY( bool value = true );
00108 
00109     /**
00110      * sets the flag that allows or disallows movement along the z axis
00111      *
00112      * \param value the flag
00113      */
00114     void setLockZ( bool value = true );
00115 
00116     /**
00117      * move the sphere with a given offset
00118      *
00119      * \param offset the distance to move
00120      */
00121     void moveSphere( WVector3d offset );
00122 
00123     /**
00124      * setter
00125      * \param x sets the x component of the position of this sphere
00126      */
00127     void setX( float x );
00128 
00129     /**
00130      * setter
00131      * \param y sets the y component of the position of this sphere
00132      */
00133     void setY( float y );
00134 
00135     /**
00136      * setter
00137      * \param z sets the z component of the position of this sphere
00138      */
00139     void setZ( float z );
00140 
00141     /**
00142      * setter
00143      * \param vector together witht he current position this sets line in space to which the movement of the
00144      * sphere is restricted
00145      */
00146     void  setLockVector( WVector3d vector );
00147 
00148     /**
00149      * setter
00150      * \param value if the the movement of the sphere is restricted to a given vector
00151      */
00152     void  setLockOnVector( bool value = true );
00153 
00154 protected:
00155 private:
00156     static size_t maxSphereId; //!< Current maximum boxId over all spheres.
00157     size_t sphereId; //!< Id of the current sphere.
00158 
00159     WPosition m_position; //!< The position of the sphere
00160 
00161     WPosition m_originalPosition; //!< The position of the sphere when created, used for locking
00162 
00163     float m_radius; //!< The radius  of the sphere
00164 
00165     bool m_isPicked; //!< Indicates whether the box is currently picked or not.
00166 
00167     WPosition m_pickedPosition; //!< Caches the old picked position to a allow for comparison
00168 
00169     WVector3d m_pickNormal; //!< Store the normal that occured when the pick action was started.
00170 
00171     WVector2d m_oldPixelPosition; //!< Caches the old picked position to a allow for cmoparison
00172 
00173     WPickInfo m_pickInfo; //!< Stores the pick information for potential redraw
00174 
00175     boost::shared_ptr< WGEViewer > m_viewer; //!< makes viewer available all over this class.
00176 
00177     osg::Vec4 m_color; //!< the color of the box
00178 
00179     osg::Vec4 m_notColor; //!< the color of the box when negated
00180 
00181     WVector3d m_lockPoint; //!< stores to point of origin of the lock vector
00182 
00183     WVector3d m_lockVector; //!< stores the lock vector
00184 
00185     bool m_lockOnVector; //!< flag indicatin wether the movement of the sphere is restricted
00186 
00187     bool m_lockX; //!< flag indicatin wether the movement of the sphere is restricted
00188     bool m_lockY; //!< flag indicatin wether the movement of the sphere is restricted
00189     bool m_lockZ; //!< flag indicatin wether the movement of the sphere is restricted
00190 
00191 
00192     /**
00193      * note that there was a pick
00194      * \param pickInfo info from pick
00195      */
00196     void registerRedrawRequest( WPickInfo pickInfo );
00197 
00198     /**
00199      *  updates the graphics
00200      */
00201     virtual void updateGFX();
00202 };
00203 
00204 #endif  // WROISPHERE_H