OFFIS DCMTK  Version 3.6.0
dirotat.h
1 /*
2  *
3  * Copyright (C) 1996-2011, OFFIS e.V.
4  * All rights reserved. See COPYRIGHT file for details.
5  *
6  * This software and supporting documentation were developed by
7  *
8  * OFFIS e.V.
9  * R&D Division Health
10  * Escherweg 2
11  * D-26121 Oldenburg, Germany
12  *
13  *
14  * Module: dcmimgle
15  *
16  * Author: Joerg Riesmeier
17  *
18  * Purpose: DicomRotateTemplate (Header)
19  *
20  * Last Update: $Author: joergr $
21  * Update Date: $Date: 2011-11-17 16:13:16 $
22  * CVS/RCS Revision: $Revision: 1.22 $
23  * Status: $State: Exp $
24  *
25  * CVS/RCS Log at end of file
26  *
27  */
28 
29 
30 #ifndef DIROTAT_H
31 #define DIROTAT_H
32 
33 #include "dcmtk/config/osconfig.h"
34 #include "dcmtk/ofstd/ofcast.h"
35 
36 #include "dcmtk/dcmimgle/dipixel.h"
37 #include "dcmtk/dcmimgle/ditranst.h"
38 
39 
40 /*---------------------*
41  * class declaration *
42  *---------------------*/
43 
47 template<class T>
49  : public DiTransTemplate<T>
50 {
51 
52  public:
53 
66  const Uint16 src_cols,
67  const Uint16 src_rows,
68  const Uint16 dest_cols,
69  const Uint16 dest_rows,
70  const Uint32 frames,
71  const int degree)
72  : DiTransTemplate<T>(0, src_cols, src_rows, dest_cols, dest_rows, frames)
73  {
74  if (pixel != NULL)
75  {
76  this->Planes = pixel->getPlanes();
77  if ((pixel->getCount() > 0) && (this->Planes > 0) &&
78  (pixel->getCount() == OFstatic_cast(unsigned long, src_cols) * OFstatic_cast(unsigned long, src_rows) * frames))
79  {
80  if (degree == 90)
81  rotateRight(OFstatic_cast(T **, pixel->getDataArrayPtr()));
82  else if (degree == 180)
83  rotateTopDown(OFstatic_cast(T **, pixel->getDataArrayPtr()));
84  else if (degree == 270)
85  rotateLeft(OFstatic_cast(T **, pixel->getDataArrayPtr()));
86  } else {
87  DCMIMGLE_WARN("could not rotate image ... corrupted data");
88  }
89  }
90  }
91 
102  DiRotateTemplate(const int planes,
103  const Uint16 src_cols,
104  const Uint16 src_rows,
105  const Uint16 dest_cols,
106  const Uint16 dest_rows,
107  const Uint32 frames)
108  : DiTransTemplate<T>(planes, src_cols, src_rows, dest_cols, dest_rows, frames)
109  {
110  }
111 
115  {
116  }
117 
124  inline void rotateData(const T *src[],
125  T *dest[],
126  const int degree)
127  {
128  if (degree == 90)
129  rotateRight(src, dest);
130  else if (degree == 180)
131  rotateTopDown(src, dest);
132  else if (degree == 270)
133  rotateLeft(src, dest);
134  else
135  this->copyPixel(src, dest);
136  }
137 
138 
139  protected:
140 
146  inline void rotateLeft(const T *src[],
147  T *dest[])
148  {
149  if ((src != NULL) && (dest != NULL))
150  {
151  register Uint16 x;
152  register Uint16 y;
153  register const T *p;
154  register T *q;
155  register T *r;
156  const unsigned long count = OFstatic_cast(unsigned long, this->Dest_X) * OFstatic_cast(unsigned long, this->Dest_Y);
157  for (int j = 0; j < this->Planes; ++j)
158  {
159  p = src[j];
160  r = dest[j];
161  for (unsigned long f = this->Frames; f != 0; --f)
162  {
163  r += count;
164  for (x = this->Dest_X; x != 0; --x)
165  {
166  q = r - x;
167  for (y = this->Dest_Y; y != 0; --y)
168  {
169  *q = *p++;
170  q -= this->Dest_X;
171  }
172  }
173  }
174  }
175  }
176  }
177 
183  inline void rotateRight(const T *src[],
184  T *dest[])
185  {
186  if ((src != NULL) && (dest != NULL))
187  {
188  register Uint16 x;
189  register Uint16 y;
190  register const T *p;
191  register T *q;
192  register T *r;
193  const unsigned long count = OFstatic_cast(unsigned long, this->Dest_X) * OFstatic_cast(unsigned long, this->Dest_Y);
194  for (int j = 0; j < this->Planes; ++j)
195  {
196  p = src[j];
197  r = dest[j];
198  for (unsigned long f = this->Frames; f != 0; --f)
199  {
200  for (x = this->Dest_X; x != 0; --x)
201  {
202  q = r + x - 1;
203  for (y = this->Dest_Y; y != 0; --y)
204  {
205  *q = *p++;
206  q += this->Dest_X;
207  }
208  }
209  r += count;
210  }
211  }
212  }
213  }
214 
220  inline void rotateTopDown(const T *src[],
221  T *dest[])
222  {
223  if ((src != NULL) && (dest != NULL))
224  {
225  register unsigned long i;
226  register const T *p;
227  register T *q;
228  const unsigned long count = OFstatic_cast(unsigned long, this->Dest_X) * OFstatic_cast(unsigned long, this->Dest_Y);
229  for (int j = 0; j < this->Planes; ++j)
230  {
231  p = src[j];
232  q = dest[j];
233  for (unsigned long f = this->Frames; f != 0; --f)
234  {
235  q += count;
236  for (i = count; i != 0; --i)
237  *--q = *p++;
238  q += count;
239  }
240  }
241  }
242  }
243 
244  private:
245 
250  inline void rotateLeft(T *data[])
251  {
252  const unsigned long count = OFstatic_cast(unsigned long, this->Dest_X) * OFstatic_cast(unsigned long, this->Dest_Y);
253  T *temp = new T[count];
254  if (temp != NULL)
255  {
256  register Uint16 x;
257  register Uint16 y;
258  register const T *p;
259  register T *q;
260  register T *r;
261  for (int j = 0; j < this->Planes; ++j)
262  {
263  r = data[j];
264  for (unsigned long f = this->Frames; f != 0; --f)
265  {
266  OFBitmanipTemplate<T>::copyMem(OFstatic_cast(const T *, r), temp, count); // create temporary copy of current frame
267  p = temp;
268  r += count;
269  for (x = this->Dest_X; x != 0; --x)
270  {
271  q = r - x;
272  for (y = this->Dest_Y; y != 0; --y)
273  {
274  *q = *p++;
275  q -= this->Dest_X;
276  }
277  }
278  }
279  }
280  delete[] temp;
281  }
282  }
283 
288  inline void rotateRight(T *data[])
289  {
290  const unsigned long count = OFstatic_cast(unsigned long, this->Dest_X) * OFstatic_cast(unsigned long, this->Dest_Y);
291  T *temp = new T[count];
292  if (temp != NULL)
293  {
294  register Uint16 x;
295  register Uint16 y;
296  register const T *p;
297  register T *q;
298  register T *r;
299  for (int j = 0; j < this->Planes; ++j)
300  {
301  r = data[j];
302  for (unsigned long f = this->Frames; f != 0; --f)
303  {
304  OFBitmanipTemplate<T>::copyMem(OFstatic_cast(const T *, r), temp, count); // create temporary copy of current frame
305  p = temp;
306  for (x = this->Dest_X; x != 0; --x)
307  {
308  q = r + x - 1;
309  for (y = this->Dest_Y; y != 0; --y)
310  {
311  *q = *p++;
312  q += this->Dest_X;
313  }
314  }
315  r += count;
316  }
317  }
318  delete[] temp;
319  }
320  }
321 
326  inline void rotateTopDown(T *data[])
327  {
328  register unsigned long i;
329  register T *p;
330  register T *q;
331  register T t;
332  T *s;
333  const unsigned long count = OFstatic_cast(unsigned long, this->Dest_X) * OFstatic_cast(unsigned long, this->Dest_Y);
334  for (int j = 0; j < this->Planes; ++j)
335  {
336  s = data[j];
337  for (unsigned long f = this->Frames; f != 0; --f)
338  {
339  p = s;
340  q = s + count;
341  for (i = count / 2; i != 0; --i)
342  {
343  t = *p;
344  *p++ = *--q;
345  *q = t;
346  }
347  s += count;
348  }
349  }
350  }
351 };
352 
353 
354 #endif
355 
356 
357 /*
358  *
359  * CVS/RCS Log:
360  * $Log: dirotat.h,v $
361  * Revision 1.22 2011-11-17 16:13:16 joergr
362  * Minor fixes to keep XCode 4.2 on Mac OS X Lion (clang compiler) quiet.
363  *
364  * Revision 1.21 2010-10-14 13:16:27 joergr
365  * Updated copyright header. Added reference to COPYRIGHT file.
366  *
367  * Revision 1.20 2010-03-01 09:08:47 uli
368  * Removed some unnecessary include directives in the headers.
369  *
370  * Revision 1.19 2009-10-28 14:38:17 joergr
371  * Fixed minor issues in log output.
372  *
373  * Revision 1.18 2009-10-28 09:53:40 uli
374  * Switched to logging mechanism provided by the "new" oflog module.
375  *
376  * Revision 1.17 2006-08-15 16:30:11 meichel
377  * Updated the code in module dcmimgle to correctly compile when
378  * all standard C++ classes remain in namespace std.
379  *
380  * Revision 1.16 2005/12/08 16:48:08 meichel
381  * Changed include path schema for all DCMTK header files
382  *
383  * Revision 1.15 2005/06/15 08:23:54 joergr
384  * Fixed bug which prevented rotateTopDown() from rotating multi-frame images
385  * correctly (only the first frame was actually rotated).
386  *
387  * Revision 1.14 2004/04/21 10:00:36 meichel
388  * Minor modifications for compilation with gcc 3.4.0
389  *
390  * Revision 1.13 2004/02/06 11:07:50 joergr
391  * Distinguish more clearly between const and non-const access to pixel data.
392  *
393  * Revision 1.12 2003/12/23 15:53:22 joergr
394  * Replaced post-increment/decrement operators by pre-increment/decrement
395  * operators where appropriate (e.g. 'i++' by '++i').
396  *
397  * Revision 1.11 2003/12/09 10:14:54 joergr
398  * Adapted type casts to new-style typecast operators defined in ofcast.h.
399  * Removed leading underscore characters from preprocessor symbols (reserved
400  * symbols). Updated copyright header.
401  *
402  * Revision 1.10 2001/06/01 15:49:50 meichel
403  * Updated copyright header
404  *
405  * Revision 1.9 2000/09/12 10:04:45 joergr
406  * Corrected bug: wrong parameter for attribute search routine led to crashes
407  * when multiple pixel data attributes were contained in the dataset (e.g.
408  * IconImageSequence). Added new checking routines to avoid crashes when
409  * processing corrupted image data.
410  *
411  * Revision 1.8 2000/03/08 16:24:24 meichel
412  * Updated copyright header.
413  *
414  * Revision 1.7 2000/03/02 12:51:37 joergr
415  * Rewrote variable initialization in class contructors to avoid warnings
416  * reported on Irix.
417  *
418  * Revision 1.6 1999/09/17 13:07:20 joergr
419  * Added/changed/completed DOC++ style comments in the header files.
420  * Enhanced efficiency of some "for" loops.
421  *
422  * Revision 1.5 1999/03/24 17:17:20 joergr
423  * Removed debug code.
424  * Added/Modified comments and formatting.
425  *
426  * Revision 1.4 1999/01/20 15:12:47 joergr
427  * Added debug code to measure time of some routines.
428  *
429  * Revision 1.3 1998/12/16 16:38:49 joergr
430  * Added additional case to copy pixels.
431  *
432  * Revision 1.2 1998/12/14 17:30:49 joergr
433  * Added (missing) implementation of methods to rotate images/frames without
434  * creating a new DicomImage.
435  *
436  * Revision 1.1 1998/11/27 14:57:46 joergr
437  * Added copyright message.
438  * Added methods and classes for flipping and rotating, changed for
439  * scaling and clipping.
440  *
441  *
442  */


Generated on Thu Dec 20 2012 for OFFIS DCMTK Version 3.6.0 by Doxygen 1.8.2