32 T
Get(
const size_t row,
const size_t col,
const size_t slice = 0)
const;
33 void GetSlice(
const size_t row,
const size_t col, T* values)
const;
39 void Set(
const size_t row,
const size_t col,
const T value);
40 void Set(
const size_t row,
87 return data_.size() *
sizeof(T);
91 T
Mat<T>::Get(
const size_t row,
const size_t col,
const size_t slice)
const {
92 return data_.at(slice * width_ * height_ + row * width_ + col);
97 for (
size_t slice = 0; slice < depth_; ++slice) {
98 values[slice] = Get(row, col, slice);
102 template <
typename T>
107 template <
typename T>
112 template <
typename T>
117 template <
typename T>
118 void Mat<T>::Set(
const size_t row,
const size_t col,
const T value) {
119 Set(row, col, 0, value);
122 template <
typename T>
127 data_.at(slice * width_ * height_ + row * width_ + col) = value;
130 template <
typename T>
132 std::fill(data_.begin(), data_.end(), value);
135 template <
typename T>
137 std::fstream text_file(
path, std::ios::in | std::ios::binary);
138 CHECK(text_file.is_open()) <<
path;
141 text_file >> width_ >> unused_char >> height_ >> unused_char >> depth_ >>
143 std::streampos pos = text_file.tellg();
147 CHECK_GT(height_, 0);
149 data_.resize(width_ * height_ * depth_);
151 std::fstream binary_file(
path, std::ios::in | std::ios::binary);
152 CHECK(binary_file.is_open()) <<
path;
153 binary_file.seekg(pos);
154 ReadBinaryLittleEndian<T>(&binary_file, &data_);
158 template <
typename T>
160 std::fstream text_file(
path, std::ios::out);
161 CHECK(text_file.is_open()) <<
path;
162 text_file << width_ <<
"&" << height_ <<
"&" << depth_ <<
"&";
165 std::fstream binary_file(
path,
166 std::ios::out | std::ios::binary | std::ios::app);
167 CHECK(binary_file.is_open()) <<
path;
168 WriteBinaryLittleEndian<T>(&binary_file, data_);
void Write(const std::string &path) const
size_t GetNumBytes() const
void Read(const std::string &path)
void Set(const size_t row, const size_t col, const T value)
Mat(const size_t width, const size_t height, const size_t depth)
T Get(const size_t row, const size_t col, const size_t slice=0) const
void Set(const size_t row, const size_t col, const size_t slice, const T value)
void GetSlice(const size_t row, const size_t col, T *values) const
const std::vector< T > & GetData() const
static const std::string path