6#ifndef _TCUBE_H_INCLUDED_
7#define _TCUBE_H_INCLUDED_
18template<
class T>
class tmtr
24 int m_height, m_width;
29 m_stride =
mtr.m_stride;
30 m_height =
mtr.m_height;
31 m_width =
mtr.m_width;
33 m_container =
new T[m_height*m_stride];
35 memcpy(m_data,
mtr.m_data, m_height*m_stride);
41 tmtr(
int nHeight,
int nWidth,
int nStride = 0) :m_height(nHeight), m_width(nWidth)
45 nStride == 0? m_stride = nWidth: m_stride = nStride;
46 m_container =
new T[m_height*m_stride];
50 tmtr(T* Data,
int nHeight,
int nWidth,
int nStride=0) :m_data(Data), m_height(nHeight), m_width(nWidth)
52 nStride == 0 ? m_stride = m_width : m_stride = nStride;
53 _ASSERTE(m_stride >= m_width);
57 T* ref(
int y,
int x) {
58 return m_data + y*m_stride + x;
66 inline T* operator[](
int row)
const
71 return m_data + row*m_stride;
75 for (
int y = 0; y< m_height; y++, p += m_stride)
76 for (
int x = 0; x<m_width; x++)
119 m_height= cube.m_height;
120 m_width= cube.m_width;
121 m_depth= cube.m_depth;
122 m_ystride= cube.m_ystride;
123 m_wstride= cube.m_wstride;
124 m_cstride= cube.m_cstride;
126 m_container =
new T[m_height*m_ystride];
127 m_data = m_container;
128 memcpy(m_data, cube.m_data, m_height*m_ystride);
132 tcube(
int Height,
int Width,
int Depth,
int WStride=0,
int CStride=0):m_height(Height), m_width(Width), m_depth(Depth)
134 WStride == 0 ? m_wstride = m_width: m_wstride=WStride;
135 CStride == 0 ? m_cstride = m_depth: m_cstride=CStride;
136 _ASSERTE(m_width<=m_wstride);
137 m_ystride = m_cstride*m_wstride;
138 m_container=
new T[m_height*m_ystride];
143 tcube(T* data,
int Height,
int Width,
int Depth,
int WStride = 0,
int CStride = 0) :m_data (data), m_height(Height), m_width(Width), m_depth(Depth)
145 WStride == 0 ? m_wstride = m_width : m_wstride = WStride;
146 CStride == 0 ? m_cstride = m_depth : m_cstride = CStride;
147 m_ystride = m_cstride*m_wstride;
151 _ASSERTE(cube.m_height == m_height);
152 _ASSERTE(cube.m_width == m_width);
153 _ASSERTE(cube.m_depth == m_depth);
154 for (
int y = 0; y < m_height; y++)
155 for (
int x = 0; x < m_width; x++)
156 for (
int c = 0; c < m_depth; c++)
157 (*
this)[y][x][c] = cube[y][x][c];
161 inline tmtr<T> operator [](
int y)
const
165 return tmtr<T>(m_data+y*m_ystride, m_width, m_depth, m_cstride);
170 _ASSERTE(m_container != (T*)-1);
172 m_container = (T*)-1;
180 void printChannel(
int ch) {
184 for (
int h = 0; h < m_height; h++) {
185 for (
int w = 0; w < m_width; w++) {
186 float v = (*this)[h][w][ch];
187 sprintf(str,
"%.2f ", v);
188 int len = strlen(str);
195 for (
int h = 0; h < m_height; h++) {
196 for (
int w = 0; w < m_width; w++) {
197 float v = (*this)[h][w][ch];
198 sprintf(str,
"%.2f ", v);
199 int len = strlen(str);
201 printf(spaces + 10 - (maxlen - len));
213 for (
int y = 0; y < m_height; y++, layer += m_ystride) {
Definition: tnmcube.h:104