00001 /* 00002 * 00003 * Copyright (C) 1996-2004, 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: joergr $ 00025 * Update Date: $Date: 2004/02/06 11:07:50 $ 00026 * CVS/RCS Revision: $Revision: 1.43 $ 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 "osconfig.h" 00038 #include "dctypes.h" 00039 #include "ofcast.h" 00040 00041 #include "diimage.h" 00042 #include "dimopx.h" 00043 #include "dimoopx.h" 00044 #include "diovlay.h" 00045 #include "diluptab.h" 00046 #include "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 ¢er, 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 DiMonoPixel *getInterData() const 00654 { 00655 return InterData; 00656 } 00657 00670 unsigned long createDIB(void *&data, 00671 const unsigned long size, 00672 const unsigned long frame, 00673 const int bits, 00674 const int upsideDown, 00675 const int padding = 1); 00676 00686 unsigned long createAWTBitmap(void *&data, 00687 const unsigned long frame, 00688 const int bits); 00689 00701 static void *createPackedBitmap(const void *buffer, 00702 const unsigned long size, 00703 const unsigned long count, 00704 const int alloc, 00705 const int stored); 00706 00715 DiImage *createOutputImage(const unsigned long frame, 00716 const int bits); 00717 00724 int writeImageToDataset(DcmItem &dataset); 00725 00735 int writePPM(ostream &stream, 00736 const unsigned long frame, 00737 const int bits); 00738 00748 int writePPM(FILE *stream, 00749 const unsigned long frame, 00750 const int bits); 00751 00760 int writeRawPPM(FILE *stream, 00761 const unsigned long frame, 00762 const int bits); 00763 00772 int writeBMP(FILE *stream, 00773 const unsigned long frame, 00774 const int bits); 00775 00776 00777 protected: 00778 00785 DiMonoImage(const DiDocument *image, 00786 const EI_Status status, 00787 const char dummy); 00788 00795 DiMonoImage(const DiMonoImage *image, 00796 const unsigned long fstart, 00797 const unsigned long fcount); 00798 00808 DiMonoImage(const DiColorImage *image, 00809 const double red, 00810 const double green, 00811 const double blue); 00812 00830 DiMonoImage(const DiMonoImage *image, 00831 const signed long left_pos, 00832 const signed long top_pos, 00833 const Uint16 src_cols, 00834 const Uint16 src_rows, 00835 const Uint16 dest_cols, 00836 const Uint16 dest_rows, 00837 const int interpolate, 00838 const int aspect, 00839 const Uint16 pvalue); 00840 00847 DiMonoImage(const DiMonoImage *image, 00848 const int horz, 00849 const int vert); 00850 00856 DiMonoImage(const DiMonoImage *image, 00857 const int degree); 00858 00867 DiMonoImage(const DiMonoImage *image, 00868 DiMonoOutputPixel *pixel, 00869 const unsigned long frame, 00870 const int stored, 00871 const int alloc); 00872 00877 void Init(DiMonoModality *modality); 00878 00883 void InitUint8(DiMonoModality *modality); 00884 00889 void InitSint8(DiMonoModality *modality); 00890 00895 void InitUint16(DiMonoModality *modality); 00896 00901 void InitSint16(DiMonoModality *modality); 00902 00907 void InitUint32(DiMonoModality *modality); 00908 00913 void InitSint32(DiMonoModality *modality); 00914 00919 int checkInterData(const int mode = 1); 00920 00927 virtual void updateImagePixelModuleAttributes(DcmItem &dataset); 00928 00941 const void *getData(void *buffer, 00942 const unsigned long size, 00943 const unsigned long frame, 00944 int bits, 00945 const int planar, 00946 const int negative); 00947 00959 void getDataUint8(void *buffer, 00960 DiDisplayFunction *disp, 00961 const int samples, 00962 const unsigned long frame, 00963 const int bits, 00964 const Uint32 low, 00965 const Uint32 high); 00966 00978 void getDataSint8(void *buffer, 00979 DiDisplayFunction *disp, 00980 const int samples, 00981 const unsigned long frame, 00982 const int bits, 00983 const Uint32 low, 00984 const Uint32 high); 00985 00997 void getDataUint16(void *buffer, 00998 DiDisplayFunction *disp, 00999 const int samples, 01000 const unsigned long frame, 01001 const int bits, 01002 const Uint32 low, 01003 const Uint32 high); 01004 01016 void getDataSint16(void *buffer, 01017 DiDisplayFunction *disp, 01018 const int samples, 01019 const unsigned long frame, 01020 const int bits, 01021 const Uint32 low, 01022 const Uint32 high); 01023 01035 void getDataUint32(void *buffer, 01036 DiDisplayFunction *disp, 01037 const int samples, 01038 const unsigned long frame, 01039 const int bits, 01040 const Uint32 low, 01041 const Uint32 high); 01042 01054 void getDataSint32(void *buffer, 01055 DiDisplayFunction *disp, 01056 const int samples, 01057 const unsigned long frame, 01058 const int bits, 01059 const Uint32 low, 01060 const Uint32 high); 01061 01070 int createLinODPresentationLut(const unsigned long count, const int bits); 01071 01073 double WindowCenter; 01075 double WindowWidth; 01077 unsigned long WindowCount; 01079 unsigned long VoiLutCount; 01080 01082 int ValidWindow; 01083 01085 OFString VoiExplanation; 01086 01088 ES_PresentationLut PresLutShape; 01089 01091 unsigned int MinDensity; 01093 unsigned int MaxDensity; 01095 unsigned int Reflection; 01097 unsigned int Illumination; 01098 01100 DiOverlay *Overlays[2]; 01102 DiLookupTable *VoiLutData; 01104 DiLookupTable *PresLutData; 01106 DiMonoPixel *InterData; 01107 01109 DiDisplayFunction *DisplayFunction; 01110 01111 01112 private: 01113 01115 DiMonoOutputPixel *OutputData; 01117 void *OverlayData; 01118 01119 // --- declarations to avoid compiler warnings 01120 01121 DiMonoImage(const DiMonoImage &); 01122 DiMonoImage &operator=(const DiMonoImage &); 01123 }; 01124 01125 01126 #endif 01127 01128 01129 /* 01130 * 01131 * CVS/RCS Log: 01132 * $Log: dimoimg.h,v $ 01133 * Revision 1.43 2004/02/06 11:07:50 joergr 01134 * Distinguish more clearly between const and non-const access to pixel data. 01135 * 01136 * Revision 1.42 2003/12/23 10:51:52 joergr 01137 * Updated documentation to get rid of doxygen warnings. 01138 * 01139 * Revision 1.41 2003/12/17 16:17:29 joergr 01140 * Added new compatibility flag that allows to ignore the third value of LUT 01141 * descriptors and to determine the bits per table entry automatically. 01142 * 01143 * Revision 1.40 2003/12/08 18:30:16 joergr 01144 * Adapted type casts to new-style typecast operators defined in ofcast.h. 01145 * Removed leading underscore characters from preprocessor symbols (reserved 01146 * symbols). Updated CVS header. 01147 * 01148 * Revision 1.39 2003/06/12 15:08:34 joergr 01149 * Fixed inconsistent API documentation reported by Doxygen. 01150 * 01151 * Revision 1.38 2003/05/20 09:20:21 joergr 01152 * Added method returning the number of bytes required to store a single 01153 * rendered frame: getOutputDataSize(). 01154 * 01155 * Revision 1.37 2002/12/09 13:32:52 joergr 01156 * Renamed parameter/local variable to avoid name clashes with global 01157 * declaration left and/or right (used for as iostream manipulators). 01158 * 01159 * Revision 1.36 2002/08/02 15:03:53 joergr 01160 * Added function to write the current image (not only a selected frame) to a 01161 * DICOM dataset. 01162 * 01163 * Revision 1.35 2002/06/26 17:20:04 joergr 01164 * Removed superfluous "inline" method specifyer (MSVC6 linker reported an 01165 * error). 01166 * 01167 * Revision 1.34 2002/06/26 16:04:44 joergr 01168 * Added support for polarity flag to color images. 01169 * Added new methods to get the explanation string of stored VOI windows and 01170 * LUTs (not only of the currently selected VOI transformation). 01171 * 01172 * Revision 1.33 2002/01/29 17:05:50 joergr 01173 * Added optional flag to the "Windows DIB" methods allowing to switch off the 01174 * scanline padding. 01175 * 01176 * Revision 1.32 2001/11/19 12:55:54 joergr 01177 * Added parameter 'frame' to setRoiWindow(). 01178 * 01179 * Revision 1.31 2001/11/09 16:27:34 joergr 01180 * Added support for Window BMP file format. 01181 * Enhanced and renamed createTrueColorDIB() method. 01182 * 01183 * Revision 1.30 2001/09/28 13:06:10 joergr 01184 * Added routines to get the currently active Polarity and PresentationLUTShape. 01185 * Added method setRoiWindow() which automatically calculates a min-max VOI 01186 * window for a specified rectangular region of the image. 01187 * Added method to extract embedded overlay planes from pixel data and store 01188 * them in group (6xxx,3000) format. 01189 * 01190 * Revision 1.29 2001/06/01 15:49:44 meichel 01191 * Updated copyright header 01192 * 01193 * Revision 1.28 2001/05/14 09:49:17 joergr 01194 * Added support for "1 bit output" of overlay planes; useful to extract 01195 * overlay planes from the pixel data and store them separately in the dataset. 01196 * 01197 * Revision 1.27 2000/07/07 13:42:30 joergr 01198 * Added support for LIN OD presentation LUT shape. 01199 * 01200 * Revision 1.26 2000/06/07 14:30:27 joergr 01201 * Added method to set the image polarity (normal, reverse). 01202 * 01203 * Revision 1.25 2000/03/08 16:24:18 meichel 01204 * Updated copyright header. 01205 * 01206 * Revision 1.24 1999/12/09 17:26:24 joergr 01207 * Split source file dimoimg.cc into 4 parts to avoid compiler problems 01208 * with gcc and additional optimization options. 01209 * 01210 * Revision 1.23 1999/10/20 10:33:15 joergr 01211 * Enhanced method getOverlayData to support 12 bit data for print. 01212 * 01213 * Revision 1.22 1999/10/06 13:38:46 joergr 01214 * Corrected creation of PrintBitmap pixel data: VOI windows should be applied 01215 * before clipping to avoid that the region outside the image (border) is also 01216 * windowed (this requires a new method in dcmimgle to create a DicomImage 01217 * with the grayscale transformations already applied). 01218 * 01219 * Revision 1.21 1999/09/17 12:24:47 joergr 01220 * Added/changed/completed DOC++ style comments in the header files. 01221 * 01222 * Revision 1.20 1999/09/10 08:45:18 joergr 01223 * Added support for CIELAB display function. 01224 * 01225 * Revision 1.19 1999/08/25 16:41:52 joergr 01226 * Added new feature: Allow clipping region to be outside the image 01227 * (overlapping). 01228 * 01229 * Revision 1.18 1999/07/23 14:03:05 joergr 01230 * Added dummy method (no implementation yet) to create inverse LUTs. 01231 * Added method to create 12 bit packed bitmap data (used for grayscale print 01232 * storage). 01233 * Added method to return pointer to currently used display function. 01234 * 01235 * Revision 1.17 1999/04/28 17:03:47 joergr 01236 * Added type casts to NULL pointers returned as 'const char *' to avoid 01237 * compiler warnings reported by gcc 2.7.2.1 (Linux). 01238 * 01239 * Revision 1.16 1999/04/28 14:49:54 joergr 01240 * Added experimental support to create grayscale images with more than 256 01241 * shades of gray to be displayed on a consumer monitor (use pastel colors). 01242 * 01243 * Revision 1.15 1999/03/24 17:20:09 joergr 01244 * Added/Modified comments and formatting. 01245 * 01246 * Revision 1.14 1999/03/22 08:51:39 joergr 01247 * Added parameter to specify (transparent) background color for method 01248 * getOverlayData(). 01249 * 01250 * Revision 1.13 1999/02/11 16:34:36 joergr 01251 * Added routine to check whether particular grayscale values are unused in 01252 * the output data. 01253 * 01254 * Revision 1.12 1999/02/08 12:39:05 joergr 01255 * Changed implementation of removeAllOverlays(). 01256 * 01257 * Revision 1.11 1999/02/05 16:43:13 joergr 01258 * Added optional parameter to method convertPValueToDDL to specify width 01259 * of output data (number of bits). 01260 * 01261 * Revision 1.10 1999/02/03 17:27:58 joergr 01262 * Added support for calibration according to Barten transformation (incl. 01263 * a DISPLAY file describing the monitor characteristic). 01264 * 01265 * Revision 1.9 1999/01/20 15:03:40 joergr 01266 * Added new output method to fill external memory buffer with rendered pixel 01267 * data. 01268 * 01269 * Revision 1.8 1999/01/11 09:35:10 joergr 01270 * Added parameter to method 'getMinMaxValues()' to return absolute minimum 01271 * and maximum values ('possible') in addition to actually 'used' pixel 01272 * values. 01273 * 01274 * Revision 1.7 1998/12/23 13:21:28 joergr 01275 * Changed parameter type (long to int) to avoid warning reported by MSVC5. 01276 * 01277 * Revision 1.6 1998/12/23 12:38:16 joergr 01278 * Corrected some typos and formatting. 01279 * 01280 * Revision 1.4 1998/12/22 14:26:19 joergr 01281 * Added new parameters to method addOverlay(). 01282 * 01283 * Revision 1.3 1998/12/16 16:34:06 joergr 01284 * Added explanation string to LUT class (retrieved from dataset). 01285 * Added explanation string for VOI transformations. 01286 * Renamed 'setNoVoiLutTransformation' method ('Voi' instead of 'VOI'). 01287 * Removed several methods used for monochrome images only in base class 01288 * 'DiImage'. Introduced mechanism to use the methods directly. 01289 * 01290 * Revision 1.2 1998/12/14 17:20:03 joergr 01291 * Added methods to add and remove additional overlay planes (still untested). 01292 * 01293 * Revision 1.1 1998/11/27 15:20:57 joergr 01294 * Added copyright message. 01295 * Added methods and constructors for flipping and rotating, changed for 01296 * scaling and clipping. 01297 * Added method to directly create java AWT bitmaps. 01298 * Added constructors to use external modality transformations. 01299 * Added methods to support presentation LUTs and shapes. 01300 * 01301 * Revision 1.6 1998/07/01 08:39:22 joergr 01302 * Minor changes to avoid compiler warnings (gcc 2.8.1 with additional 01303 * options), e.g. add copy constructors. 01304 * 01305 * Revision 1.5 1998/05/11 14:53:20 joergr 01306 * Added CVS/RCS header to each file. 01307 * 01308 * 01309 */