voxelhierarchymapper.h 4.48 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
// ================================================================================================
// 
// This file is part of the CAMPVis Software Framework.
// 
// If not explicitly stated otherwise: Copyright (C) 2012-2013, all rights reserved,
//      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
// 
// For a full list of authors and contributors, please refer to the file "AUTHORS.txt".
// 
// 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
// 
// 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.
// 
// ================================================================================================

#ifndef VOXELHIERARCHYMAPPER_H__
#define VOXELHIERARCHYMAPPER_H__

#include <string>

30
31
#include "cgt/framebufferobject.h"
#include "cgt/shadermanager.h"
32

33
#include "core/datastructures/facegeometry.h"
34
#include "modules/modulesapi.h"
35

36
37
#include <memory>

38
namespace cgt {
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
    class FramebufferObject;
    class Shader;
    class Texture;
}

namespace campvis {
    class AbstractTransferFunction;
    class ImageRepresentationGL;

    /**
     * Helper class to create and manage a voxel hierarchy texture using mip maps.
     * Implementation following the Paper "Voxel-based Global Illumination" by Thiedemann et al. (2011)
     * 
     * \note    All methods (incl. constructor) need a valid OpenGL context when called.
     */
54
    class CAMPVIS_MODULES_API VoxelHierarchyMapper {
55
56
57
58
59
60
61
62
63
64
65
66
67
68
    public:
        /**
         * Creates a VoxelHierarchyMapper and prepare the framebuffer and shader for next function calls of the object.
         * \note    Needs valid OpenGL context!
         */
        VoxelHierarchyMapper();

        /// Destructor
        ~VoxelHierarchyMapper();


        void createHierarchy(const ImageRepresentationGL* image, AbstractTransferFunction* transferFunction);


69
70
71
        cgt::Texture* getXorBitmaskTexture() { return _xorBitmaskTexture; }
        cgt::Texture* getHierarchyTexture() { return _hierarchyTexture; }

72
73
74
75
76
77
        size_t getBrickSize() { return _brickSize; }
        size_t getBrickDepth() { return _brickDepth; }
        GLuint getMaxMipmapLevel() { return _maxMipmapLevel; }

    private:

78
79
        void createXorBitmaskTexture();

80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
        /**
         * Computes the maximum level of mipmapping.
         * \param   resolution                  largest dimension of the voxelized volume.
         */
        GLuint computeMaxLevel(size_t resolutionX, size_t resolutionY);
        
        /**
         * renders the mipmaps of the texture with the passed texture object and resolution.
         */
        void renderMipmaps();

        void createEmptyTextureWithMipMaps();

        void renderInitialHierarchy(const ImageRepresentationGL* image, AbstractTransferFunction* transferFunction);

95
96
        cgt::svec3 _dimBricks;                      ///< number of bricks in each dimension
        cgt::svec3 _dimPackedBricks;                ///< number of elements when bricks are tightly packed
97
98
99
100
        size_t _brickSize;                          ///< number of voxels a brick is covering in x, y dimension
        size_t _brickDepth;                         ///< number of voxel a brick is covering in its depth dimension
        GLuint _maxMipmapLevel;                     ///< Maximum mipmap level

101
        cgt::Shader* _xorBitmaskShader;             ///< Shader to create the XOR bitmask texture
102
103
        cgt::Shader* _hierarchyRendererShader;      ///< Shader to render the initial hierarchy texture
        cgt::Shader* _mimapRendererShader;          ///< Shader to render the mipmap pyramid
104

105
        cgt::FramebufferObject* _fbo;               ///< FBO used for rendering
106
        cgt::Texture* _xorBitmaskTexture;           ///< Texture holding the 128x128 possible combinations of uvec4 bitmasks
107
        cgt::Texture* _hierarchyTexture;            ///< The OpenGL texture storing the voxel hierarchy
108

109
        std::unique_ptr<FaceGeometry> _quad;
110
111
112
113
114
115
116
117


        static std::string loggerCat_;
    };

}

#endif // VOXELHIERARCHYMAPPER_H__