glreduction.h 4.14 KB
Newer Older
1
2
3
4
// ================================================================================================
// 
// This file is part of the CAMPVis Software Framework.
// 
5
// If not explicitly stated otherwise: Copyright (C) 2012-2013, all rights reserved,
6
7
8
9
//      Christian Schulte zu Berge <christian.szb@in.tum.de>
//      Chair for Computer Aided Medical Procedures
//      Technische Universität München
//      Boltzmannstr. 3, 85748 Garching b. München, Germany
10
// 
11
12
// For a full list of authors and contributors, please refer to the file "AUTHORS.txt".
// 
13
14
15
16
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file 
// except in compliance with the License. You may obtain a copy of the License at
// 
// http://www.apache.org/licenses/LICENSE-2.0
17
// 
18
19
20
21
// Unless required by applicable law or agreed to in writing, software distributed under the 
// License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 
// either express or implied. See the License for the specific language governing permissions 
// and limitations under the License.
22
23
24
25
26
27
28
29
30
31
32
// 
// ================================================================================================

#ifndef GLREDUCTION_H__
#define GLREDUCTION_H__

#include "tgt/exception.h"
#include "tgt/tgt_gl.h"
#include "tgt/vector.h"

#include <string>
33
#include <vector>
34
35
36
37
38
39
40
41
42
43
44
45
46

namespace tgt {
    class FramebufferObject;
    class Shader;
    class Texture;
}

namespace campvis {
    class ImageData;
    class FaceGeometry;

    /**
     * Class performing a reduction of 2D image data using OpenGL.
47
     * \note    All methods need to be called from a valid OpenGL context.
48
49
50
     */
    class GlReduction {
    public:
51
52
53
54
55
        /// Operation to be performed by reduction
        enum ReductionOperator {
            MIN,                ///< Minimum
            MAX,                ///< Maximum
            PLUS,               ///< Sum (plus)
56
            MULTIPLICATION,     ///< Product (multiplication)
57
            MIN_MAX_DEPTH_ONLY  ///< Minimum/Maximum (CAUTION: WORKS ONLY with depth images!!!)
58
        };
59

60
61
62
63
64
        /**
         * Constructor
         * \param   reductionOperator   Operation to be performed by reduction
         */
        GlReduction(ReductionOperator reductionOperator);
65

66
67
68
69
        /**
         * Destructor
         */
        ~GlReduction();
70

71
72
73
74
75
76
77
        /**
         * Performs the reduction on the given image.
         * \note    Image must be two-dimensional!
         * \note    Reduction will be performed on a copy, \a image will not change.
         * \param   image   Pointer to ImageData to perform reduction on, must be two-dimensional.
         * \return  A vector of floats containing the reduction results for each channel of the input image.
         */
78
        std::vector<float> reduce(const ImageData* image);
79

80
81
82
83
84
85
86
        /**
         * Performs the reduction on the given OpenGL texture.
         * \note    Image must be two-dimensional!
         * \note    Reduction will be performed on a copy, \a texture will not change.
         * \param   image   Pointer to a texture to perform reduction on, must be two-dimensional.
         * \return  A vector of floats containing the reduction results for each channel of the input texture.
         */
87
        std::vector<float> reduce(const tgt::Texture* texture);
88

89
90

    private:
91
92
93
94
95
96
97
        /**
         * Generates the GLSL header corresponding to the given reduction operator.
         * \param   reductionOperator   Operation to be performed by reduction
         * \return  A std::string with the corresponding GLSL header.
         */
        static std::string generateGlslHeader(ReductionOperator reductionOperator);

98

99
        ReductionOperator _reductionOperator;   ///< Operation to be performed by reduction
100
        tgt::Shader* _shader1d;                 ///< OpenGL shader performing 1D reduction
101
102
        tgt::Shader* _shader2d;                 ///< OpenGL shader performing 2D reduction
        tgt::Shader* _shader3d;                 ///< OpenGL shader performing 3D reduction
103
        tgt::FramebufferObject* _fbo;           ///< FBO performing the reduction
104
105
106
107
108
109
110

        const static std::string loggerCat_;
    };

}

#endif // GLREDUCTION_H__