glreduction.h 4.18 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
// 
// ================================================================================================

#ifndef GLREDUCTION_H__
#define GLREDUCTION_H__

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

32
33
#include "core/coreapi.h"

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

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

namespace campvis {
    class ImageData;
    class FaceGeometry;

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

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

68
69
70
71
        /**
         * Destructor
         */
        ~GlReduction();
72

73
74
75
76
77
78
79
        /**
         * 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.
         */
80
        std::vector<float> reduce(const ImageData* image);
81

82
83
84
85
86
87
88
        /**
         * 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.
         */
89
        std::vector<float> reduce(const tgt::Texture* texture);
90

91
92

    private:
93
94
95
96
97
98
99
        /**
         * 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);

100

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

        const static std::string loggerCat_;
    };

}

#endif // GLREDUCTION_H__