Repository navigation
Expand file tree
/
Copy pathrawFile.h
More file actions
167 lines (132 loc) · 4.02 KB
/
Copy pathrawFile.h
File metadata and controls
167 lines (132 loc) · 4.02 KB
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
// This file is distributed under the MIT license.
// See the LICENSE file for details.
#pragma once
#include <cstdio>
#include <cstddef>
#include <cstdint>
#include <limits>
// #include "common.hpp"
// #include "linalg.hpp"
#include <owl/common/math/vec.h>
#include <owl/common/math/box.h>
namespace raw
{
using Vec3i = owl::vec3i;
using Vec3l = owl::vec3l;
enum class DataFormat
{
Unspecified,
Int8,
Int16,
Int32,
UInt8,
UInt16,
UInt32,
Float32,
Double64,
// Keep last!
Count,
};
struct DataFormatInfo
{
DataFormat dataFormat;
uint8_t sizeInBytes;
};
static DataFormatInfo DataFormatInfoTable[(int)DataFormat::Count] = {
{ DataFormat::Unspecified, 0 },
{ DataFormat::Int8, 1 },
{ DataFormat::Int16, 2 },
{ DataFormat::Int32, 4 },
{ DataFormat::UInt8, 1 },
{ DataFormat::UInt16, 2 },
{ DataFormat::UInt32, 4 },
{ DataFormat::Float32, 4 },
{ DataFormat::Double64, 8}
};
// Equivalent to table, but can be used in CUDA device code
constexpr inline uint8_t getSizeInBytes(DataFormat dataFormat)
{
if (dataFormat == DataFormat::Int8 || dataFormat == DataFormat::UInt8)
return 1;
if (dataFormat == DataFormat::Int16 || dataFormat == DataFormat::UInt16)
return 2;
if (dataFormat == DataFormat::Int32 || dataFormat == DataFormat::UInt32)
return 4;
if (dataFormat == DataFormat::Float32)
return 4;
if (dataFormat == DataFormat::Double64)
return 8;
return 255;
}
/*!
* @brief Data source base class for file I/O
*/
class DataSource
{
public:
virtual ~DataSource() {}
virtual std::size_t read(char* buf, std::size_t len) = 0;
virtual std::size_t write(char const* buf, std::size_t len) = 0;
virtual bool seek(std::size_t pos) = 0;
virtual bool flush() = 0;
virtual bool good() const = 0;
};
class RawR : public DataSource
{
public:
RawR(char const* fileName, char const* mode);
RawR(FILE* file);
~RawR();
virtual std::size_t read(char* buf, std::size_t len);
virtual std::size_t write(char const* buf, std::size_t len);
virtual bool seek(std::size_t pos);
virtual bool flush();
virtual bool good() const;
/*!
* @brief Set structured volume dimensions
*/
void setDims(Vec3l dims);
/*!
* @brief Structured volume dimensions parsed from file name,
* 0 if not successful
*/
Vec3l getDims() const;
/*!
* @brief Set structured volume data format
*/
void setDataFormat(DataFormat dataFormat);
/*!
* @brief Get structured volume data format
*/
DataFormat getDataFormat() const;
/*!
* @brief Get bytes per voxel
*/
size_t getBytesPerVoxel() const;
/*!
* @brief Get data
*/
const std::vector<float> getDataVector() const;
/*!
* @brief Get domain of the values in the volume
*/
owl::box4f getBounds4f() const;
/*!
* @brief Get domain of the values in the volume
*/
owl::box3f getBounds() const;
/*!
* @brief Reshape the geometric bounds proportionally to the grid dimensions
*/
void reshapeBounds();
void reshapeBounds(const owl::vec3f remap_dims);
private:
char const* fileName_ = 0;
char const* mode_ = 0;
FILE* file_ = 0;
std::vector<float> data_;// I will assume they are all floats for now
Vec3l dims_ = { 0, 0, 0 };
owl::box4f bounds_ = {{0,0,0,0},{1,1,1,1}};
DataFormat dataFormat_ = DataFormat::UInt8;
};
} // raw