imagedata.cpp 5.18 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 cgt::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
36
        , _numElements(cgt::hmul(size))
        , _mappingInformation(size, cgt::vec3(0.f), cgt::vec3(1.f)) // TODO: get offset/voxel size as parameter or put default values into ImageMappingInformation ctor.
schultezub's avatar
schultezub committed
37
    {
38
        cgtAssert(numChannels > 0, "Number of channels must be greater than 0!");
schultezub's avatar
schultezub committed
39
40
41
    }

    ImageData::~ImageData() {
42
43
44
45
        clearRepresentations();
    }

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

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

        return toReturn;
    }

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

        return toReturn;
schultezub's avatar
schultezub committed
68
69
70
71
72
73
    }

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

74
    const cgt::svec3& ImageData::getSize() const {
schultezub's avatar
schultezub committed
75
76
77
        return _size;
    }

78
79
80
81
    size_t ImageData::getNumChannels() const {
        return _numChannels;
    }

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

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

90
    cgt::Bounds ImageData::getWorldBounds() const {
91
        return getWorldBounds(cgt::svec3(0, 0, 0), cgt::svec3(_size));
schultezub's avatar
schultezub committed
92
    }
93

94
    cgt::Bounds ImageData::getWorldBounds(const cgt::svec3& llf, const cgt::svec3& urb) const {
95
        return cgt::Bounds(_mappingInformation.getVoxelToWorldMatrix() * cgt::vec3(llf), _mappingInformation.getVoxelToWorldMatrix() * cgt::vec3(urb));
schultezub's avatar
schultezub committed
96
97
    }

98
99
100
101
    size_t ImageData::getNumElements() const {
        return _numElements;
    }

102
    size_t ImageData::positionToIndex(const cgt::svec3& position) const {
103
104
        return position.x + (position.y * _size.x) + (position.z * _size.x * _size.y);
    }
105

106
    cgt::svec3 ImageData::indexToPosition(size_t index) const {
107
108
109
        size_t z = index / (_size.x * _size.y);
        size_t y = (index % (_size.x * _size.y)) / _size.x;
        size_t x = index % _size.x;
110
        return cgt::svec3(x, y, z);
111
112
    }

113
    void ImageData::clearRepresentations() {
114
        for (tbb::concurrent_vector<const AbstractImageRepresentation*>::iterator it = _representations.begin(); it != _representations.end(); ++it)
115
116
117
118
            delete *it;
        _representations.clear();
    }

119
    void ImageData::addRepresentation(const AbstractImageRepresentation* representation) {
120
        cgtAssert(representation != 0, "Representation must not be 0.");
121
122
123
124
125
126
127
128
        _representations.push_back(representation);
    }

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

129
130
131
132
    std::string ImageData::getTypeAsString() const {
        return "Image Data";
    }

schultezub's avatar
schultezub committed
133
}