2 #include <muda/viewer/viewer_base.h> 18 template <
bool IsConst,
typename T>
26 using auto_const_t =
typename Base::template auto_const_t<U>;
28 auto_const_t<T>* m_data;
32 int m_pitch_bytes_area;
40 MUDA_GENERIC
Dense3DBase() MUDA_NOEXCEPT : m_data(
nullptr){};
46 int pitch_bytes_area) MUDA_NOEXCEPT
50 m_pitch_bytes(pitch_bytes),
51 m_pitch_bytes_area(pitch_bytes_area)
55 MUDA_GENERIC
auto as_const()
const MUDA_NOEXCEPT
57 return ConstViewer{m_data, m_offset, m_dim, m_pitch_bytes, m_pitch_bytes_area};
60 MUDA_GENERIC
operator ConstViewer()
const MUDA_NOEXCEPT
65 MUDA_GENERIC auto_const_t<T>& operator()(
int x,
int y,
int z) MUDA_NOEXCEPT
69 auto depth_begin =
reinterpret_cast<std::byte*
>(m_data) + x * m_pitch_bytes_area;
70 auto height_begin = depth_begin + y * m_pitch_bytes;
71 return *(
reinterpret_cast<T*
>(height_begin) + z);
74 MUDA_GENERIC auto_const_t<T>& operator()(
const int3& xyz) MUDA_NOEXCEPT
76 return operator()(xyz.x, xyz.y, xyz.z);
79 MUDA_GENERIC auto_const_t<T>& flatten(
int i) MUDA_NOEXCEPT
81 if constexpr(DEBUG_VIEWER)
83 MUDA_KERNEL_ASSERT(i >= 0 && i < total_size(),
84 "Dense3D[%s:%s]: out of range, index=%d, total_size=%d",
90 auto area = m_dim.y * m_dim.z;
92 auto i_in_area = i % area;
93 auto y = i_in_area / m_dim.z;
94 auto i_in_width = i_in_area % m_dim.z;
96 return operator()(x, y, z);
99 MUDA_GENERIC auto_const_t<T>* data() MUDA_NOEXCEPT {
return m_data; }
102 MUDA_GENERIC
const T& operator()(
int x,
int y,
int z)
const MUDA_NOEXCEPT
104 return remove_const(*
this)(x, y, z);
108 MUDA_GENERIC
const T& operator()(
const int3& xyz)
const MUDA_NOEXCEPT
110 return remove_const(*
this)(xyz.x, xyz.y, xyz.z);
113 MUDA_GENERIC
const T& flatten(
int i)
const MUDA_NOEXCEPT
115 return remove_const(*this).flatten(i);
118 MUDA_GENERIC
const T* data()
const MUDA_NOEXCEPT {
return m_data; }
121 MUDA_GENERIC
auto dim()
const MUDA_NOEXCEPT {
return m_dim; }
122 MUDA_GENERIC
int area()
const MUDA_NOEXCEPT {
return m_dim.y * m_dim.z; }
123 MUDA_GENERIC
int volume()
const MUDA_NOEXCEPT {
return total_size(); }
124 MUDA_GENERIC
int total_size()
const MUDA_NOEXCEPT
126 return m_dim.x * area();
128 MUDA_GENERIC
int pitch_bytes()
const MUDA_NOEXCEPT {
return m_pitch_bytes; }
129 MUDA_GENERIC
int pitch_bytes_area()
const MUDA_NOEXCEPT
131 return m_pitch_bytes_area;
133 MUDA_GENERIC
int total_bytes()
const MUDA_NOEXCEPT
135 return m_pitch_bytes_area * m_dim.x;
139 MUDA_INLINE MUDA_GENERIC
void check_range(
int x,
int y,
int z)
const MUDA_NOEXCEPT
141 if constexpr(DEBUG_VIEWER)
143 if(!(x >= 0 && x < m_dim.x && y >= 0 && y < m_dim.y && z >= 0
145 MUDA_KERNEL_ERROR(
"Dense3D[%s:%s]: out of range, index=(%d,%d,%d) dim=(%d,%d,%d)",
157 MUDA_INLINE MUDA_GENERIC
void check()
const MUDA_NOEXCEPT
159 if constexpr(DEBUG_VIEWER)
160 if(m_data ==
nullptr)
161 MUDA_KERNEL_ERROR(
"Dense3D[%s:%s]: data is null",
163 this->kernel_name());
167 template <
typename T>
170 template <
typename T>
174 template <
typename T>
180 template <
typename T>
187 template <
typename T>
188 MUDA_INLINE MUDA_GENERIC
auto make_cdense_3d(
const T* data,
const int3& dim) MUDA_NOEXCEPT
190 auto pitch_bytes = dim.z *
sizeof(T);
194 static_cast<int>(pitch_bytes),
195 static_cast<int>(dim.y * pitch_bytes)};
198 template <
typename T>
199 MUDA_INLINE MUDA_GENERIC
auto make_dense_3d(T* data,
const int3& dim) MUDA_NOEXCEPT
201 auto pitch_bytes = dim.z *
sizeof(T);
205 static_cast<int>(pitch_bytes),
206 static_cast<int>(dim.y * pitch_bytes)};
209 template <
typename T>
210 MUDA_INLINE MUDA_GENERIC
auto make_cdense_3d(
const T* data,
int dimx,
int dimy,
int dimz) MUDA_NOEXCEPT
212 return make_cdense_3d(data, make_int3(dimx, dimy, dimz));
215 template <
typename T>
216 MUDA_INLINE MUDA_GENERIC
auto make_dense_3d(T* data,
int dimx,
int dimy,
int dimz) MUDA_NOEXCEPT
218 return make_dense_3d(data, make_int3(dimx, dimy, dimz));
Definition: dense_3d.h:19
Definition: type_modifier.h:21
Definition: type_modifier.h:27
Definition: viewer_base.h:21