The expiration time for new job artifacts in CI/CD pipelines is now 30 days (GitLab default). Previously generated 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

imagerepresentationlocal.cpp 5.52 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
//      Christian Schulte zu Berge <christian.szb@in.tum.de>
//      Chair for Computer Aided Medical Procedures
8
9
//      Technische Universitt Mnchen
//      Boltzmannstr. 3, 85748 Garching b. Mnchen, 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
// 
// ================================================================================================

#include "imagerepresentationlocal.h"

27
#include "tgt/glcontextmanager.h"
28
29
#include <tbb/tbb.h>
#include <tbb/spin_mutex.h>
30
#include "core/datastructures/imagerepresentationdisk.h"
31
#include "core/datastructures/imagerepresentationgl.h"
32
#include "core/datastructures/genericimagerepresentationlocal.h"
33
34
#include "core/tools/opengljobprocessor.h"
#include "core/tools/job.h"
35

36
37
38
39
#ifdef CAMPVIS_HAS_MODULE_ITK
#include "modules/itk/core/genericimagerepresentationitk.h"
#endif

40
41
42
43
44
45
#include <limits>

namespace campvis {
    
    const std::string ImageRepresentationLocal::loggerCat_ = "CAMPVis.core.datastructures.ImageRepresentationLocal";

46
    ImageRepresentationLocal::ImageRepresentationLocal(ImageData* parent, WeaklyTypedPointer::BaseType baseType)
47
        : GenericAbstractImageRepresentation<ImageRepresentationLocal>(parent)
48
49
50
51
52
53
        , _baseType(baseType)
    {
        _intensityRangeDirty = true;
    }

    ImageRepresentationLocal::~ImageRepresentationLocal() {
54

55
56
57
58
59
60
61
62
63
64
    }

    const Interval<float>& ImageRepresentationLocal::getNormalizedIntensityRange() const {
        if (_intensityRangeDirty)
            computeNormalizedIntensityRange();

        return _normalizedIntensityRange;
    }

    void ImageRepresentationLocal::computeNormalizedIntensityRange() const {
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
        _normalizedIntensityRange = Interval<float>(); // reset interval to empty one
        tbb::spin_mutex _mutex; // mutex to protect for concurrent access

        tbb::parallel_for(tbb::blocked_range<size_t>(0, getNumElements()), [&] (const tbb::blocked_range<size_t>& range) {
            float localMin = std::numeric_limits<float>::max();
            float localMax = -std::numeric_limits<float>::max();

            for (size_t i = range.begin(); i != range.end(); ++i) {
                float value = this->getElementNormalized(i, 0);
                localMax = std::max(localMax, value);
                localMin = std::min(localMin, value);
            }

            {
                // TODO: there is probably a more elegant method...
                tbb::spin_mutex::scoped_lock(mutex);
                _normalizedIntensityRange.nibble(localMin);
                _normalizedIntensityRange.nibble(localMax);
            }
        });

86
87
88
        _intensityRangeDirty = false;
    }

89
    ImageRepresentationLocal* ImageRepresentationLocal::create(const ImageData* parent, WeaklyTypedPointer wtp) {
90
#define CONVERT_DISK_TO_GENERIC_LOCAL(baseType,numChannels) \
91
        return GenericImageRepresentationLocal<baseType, numChannels>::create( \
92
            const_cast<ImageData*>(parent), \
93
94
            reinterpret_cast< TypeTraits<baseType, numChannels>::ElementType*>(wtp._pointer));

95
#define DISPATCH_DISK_TO_GENERIC_LOCAL_CONVERSION(numChannels) \
96
        if (parent->getNumChannels() == (numChannels)) { \
97
            switch (wtp._baseType) { \
98
                case WeaklyTypedPointer::UINT8: \
99
                    CONVERT_DISK_TO_GENERIC_LOCAL(uint8_t, (numChannels)) \
100
                case WeaklyTypedPointer::INT8: \
101
                    CONVERT_DISK_TO_GENERIC_LOCAL(int8_t, (numChannels)) \
102
                case WeaklyTypedPointer::UINT16: \
103
                    CONVERT_DISK_TO_GENERIC_LOCAL(uint16_t, (numChannels)) \
104
                case WeaklyTypedPointer::INT16: \
105
                    CONVERT_DISK_TO_GENERIC_LOCAL(int16_t, (numChannels)) \
106
                case WeaklyTypedPointer::UINT32: \
107
                    CONVERT_DISK_TO_GENERIC_LOCAL(uint32_t, (numChannels)) \
108
                case WeaklyTypedPointer::INT32: \
109
                    CONVERT_DISK_TO_GENERIC_LOCAL(int32_t, (numChannels)) \
110
                case WeaklyTypedPointer::FLOAT: \
111
                    CONVERT_DISK_TO_GENERIC_LOCAL(float, (numChannels)) \
112
113
114
115
116
117
                default: \
                    tgtAssert(false, "Should not reach this - wrong base data type!"); \
                    return 0; \
            } \
        }

118
119
120
121
        DISPATCH_DISK_TO_GENERIC_LOCAL_CONVERSION(1)
        else DISPATCH_DISK_TO_GENERIC_LOCAL_CONVERSION(2)
        else DISPATCH_DISK_TO_GENERIC_LOCAL_CONVERSION(3)
        else DISPATCH_DISK_TO_GENERIC_LOCAL_CONVERSION(4)
122
        else DISPATCH_DISK_TO_GENERIC_LOCAL_CONVERSION(6)
123
124
125
126
127
        else {
            tgtAssert(false, "Should not reach this - wrong number of channel!");
            return 0;
        }
    }
128
129


130
}