dimoimg.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: DicomMonochromeImage (Header)
00023  *
00024  *  Last Update:      $Author: meichel $
00025  *  Update Date:      $Date: 2005/12/08 16:47:50 $
00026  *  CVS/RCS Revision: $Revision: 1.46 $
00027  *  Status:           $State: Exp $
00028  *
00029  *  CVS/RCS Log at end of file
00030  *
00031  */
00032 
00033 
00034 #ifndef DIMOIMG_H
00035 #define DIMOIMG_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/diimage.h"
00042 #include "dcmtk/dcmimgle/dimopx.h"
00043 #include "dcmtk/dcmimgle/dimoopx.h"
00044 #include "dcmtk/dcmimgle/diovlay.h"
00045 #include "dcmtk/dcmimgle/diluptab.h"
00046 #include "dcmtk/dcmimgle/didispfn.h"
00047 
00048 
00049 /*------------------------*
00050  *  forward declarations  *
00051  *------------------------*/
00052 
00053 class DiColorImage;
00054 
00055 
00056 /*---------------------*
00057  *  class declaration  *
00058  *---------------------*/
00059 
00062 class DiMonoImage
00063   : public DiImage
00064 {
00065 
00066  public:
00067 
00073     DiMonoImage(const DiDocument *docu,
00074                 const EI_Status status);
00075 
00083     DiMonoImage(const DiDocument *docu,
00084                 const EI_Status status,
00085                 const double slope,
00086                 const double intercept);
00087 
00096     DiMonoImage(const DiDocument *docu,
00097                 const EI_Status status,
00098                 const DcmUnsignedShort &data,
00099                 const DcmUnsignedShort &descriptor,
00100                 const DcmLongString *explanation);
00101 
00104     virtual ~DiMonoImage();
00105 
00117     int getMinMaxValues(double &min,
00118                         double &max,
00119                         const int mode) const;
00120 
00125     DiDisplayFunction *getDisplayFunction() const
00126     {
00127         return DisplayFunction;
00128     }
00129 
00136     int setDisplayFunction(DiDisplayFunction *display);
00137 
00145     int setNoDisplayFunction();
00146 
00154     int setNoVoiTransformation();
00155 
00162     inline int deleteDisplayLUT(const int bits)
00163     {
00164         return (DisplayFunction != NULL) ? DisplayFunction->deleteLookupTable(bits) : 0;
00165     }
00166 
00173     inline int isValueUnused(const unsigned long value)
00174     {
00175         return (OutputData != NULL) ? OutputData->isUnused(value) : 0;
00176     }
00177 
00189     int convertPValueToDDL(const Uint16 pvalue,
00190                            Uint16 &ddl,
00191                            const int bits);
00192 
00202     int setMinMaxWindow(const int idx = 1);
00203 
00218     int setRoiWindow(const unsigned long left_pos,
00219                      const unsigned long top_pos,
00220                      const unsigned long width,
00221                      const unsigned long height,
00222                      const unsigned long frame);
00223 
00231     int setHistogramWindow(const double thresh);
00232 
00240     int setWindow(const unsigned long pos = 0);
00241 
00253     int setWindow(const double center,
00254                   const double width,
00255                   const char *explanation = NULL);
00256 
00264     int getWindow(double &center,
00265                   double &width);
00266 
00271     inline unsigned long getWindowCount() const
00272     {
00273         return WindowCount;
00274     }
00275 
00287     int setVoiLut(const DcmUnsignedShort &data,
00288                   const DcmUnsignedShort &descriptor,
00289                   const DcmLongString *explanation,
00290                   const OFBool ignoreDepth = OFFalse);
00291 
00301     int setVoiLut(const unsigned long pos,
00302                   const OFBool ignoreDepth = OFFalse);
00303 
00308     inline unsigned long getVoiLutCount() const
00309     {
00310         return VoiLutCount;
00311     }
00312 
00317     inline const char *getVoiTransformationExplanation() const
00318     {
00319         return VoiExplanation.c_str();
00320     }
00321 
00329     const char *getVoiWindowExplanation(const unsigned long pos,
00330                                         OFString &explanation) const;
00331 
00339     const char *getVoiLutExplanation(const unsigned long pos,
00340                                      OFString &explanation) const;
00341 
00346     inline const char *getModalityLutExplanation() const
00347     {
00348         return (InterData != NULL) ? InterData->getModalityLutExplanation() : OFstatic_cast(const char *, NULL);
00349     }
00350 
00362      int setHardcopyParameters(const unsigned int min,
00363                                const unsigned int max,
00364                                const unsigned int reflect,
00365                                const unsigned int illumin);
00366 
00373     ES_PresentationLut getPresentationLutShape() const;
00374 
00386     int setPresentationLutShape(const ES_PresentationLut shape);
00387 
00399     int setPresentationLut(const DcmUnsignedShort &data,
00400                            const DcmUnsignedShort &descriptor,
00401                            const DcmLongString *explanation = NULL,
00402                            const OFBool ignoreDepth = OFFalse);
00403 
00415     int setInversePresentationLut(const DcmUnsignedShort &data,
00416                                   const DcmUnsignedShort &descriptor,
00417                                   const OFBool ignoreDepth = OFFalse);
00418 
00423     inline const char *getPresentationLutExplanation() const
00424     {
00425         return (PresLutData != NULL) ? PresLutData->getExplanation() : OFstatic_cast(const char *, NULL);
00426     }
00427 
00444     int addOverlay(const unsigned int group,
00445                    const signed int left_pos,
00446                    const signed int top_pos,
00447                    const unsigned int columns,
00448                    const unsigned int rows,
00449                    const DcmOverlayData &data,
00450                    const DcmLongString &label,
00451                    const DcmLongString &description,
00452                    const EM_Overlay mode);
00453 
00458     int removeAllOverlays();
00459 
00466     inline DiOverlay *getOverlayPtr(const unsigned int idx)
00467     {
00468         return (idx < 2) ? Overlays[idx] : OFstatic_cast(DiOverlay *, NULL);
00469     }
00470 
00475     inline DiMonoImage *getMonoImagePtr()
00476     {
00477         return this;
00478     }
00479 
00489     int flip(const int horz,
00490              const int vert);
00491 
00500     int rotate(const int degree);
00501 
00512     virtual int getBits(const int bits = 0) const
00513     {
00514         return (((bits < 1) || (bits > MAX_BITS)) && (bits != MI_PastelColor)) ? BitsPerSample : bits;
00515     }
00516 
00523     virtual unsigned long getOutputDataSize(const int bits = 0) const;
00524 
00534     virtual const void *getOutputData(const unsigned long frame,
00535                                       const int bits,
00536                                       const int planar = 0) = 0;
00537 
00549     virtual int getOutputData(void *buffer,
00550                               const unsigned long size,
00551                               const unsigned long frame,
00552                               const int bits,
00553                               const int planar = 0) = 0;
00554 
00562     const void *getOutputPlane(const int dummy) const;
00563 
00567     void deleteOutputData();
00568 
00586     const void *getOverlayData(const unsigned long frame,
00587                                 const unsigned int plane,
00588                                 unsigned int &left_pos,
00589                                 unsigned int &top_pos,
00590                                 unsigned int &width,
00591                                 unsigned int &height,
00592                                 EM_Overlay &mode,
00593                                 const unsigned int idx,
00594                                 const int bits = 8,
00595                                 const Uint16 fore = 0xff,
00596                                 const Uint16 back = 0x0);
00597 
00612     const void *getFullOverlayData(const unsigned long frame,
00613                                    const unsigned int plane,
00614                                    unsigned int &width,
00615                                    unsigned int &height,
00616                                    const unsigned int idx,
00617                                    const int bits = 8,
00618                                    const Uint16 fore = 0xff,
00619                                    const Uint16 back = 0x0);
00620 
00624     void deleteOverlayData();
00625 
00642     unsigned long create6xxx3000OverlayData(Uint8 *&buffer,
00643                                             const unsigned int plane,
00644                                             unsigned int &width,
00645                                             unsigned int &height,
00646                                             unsigned long &frames,
00647                                             const unsigned int idx = 0);
00648 
00653     const DiPixel *getInterData() const
00654     {
00655         return InterData;
00656     }
00657 
00662     const DiMonoPixel *getMonoInterData() const
00663     {
00664         return InterData;
00665     }
00666 
00679     unsigned long createDIB(void *&data,
00680                             const unsigned long size,
00681                             const unsigned long frame,
00682                             const int bits,
00683                             const int upsideDown,
00684                             const int padding = 1);
00685 
00695     unsigned long createAWTBitmap(void *&data,
00696                                   const unsigned long frame,
00697                                   const int bits);
00698 
00710     static void *createPackedBitmap(const void *buffer,
00711                                     const unsigned long size,
00712                                     const unsigned long count,
00713                                     const int alloc,
00714                                     const int stored);
00715 
00724     DiImage *createOutputImage(const unsigned long frame,
00725                                const int bits);
00726 
00735     int writeImageToDataset(DcmItem &dataset,
00736                             const int mode);
00737 
00747     int writePPM(ostream &stream,
00748                  const unsigned long frame,
00749                  const int bits);
00750 
00760     int writePPM(FILE *stream,
00761                  const unsigned long frame,
00762                  const int bits);
00763 
00772     int writeRawPPM(FILE *stream,
00773                     const unsigned long frame,
00774                     const int bits);
00775 
00784     int writeBMP(FILE *stream,
00785                  const unsigned long frame,
00786                  const int bits);
00787 
00788 
00789  protected:
00790 
00797     DiMonoImage(const DiDocument *image,
00798                 const EI_Status status,
00799                 const char dummy);
00800 
00807     DiMonoImage(const DiMonoImage *image,
00808                 const unsigned long fstart,
00809                 const unsigned long fcount);
00810 
00820     DiMonoImage(const DiColorImage *image,
00821                 const double red,
00822                 const double green,
00823                 const double blue);
00824 
00842     DiMonoImage(const DiMonoImage *image,
00843                 const signed long left_pos,
00844                 const signed long top_pos,
00845                 const Uint16 src_cols,
00846                 const Uint16 src_rows,
00847                 const Uint16 dest_cols,
00848                 const Uint16 dest_rows,
00849                 const int interpolate,
00850                 const int aspect,
00851                 const Uint16 pvalue);
00852 
00859     DiMonoImage(const DiMonoImage *image,
00860                 const int horz,
00861                 const int vert);
00862 
00868     DiMonoImage(const DiMonoImage *image,
00869                 const int degree);
00870 
00879      DiMonoImage(const DiMonoImage *image,
00880                  DiMonoOutputPixel *pixel,
00881                  const unsigned long frame,
00882                  const int stored,
00883                  const int alloc);
00884 
00889     void Init(DiMonoModality *modality);
00890 
00895     void InitUint8(DiMonoModality *modality);
00896 
00901     void InitSint8(DiMonoModality *modality);
00902 
00907     void InitUint16(DiMonoModality *modality);
00908 
00913     void InitSint16(DiMonoModality *modality);
00914 
00919     void InitUint32(DiMonoModality *modality);
00920 
00925     void InitSint32(DiMonoModality *modality);
00926 
00931     int checkInterData(const int mode = 1);
00932 
00940     virtual void updateImagePixelModuleAttributes(DcmItem &dataset);
00941 
00954     const void *getData(void *buffer,
00955                         const unsigned long size,
00956                         const unsigned long frame,
00957                         int bits,
00958                         const int planar,
00959                         const int negative);
00960 
00972     void getDataUint8(void *buffer,
00973                       DiDisplayFunction *disp,
00974                       const int samples,
00975                       const unsigned long frame,
00976                       const int bits,
00977                       const Uint32 low,
00978                       const Uint32 high);
00979 
00991     void getDataSint8(void *buffer,
00992                       DiDisplayFunction *disp,
00993                       const int samples,
00994                       const unsigned long frame,
00995                       const int bits,
00996                       const Uint32 low,
00997                       const Uint32 high);
00998 
01010     void getDataUint16(void *buffer,
01011                        DiDisplayFunction *disp,
01012                        const int samples,
01013                        const unsigned long frame,
01014                        const int bits,
01015                        const Uint32 low,
01016                        const Uint32 high);
01017 
01029     void getDataSint16(void *buffer,
01030                        DiDisplayFunction *disp,
01031                        const int samples,
01032                        const unsigned long frame,
01033                        const int bits,
01034                        const Uint32 low,
01035                        const Uint32 high);
01036 
01048     void getDataUint32(void *buffer,
01049                        DiDisplayFunction *disp,
01050                        const int samples,
01051                        const unsigned long frame,
01052                        const int bits,
01053                        const Uint32 low,
01054                        const Uint32 high);
01055 
01067     void getDataSint32(void *buffer,
01068                        DiDisplayFunction *disp,
01069                        const int samples,
01070                        const unsigned long frame,
01071                        const int bits,
01072                        const Uint32 low,
01073                        const Uint32 high);
01074 
01083     int createLinODPresentationLut(const unsigned long count, const int bits);
01084 
01086     double WindowCenter;
01088     double WindowWidth;
01090     unsigned long WindowCount;
01092     unsigned long VoiLutCount;
01093 
01095     int ValidWindow;
01096 
01098     OFString VoiExplanation;
01099 
01101     ES_PresentationLut PresLutShape;
01102 
01104     unsigned int MinDensity;
01106     unsigned int MaxDensity;
01108     unsigned int Reflection;
01110     unsigned int Illumination;
01111 
01113     DiOverlay *Overlays[2];
01115     DiLookupTable *VoiLutData;
01117     DiLookupTable *PresLutData;
01119     DiMonoPixel *InterData;
01120 
01122     DiDisplayFunction *DisplayFunction;
01123 
01124 
01125  private:
01126 
01128     DiMonoOutputPixel *OutputData;
01130     void *OverlayData;
01131 
01132  // --- declarations to avoid compiler warnings
01133 
01134     DiMonoImage(const DiMonoImage &);
01135     DiMonoImage &operator=(const DiMonoImage &);
01136 };
01137 
01138 
01139 #endif
01140 
01141 
01142 /*
01143  *
01144  * CVS/RCS Log:
01145  * $Log: dimoimg.h,v $
01146  * Revision 1.46  2005/12/08 16:47:50  meichel
01147  * Changed include path schema for all DCMTK header files
01148  *
01149  * Revision 1.45  2005/03/09 17:33:16  joergr
01150  * Added mode to writeImageToDataset() which allows the value of BitsStored to
01151  * be determined either from 'used' or from 'possible' pixel values.
01152  *
01153  * Revision 1.44  2004/07/20 18:12:16  joergr
01154  * Added API method to "officially" access the internal intermediate pixel data
01155  * representation (e.g. to get Hounsfield Units for CT images).
01156  *
01157  * Revision 1.43  2004/02/06 11:07:50  joergr
01158  * Distinguish more clearly between const and non-const access to pixel data.
01159  *
01160  * Revision 1.42  2003/12/23 10:51:52  joergr
01161  * Updated documentation to get rid of doxygen warnings.
01162  *
01163  * Revision 1.41  2003/12/17 16:17:29  joergr
01164  * Added new compatibility flag that allows to ignore the third value of LUT
01165  * descriptors and to determine the bits per table entry automatically.
01166  *
01167  * Revision 1.40  2003/12/08 18:30:16  joergr
01168  * Adapted type casts to new-style typecast operators defined in ofcast.h.
01169  * Removed leading underscore characters from preprocessor symbols (reserved
01170  * symbols). Updated CVS header.
01171  *
01172  * Revision 1.39  2003/06/12 15:08:34  joergr
01173  * Fixed inconsistent API documentation reported by Doxygen.
01174  *
01175  * Revision 1.38  2003/05/20 09:20:21  joergr
01176  * Added method returning the number of bytes required to store a single
01177  * rendered frame: getOutputDataSize().
01178  *
01179  * Revision 1.37  2002/12/09 13:32:52  joergr
01180  * Renamed parameter/local variable to avoid name clashes with global
01181  * declaration left and/or right (used for as iostream manipulators).
01182  *
01183  * Revision 1.36  2002/08/02 15:03:53  joergr
01184  * Added function to write the current image (not only a selected frame) to a
01185  * DICOM dataset.
01186  *
01187  * Revision 1.35  2002/06/26 17:20:04  joergr
01188  * Removed superfluous "inline" method specifyer (MSVC6 linker reported an
01189  * error).
01190  *
01191  * Revision 1.34  2002/06/26 16:04:44  joergr
01192  * Added support for polarity flag to color images.
01193  * Added new methods to get the explanation string of stored VOI windows and
01194  * LUTs (not only of the currently selected VOI transformation).
01195  *
01196  * Revision 1.33  2002/01/29 17:05:50  joergr
01197  * Added optional flag to the "Windows DIB" methods allowing to switch off the
01198  * scanline padding.
01199  *
01200  * Revision 1.32  2001/11/19 12:55:54  joergr
01201  * Added parameter 'frame' to setRoiWindow().
01202  *
01203  * Revision 1.31  2001/11/09 16:27:34  joergr
01204  * Added support for Window BMP file format.
01205  * Enhanced and renamed createTrueColorDIB() method.
01206  *
01207  * Revision 1.30  2001/09/28 13:06:10  joergr
01208  * Added routines to get the currently active Polarity and PresentationLUTShape.
01209  * Added method setRoiWindow() which automatically calculates a min-max VOI
01210  * window for a specified rectangular region of the image.
01211  * Added method to extract embedded overlay planes from pixel data and store
01212  * them in group (6xxx,3000) format.
01213  *
01214  * Revision 1.29  2001/06/01 15:49:44  meichel
01215  * Updated copyright header
01216  *
01217  * Revision 1.28  2001/05/14 09:49:17  joergr
01218  * Added support for "1 bit output" of overlay planes; useful to extract
01219  * overlay planes from the pixel data and store them separately in the dataset.
01220  *
01221  * Revision 1.27  2000/07/07 13:42:30  joergr
01222  * Added support for LIN OD presentation LUT shape.
01223  *
01224  * Revision 1.26  2000/06/07 14:30:27  joergr
01225  * Added method to set the image polarity (normal, reverse).
01226  *
01227  * Revision 1.25  2000/03/08 16:24:18  meichel
01228  * Updated copyright header.
01229  *
01230  * Revision 1.24  1999/12/09 17:26:24  joergr
01231  * Split source file dimoimg.cc into 4 parts to avoid compiler problems
01232  * with gcc and additional optimization options.
01233  *
01234  * Revision 1.23  1999/10/20 10:33:15  joergr
01235  * Enhanced method getOverlayData to support 12 bit data for print.
01236  *
01237  * Revision 1.22  1999/10/06 13:38:46  joergr
01238  * Corrected creation of PrintBitmap pixel data: VOI windows should be applied
01239  * before clipping to avoid that the region outside the image (border) is also
01240  * windowed (this requires a new method in dcmimgle to create a DicomImage
01241  * with the grayscale transformations already applied).
01242  *
01243  * Revision 1.21  1999/09/17 12:24:47  joergr
01244  * Added/changed/completed DOC++ style comments in the header files.
01245  *
01246  * Revision 1.20  1999/09/10 08:45:18  joergr
01247  * Added support for CIELAB display function.
01248  *
01249  * Revision 1.19  1999/08/25 16:41:52  joergr
01250  * Added new feature: Allow clipping region to be outside the image
01251  * (overlapping).
01252  *
01253  * Revision 1.18  1999/07/23 14:03:05  joergr
01254  * Added dummy method (no implementation yet) to create inverse LUTs.
01255  * Added method to create 12 bit packed bitmap data (used for grayscale print
01256  * storage).
01257  * Added method to return pointer to currently used display function.
01258  *
01259  * Revision 1.17  1999/04/28 17:03:47  joergr
01260  * Added type casts to NULL pointers returned as 'const char *' to avoid
01261  * compiler warnings reported by gcc 2.7.2.1 (Linux).
01262  *
01263  * Revision 1.16  1999/04/28 14:49:54  joergr
01264  * Added experimental support to create grayscale images with more than 256
01265  * shades of gray to be displayed on a consumer monitor (use pastel colors).
01266  *
01267  * Revision 1.15  1999/03/24 17:20:09  joergr
01268  * Added/Modified comments and formatting.
01269  *
01270  * Revision 1.14  1999/03/22 08:51:39  joergr
01271  * Added parameter to specify (transparent) background color for method
01272  * getOverlayData().
01273  *
01274  * Revision 1.13  1999/02/11 16:34:36  joergr
01275  * Added routine to check whether particular grayscale values are unused in
01276  * the output data.
01277  *
01278  * Revision 1.12  1999/02/08 12:39:05  joergr
01279  * Changed implementation of removeAllOverlays().
01280  *
01281  * Revision 1.11  1999/02/05 16:43:13  joergr
01282  * Added optional parameter to method convertPValueToDDL to specify width
01283  * of output data (number of bits).
01284  *
01285  * Revision 1.10  1999/02/03 17:27:58  joergr
01286  * Added support for calibration according to Barten transformation (incl.
01287  * a DISPLAY file describing the monitor characteristic).
01288  *
01289  * Revision 1.9  1999/01/20 15:03:40  joergr
01290  * Added new output method to fill external memory buffer with rendered pixel
01291  * data.
01292  *
01293  * Revision 1.8  1999/01/11 09:35:10  joergr
01294  * Added parameter to method 'getMinMaxValues()' to return absolute minimum
01295  * and maximum values ('possible') in addition to actually 'used' pixel
01296  * values.
01297  *
01298  * Revision 1.7  1998/12/23 13:21:28  joergr
01299  * Changed parameter type (long to int) to avoid warning reported by MSVC5.
01300  *
01301  * Revision 1.6  1998/12/23 12:38:16  joergr
01302  * Corrected some typos and formatting.
01303  *
01304  * Revision 1.4  1998/12/22 14:26:19  joergr
01305  * Added new parameters to method addOverlay().
01306  *
01307  * Revision 1.3  1998/12/16 16:34:06  joergr
01308  * Added explanation string to LUT class (retrieved from dataset).
01309  * Added explanation string for VOI transformations.
01310  * Renamed 'setNoVoiLutTransformation' method ('Voi' instead of 'VOI').
01311  * Removed several methods used for monochrome images only in base class
01312  * 'DiImage'. Introduced mechanism to use the methods directly.
01313  *
01314  * Revision 1.2  1998/12/14 17:20:03  joergr
01315  * Added methods to add and remove additional overlay planes (still untested).
01316  *
01317  * Revision 1.1  1998/11/27 15:20:57  joergr
01318  * Added copyright message.
01319  * Added methods and constructors for flipping and rotating, changed for
01320  * scaling and clipping.
01321  * Added method to directly create java AWT bitmaps.
01322  * Added constructors to use external modality transformations.
01323  * Added methods to support presentation LUTs and shapes.
01324  *
01325  * Revision 1.6  1998/07/01 08:39:22  joergr
01326  * Minor changes to avoid compiler warnings (gcc 2.8.1 with additional
01327  * options), e.g. add copy constructors.
01328  *
01329  * Revision 1.5  1998/05/11 14:53:20  joergr
01330  * Added CVS/RCS header to each file.
01331  *
01332  *
01333  */


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