2 #include <muda/viewer/viewer_base.h> 18 template <
bool IsConst,
typename T>
28 using auto_const_t =
typename Base::template auto_const_t<U>;
30 auto_const_t<T>* m_data;
42 MUDA_GENERIC
Dense2DBase() MUDA_NOEXCEPT : m_data(
nullptr) {}
44 MUDA_GENERIC
Dense2DBase(auto_const_t<T>* p,
const int2& offset,
const int2& dim,
int pitch_bytes) MUDA_NOEXCEPT
48 m_pitch_bytes(pitch_bytes)
52 MUDA_GENERIC
auto as_const()
const MUDA_NOEXCEPT
54 return ConstViewer{m_data, m_offset, m_dim, m_pitch_bytes};
57 MUDA_GENERIC
operator ConstViewer()
const MUDA_NOEXCEPT
63 MUDA_GENERIC auto_const_t<T>& operator()(
int x,
int y) MUDA_NOEXCEPT
71 reinterpret_cast<auto_const_t<std::byte>*
>(m_data) + x * m_pitch_bytes;
72 return *((auto_const_t<T>*)(height_begin) + y);
75 MUDA_GENERIC auto_const_t<T>& operator()(
const int2& xy) MUDA_NOEXCEPT
77 return operator()(xy.x, xy.y);
80 MUDA_GENERIC auto_const_t<T>& flatten(
int i)
82 if constexpr(DEBUG_VIEWER)
84 MUDA_KERNEL_ASSERT(i >= 0 && i < total_size(),
85 "Dense2D[%s:%s]: out of range, index=%d, total_size=%d",
93 return operator()(x, y);
96 MUDA_GENERIC auto_const_t<T>* data() MUDA_NOEXCEPT {
return m_data; }
99 MUDA_GENERIC
const T& operator()(
const int2& xy)
const MUDA_NOEXCEPT
101 return remove_const(*
this)(xy);
105 MUDA_GENERIC
const T& operator()(
int x,
int y)
const MUDA_NOEXCEPT
107 return remove_const(*
this)(x, y);
110 MUDA_GENERIC
const T& flatten(
int i)
const 112 return remove_const(*this).flatten(i);
115 MUDA_GENERIC
const T* data()
const MUDA_NOEXCEPT {
return m_data; }
117 MUDA_GENERIC
auto total_size()
const MUDA_NOEXCEPT
119 return m_dim.x * m_dim.y;
122 MUDA_GENERIC
auto area()
const MUDA_NOEXCEPT {
return total_size(); }
124 MUDA_GENERIC
auto dim()
const MUDA_NOEXCEPT {
return m_dim; }
126 MUDA_GENERIC
auto pitch_bytes()
const MUDA_NOEXCEPT
128 return m_pitch_bytes;
132 MUDA_INLINE MUDA_GENERIC
void check_range(
int x,
int y)
const MUDA_NOEXCEPT
134 if constexpr(DEBUG_VIEWER)
135 if(!(x >= 0 && x < m_dim.x && y >= 0 && y < m_dim.y))
137 MUDA_KERNEL_ERROR(
"Dense2D[%s:%s]: out of range, index=(%d,%d) dim=(%d,%d)",
147 MUDA_INLINE MUDA_GENERIC
void check()
const MUDA_NOEXCEPT
149 if constexpr(DEBUG_VIEWER)
151 MUDA_KERNEL_ASSERT(m_data,
152 "Dense2D[%s:%s]: m_data is null",
154 this->kernel_name());
159 template <
typename T>
162 template <
typename T>
167 template <
typename T>
173 template <
typename T>
180 template <
typename T>
181 MUDA_INLINE MUDA_GENERIC
auto make_cdense_2d(
const T* data,
const int2& dim) MUDA_NOEXCEPT
183 return CDense2D<T>{data, make_int2(0, 0), dim,
static_cast<int>(dim.y *
sizeof(T))};
186 template <
typename T>
187 MUDA_INLINE MUDA_GENERIC
auto make_dense_2d(T* data,
const int2& dim) MUDA_NOEXCEPT
189 return Dense2D<T>{data, make_int2(0, 0), dim,
static_cast<int>(dim.y *
sizeof(T))};
192 template <
typename T>
193 MUDA_INLINE MUDA_GENERIC
auto make_cdense_2d(
const T* data,
int dimx,
int dimy) MUDA_NOEXCEPT
195 return make_cdense_2d(data, make_int2(dimx, dimy));
198 template <
typename T>
199 MUDA_INLINE MUDA_GENERIC
auto make_dense_2d(T* data,
int dimx,
int dimy) MUDA_NOEXCEPT
201 return make_dense_2d(data, make_int2(dimx, dimy));
Definition: type_modifier.h:21
Definition: type_modifier.h:27
Definition: dense_2d.h:19
Definition: viewer_base.h:21