dcmimgle/include/dcmtk/dcmimgle/diimage.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: DicomImage (Header)
00019  *
00020  *  Last Update:      $Author: joergr $
00021  *  Update Date:      $Date: 2010-10-14 13:16:26 $
00022  *  CVS/RCS Revision: $Revision: 1.47 $
00023  *  Status:           $State: Exp $
00024  *
00025  *  CVS/RCS Log at end of file
00026  *
00027  */
00028 
00029 
00030 #ifndef DIIMAGE_H
00031 #define DIIMAGE_H
00032 
00033 #include "dcmtk/config/osconfig.h"
00034 
00035 #include "dcmtk/dcmdata/dcitem.h"
00036 #include "dcmtk/dcmdata/dcfcache.h"
00037 
00038 #ifdef SUNCC
00039 #include "dcmtk/dcmimgle/didocu.h"
00040 #endif
00041 
00042 #include "dcmtk/dcmimgle/diovlay.h"
00043 #include "dcmtk/dcmimgle/diutils.h"
00044 
00045 #define INCLUDE_CSTDIO
00046 #include "dcmtk/ofstd/ofstdinc.h"
00047 
00048 #include "dcmtk/ofstd/ofstream.h"
00049 
00050 
00051 /*------------------------*
00052  *  forward declarations  *
00053  *------------------------*/
00054 
00055 class DcmPixelData;
00056 class DcmUnsignedShort;
00057 
00058 #ifndef SUNCC
00059  class DiDocument;
00060 #endif
00061 
00062 class DiPixel;
00063 class DiMonoImage;
00064 class DiInputPixel;
00065 
00066 
00067 /*---------------------*
00068  *  class declaration  *
00069  *---------------------*/
00070 
00075 class DiImage
00076 {
00077 
00078  public:
00079 
00086     DiImage(const DiDocument *docu,
00087             const EI_Status status,
00088             const int spp);
00089 
00092     virtual ~DiImage();
00093 
00100     virtual int processNextFrames(const unsigned long fcount);
00101 
00106     inline EI_Status getStatus() const
00107     {
00108         return ImageStatus;
00109     }
00110 
00115     inline Uint32 getNumberOfFrames() const
00116     {
00117         return NumberOfFrames;
00118     }
00119 
00124     inline Uint32 getFirstFrame() const
00125     {
00126         return FirstFrame;
00127     }
00128 
00133     inline Uint32 getRepresentativeFrame() const
00134     {
00135         return RepresentativeFrame;
00136     }
00137 
00142     inline Uint16 getRows() const
00143     {
00144         return Rows;
00145     }
00146 
00151     inline Uint16 getColumns() const
00152     {
00153          return Columns;
00154     }
00155 
00160     inline double getPixelWidth() const
00161     {
00162         return (PixelWidth > 0) ? PixelWidth : 1;
00163     }
00164 
00169     inline double getPixelHeight() const
00170     {
00171         return (PixelHeight > 0) ? PixelHeight : 1;
00172     }
00173 
00178     inline double getRowColumnRatio() const
00179     {
00180         return getPixelHeight() / getPixelWidth();
00181     }
00182 
00187     inline double getColumnRowRatio() const
00188     {
00189         return getPixelWidth() / getPixelHeight();
00190     }
00191 
00198     int setRowColumnRatio(const double ratio);
00199 
00206     int setColumnRowRatio(const double ratio);
00207 
00213     inline EP_Polarity getPolarity() const
00214     {
00215         return Polarity;
00216     }
00217 
00226     int setPolarity(const EP_Polarity polarity);
00227 
00238     virtual int getBits(const int bits = 0) const
00239     {
00240         return ((bits < 1) || (bits > MAX_BITS)) ? BitsPerSample : bits;
00241     }
00242 
00248     virtual EP_Interpretation getInternalColorModel() const = 0;
00249 
00254     virtual const DiPixel *getInterData() const = 0;
00255 
00262     virtual unsigned long getOutputDataSize(const int bits = 0) const = 0;
00263 
00273     virtual const void *getOutputData(const unsigned long frame,
00274                                       const int bits,
00275                                       const int planar) = 0;
00276 
00288     virtual int getOutputData(void *buffer,
00289                               const unsigned long size,
00290                               const unsigned long frame,
00291                               const int bits,
00292                               const int planar) = 0;
00293 
00301     virtual const void *getOutputPlane(const int plane) const = 0;
00302 
00305     virtual void deleteOutputData() = 0;
00306 
00313     virtual DiOverlay *getOverlayPtr(const unsigned int /*idx*/)
00314     {
00315         return NULL;
00316     }
00317 
00322     virtual DiMonoImage *getMonoImagePtr()
00323     {
00324         return NULL;
00325     }
00326 
00334     virtual DiImage *createImage(const unsigned long fstart,
00335                                  const unsigned long fcount) const = 0;
00336 
00357     virtual DiImage *createScale(const signed long left_pos,
00358                                  const signed long top_pos,
00359                                  const unsigned long clip_width,
00360                                  const unsigned long clip_height,
00361                                  const unsigned long scale_width,
00362                                  const unsigned long scale_height,
00363                                  const int interpolate,
00364                                  const int aspect,
00365                                  const Uint16 pvalue) const = 0;
00366 
00374     virtual int flip(const int horz,
00375                      const int vert) = 0;
00376 
00384     virtual DiImage *createFlip(const int horz,
00385                                 const int vert) const = 0;
00386 
00393     virtual int rotate(const int degree);
00394 
00401     virtual DiImage *createRotate(const int degree) const = 0;
00402 
00411     virtual DiImage *createMono(const double red,
00412                                 const double green,
00413                                 const double blue) const = 0;
00414 
00426     virtual unsigned long createDIB(void *&data,
00427                                     const unsigned long size,
00428                                     const unsigned long frame,
00429                                     const int bits,
00430                                     const int upsideDown,
00431                                     const int padding = 1) = 0;
00432 
00441     virtual unsigned long createAWTBitmap(void *&data,
00442                                           const unsigned long frame,
00443                                           const int bits) = 0;
00444 
00454     int writeFrameToDataset(DcmItem &dataset,
00455                             const unsigned long frame = 0,
00456                             const int bits = 0,
00457                             const int planar = 0);
00458 
00467     virtual int writeImageToDataset(DcmItem &dataset,
00468                                     const int mode = 0,
00469                                     const int planar = 2) = 0;
00470 
00480     virtual int writePPM(STD_NAMESPACE ostream& stream,
00481                          const unsigned long frame,
00482                          const int bits) = 0;
00483 
00493     virtual int writePPM(FILE *stream,
00494                          const unsigned long frame,
00495                          const int bits) = 0;
00496 
00505     virtual int writeRawPPM(FILE *stream,
00506                             const unsigned long frame,
00507                             const int bits) = 0;
00508 
00517     virtual int writeBMP(FILE *stream,
00518                          const unsigned long frame,
00519                          const int bits);
00520 
00521 
00522  protected:
00523 
00529     DiImage(const DiDocument *docu,
00530             const EI_Status status);
00531 
00538     DiImage(const DiImage *image,
00539             const unsigned long fstart,
00540             const unsigned long fcount);
00541 
00549     DiImage(const DiImage *image,
00550             const Uint16 width,
00551             const Uint16 height,
00552             const int aspect = 0);
00553 
00559     DiImage(const DiImage *image,
00560             const int degree = 0);
00561 
00569     DiImage(const DiImage *image,
00570             const unsigned long frame,
00571             const int stored,
00572             const int alloc);
00573 
00576     void deleteInputData();
00577 
00580     void checkPixelExtension();
00581 
00584     void convertPixelData();
00585 
00593     virtual void updateImagePixelModuleAttributes(DcmItem &dataset);
00594 
00598     int detachPixelData();
00599 
00601     EI_Status ImageStatus;
00603     const DiDocument *Document;
00604 
00606     Uint32 FirstFrame;
00608     Uint32 NumberOfFrames;
00610     Uint32 TotalNumberOfFrames;
00612     Uint32 RepresentativeFrame;
00614     Uint16 Rows;
00616     Uint16 Columns;
00618     double PixelWidth;
00620     double PixelHeight;
00622     Uint16 BitsAllocated;
00624     Uint16 BitsStored;
00626     Uint16 HighBit;
00627 
00629     int BitsPerSample;
00631     int SamplesPerPixel;
00632 
00634     EP_Polarity Polarity;
00635 
00637     int hasSignedRepresentation;
00639     int hasPixelSpacing;
00641     int hasImagerPixelSpacing;
00643     int hasNominalScannedPixelSpacing;
00645     int hasPixelAspectRatio;
00647     int isOriginal;
00648 
00650     DiInputPixel *InputData;
00652     DcmFileCache FileCache;
00654     Uint32 CurrentFragment;
00655 
00656  // --- declarations to avoid compiler warnings
00657 
00658     DiImage(const DiImage &);
00659     DiImage &operator=(const DiImage &);
00660 };
00661 
00662 
00663 #endif
00664 
00665 
00666 /*
00667  *
00668  * CVS/RCS Log:
00669  * $Log: diimage.h,v $
00670  * Revision 1.47  2010-10-14 13:16:26  joergr
00671  * Updated copyright header. Added reference to COPYRIGHT file.
00672  *
00673  * Revision 1.46  2010-10-05 15:26:28  joergr
00674  * Fixed various Doxygen API documentation issues.
00675  *
00676  * Revision 1.45  2010-03-01 09:08:46  uli
00677  * Removed some unnecessary include directives in the headers.
00678  *
00679  * Revision 1.44  2009-11-25 15:59:10  joergr
00680  * Adapted code for new approach to access individual frames of a DICOM image.
00681  *
00682  * Revision 1.43  2009-02-12 12:01:17  joergr
00683  * Added support for NominalScannedPixelSpacing in order to determine the pixel
00684  * aspect ratio (used for the new SC image IODs).
00685  *
00686  * Revision 1.42  2008-05-20 10:03:53  joergr
00687  * Added new bilinear and bicubic scaling algorithms for image magnification.
00688  *
00689  * Revision 1.41  2008-05-13 09:54:40  joergr
00690  * Added new parameter to writeImageToDataset() in order to affect the planar
00691  * configuration of the output image/dataset. Changed behaviour: By default,
00692  * the output now uses the same planar configuration as the "original" image
00693  * (previously: always color-by-plane).
00694  *
00695  * Revision 1.40  2006/08/15 16:30:11  meichel
00696  * Updated the code in module dcmimgle to correctly compile when
00697  *   all standard C++ classes remain in namespace std.
00698  *
00699  * Revision 1.39  2006/07/10 10:52:27  joergr
00700  * Added support for 32-bit BMP images.
00701  *
00702  * Revision 1.38  2005/12/08 16:47:42  meichel
00703  * Changed include path schema for all DCMTK header files
00704  *
00705  * Revision 1.37  2005/03/09 17:32:35  joergr
00706  * Added mode to writeImageToDataset() which allows the value of BitsStored to
00707  * be determined either from 'used' or from 'possible' pixel values.
00708  *
00709  * Revision 1.36  2004/09/22 11:33:14  joergr
00710  * Introduced new member variable "TotalNumberOfFrames".
00711  *
00712  * Revision 1.35  2004/07/20 18:12:16  joergr
00713  * Added API method to "officially" access the internal intermediate pixel data
00714  * representation (e.g. to get Hounsfield Units for CT images).
00715  *
00716  * Revision 1.34  2004/02/06 11:07:50  joergr
00717  * Distinguish more clearly between const and non-const access to pixel data.
00718  *
00719  * Revision 1.33  2004/01/05 14:52:20  joergr
00720  * Removed acknowledgements with e-mail addresses from CVS log.
00721  *
00722  * Revision 1.32  2003/12/08 18:22:26  joergr
00723  * Removed leading underscore characters from preprocessor symbols (reserved
00724  * symbols). Updated CVS header.
00725  *
00726  * Revision 1.31  2003/06/12 15:08:34  joergr
00727  * Fixed inconsistent API documentation reported by Doxygen.
00728  *
00729  * Revision 1.30  2003/05/20 09:20:41  joergr
00730  * Added method returning the number of bytes required to store a single
00731  * rendered frame: getOutputDataSize().
00732  *
00733  * Revision 1.29  2002/12/09 13:32:51  joergr
00734  * Renamed parameter/local variable to avoid name clashes with global
00735  * declaration left and/or right (used for as iostream manipulators).
00736  *
00737  * Revision 1.28  2002/11/27 14:08:04  meichel
00738  * Adapted module dcmimgle to use of new header file ofstdinc.h
00739  *
00740  * Revision 1.27  2002/11/26 14:48:32  joergr
00741  * Added Smallest/LargestImagePixelValue to the list of attributes to be
00742  * removed from a newly created dataset.
00743  *
00744  * Revision 1.26  2002/08/02 15:03:20  joergr
00745  * Enhanced writeFrameToDataset() routine (remove out-data DICOM attributes
00746  * from the dataset).
00747  * Added function to write the current image (not only a selected frame) to a
00748  * DICOM dataset.
00749  *
00750  * Revision 1.25  2002/06/26 16:01:55  joergr
00751  * Added support for polarity flag to color images.
00752  * Added new method to write a selected frame to a DICOM dataset (incl. required
00753  * attributes from the "Image Pixel Module").
00754  *
00755  * Revision 1.24  2002/04/16 13:53:11  joergr
00756  * Added configurable support for C++ ANSI standard includes (e.g. streams).
00757  *
00758  * Revision 1.23  2002/01/29 17:05:50  joergr
00759  * Added optional flag to the "Windows DIB" methods allowing to switch off the
00760  * scanline padding.
00761  *
00762  * Revision 1.22  2001/11/27 18:18:22  joergr
00763  * Added support for plugable output formats in class DicomImage. First
00764  * implementation is JPEG.
00765  *
00766  * Revision 1.21  2001/11/09 16:26:37  joergr
00767  * Added support for Window BMP file format.
00768  * Enhanced and renamed createTrueColorDIB() method.
00769  *
00770  * Revision 1.20  2001/06/20 15:12:49  joergr
00771  * Enhanced multi-frame support for command line tool 'dcm2pnm': extract all
00772  * or a range of frames with one call.
00773  *
00774  * Revision 1.19  2001/06/01 15:49:42  meichel
00775  * Updated copyright header
00776  *
00777  * Revision 1.18  2000/03/08 16:24:16  meichel
00778  * Updated copyright header.
00779  *
00780  * Revision 1.17  2000/02/02 11:02:38  joergr
00781  * Removed space characters before preprocessor directives.
00782  *
00783  * Revision 1.16  1999/10/06 13:28:21  joergr
00784  * Corrected creation of PrintBitmap pixel data: VOI windows should be applied
00785  * before clipping to avoid that the region outside the image (border) is also
00786  * windowed (this requires a new method in dcmimgle to create a DicomImage
00787  * with the grayscale transformations already applied).
00788  *
00789  * Revision 1.15  1999/09/17 12:12:18  joergr
00790  * Added/changed/completed DOC++ style comments in the header files.
00791  *
00792  * Revision 1.14  1999/08/25 16:39:31  joergr
00793  * Allow clipping region to be outside the image (overlapping).
00794  *
00795  * Revision 1.13  1999/07/23 13:53:00  joergr
00796  * Added support for attribute 'ImagerPixelSpacing'.
00797  * Added support for attribute 'RepresentativeFrameNumber'.
00798  * Added methods to set 'PixelAspectRatio'.
00799  *
00800  * Revision 1.12  1999/04/28 14:47:34  joergr
00801  * Added experimental support to create grayscale images with more than 256
00802  * shades of gray to be displayed on a consumer monitor (use pastel colors).
00803  *
00804  * Revision 1.11  1999/03/24 17:20:01  joergr
00805  * Added/Modified comments and formatting.
00806  *
00807  * Revision 1.10  1999/02/08 12:38:12  joergr
00808  * Added parameter 'idx' to some overlay methods to distinguish between
00809  * built-in and additional overlay planes.
00810  *
00811  * Revision 1.9  1999/02/03 17:01:45  joergr
00812  * Added BEGIN_EXTERN_C and END_EXTERN_C to some C includes.
00813  *
00814  * Revision 1.8  1999/01/20 14:59:37  joergr
00815  * Added new output method to fill external memory buffer with rendered pixel
00816  * data.
00817  *
00818  * Revision 1.7  1999/01/11 09:32:32  joergr
00819  * Removed method 'getMinMaxValues()' in class 'DicomImage'.
00820  *
00821  * Revision 1.6  1998/12/23 11:33:08  joergr
00822  * Corrected some typos and formatting.
00823  *
00824  * Revision 1.5  1998/12/22 14:03:53  joergr
00825  * Changed parameter declaration to avoid compiler warnings (hide parameter
00826  * name).
00827  *
00828  * Revision 1.4  1998/12/16 16:29:04  joergr
00829  * Removed several methods used for monochrome images only in base class
00830  * 'DiImage'. Introduced mechanism to use the methods directly.
00831  *
00832  * Revision 1.3  1998/12/14 17:17:29  joergr
00833  * Added methods to add and remove additional overlay planes (still untested).
00834  *
00835  * Revision 1.2  1998/11/30 12:24:07  joergr
00836  * Added const type qualifier to some parameters to avoid errors with MSVC5
00837  * (couldn't create instance of abstract class).
00838  *
00839  * Revision 1.1  1998/11/27 15:06:08  joergr
00840  * Added copyright message.
00841  * Added methods and constructors for flipping and rotating, changed for
00842  * scaling and clipping.
00843  * Added method to directly create java AWT bitmaps.
00844  * Renamed variable 'Status' to 'ImageStatus' because of possible conflicts
00845  * with X windows systems.
00846  * Added method to detach pixel data if it is no longer needed.
00847  * Added methods to support presentation LUTs and shapes.
00848  *
00849  * Revision 1.6  1998/07/01 08:39:21  joergr
00850  * Minor changes to avoid compiler warnings (gcc 2.8.1 with additional
00851  * options), e.g. add copy constructors.
00852  *
00853  * Revision 1.5  1998/05/11 14:53:16  joergr
00854  * Added CVS/RCS header to each file.
00855  *
00856  *
00857  */


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