OpenWalnut 1.3.1
|
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 WROIBOX_H 00026 #define WROIBOX_H 00027 00028 #include <string> 00029 #include <utility> 00030 00031 #include <boost/thread.hpp> 00032 00033 #include <osg/Geometry> 00034 00035 #include "WPickHandler.h" 00036 class WGEViewer; 00037 00038 #include "WROI.h" 00039 00040 00041 /** 00042 * A box representing a region of interest. 00043 */ 00044 class WROIBox : public WROI 00045 { 00046 public: 00047 /** 00048 * Yields box with desired extremal points minPos and maxPos 00049 * \param minPos Left, lower, front corner. Minimal x, y and z coordinates. 00050 * \param maxPos Right, upper, back corner. Maximal x, y and z coordinates. 00051 */ 00052 WROIBox( WPosition minPos, WPosition maxPos ); 00053 00054 virtual ~WROIBox(); 00055 00056 /** 00057 * Get the corner of the box that has minimal x, y and z values 00058 * 00059 * \return the corner position 00060 */ 00061 WPosition getMinPos() const; 00062 00063 /** 00064 * Get the corner of the box that has maximal x, y and z values 00065 * 00066 * \return the corner position 00067 */ 00068 WPosition getMaxPos() const; 00069 00070 /** 00071 * Setter for standard color 00072 * \param color The new color. 00073 */ 00074 void setColor( osg::Vec4 color ); 00075 00076 /** 00077 * Setter for color in negated state 00078 * \param color The new color. 00079 */ 00080 void setNotColor( osg::Vec4 color ); 00081 00082 protected: 00083 private: 00084 static size_t maxBoxId; //!< Current maximum boxId over all boxes. 00085 size_t boxId; //!< Id of the current box. 00086 00087 WPosition m_minPos; //!< The minimum position of the box 00088 WPosition m_maxPos; //!< The maximum position of the box 00089 bool m_isPicked; //!< Indicates whether the box is currently picked or not. 00090 WPosition m_pickedPosition; //!< Caches the old picked position to a allow for cmoparison 00091 WVector3d m_pickNormal; //!< Store the normal that occured when the pick action was started. 00092 WVector2d m_oldPixelPosition; //!< Caches the old picked position to a allow for cmoparison 00093 int16_t m_oldScrollWheel; //!< caches scroll wheel value 00094 boost::shared_mutex m_updateLock; //!< Lock to prevent concurrent threads trying to update the osg node 00095 osg::ref_ptr< osg::Geometry > m_surfaceGeometry; //!< store this pointer for use in updates 00096 00097 WPickInfo m_pickInfo; //!< Stores the pick information for potential redraw 00098 00099 boost::shared_ptr< WGEViewer > m_viewer; //!< makes viewer available all over this class. 00100 00101 osg::Vec4 m_color; //!< the color of the box 00102 00103 osg::Vec4 m_notColor; //!< the color of the box when negated 00104 00105 /** 00106 * note that there was a pick 00107 * \param pickInfo info from pick 00108 */ 00109 void registerRedrawRequest( WPickInfo pickInfo ); 00110 00111 /** 00112 * updates the graphics 00113 */ 00114 virtual void updateGFX(); 00115 00116 /** 00117 * Node callback to handle updates properly 00118 */ 00119 class ROIBoxNodeCallback : public osg::NodeCallback 00120 { 00121 public: // NOLINT 00122 /** 00123 * operator () 00124 * 00125 * \param node the osg node 00126 * \param nv the node visitor 00127 */ 00128 virtual void operator()( osg::Node* node, osg::NodeVisitor* nv ) 00129 { 00130 osg::ref_ptr< WROIBox > module = static_cast< WROIBox* > ( node->getUserData() ); 00131 if( module ) 00132 { 00133 module->updateGFX(); 00134 } 00135 traverse( node, nv ); 00136 } 00137 }; 00138 }; 00139 00140 #endif // WROIBOX_H