00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
#ifndef DIROTAT_H
00035
#define DIROTAT_H
00036
00037
#include "osconfig.h"
00038
#include "ofcast.h"
00039
#include "dctypes.h"
00040
00041
#include "dipixel.h"
00042
#include "ditranst.h"
00043
00044
00045
00046
00047
00048
00052
template<
class T>
00053 class DiRotateTemplate
00054 :
public DiTransTemplate<T>
00055 {
00056
00057
public:
00058
00070 DiRotateTemplate(
DiPixel *pixel,
00071
const Uint16 src_cols,
00072
const Uint16 src_rows,
00073
const Uint16 dest_cols,
00074
const Uint16 dest_rows,
00075
const Uint32 frames,
00076
const int degree)
00077 :
DiTransTemplate<T>(0, src_cols, src_rows, dest_cols, dest_rows, frames)
00078 {
00079
if (pixel != NULL)
00080 {
00081 this->Planes = pixel->
getPlanes();
00082
if ((pixel->
getCount() > 0) && (this->Planes > 0) &&
00083 (pixel->
getCount() == OFstatic_cast(
unsigned long, src_cols) * OFstatic_cast(
unsigned long, src_rows) * frames))
00084 {
00085
if (degree == 90)
00086
rotateRight(OFstatic_cast(T **, pixel->
getDataArrayPtr()));
00087
else if (degree == 180)
00088
rotateTopDown(OFstatic_cast(T **, pixel->
getDataArrayPtr()));
00089
else if (degree == 270)
00090
rotateLeft(OFstatic_cast(T **, pixel->
getDataArrayPtr()));
00091 }
else {
00092
if (
DicomImageClass::checkDebugLevel(DicomImageClass::DL_Warnings))
00093 {
00094 ofConsole.lockCerr() <<
"WARNING: could not rotate image ... corrupted data." << endl;
00095 ofConsole.unlockCerr();
00096 }
00097 }
00098 }
00099 }
00100
00111 DiRotateTemplate(
const int planes,
00112
const Uint16 src_cols,
00113
const Uint16 src_rows,
00114
const Uint16 dest_cols,
00115
const Uint16 dest_rows,
00116
const Uint32 frames)
00117 :
DiTransTemplate<T>(planes, src_cols, src_rows, dest_cols, dest_rows, frames)
00118 {
00119 }
00120
00123 virtual ~DiRotateTemplate()
00124 {
00125 }
00126
00133 inline void rotateData(
const T *src[],
00134 T *dest[],
00135
const int degree)
00136 {
00137
if (degree == 90)
00138
rotateRight(src, dest);
00139
else if (degree == 180)
00140
rotateTopDown(src, dest);
00141
else if (degree == 270)
00142
rotateLeft(src, dest);
00143
else
00144
copyPixel(src, dest);
00145 }
00146
00147
00148
protected:
00149
00155 inline void rotateLeft(
const T *src[],
00156 T *dest[])
00157 {
00158
if ((src != NULL) && (dest != NULL))
00159 {
00160
register Uint16 x;
00161
register Uint16 y;
00162
register const T *p;
00163
register T *q;
00164
register T *r;
00165
const unsigned long count = OFstatic_cast(
unsigned long, this->Dest_X) * OFstatic_cast(
unsigned long, this->Dest_Y);
00166
for (
int j = 0; j < this->Planes; ++j)
00167 {
00168 p = src[j];
00169 r = dest[j];
00170
for (
unsigned long f = this->Frames; f != 0; --f)
00171 {
00172 r += count;
00173
for (x = this->Dest_X; x != 0; --x)
00174 {
00175 q = r - x;
00176
for (y = this->Dest_Y; y != 0; --y)
00177 {
00178 *q = *p++;
00179 q -= this->Dest_X;
00180 }
00181 }
00182 }
00183 }
00184 }
00185 }
00186
00192 inline void rotateRight(
const T *src[],
00193 T *dest[])
00194 {
00195
if ((src != NULL) && (dest != NULL))
00196 {
00197
register Uint16 x;
00198
register Uint16 y;
00199
register const T *p;
00200
register T *q;
00201
register T *r;
00202
const unsigned long count = OFstatic_cast(
unsigned long, this->Dest_X) * OFstatic_cast(
unsigned long, this->Dest_Y);
00203
for (
int j = 0; j < this->Planes; ++j)
00204 {
00205 p = src[j];
00206 r = dest[j];
00207
for (
unsigned long f = this->Frames; f != 0; --f)
00208 {
00209
for (x = this->Dest_X; x != 0; --x)
00210 {
00211 q = r + x - 1;
00212
for (y = this->Dest_Y; y != 0; --y)
00213 {
00214 *q = *p++;
00215 q += this->Dest_X;
00216 }
00217 }
00218 r += count;
00219 }
00220 }
00221 }
00222 }
00223
00229 inline void rotateTopDown(
const T *src[],
00230 T *dest[])
00231 {
00232
if ((src != NULL) && (dest != NULL))
00233 {
00234
register unsigned long i;
00235
register const T *p;
00236
register T *q;
00237
const unsigned long count = OFstatic_cast(
unsigned long, this->Dest_X) * OFstatic_cast(
unsigned long, this->Dest_Y);
00238
for (
int j = 0; j < this->Planes; ++j)
00239 {
00240 p = src[j];
00241 q = dest[j];
00242
for (
unsigned long f = this->Frames; f != 0; --f)
00243 {
00244 q += count;
00245
for (i = count; i != 0; --i)
00246 *--q = *p++;
00247 q += count;
00248 }
00249 }
00250 }
00251 }
00252
00253
private:
00254
00259 inline void rotateLeft(T *data[])
00260 {
00261
const unsigned long count = OFstatic_cast(
unsigned long, this->Dest_X) * OFstatic_cast(
unsigned long, this->Dest_Y);
00262 T *temp =
new T[count];
00263
if (temp != NULL)
00264 {
00265
register Uint16 x;
00266
register Uint16 y;
00267
register const T *p;
00268
register T *q;
00269
register T *r;
00270
for (
int j = 0; j < this->Planes; ++j)
00271 {
00272 r = data[j];
00273
for (
unsigned long f = this->Frames; f != 0; --f)
00274 {
00275
OFBitmanipTemplate<T>::copyMem(OFstatic_cast(
const T *, r), temp, count);
00276 p = temp;
00277 r += count;
00278
for (x = this->Dest_X; x != 0; --x)
00279 {
00280 q = r - x;
00281
for (y = this->Dest_Y; y != 0; --y)
00282 {
00283 *q = *p++;
00284 q -= this->Dest_X;
00285 }
00286 }
00287 }
00288 }
00289
delete[] temp;
00290 }
00291 }
00292
00297 inline void rotateRight(T *data[])
00298 {
00299
const unsigned long count = OFstatic_cast(
unsigned long, this->Dest_X) * OFstatic_cast(
unsigned long, this->Dest_Y);
00300 T *temp =
new T[count];
00301
if (temp != NULL)
00302 {
00303
register Uint16 x;
00304
register Uint16 y;
00305
register const T *p;
00306
register T *q;
00307
register T *r;
00308
for (
int j = 0; j < this->Planes; ++j)
00309 {
00310 r = data[j];
00311
for (
unsigned long f = this->Frames; f != 0; --f)
00312 {
00313
OFBitmanipTemplate<T>::copyMem(OFstatic_cast(
const T *, r), temp, count);
00314 p = temp;
00315
for (x = this->Dest_X; x != 0; --x)
00316 {
00317 q = r + x - 1;
00318
for (y = this->Dest_Y; y != 0; --y)
00319 {
00320 *q = *p++;
00321 q += this->Dest_X;
00322 }
00323 }
00324 r += count;
00325 }
00326 }
00327
delete[] temp;
00328 }
00329 }
00330
00335 inline void rotateTopDown(T *data[])
00336 {
00337
register unsigned long i;
00338
register T *p;
00339
register T *q;
00340
register T t;
00341 T *s;
00342
const unsigned long count = OFstatic_cast(
unsigned long, this->Dest_X) * OFstatic_cast(
unsigned long, this->Dest_Y);
00343
for (
int j = 0; j < this->Planes; ++j)
00344 {
00345 s = data[j];
00346
for (
unsigned long f = this->Frames; f != 0; --f)
00347 {
00348 p = s;
00349 q = s + count;
00350
for (i = count / 2; i != 0; --i)
00351 {
00352 t = *p;
00353 *p++ = *--q;
00354 *q = t;
00355 }
00356 }
00357 }
00358 }
00359 };
00360
00361
00362
#endif
00363
00364
00365
00366
00367
00368
00369
00370
00371
00372
00373
00374
00375
00376
00377
00378
00379
00380
00381
00382
00383
00384
00385
00386
00387
00388
00389
00390
00391
00392
00393
00394
00395
00396
00397
00398
00399
00400
00401
00402
00403
00404
00405
00406
00407
00408
00409
00410
00411
00412
00413
00414
00415
00416
00417
00418
00419
00420
00421
00422
00423
00424