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

imagedata.cpp 5.5 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
#include "imagedata.h"

schultezub's avatar
schultezub committed
27
28
namespace campvis {
    const std::string ImageData::loggerCat_ = "CAMPVis.core.datastructures.ImageData";
schultezub's avatar
schultezub committed
29

30
    ImageData::ImageData(size_t dimensionality, const tgt::svec3& size, size_t numChannels) 
schultezub's avatar
schultezub committed
31
32
        : AbstractData()
        , _dimensionality(dimensionality)
schultezub's avatar
schultezub committed
33
        , _size(size)
34
        , _numChannels(numChannels)
35
        , _numElements(tgt::hmul(size))
36
        , _mappingInformation(size, tgt::vec3(0.f), tgt::vec3(1.f)) // TODO: get offset/voxel size as parameter or put default values into ImageMappingInformation ctor.
schultezub's avatar
schultezub committed
37
    {
38
        tgtAssert(numChannels > 0, "Number of channels must be greater than 0!");
39
40
        tgtAssert(_dimensionality >= 3 || _size.z == 1, "Dimensionality and size mismatch: A 2D image must have size.z = 1!");
        tgtAssert(_dimensionality >= 2 || _size.y == 1, "Dimensionality and size mismatch: A 1D image must have size.y = 1!");
schultezub's avatar
schultezub committed
41
42
43
    }

    ImageData::~ImageData() {
44
45
46
47
        clearRepresentations();
    }

    ImageData* ImageData::clone() const {
48
        ImageData* toReturn = new ImageData(_dimensionality, _size, _numChannels);
49
        toReturn->_mappingInformation = _mappingInformation;
50
51
52
        for (auto it = this->_representations.begin(); it != this->_representations.end(); ++it) {
            (*it)->clone(toReturn);
        }
53
54
55
56
57
        return toReturn;
    }

    size_t ImageData::getLocalMemoryFootprint() const {
        size_t toReturn = sizeof(*this) + _representations.size() * sizeof(AbstractImageRepresentation*);
58
        for (tbb::concurrent_vector<const AbstractImageRepresentation*>::const_iterator it = _representations.begin(); it != _representations.end(); ++it)
59
60
61
62
63
64
65
            toReturn += (*it)->getLocalMemoryFootprint();

        return toReturn;
    }

    size_t ImageData::getVideoMemoryFootprint() const {
        size_t toReturn = 0;
66
        for (tbb::concurrent_vector<const AbstractImageRepresentation*>::const_iterator it = _representations.begin(); it != _representations.end(); ++it)
67
68
69
            toReturn += (*it)->getVideoMemoryFootprint();

        return toReturn;
schultezub's avatar
schultezub committed
70
71
72
73
74
75
76
77
78
79
    }

    size_t ImageData::getDimensionality() const {
        return _dimensionality;
    }

    const tgt::svec3& ImageData::getSize() const {
        return _size;
    }

80
81
82
83
    size_t ImageData::getNumChannels() const {
        return _numChannels;
    }

schultezub's avatar
schultezub committed
84
85
86
87
    const ImageMappingInformation& ImageData::getMappingInformation() const {
        return _mappingInformation;
    }

88
89
90
91
    void ImageData::setMappingInformation(const ImageMappingInformation& imi) {
        _mappingInformation = imi;
    }

92
93
    tgt::Bounds ImageData::getWorldBounds() const {
        return tgt::Bounds(_mappingInformation.getOffset(), _mappingInformation.getOffset() + (tgt::vec3(_size) * _mappingInformation.getVoxelSize()));
schultezub's avatar
schultezub committed
94
    }
95

schultezub's avatar
schultezub committed
96
97
98
99
100
101
    tgt::Bounds ImageData::getWorldBounds(const tgt::svec3& llf, const tgt::svec3& urb) const {
        return tgt::Bounds(
            _mappingInformation.getOffset() + (tgt::vec3(llf) * _mappingInformation.getVoxelSize()),
            _mappingInformation.getOffset() + (tgt::vec3(urb) * _mappingInformation.getVoxelSize()));
    }

102
103
104
105
106
107
108
    size_t ImageData::getNumElements() const {
        return _numElements;
    }

    size_t ImageData::positionToIndex(const tgt::svec3& position) const {
        return position.x + (position.y * _size.x) + (position.z * _size.x * _size.y);
    }
109
110
111
112
113
114
115
116

    tgt::svec3 ImageData::indexToPosition(size_t index) const {
        size_t z = index / (_size.x * _size.y);
        size_t y = (index % (_size.x * _size.y)) / _size.x;
        size_t x = index % _size.x;
        return tgt::svec3(x, y, z);
    }

117
    void ImageData::clearRepresentations() {
118
        for (tbb::concurrent_vector<const AbstractImageRepresentation*>::iterator it = _representations.begin(); it != _representations.end(); ++it)
119
120
121
122
            delete *it;
        _representations.clear();
    }

123
124
125
126
127
128
129
130
131
132
    void ImageData::addRepresentation(const AbstractImageRepresentation* representation) {
        tgtAssert(representation != 0, "Representation must not be 0.");
        _representations.push_back(representation);
    }

    void ImageData::setInitialRepresentation(const AbstractImageRepresentation* representation) {
        clearRepresentations();
        addRepresentation(representation);
    }

schultezub's avatar
schultezub committed
133
}