diflipt.h

00001 /*
00002  *
00003  *  Copyright (C) 1996-2005, OFFIS
00004  *
00005  *  This software and supporting documentation were developed by
00006  *
00007  *    Kuratorium OFFIS e.V.
00008  *    Healthcare Information and Communication Systems
00009  *    Escherweg 2
00010  *    D-26121 Oldenburg, Germany
00011  *
00012  *  THIS SOFTWARE IS MADE AVAILABLE,  AS IS,  AND OFFIS MAKES NO  WARRANTY
00013  *  REGARDING  THE  SOFTWARE,  ITS  PERFORMANCE,  ITS  MERCHANTABILITY  OR
00014  *  FITNESS FOR ANY PARTICULAR USE, FREEDOM FROM ANY COMPUTER DISEASES  OR
00015  *  ITS CONFORMITY TO ANY SPECIFICATION. THE ENTIRE RISK AS TO QUALITY AND
00016  *  PERFORMANCE OF THE SOFTWARE IS WITH THE USER.
00017  *
00018  *  Module:  dcmimgle
00019  *
00020  *  Author:  Joerg Riesmeier
00021  *
00022  *  Purpose: DicomFlipTemplate (Header)
00023  *
00024  *  Last Update:      $Author: meichel $
00025  *  Update Date:      $Date: 2005/12/08 16:47:39 $
00026  *  CVS/RCS Revision: $Revision: 1.18 $
00027  *  Status:           $State: Exp $
00028  *
00029  *  CVS/RCS Log at end of file
00030  *
00031  */
00032 
00033 
00034 #ifndef DIFLIPT_H
00035 #define DIFLIPT_H
00036 
00037 #include "dcmtk/config/osconfig.h"
00038 #include "dcmtk/dcmdata/dctypes.h"
00039 #include "dcmtk/ofstd/ofcast.h"
00040 
00041 #include "dcmtk/dcmimgle/dipixel.h"
00042 #include "dcmtk/dcmimgle/ditranst.h"
00043 
00044 
00045 /*---------------------*
00046  *  class declaration  *
00047  *---------------------*/
00048 
00052 template<class T>
00053 class DiFlipTemplate
00054   : public DiTransTemplate<T>
00055 {
00056 
00057  public:
00058 
00069     DiFlipTemplate(DiPixel *pixel,
00070                    const Uint16 columns,
00071                    const Uint16 rows,
00072                    const Uint32 frames,
00073                    const int horz,
00074                    const int vert)
00075       : DiTransTemplate<T>(0, columns, rows, columns, rows, frames)
00076     {
00077         if (pixel != NULL)
00078         {
00079             this->Planes = pixel->getPlanes();
00080             if ((pixel->getCount() > 0) && (this->Planes > 0) &&
00081                 (pixel->getCount() == OFstatic_cast(unsigned long, columns) * OFstatic_cast(unsigned long, rows) * frames))
00082             {
00083                 if (horz && vert)
00084                     flipHorzVert(OFstatic_cast(T **, pixel->getDataArrayPtr()));
00085                 else if (horz)
00086                     flipHorz(OFstatic_cast(T **, pixel->getDataArrayPtr()));
00087                 else if (vert)
00088                     flipVert(OFstatic_cast(T **, pixel->getDataArrayPtr()));
00089             } else {
00090                 if (DicomImageClass::checkDebugLevel(DicomImageClass::DL_Warnings))
00091                 {
00092                    ofConsole.lockCerr() << "WARNING: could not flip image ... corrupted data." << endl;
00093                    ofConsole.unlockCerr();
00094                 }
00095             }
00096         }
00097     }
00098 
00107     DiFlipTemplate(const int planes,
00108                    const Uint16 columns,
00109                    const Uint16 rows,
00110                    const Uint32 frames)
00111       : DiTransTemplate<T>(planes, columns, rows, columns, rows, frames)
00112     {
00113     }
00114 
00117     virtual ~DiFlipTemplate()
00118     {
00119     }
00120 
00128     inline void flipData(const T *src[],
00129                          T *dest[],
00130                          const int horz,
00131                          const int vert)
00132     {
00133         if ((src != NULL) && (dest != NULL))
00134         {
00135             if (horz && vert)
00136                 flipHorzVert(src, dest);
00137             else if (horz)
00138                 flipHorz(src, dest);
00139             else if (vert)
00140                 flipVert(src, dest);
00141             else
00142                 copyPixel(src, dest);
00143         }
00144     }
00145 
00146 
00147  protected:
00148 
00154     inline void flipHorz(const T *src[],
00155                          T *dest[])
00156     {
00157         if ((src != NULL) && (dest != NULL))
00158         {
00159             register Uint16 x;
00160             register Uint16 y;
00161             register const T *p;
00162             register T *q;
00163             register T *r;
00164             for (int j = 0; j < this->Planes; ++j)
00165             {
00166                 p = src[j];
00167                 r = dest[j];
00168                 for (Uint32 f = this->Frames; f != 0; --f)
00169                 {
00170                     for (y = this->Src_Y; y != 0; --y)
00171                     {
00172                         q = r + this->Dest_X;
00173                         for (x = this->Src_X; x != 0; --x)
00174                             *--q = *p++;
00175                         r += this->Dest_X;
00176                     }
00177                 }
00178             }
00179         }
00180     }
00181 
00187     inline void flipVert(const T *src[],
00188                          T *dest[])
00189     {
00190         if ((src != NULL) && (dest != NULL))
00191         {
00192             register Uint16 x;
00193             register Uint16 y;
00194             register const T *p;
00195             register T *q;
00196             register T *r;
00197             const unsigned long count = OFstatic_cast(unsigned long, this->Dest_X) * OFstatic_cast(unsigned long, this->Dest_Y);
00198             for (int j = 0; j < this->Planes; ++j)
00199             {
00200                 p = src[j];
00201                 r = dest[j];
00202                 for (Uint32 f = this->Frames; f != 0; --f)
00203                 {
00204                     r += count;
00205                     for (y = this->Src_Y; y != 0; --y)
00206                     {
00207                         q = r - this->Dest_X;
00208                         for (x = this->Src_X; x != 0; --x)
00209                             *q++ = *p++;
00210                         r -= this->Dest_X;
00211                     }
00212                     r += count;
00213                 }
00214             }
00215         }
00216     }
00217 
00223     inline void flipHorzVert(const T *src[],
00224                              T *dest[])
00225     {
00226        if ((src != NULL) && (dest != NULL))
00227        {
00228             register unsigned long i;
00229             register const T *p;
00230             register T *q;
00231             const unsigned long count = OFstatic_cast(unsigned long, this->Dest_X) * OFstatic_cast(unsigned long, this->Dest_Y);
00232             for (int j = 0; j < this->Planes; ++j)
00233             {
00234                 p = src[j];
00235                 q = dest[j];
00236                 for (Uint32 f = this->Frames; f != 0; --f)
00237                 {
00238                     q += count;
00239                     for (i = count; i != 0; --i)
00240                         *--q = *p++;
00241                     q += count;
00242                 }
00243             }
00244         }
00245     }
00246 
00247  private:
00248 
00253     inline void flipHorz(T *data[])
00254     {
00255         register Uint16 x;
00256         register Uint16 y;
00257         register T *p;
00258         register T *q;
00259         register T t;
00260         T *r;
00261         for (int j = 0; j < this->Planes; ++j)
00262         {
00263             r = data[j];
00264             for (Uint32 f = this->Frames; f != 0; --f)
00265             {
00266                 for (y = this->Src_Y; y != 0; --y)
00267                 {
00268                     p = r;
00269                     r += this->Dest_X;
00270                     q = r;
00271                     for (x = this->Src_X / 2; x != 0; --x)
00272                     {
00273                         t = *p;
00274                         *p++ = *--q;
00275                         *q = t;
00276                     }
00277                 }
00278             }
00279         }
00280     }
00281 
00286     inline void flipVert(T *data[])
00287     {
00288         register Uint16 x;
00289         register Uint16 y;
00290         register T *p;
00291         register T *q;
00292         register T *r;
00293         register T t;
00294         T *s;
00295         const unsigned long count = OFstatic_cast(unsigned long, this->Dest_X) * OFstatic_cast(unsigned long, this->Dest_Y);
00296         for (int j = 0; j < this->Planes; ++j)
00297         {
00298             s = data[j];
00299             for (Uint32 f = this->Frames; f != 0; --f)
00300             {
00301                 p = s;
00302                 s += count;
00303                 r = s;
00304                 for (y = this->Src_Y / 2; y != 0; --y)
00305                 {
00306                     r -= this->Dest_X;
00307                     q = r;
00308                     for (x = this->Src_X; x != 0; --x)
00309                     {
00310                         t = *p;
00311                         *p++ = *q;
00312                         *q++ = t;
00313                     }
00314                 }
00315             }
00316         }
00317     }
00318 
00323     inline void flipHorzVert(T *data[])
00324     {
00325         register unsigned long i;
00326         register T *p;
00327         register T *q;
00328         register T t;
00329         T *s;
00330         const unsigned long count = OFstatic_cast(unsigned long, this->Dest_X) * OFstatic_cast(unsigned long, this->Dest_Y);
00331         for (int j = 0; j < this->Planes; ++j)
00332         {
00333             s = data[j];
00334             for (Uint32 f = this->Frames; f != 0; --f)
00335             {
00336                 p = s;
00337                 q = s + count;
00338                 for (i = count / 2; i != 0; --i)
00339                 {
00340                     t = *p;
00341                     *p++ = *--q;
00342                     *q = t;
00343                 }
00344                 s += count;
00345             }
00346         }
00347     }
00348 };
00349 
00350 
00351 #endif
00352 
00353 
00354 /*
00355  *
00356  * CVS/RCS Log:
00357  * $Log: diflipt.h,v $
00358  * Revision 1.18  2005/12/08 16:47:39  meichel
00359  * Changed include path schema for all DCMTK header files
00360  *
00361  * Revision 1.17  2005/06/15 08:25:18  joergr
00362  * Fixed bug which prevented flipHorzVert() from flipping multi-frame images
00363  * correctly (only the first frame was actually flipped).
00364  *
00365  * Revision 1.16  2004/04/21 10:00:36  meichel
00366  * Minor modifications for compilation with gcc 3.4.0
00367  *
00368  * Revision 1.15  2004/02/06 11:07:50  joergr
00369  * Distinguish more clearly between const and non-const access to pixel data.
00370  *
00371  * Revision 1.14  2003/12/23 15:53:22  joergr
00372  * Replaced post-increment/decrement operators by pre-increment/decrement
00373  * operators where appropriate (e.g. 'i++' by '++i').
00374  *
00375  * Revision 1.13  2003/12/08 18:55:45  joergr
00376  * Adapted type casts to new-style typecast operators defined in ofcast.h.
00377  * Removed leading underscore characters from preprocessor symbols (reserved
00378  * symbols). Updated copyright header.
00379  *
00380  * Revision 1.12  2001/06/01 15:49:41  meichel
00381  * Updated copyright header
00382  *
00383  * Revision 1.11  2000/09/12 10:04:44  joergr
00384  * Corrected bug: wrong parameter for attribute search routine led to crashes
00385  * when multiple pixel data attributes were contained in the dataset (e.g.
00386  * IconImageSequence). Added new checking routines to avoid crashes when
00387  * processing corrupted image data.
00388  *
00389  * Revision 1.10  2000/03/08 16:24:15  meichel
00390  * Updated copyright header.
00391  *
00392  * Revision 1.9  2000/03/02 12:51:36  joergr
00393  * Rewrote variable initialization in class contructors to avoid warnings
00394  * reported on Irix.
00395  *
00396  * Revision 1.8  1999/09/17 12:10:55  joergr
00397  * Added/changed/completed DOC++ style comments in the header files.
00398  * Enhanced efficiency of some "for" loops.
00399  *
00400  * Revision 1.7  1999/05/03 11:09:28  joergr
00401  * Minor code purifications to keep Sun CC 2.0.1 quiet.
00402  *
00403  * Revision 1.6  1999/04/28 14:46:54  joergr
00404  * Removed debug code.
00405  *
00406  * Revision 1.5  1999/03/24 17:20:00  joergr
00407  * Added/Modified comments and formatting.
00408  *
00409  * Revision 1.4  1999/02/03 17:01:16  joergr
00410  * Removed some debug code.
00411  *
00412  * Revision 1.3  1999/01/20 14:59:05  joergr
00413  * Added debug code to measure time of some routines.
00414  *
00415  * Revision 1.2  1998/12/16 16:27:54  joergr
00416  * Added additional case to copy pixels.
00417  *
00418  * Revision 1.1  1998/11/27 14:57:46  joergr
00419  * Added copyright message.
00420  * Added methods and classes for flipping and rotating, changed for
00421  * scaling and clipping.
00422  *
00423  *
00424  */


Generated on 20 Dec 2005 for OFFIS DCMTK Version 3.5.4 by Doxygen 1.4.5