Currently job artifacts in CI/CD pipelines on LRZ GitLab never expire. Starting from Wed 26.1.2022 the default expiration time will be 30 days (GitLab default). Currently existing artifacts in already completed jobs will not be affected by the change. The latest artifacts for all jobs in the latest successful pipelines will be kept. More information: https://gitlab.lrz.de/help/user/admin_area/settings/continuous_integration.html#default-artifacts-expiration

weaklytypedpointer.h 7.15 KB
Newer Older
1
2
// ================================================================================================
// 
schultezub's avatar
schultezub committed
3
// This file is part of the CAMPVis Software Framework.
4
// 
5
// If not explicitly stated otherwise: Copyright (C) 2012-2014, all rights reserved,
schultezub's avatar
schultezub committed
6
//      Christian Schulte zu Berge <christian.szb@in.tum.de>
7
//      Chair for Computer Aided Medical Procedures
8
9
//      Technische Universitaet Muenchen
//      Boltzmannstr. 3, 85748 Garching b. Muenchen, Germany
10
// 
schultezub's avatar
schultezub committed
11
// For a full list of authors and contributors, please refer to the file "AUTHORS.txt".
12
// 
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
// 
// ================================================================================================

schultezub's avatar
schultezub committed
25
26
27
#ifndef WEAKLYTYPEDPOINTER_H__
#define WEAKLYTYPEDPOINTER_H__

28
29
30
31
32
#include "cgt/assert.h"
#include "cgt/logmanager.h"
#include "cgt/texture.h"
#include "cgt/tgt_gl.h"
#include "cgt/types.h"
schultezub's avatar
schultezub committed
33

34
35
36
37
38
#ifdef CAMPVIS_HAS_MODULE_DEVIL
#include <IL/il.h>
#include <IL/ilu.h>
#endif

39
40
#include "core/coreapi.h"

schultezub's avatar
schultezub committed
41
namespace campvis {
schultezub's avatar
schultezub committed
42

schultezub's avatar
schultezub committed
43
    /**
44
45
     * Struct for handling void pointers slightly more type safe.
     * Therefore it stores an enum value together with the pointer for deducing its data type.
46
     * \note    WeaklyTypedPointer takes _not_ take ownership of its pointer, hence it won't take care of deleting it!
47
     */
48
    struct CAMPVIS_CORE_API WeaklyTypedPointer {
schultezub's avatar
schultezub committed
49
50
51
        /**
         * Base data type.
         **/
52
        enum BaseType {
schultezub's avatar
schultezub committed
53
54
55
56
57
58
            UINT8,      ///< unsigned 8 bit integer
            INT8,       ///< signed 8 bit integer
            UINT16,     ///< unsigned 16 bit integer
            INT16,      ///< signed 16 bit integer
            UINT32,     ///< unsigned 32 bit integer
            INT32,      ///< signed 32 bit integer
schultezub's avatar
schultezub committed
59
            FLOAT      ///< float
schultezub's avatar
schultezub committed
60
61
62
        };

        /**
schultezub's avatar
schultezub committed
63
         * Returns the number of bytes occupied by one element of the type \a bt with \a numChannels channels.
64
         * 
65
         * \note    There is a compile time version in WeaklyTypedPointerTraits.
66
         * \sa      WeaklyTypedPointerTraits::numBytes()
schultezub's avatar
schultezub committed
67
68
69
         * \param   bt          Image base type
         * \param   numChannels Number of channels per element.
         * \returns The number of bytes occupied by one image element with \a numChannels channels of the type \a bt.
70
         */
schultezub's avatar
schultezub committed
71
        static size_t numBytes(BaseType bt, size_t numChannels = 1);
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91

        /**
         * Calculates the number of channels for the given OpenGL format.
         * Kinda inverse function of getGlFormat().
         * \sa      WeaklyTypedPointer::getGlFormat()
         * \param   glFormat    OpenGL format
         * \return  Number of channels of the given OpenGL format.
         */
        static size_t numChannels(GLint glFormat);

        /**
         * Calculates the base type for the given OpenGL data type.
         * Kinda inverse function of getGlDataType().
         * \sa      WeaklyTypedPointer::getGlDataTypet()
         * \param   glDataType  OpenGL format
         * \return  Base type of the given OpenGL data type.
         */
        static WeaklyTypedPointer::BaseType baseType(GLenum glDataType);

// = Starting with the real stuff =================================================================
schultezub's avatar
schultezub committed
92
93

