OpenWalnut
1.4.0
|
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 #include "shaders/WGEShader.h" 00037 00038 class WGEViewer; 00039 00040 #include "WROI.h" 00041 00042 /** 00043 * A box representing a region of interest. 00044 */ 00045 class WROIBox : public WROI 00046 { 00047 public: 00048 /** 00049 * Yields box with desired extremal points minPos and maxPos 00050 * \param minPos Left, lower, front corner. Minimal x, y and z coordinates. 00051 * \param maxPos Right, upper, back corner. Maximal x, y and z coordinates. 00052 */ 00053 WROIBox( WPosition minPos, WPosition maxPos ); 00054 00055 virtual ~WROIBox(); 00056 00057 /** 00058 * Get the corner of the box that has minimal x, y and z values 00059 * 00060 * \return the corner position 00061 */ 00062 WPosition getMinPos() const; 00063 00064 /** 00065 * Get the corner of the box that has maximal x, y and z values 00066 * 00067 * \return the corner position 00068 */ 00069 WPosition getMaxPos() const; 00070 00071 /** 00072 * Get the corner of the box that has minimal x, y and z values 00073 * 00074 * \return the corner position 00075 */ 00076 WPropPosition getMinPosProperty(); 00077 00078 /** 00079 * Get the corner of the box that has maximal x, y and z values 00080 * 00081 * \return the corner position 00082 */ 00083 WPropPosition getMaxPosProperty(); 00084 00085 /** 00086 * Setter for standard color 00087 * \param color The new color. 00088 */ 00089 void setColor( osg::Vec4 color ); 00090 00091 /** 00092 * Setter for color in negated state 00093 * \param color The new color. 00094 */ 00095 void setNotColor( osg::Vec4 color ); 00096 00097 protected: 00098 private: 00099 static size_t maxBoxId; //!< Current maximum boxId over all boxes. 00100 size_t boxId; //!< Id of the current box. 00101 00102 /** 00103 * Group for box specific props 00104 */ 00105 WPropGroup m_propGrp; 00106 WPropPosition m_minPos; //!< The minimum position of the box 00107 WPropPosition m_maxPos; //!< The maximum position of the box 00108 00109 /** 00110 * Shader for proper lighting. 00111 */ 00112 WGEShader::RefPtr m_lightShader; 00113 00114 /** 00115 * If true, the box' vertex data is updated. 00116 */ 00117 bool m_needVertexUpdate; 00118 bool m_isPicked; //!< Indicates whether the box is currently picked or not. 00119 WPosition m_pickedPosition; //!< Caches the old picked position to a allow for cmoparison 00120 WVector3d m_pickNormal; //!< Store the normal that occured when the pick action was started. 00121 WVector2d m_oldPixelPosition; //!< Caches the old picked position to a allow for cmoparison 00122 int16_t m_oldScrollWheel; //!< caches scroll wheel value 00123 boost::shared_mutex m_updateLock; //!< Lock to prevent concurrent threads trying to update the osg node 00124 osg::ref_ptr< osg::Geometry > m_surfaceGeometry; //!< store this pointer for use in updates 00125 00126 WPickInfo m_pickInfo; //!< Stores the pick information for potential redraw 00127 00128 boost::shared_ptr< WGEViewer > m_viewer; //!< makes viewer available all over this class. 00129 00130 osg::Vec4 m_color; //!< the color of the box 00131 00132 osg::Vec4 m_notColor; //!< the color of the box when negated 00133 00134 /** 00135 * note that there was a pick 00136 * \param pickInfo info from pick 00137 */ 00138 void registerRedrawRequest( WPickInfo pickInfo ); 00139 00140 /** 00141 * updates the graphics 00142 */ 00143 virtual void updateGFX(); 00144 00145 /** 00146 * Node callback to handle updates properly 00147 */ 00148 class ROIBoxNodeCallback : public osg::NodeCallback 00149 { 00150 public: // NOLINT 00151 /** 00152 * operator () 00153 * 00154 * \param node the osg node 00155 * \param nv the node visitor 00156 */ 00157 virtual void operator()( osg::Node* node, osg::NodeVisitor* nv ) 00158 { 00159 osg::ref_ptr< WROIBox > module = static_cast< WROIBox* > ( node->getUserData() ); 00160 if( module ) 00161 { 00162 module->updateGFX(); 00163 } 00164 traverse( node, nv ); 00165 } 00166 }; 00167 00168 /** 00169 * Called when the specified property has changed. Used to update the ROI when modifying box properties. 00170 * 00171 * \param property the property 00172 */ 00173 void boxPropertiesChanged( boost::shared_ptr< WPropertyBase > property ); 00174 00175 /** 00176 * Set new color of the box in the geometry 00177 * 00178 * \param color the new color 00179 */ 00180 void updateColor( osg::Vec4 color ); 00181 }; 00182 00183 #endif // WROIBOX_H