2.12.2021, 9:00 - 11:00: Due to updates GitLab may be unavailable for some minutes between 09:00 and 11:00.

imagerepresentationdisk.h 7.06 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-2014, all rights reserved,
6
7
//      Christian Schulte zu Berge <christian.szb@in.tum.de>
//      Chair for Computer Aided Medical Procedures
8
9
//      Technische Universitaet Muenchen
//      Boltzmannstr. 3, 85748 Garching b. Muenchen, 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
27
// 
// ================================================================================================

#ifndef IMAGEREPRESENTATIONDISK_H__
#define IMAGEREPRESENTATIONDISK_H__

28
#include "core/datastructures/genericabstractimagerepresentation.h"
29
30
31
32
33
34
35
36
#include "core/tools/endianhelper.h"
#include "core/tools/weaklytypedpointer.h"

namespace campvis {

    /**
     * Subclass of ImageData offering access to image data stored in binary form on the local harddisk.
     */
37
    class CAMPVIS_CORE_API ImageRepresentationDisk : public GenericAbstractImageRepresentation<ImageRepresentationDisk> {
38
39
    public:
        /**
40
41
         * Creates a new ImageRepresentationDisk with the given parameters and automatically
         * adds it to \a parent which will take ownerwhip.
42
         *
43
44
45
46
47
48
49
50
         * \note    You do \b not own the returned pointer.
         *
         * \param   parent     Image this representation represents, must not be 0, will take ownership of the returned pointer.
         * \param   url        Path to file with raw data
         * \param   type       Base type of data
         * \param   offset     Offset of first data element in file (in bytes)
         * \param   endianness Endianess of data
         * \param   stride     Number of _elements_ _between_ adjacent elements for each dimension (\see ImageRepresentationDisk::_stride).
51
         * \param   multichannelSideBySide  Flag whether multichannel images are stored side by side
52
         * \return  A pointer to the newly created ImageRepresentationDisk, you do \b not own this pointer!
53
         */
54
        static ImageRepresentationDisk* create(
55
            ImageData* parent,
56
57
58
            const std::string& url,
            WeaklyTypedPointer::BaseType type,
            size_t offset = 0,
schultezub's avatar
schultezub committed
59
            EndianHelper::Endianness endianness = EndianHelper::IS_LITTLE_ENDIAN,
60
61
            const tgt::svec3& stride = tgt::svec3::zero,
            bool multichannelSideBySide = false
62
63
            );

64

65
66
67
68
69
        /**
         * Destructor
         */
        virtual ~ImageRepresentationDisk();

70
71
72
        /**
         * Performs a conversion of \a source to an ImageRepresentationLocal if feasible.
         * Returns 0 if conversion was not successful or source representation type is not compatible.
73
         * \note    The callee, respectively the callee's parent, has the ownership of the returned pointer.
74
         * \param   source  Source image representation for conversion.
75
         * \return  A pointer to a local representation of \a source or 0 on failure. The caller does \b not have ownership.
76
77
         */
        static ImageRepresentationDisk* tryConvertFrom(const AbstractImageRepresentation* source);
78

79
80
        /// \see AbstractImageRepresentation::clone()
        virtual ImageRepresentationDisk* clone(ImageData* newParent) const;
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102

        /// \see AbstractImageRepresentation::getLocalMemoryFootprint()
        virtual size_t getLocalMemoryFootprint() const;

        /// \see AbstractImageRepresentation::getVideoMemoryFootprint()
        virtual size_t getVideoMemoryFootprint() const;


        /**
         * Downloads the whole image data to local memory.
         * \note    The caller has to take ownership of the returned pointer.
         * \return  Pointer to the image data in the local memory, to be owned by caller.
         */
        WeaklyTypedPointer getImageData() const;


        /**
         * Returns the base type of the data
         * \return _type
         */
        WeaklyTypedPointer::BaseType getBaseType() const;

103
104
105
106
107
108
109
110
111
112
113
114
    protected:
        /**
         * Creates a new ImageData disk representation.
         * \note  The Constructor is protected since image representations are not supposed to be
         *        created via the new operator - use ImageRepresentationDisk::create() instead.
         *
         * \param parent            Image this representation represents, must not be 0.
         * \param url               Path to file with raw data
         * \param type              Base type of data
         * \param offset            Offset of first data element in file (in bytes)
         * \param endianness        Endianess of data
         * \param stride            Number of _elements_ _between_ adjacent elements for each dimension (\see ImageRepresentationDisk::_stride).
115
         * \param multichannelSideBySide    Flag whether multichannel images are stored side by side
116
117
118
119
120
121
         */
        ImageRepresentationDisk(
            ImageData* parent,
            const std::string& url,
            WeaklyTypedPointer::BaseType type,
            size_t offset = 0,
schultezub's avatar
schultezub committed
122
            EndianHelper::Endianness endianness = EndianHelper::IS_LITTLE_ENDIAN,
123
124
            const tgt::svec3& stride = tgt::svec3::zero,
            bool multichannelSideBySide = false
125
126
            );

127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
        /**
         * Calculates the canonical stride for the given image size.
         * \param size  Image size (number of elements per dimension).
         * \return      (0, size.x, size.x * size.y)
         */
        tgt::svec3 getCanonicStride(const tgt::svec3& size) const;

        std::string _url;                       ///< path to file with raw data
        size_t _offset;                         ///< offset of first data element in file (in bytes)
        WeaklyTypedPointer::BaseType _type;     ///< base type of data
        EndianHelper::Endianness _endianess;    ///< endianess of data
        
        /**
         * Number of _elements_ _between_ adjacent elements for each dimension.
         * If the stride is 0 for a dimension, the elements are assumed to be tightly packed, hence for
         * the x-dimension 0, for the y-dimension _size.x and for the z-dimension (_size.x * _size.y).
         **/
        tgt::svec3 _stride;

146
147
        bool _multichannelSideBySide;           ///< Flag whether multichannel images are stored side by side

148
149
150
151
152
153
        static const std::string loggerCat_;
    };

}

#endif // IMAGEREPRESENTATIONDISK_H__