        /**
schultezub's avatar
schultezub committed
94
         * Constructs a new weakly typed pointer.
95
96
         * \param pt            Base data type of the pointer.
         * \param numChannels   Number of channels, must be in [1, 4]!
97
         * \param ptr           Pointer to the data, WeaklyTypedPointer will _not_ take ownership of it.
schultezub's avatar
schultezub committed
98
         */
99
100
101
        WeaklyTypedPointer(BaseType pt, size_t numChannels, void* ptr);

        /**
102
103
104
105
106
         * Empty default constructor, you have to initialize everything yourself.
         */
        WeaklyTypedPointer();

        /**
107
108
109
110
         * Destructor, does _not_ delete the handled pointer!
         */
        virtual ~WeaklyTypedPointer();

111
112
        bool operator==(const WeaklyTypedPointer& rhs) const;

schultezub's avatar
schultezub committed
113

schultezub's avatar
schultezub committed
114
115
116
117
        /**
         * Returns the number of bytes occupied by one element of the type of this pointer.
         * \returns The number of bytes occupied by one element of the type of this pointer.
         */
118
119
120
121
122
        size_t getNumBytesPerElement() const;

        GLint getGlFormat() const;

        GLenum getGlDataType() const;
schultezub's avatar
schultezub committed
123

124
125
        GLint getGlInternalFormat() const;

126
127
128
129
        bool isInteger() const;

        bool isSigned() const;

130
131
132
133
134
135
#ifdef CAMPVIS_HAS_MODULE_DEVIL
        ILenum getIlFormat() const;

        ILenum getIlDataType() const;
#endif

schultezub's avatar
schultezub committed
136

137
        BaseType _baseType;         ///< Base data type of the pointer
138
        size_t _numChannels;        ///< Number of channels, must be in [1, 4]!
schultezub's avatar
schultezub committed
139
        void* _pointer;             ///< Pointer to the data
140
141
142
143

    private:

        static const std::string loggerCat_;
schultezub's avatar
schultezub committed
144
145
    };

146
// = Some traits for WeaklyTypedPointers ==========================================================
147
148
149
150
151

    /**
     * Some compile time traits for WeaklyTypedPointers.
     * \tparam  pt  Data type to check.
     */
152
    template<WeaklyTypedPointer::BaseType pt>
153
154
155
156
157
158
    struct WeaklyTypedPointerTraits {
        /**
         * Returns the number of bytes occupied by one element of the given type.
         * 
         * \note    There is a runtime version in WeaklyTypedPointer.
         * \sa      WeaklyTypedPointer::numBytes()
159
         * \tparam  bt  Data type to check.
160
161
162
163
164
165
166
167
         * \returns The number of bytes occupied by one element of the given type.
         */
        static size_t numBytes() { return 0; };
    };

// - Template Specialization ----------------------------------------------------------------------

    template<>
schultezub's avatar
schultezub committed
168
    struct WeaklyTypedPointerTraits<WeaklyTypedPointer::UINT8> {
169
        static size_t numBytes() { return 1; };
170
171
172
    };

    template<>
schultezub's avatar
schultezub committed
173
174
    struct WeaklyTypedPointerTraits<WeaklyTypedPointer::INT8> {
        static size_t numBytes() { return 1; };
175
176
177
    };

    template<>
schultezub's avatar
schultezub committed
178
179
    struct WeaklyTypedPointerTraits<WeaklyTypedPointer::UINT16> {
        static size_t numBytes() { return 2; };
180
181
182
    };

    template<>
schultezub's avatar
schultezub committed
183
184
    struct WeaklyTypedPointerTraits<WeaklyTypedPointer::INT16> {
        static size_t numBytes() { return 2; };
185
186
187
    };

    template<>
schultezub's avatar
schultezub committed
188
189
    struct WeaklyTypedPointerTraits<WeaklyTypedPointer::UINT32> {
        static size_t numBytes() { return 4; };
190
191
192
    };

    template<>
schultezub's avatar
schultezub committed
193
194
    struct WeaklyTypedPointerTraits<WeaklyTypedPointer::INT32> {
        static size_t numBytes() { return 4; };
195
196
197
198
199
200
201
    };

    template<>
    struct WeaklyTypedPointerTraits<WeaklyTypedPointer::FLOAT> {
        static size_t numBytes() { return sizeof(float); };
    };

schultezub's avatar
schultezub committed
202
203
204
}

#endif // WEAKLYTYPEDPOINTER_H__