forked from carlren/ORUtils
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathImage.h
executable file
·109 lines (93 loc) · 3.12 KB
/
Image.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
// Copyright 2014-2017 Oxford University Innovation Limited and the authors of InfiniTAM
#pragma once
#include "MemoryBlock.h"
#include "Vector.h"
#ifndef __METALC__
namespace ORUtils
{
/** \brief
Represents images, templated on the pixel type
*/
template <typename T>
class Image : private MemoryBlock<T>
{
public:
/** Expose public MemoryBlock<T> member variables. */
using MemoryBlock<T>::dataSize;
using MemoryBlock<T>::hasCPU;
using MemoryBlock<T>::hasCUDA;
/** Expose public MemoryBlock<T> datatypes. */
using typename MemoryBlock<T>::MemoryCopyDirection;
using MemoryBlock<T>::CPU_TO_CPU;
using MemoryBlock<T>::CPU_TO_CUDA;
using MemoryBlock<T>::CUDA_TO_CPU;
using MemoryBlock<T>::CUDA_TO_CUDA;
/** Expose public MemoryBlock<T> member functions. */
using MemoryBlock<T>::Clear;
using MemoryBlock<T>::GetData;
using MemoryBlock<T>::GetDataConst;
using MemoryBlock<T>::GetElement;
#ifdef COMPILE_WITH_METAL
using MemoryBlock<T>::GetMetalBuffer();
#endif
using MemoryBlock<T>::UpdateDeviceFromHost;
using MemoryBlock<T>::UpdateHostFromDevice;
/** Size of the image in pixels. */
Vector2<int> noDims;
/** Initialize an empty image of the given size, either
on CPU only or on both CPU and GPU.
*/
Image(Vector2<int> noDims, bool allocate_CPU, bool allocate_CUDA, bool metalCompatible = true)
: MemoryBlock<T>(noDims.x * noDims.y, allocate_CPU, allocate_CUDA, metalCompatible)
{
this->noDims = noDims;
}
Image(bool allocate_CPU, bool allocate_CUDA, bool metalCompatible = true)
: MemoryBlock<T>(0, allocate_CPU, allocate_CUDA, metalCompatible)
{
this->noDims = Vector2<int>(0, 0);
}
Image(Vector2<int> noDims, MemoryDeviceType memoryType)
: MemoryBlock<T>(noDims.x * noDims.y, memoryType)
{
this->noDims = noDims;
}
/** Resize an image, losing all old image data.
Essentially any previously allocated data is
released, new memory is allocated.
*/
void ChangeDims(Vector2<int> newDims, bool forceReallocation = true)
{
MemoryBlock<T>::Resize(newDims.x * newDims.y, forceReallocation);
noDims = newDims;
}
void SetFrom(const Image<T> *source, MemoryCopyDirection memoryCopyDirection, void *stream = nullptr)
{
ChangeDims(source->noDims);
MemoryBlock<T>::SetFrom(source, memoryCopyDirection, stream);
}
// void SetTo(T value, MemoryCopyDirection memoryCopyDirection)
// {
// MemoryBlock<T>::SetTo(value, memoryCopyDirection);
// }
void Swap(Image<T>& rhs)
{
MemoryBlock<T>::Swap(rhs);
std::swap(this->noDims, rhs.noDims);
}
// Suppress the default copy constructor and assignment operator
Image(const Image& image)
: MemoryBlock<T>(image.noDims.x * image.noDims.y, image.isAllocated_CPU,image.isAllocated_CUDA, image.isMetalCompatible){
this->noDims = image.noDims;
if(this->isAllocated_CPU)
this->SetFrom(&image, CPU_TO_CPU);
if(this->isAllocated_CUDA)
this->SetFrom(&image, CUDA_TO_CUDA);
#ifndef NDEBUG
MemoryBlock<T>::SyncronizeTimeStamp();
#endif
};
Image& operator=(const Image&);
};
}
#endif