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;
37 const std::vector<T>&
GetData()
const;
39 void Set(
const size_t row,
const size_t col,
const T value);
40 void Set(
const size_t row,
45 void Fill(
const T value);
48 void Write(
const std::string&
path)
const;
67 data_.resize(width_ * height_ * depth_, 0);
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_);