OpenWalnut  1.4.0
WGEGridNode.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 WGEGRIDNODE_H
00026 #define WGEGRIDNODE_H
00027 
00028 #include <osg/Geode>
00029 #include <osg/MatrixTransform>
00030 
00031 #include "../../dataHandler/WGridRegular3D.h"
00032 #include "../../common/WSharedObject.h"
00033 #include "../../common/WProperties_Fwd.h"
00034 
00035 #include "../widgets/labeling/WGELabel.h"
00036 
00037 /**
00038  * This node is able to represent a grid in certain ways. It can show its boundary or the whole grid if desired.
00039  */
00040 class WGEGridNode: public osg::MatrixTransform
00041 {
00042 public:
00043     /**
00044      * Convenience typedef for a osg::ref_ptr< WGEGridNode >.
00045      */
00046     typedef osg::ref_ptr< WGEGridNode > SPtr;
00047 
00048     /**
00049      * Convenience typedef for a osg::ref_ptr< const WGEGridNode >.
00050      */
00051     typedef osg::ref_ptr< const WGEGridNode > ConstSPtr;
00052 
00053     /**
00054      * Creates a node representing the specified grid.
00055      *
00056      * \param grid the grid to represent.
00057      */
00058     explicit WGEGridNode( WGridRegular3D::ConstSPtr grid );
00059 
00060     /**
00061      * Destructor.
00062      */
00063     virtual ~WGEGridNode();
00064 
00065     /**
00066      * Updates the node to use the new specified grid
00067      *
00068      * \param grid the new grid to use
00069      */
00070     void setGrid( WGridRegular3D::ConstSPtr grid );
00071 
00072     /**
00073      * Returns the currently set grid.
00074      *
00075      * \return the current grid.
00076      */
00077     WGridRegular3D::ConstSPtr getGrid() const;
00078 
00079     /**
00080      * Returns whether labels on the corners are enabled or not.
00081      *
00082      * \return true if labels are enabled
00083      */
00084     bool getEnableLabels() const;
00085 
00086     /**
00087      * En- or disable labels on the boundary corners.
00088      *
00089      * \param enable true to enbable
00090      */
00091     void setEnableLabels( bool enable = true );
00092 
00093     /**
00094      * Returns whether bbox mode is enabled or not.
00095      *
00096      * \return true if bbox rendering are enabled
00097      */
00098     bool getEnableBBox() const;
00099 
00100     /**
00101      * En- or disable bbox mode.
00102      *
00103      * \param enable true to enbable
00104      */
00105     void setEnableBBox( bool enable = true );
00106 
00107     /**
00108      * Returns whether grid mode is enabled or not.
00109      *
00110      * \return true if grid rendering are enabled
00111      */
00112     bool getEnableGrid() const;
00113 
00114     /**
00115      * En- or disable grid mode.
00116      *
00117      * \param enable true to enbable
00118      */
00119     void setEnableGrid( bool enable = true );
00120 
00121     /**
00122      * The currently set color used for rendering the bbox.
00123      *
00124      * \return the current color.
00125      */
00126     const WColor& getBBoxColor() const;
00127 
00128     /**
00129      * Sets the color of the rendered bbox.
00130      *
00131      * \param color the color
00132      */
00133     void setBBoxColor( const WColor& color );
00134 
00135     /**
00136      * The currently set color used for rendering the grid.
00137      *
00138      * \return the current color.
00139      */
00140     const WColor& getGridColor() const;
00141 
00142     /**
00143      * Sets the color of the rendered grid.
00144      *
00145      * \param color the color
00146      */
00147     void setGridColor( const WColor& color );
00148 
00149 protected:
00150 private:
00151     /**
00152      * The actual grid which should be represented by this node.
00153      */
00154     WSharedObject< WGridRegular3D::ConstSPtr > m_grid;
00155 
00156     /**
00157      * The geometry for the boundary.
00158      */
00159     osg::ref_ptr< osg::Geode > m_boundaryGeode;
00160 
00161     /**
00162      * The geometry for the whole grid.
00163      */
00164     osg::ref_ptr< osg::Geode > m_innerGridGeode;
00165 
00166     /**
00167      * The labels at the corner.
00168      */
00169     WGELabel::SPtr m_borderLabels[8];
00170 
00171     /**
00172      * The geode keeping the labels
00173      */
00174     osg::ref_ptr< osg::Geode > m_labelGeode;
00175 
00176     /**
00177      * The actual callback handling changes in the grid
00178      *
00179      * \param node the node. This will be the this pointer.
00180      */
00181     void callback( osg::Node* node );
00182 
00183     /**
00184      * If true, the labels and geometry gets adapted properly.
00185      */
00186     bool m_gridUpdate;
00187 
00188     /**
00189      * If true, the inner grid geometry gets recreated.
00190      */
00191     bool m_gridGeometryUpdate;
00192 
00193     /**
00194      * If true, labels get used.
00195      */
00196     bool m_showLabels;
00197 
00198     /**
00199      * True if the bbox should be rendered
00200      */
00201     bool m_showBBox;
00202 
00203     /**
00204      * True if the grid should be rendered.
00205      */
00206     bool m_showGrid;
00207 
00208     /**
00209      * The color of bbox/grid
00210      */
00211     WColor m_bbColor;
00212 
00213     /**
00214      * The color of the grid.
00215      */
00216     WColor m_gridColor;
00217 };
00218 
00219 #endif  // WGEGRIDNODE_H
00220