WMNavSlices.h 5.6 KB
Newer Older
1 2
//---------------------------------------------------------------------------
//
3
// Project: OpenWalnut ( http://www.openwalnut.org )
4
//
5 6
// Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
// For more information see http://www.openwalnut.org/copying
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
//
// This file is part of OpenWalnut.
//
// OpenWalnut is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// OpenWalnut is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
//
//---------------------------------------------------------------------------

25 26
#ifndef WMNAVSLICES_H
#define WMNAVSLICES_H
27

28
#include <list>
29 30
#include <string>
#include <vector>
31

32
#include <osg/Node>
33

34
#include "../../dataHandler/WDataSet.h"
35
#include "../../graphicsEngine/WShader.h"
36
#include "../../kernel/WModule.h"
37
#include "../../kernel/WModuleConnector.h"
38
#include "../../kernel/WModuleInputData.h"
39

40 41
/**
 * \par Description:
schurade's avatar
schurade committed
42
 *
43
 * Navigation slice module
44
 */
45
class WMNavSlices: public WModule, public osg::Referenced
46 47 48 49 50 51 52
{
public:

    /**
     * \par Description
     * Default constructor.
     */
53
    WMNavSlices();
54 55 56 57 58

    /**
     * \par Description
     * Destructor.
     */
59
    virtual ~WMNavSlices();
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74

    /**
     * \par Description
     * Gives back the name of this module.
     * \return the module's name.
     */
    virtual const std::string getName() const;

    /**
     * \par Description
     * Gives back a description of this module.
     * \return description to module.
     */
    virtual const std::string getDescription() const;

75
    /**
76
     * updates the positions of the navigation slices
77
     */
78
    void updateGeometry();
79 80 81 82 83

    /**
     *  updates textures and shader parameters
     */
    void updateTextures();
84

85 86 87
    /**
     * Due to the prototype design pattern used to build modules, this method returns a new instance of this method. NOTE: it
     * should never be initialized or modified in some other way. A simple new instance is required.
88
     *
89 90 91 92
     * \return the prototype used to create every module in OpenWalnut.
     */
    virtual boost::shared_ptr< WModule > factory() const;

93 94 95 96 97 98
protected:

    /**
     * \par Description
     * Entry point after loading the module. Runs in separate thread.
     */
99
    virtual void moduleMain();
100

schurade's avatar
schurade committed
101
    /**
102 103
     * Initialize the connectors this module is using.
     */
104
    virtual void connectors();
105

106 107 108 109 110
    /**
     * Initialize the properties for this module.
     */
    virtual void properties();

schurade's avatar
schurade committed
111
    /**
112
     * Receive DATA_CHANGE notifications.
schurade's avatar
schurade committed
113
     *
114 115 116
     * \param input the input connector that got the change signal. Typically it is one of the input connectors from this module.
     * \param output the output connector that sent the signal. Not part of this module instance.
     */
117 118
    virtual void notifyDataChange( boost::shared_ptr<WModuleConnector> input,
                                   boost::shared_ptr<WModuleConnector> output );
119

120

121
private:
122 123 124
    /**
     * initial create method
     */
125
    void create();
126

127
    /**
128
     * initial creation function for the slice geometry
129
     */
130
    osg::ref_ptr<osg::Geometry> createGeometry( int slice );
131

132 133 134 135
    /**
     * creates and initializes the uniform parameters for the shader
     */
    void initUniforms( osg::StateSet* sliceState );
136

137
    /**
138
     * the root node for this module
139
     */
140 141 142 143 144 145 146
    osg::ref_ptr<osg::Group> m_rootNode;

    /**
     * nodes for each slice, to be reused in other widgets
     */
    osg::ref_ptr<osg::Geode> m_xSliceNode;

147 148 149 150
    /**
     * nodes for each slice, to be reused in other widgets
     */
    osg::ref_ptr<osg::Geode> m_ySliceNode;
151

152 153 154 155
    /**
     * nodes for each slice, to be reused in other widgets
     */
    osg::ref_ptr<osg::Geode> m_zSliceNode;
156

157
    /**
158
     * the shader object for this module
159
     */
160
    boost::shared_ptr< WShader >m_shader;
161

schurade's avatar
schurade committed
162
    /**
163 164
     * Input connector required by this module.
     */
165
    boost::shared_ptr<WModuleInputData< WDataSetSingle > > m_input;
166

167 168 169 170 171
    /**
     * lock to prevent concurrent threads trying to update the osg node
     */
    boost::shared_mutex m_updateLock;

172 173 174
    /**
     * vector of uniforms for type of texture
     */
175
    std::vector< osg::ref_ptr<osg::Uniform> > m_typeUniforms;
176 177 178 179

    /**
     * vector of alpha values per texture
     */
180
    std::vector< osg::ref_ptr<osg::Uniform> > m_alphaUniforms;
181 182 183 184

    /**
     * vector of thresholds per texture
     */
185
    std::vector< osg::ref_ptr<osg::Uniform> > m_thresholdUniforms;
186 187 188 189

    /**
     * vector of samplers
     */
190
    std::vector< osg::ref_ptr<osg::Uniform> > m_samplerUniforms;
191

192 193 194
    /**
     * Node callback to handle updates properly
     */
195
    class sliceNodeCallback : public osg::NodeCallback
196
    {
schurade's avatar
schurade committed
197
    public: // NOLINT
198 199 200 201 202 203
        /**
         * operator ()
         *
         * \param node the osg node
         * \param nv the node visitor
         */
204
        virtual void operator()( osg::Node* node, osg::NodeVisitor* nv )
205
        {
206 207 208 209 210 211 212 213
            osg::ref_ptr< WMNavSlices > module = static_cast< WMNavSlices* > ( node->getUserData() );

            if ( module )
            {
                module->updateGeometry();
                module->updateTextures();
            }
            traverse( node, nv );
214
        }
215
    };
216 217
};

218 219


220
#endif  // WMNAVSLICES_H
221