dcmimgle/include/dcmtk/dcmimgle/diovpln.h

00001 /*
00002  *
00003  *  Copyright (C) 1996-2010, OFFIS e.V.
00004  *  All rights reserved.  See COPYRIGHT file for details.
00005  *
00006  *  This software and supporting documentation were developed by
00007  *
00008  *    OFFIS e.V.
00009  *    R&D Division Health
00010  *    Escherweg 2
00011  *    D-26121 Oldenburg, Germany
00012  *
00013  *
00014  *  Module:  dcmimgle
00015  *
00016  *  Author:  Joerg Riesmeier
00017  *
00018  *  Purpose: DicomOverlayPlane (Header)
00019  *
00020  *  Last Update:      $Author: joergr $
00021  *  Update Date:      $Date: 2010-10-14 13:16:27 $
00022  *  CVS/RCS Revision: $Revision: 1.32 $
00023  *  Status:           $State: Exp $
00024  *
00025  *  CVS/RCS Log at end of file
00026  *
00027  */
00028 
00029 
00030 #ifndef DIOVPLN_H
00031 #define DIOVPLN_H
00032 
00033 #include "dcmtk/config/osconfig.h"
00034 #include "dcmtk/ofstd/ofstring.h"
00035 #include "dcmtk/ofstd/ofcast.h"
00036 
00037 #include "dcmtk/dcmimgle/diutils.h"
00038 
00039 #define INCLUDE_CSTDDEF
00040 #include "dcmtk/ofstd/ofstdinc.h"
00041 
00042 
00043 /*------------------------*
00044  *  forward declarations  *
00045  *------------------------*/
00046 
00047 class DcmOverlayData;
00048 class DcmLongString;
00049 
00050 class DiDocument;
00051 
00052 
00053 /*---------------------*
00054  *  class declaration  *
00055  *---------------------*/
00056 
00059 class DiOverlayPlane
00060 {
00061 
00062  public:
00063 
00072     DiOverlayPlane(const DiDocument *docu,
00073                    const unsigned int group,
00074                    Uint16 alloc,
00075                    const Uint16 stored,
00076                    const Uint16 high);
00077 
00090     DiOverlayPlane(const unsigned int group,
00091                    const Sint16 left_pos,
00092                    const Sint16 top_pos,
00093                    const Uint16 columns,
00094                    const Uint16 rows,
00095                    const DcmOverlayData &data,
00096                    const DcmLongString &label,
00097                    const DcmLongString &description,
00098                    const EM_Overlay mode);
00099 
00111     DiOverlayPlane(DiOverlayPlane *plane,
00112                    const unsigned int bit,
00113                    Uint16 *data,
00114                    Uint16 *temp,
00115                    const Uint16 width,
00116                    const Uint16 height,
00117                    const Uint16 columns,
00118                    const Uint16 rows);
00119 
00122     ~DiOverlayPlane();
00123 
00130     inline Sint16 getLeft(const Sint32 left_pos = 0) const
00131     {
00132         return OFstatic_cast(Sint16, OFstatic_cast(Sint32, Left) - left_pos);
00133     }
00134 
00141     inline Sint16 getTop(const Sint32 top_pos = 0) const
00142     {
00143         return OFstatic_cast(Sint16, OFstatic_cast(Sint32, Top) - top_pos);
00144     }
00145 
00150     inline Uint16 getWidth() const
00151     {
00152         return Width;
00153     }
00154 
00159     inline Uint16 getHeight() const
00160     {
00161         return Height;
00162     }
00163 
00170     inline Uint16 getRight(const Sint32 left_pos = 0) const
00171     {
00172         return (OFstatic_cast(Sint32, Left) + OFstatic_cast(Sint32, Width) - left_pos > 0) ?
00173             OFstatic_cast(Uint16, OFstatic_cast(Sint32, Left) + OFstatic_cast(Sint32, Width) - left_pos) : 0;
00174     }
00175 
00182     inline Uint16 getBottom(const Sint32 top_pos = 0) const
00183     {
00184         return (OFstatic_cast(Sint32, Top) + OFstatic_cast(Sint32, Height) - top_pos > 0) ?
00185             OFstatic_cast(Uint16, OFstatic_cast(Sint32, Top) + OFstatic_cast(Sint32, Height) - top_pos) : 0;
00186     }
00187 
00192     inline int isValid() const
00193     {
00194         return Valid;
00195     }
00196 
00201     inline int isVisible() const
00202     {
00203         return Visible;
00204     }
00205 
00208     inline void show()
00209     {
00210         Visible = 1;
00211     }
00212 
00215     inline void hide()
00216     {
00217         Visible = 0;
00218     }
00219 
00225     void place(const signed int left_pos,
00226                const signed int top_pos);
00227 
00233     void setScaling(const double xfactor,
00234                     const double yfactor);
00235 
00243     void setFlipping(const int horz,
00244                      const int vert,
00245                      const signed long columns,
00246                      const signed long rows);
00247 
00256     void setRotation(const int degree,
00257                      const signed long left_pos,
00258                      const signed long top_pos,
00259                      const Uint16 columns,
00260                      const Uint16 rows);
00261 
00268     void show(const double fore,
00269               const double thresh,
00270               const EM_Overlay mode);
00271 
00279     int show(const Uint16 pvalue);
00280 
00285     inline unsigned long getNumberOfFrames() const
00286     {
00287         return NumberOfFrames;
00288     }
00289 
00294     inline double getForeground() const
00295     {
00296         return Foreground;
00297     }
00298 
00303     inline double getThreshold() const
00304     {
00305         return Threshold;
00306     }
00307 
00313     inline Uint16 getPValue() const
00314     {
00315         return PValue;
00316     }
00317 
00322     inline EM_Overlay getMode() const
00323     {
00324         return Mode;
00325     }
00326 
00331     inline int isEmbedded() const
00332     {
00333         return EmbeddedData;
00334     }
00335 
00340     const char *getLabel() const
00341     {
00342         return (Label.empty()) ? OFstatic_cast(const char *, NULL) : Label.c_str();
00343     }
00344 
00349     const char *getDescription() const
00350     {
00351         return (Description.empty()) ? OFstatic_cast(const char *, NULL) : Description.c_str();
00352     }
00353 
00358     Uint16 getGroupNumber() const
00359     {
00360         return GroupNumber;
00361     }
00362 
00378     void *getData(const unsigned long frame,
00379                   const Uint16 xmin,
00380                   const Uint16 ymin,
00381                   const Uint16 xmax,
00382                   const Uint16 ymax,
00383                   const int bits,
00384                   const Uint16 fore,
00385                   const Uint16 back);
00386 
00399     unsigned long create6xxx3000Data(Uint8 *&buffer,
00400                                      unsigned int &width,
00401                                      unsigned int &height,
00402                                      unsigned long &frames);
00403 
00410     inline int reset(const unsigned long frame);
00411 
00416     inline int getNextBit();
00417 
00423     inline void setStart(const Uint16 x,
00424                          const Uint16 y);
00425 
00426 
00427  protected:
00428 
00430     Uint32 NumberOfFrames;
00432     Uint16 ImageFrameOrigin;
00433 
00435     Sint16 Top;
00437     Sint16 Left;
00439     Uint16 Height;
00441     Uint16 Width;
00443     Uint16 Rows;
00445     Uint16 Columns;
00447     Uint16 BitsAllocated;
00449     Uint16 BitPosition;
00450 
00452     double Foreground;
00454     double Threshold;
00456     Uint16 PValue;
00457 
00459     EM_Overlay Mode;
00461     EM_Overlay DefaultMode;
00462 
00464     OFString Label;
00466     OFString Description;
00467 
00469     Uint16 GroupNumber;
00470 
00472     int Valid;
00474     int Visible;
00475 
00476 
00477  private:
00478 
00480     unsigned long BitPos;
00482     unsigned long StartBitPos;
00483 
00485     unsigned int StartLeft;
00487     unsigned int StartTop;
00488 
00490     int EmbeddedData;
00491 
00493     const Uint16 *Ptr;
00495     const Uint16 *StartPtr;
00497     const Uint16 *Data;
00498 
00499  // --- declarations to avoid compiler warnings
00500 
00501     DiOverlayPlane(const DiOverlayPlane &);
00502     DiOverlayPlane &operator=(const DiOverlayPlane &);
00503 };
00504 
00505 
00506 /********************************************************************/
00507 
00508 
00509 inline int DiOverlayPlane::reset(const unsigned long frame)
00510 {
00511     int result = 0;
00512     if (Valid && (Data != NULL) && (frame >= ImageFrameOrigin) && (frame < ImageFrameOrigin + NumberOfFrames))
00513     {
00514         const unsigned long bits = (OFstatic_cast(unsigned long, StartLeft) + OFstatic_cast(unsigned long, StartTop) *
00515             OFstatic_cast(unsigned long, Columns) + frame * OFstatic_cast(unsigned long, Rows) *
00516             OFstatic_cast(unsigned long, Columns)) * OFstatic_cast(unsigned long, BitsAllocated);
00517         StartBitPos = BitPos = OFstatic_cast(unsigned long, BitPosition) + bits;
00518         /* distinguish between embedded and separate overlay data */
00519         if (BitsAllocated == 16)
00520             StartPtr = Ptr = Data + (bits >> 4);
00521         else
00522             StartPtr = Data;
00523         result = (getRight() > 0) && (getBottom() > 0);
00524     }
00525     return result;
00526 }
00527 
00528 
00529 inline int DiOverlayPlane::getNextBit()
00530 {
00531     int result;
00532     if (BitsAllocated == 16)                                        // optimization
00533         result = OFstatic_cast(int, *(Ptr++) & (1 << BitPosition));
00534     else
00535     {
00536         Ptr = StartPtr + (BitPos >> 4);                             // div 16
00537         result = OFstatic_cast(int, *Ptr & (1 << (BitPos & 0xf)));  // mod 16
00538         BitPos += BitsAllocated;                                    // next bit
00539     }
00540     return result;
00541 }
00542 
00543 
00544 inline void DiOverlayPlane::setStart(const Uint16 x,
00545                                      const Uint16 y)
00546 {
00547     if (BitsAllocated == 16)
00548         Ptr = StartPtr + OFstatic_cast(unsigned long, y - Top) * OFstatic_cast(unsigned long, Columns) +
00549             OFstatic_cast(unsigned long, x - Left);
00550     else
00551         BitPos = StartBitPos + (OFstatic_cast(unsigned long, y - Top) * OFstatic_cast(unsigned long, Columns) +
00552             OFstatic_cast(unsigned long, x - Left)) * OFstatic_cast(unsigned long, BitsAllocated);
00553 }
00554 
00555 
00556 #endif
00557 
00558 
00559 /*
00560  *
00561  * CVS/RCS Log:
00562  * $Log: diovpln.h,v $
00563  * Revision 1.32  2010-10-14 13:16:27  joergr
00564  * Updated copyright header. Added reference to COPYRIGHT file.
00565  *
00566  * Revision 1.31  2010-06-16 08:10:53  joergr
00567  * Removed inline declaration from place() function.
00568  *
00569  * Revision 1.30  2010-06-16 07:08:08  joergr
00570  * Added type cast to integer variables in order to avoid compiler warnings
00571  * reported by VisualStudio 2008 with warning level 4 (highest).
00572  *
00573  * Revision 1.29  2010-03-01 09:08:47  uli
00574  * Removed some unnecessary include directives in the headers.
00575  *
00576  * Revision 1.28  2008-11-18 11:01:28  joergr
00577  * Fixed issue with incorrectly encoded overlay planes (wrong values for
00578  * OverlayBitsAllocated and OverlayBitPosition).
00579  *
00580  * Revision 1.27  2006/11/09 11:03:51  joergr
00581  * Fixed possible program crash when processing multi-frame overlay data stored in
00582  * data element OverlayData (60xx,3000).
00583  *
00584  * Revision 1.26  2005/12/08 16:48:03  meichel
00585  * Changed include path schema for all DCMTK header files
00586  *
00587  * Revision 1.25  2004/01/05 14:52:20  joergr
00588  * Removed acknowledgements with e-mail addresses from CVS log.
00589  *
00590  * Revision 1.24  2003/12/09 10:11:28  joergr
00591  * Adapted type casts to new-style typecast operators defined in ofcast.h.
00592  * Removed leading underscore characters from preprocessor symbols (reserved
00593  * symbols). Updated copyright header.
00594  *
00595  * Revision 1.23  2003/06/12 15:08:34  joergr
00596  * Fixed inconsistent API documentation reported by Doxygen.
00597  *
00598  * Revision 1.22  2002/12/09 13:32:55  joergr
00599  * Renamed parameter/local variable to avoid name clashes with global
00600  * declaration left and/or right (used for as iostream manipulators).
00601  *
00602  * Revision 1.21  2002/11/27 14:08:07  meichel
00603  * Adapted module dcmimgle to use of new header file ofstdinc.h
00604  *
00605  * Revision 1.20  2002/04/16 13:53:12  joergr
00606  * Added configurable support for C++ ANSI standard includes (e.g. streams).
00607  *
00608  * Revision 1.19  2001/09/28 13:10:32  joergr
00609  * Added method to extract embedded overlay planes from pixel data and store
00610  * them in group (6xxx,3000) format.
00611  *
00612  * Revision 1.18  2001/06/01 15:49:49  meichel
00613  * Updated copyright header
00614  *
00615  * Revision 1.17  2001/05/22 13:20:44  joergr
00616  * Enhanced checking routines for corrupt overlay data (e.g. invalid value for
00617  * OverlayBitsAllocated).
00618  *
00619  * Revision 1.16  2000/03/08 16:24:22  meichel
00620  * Updated copyright header.
00621  *
00622  * Revision 1.15  2000/02/02 11:02:39  joergr
00623  * Removed space characters before preprocessor directives.
00624  *
00625  * Revision 1.14  1999/10/20 10:34:06  joergr
00626  * Enhanced method getOverlayData to support 12 bit data for print.
00627  *
00628  * Revision 1.13  1999/09/17 12:46:59  joergr
00629  * Added/changed/completed DOC++ style comments in the header files.
00630  *
00631  * Revision 1.12  1999/08/25 16:41:55  joergr
00632  * Added new feature: Allow clipping region to be outside the image
00633  * (overlapping).
00634  *
00635  * Revision 1.11  1999/05/03 11:09:31  joergr
00636  * Minor code purifications to keep Sun CC 2.0.1 quiet.
00637  *
00638  * Revision 1.10  1999/04/29 16:46:47  meichel
00639  * Minor code purifications to keep DEC cxx 6 quiet.
00640  *
00641  * Revision 1.9  1999/03/24 17:20:21  joergr
00642  * Added/Modified comments and formatting.
00643  *
00644  * Revision 1.8  1999/03/22 08:52:18  joergr
00645  * Added parameter to specify (transparent) background color for method
00646  * getOverlayData().
00647  *
00648  * Revision 1.7  1999/02/03 17:34:36  joergr
00649  * Added BEGIN_EXTERN_C and END_EXTERN_C to some C includes.
00650  * Added support for calibration according to Barten transformation (incl.
00651  * a DISPLAY file describing the monitor characteristic).
00652  *
00653  * Revision 1.6  1998/12/23 13:21:29  joergr
00654  * Changed parameter type (long to int) to avoid warning reported by MSVC5.
00655  *
00656  * Revision 1.5  1998/12/23 11:37:42  joergr
00657  * Changed order of parameters for addOverlay() and getOverlayData().
00658  * Changed behaviour of getLabel/Description/Explanation() methods: return
00659  * NULL if string empty, no empty string "".
00660  *
00661  * Revision 1.4  1998/12/22 14:36:30  joergr
00662  * Added method to check whether plane is visible, to get plane mode and to
00663  * remove all planes. Set 'value' used for getOverlay/PlaneData().
00664  *
00665  * Revision 1.3  1998/12/16 16:37:51  joergr
00666  * Added method to export overlay planes (create 8-bit bitmap).
00667  * Implemented flipping and rotation of overlay planes.
00668  *
00669  * Revision 1.2  1998/12/14 17:28:18  joergr
00670  * Added methods to add and remove additional overlay planes (still untested).
00671  * Added methods to support overlay labels and descriptions.
00672  *
00673  * Revision 1.1  1998/11/27 15:45:09  joergr
00674  * Added copyright message.
00675  * Added method to detach pixel data if it is no longer needed.
00676  * Added methods and constructors for flipping and rotating, changed for
00677  * scaling and clipping.
00678  *
00679  * Revision 1.7  1998/07/01 08:39:26  joergr
00680  * Minor changes to avoid compiler warnings (gcc 2.8.1 with additional
00681  * options), e.g. add copy constructors.
00682  *
00683  * Revision 1.6  1998/05/11 14:53:26  joergr
00684  * Added CVS/RCS header to each file.
00685  *
00686  *
00687  */


Generated on 6 Jan 2011 for OFFIS DCMTK Version 3.6.0 by Doxygen 1.5.1