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