00001 /* 00002 * 00003 * Copyright (C) 1994-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: dcmdata 00019 * 00020 * Author: Gerd Ehlers 00021 * 00022 * Purpose: 00023 * This file contains the interface to routines which provide 00024 * DICOM object encoding/decoding, search and lookup facilities. 00025 * 00026 * Last Update: $Author: meichel $ 00027 * Update Date: $Date: 2005/12/08 16:28:22 $ 00028 * CVS/RCS Revision: $Revision: 1.41 $ 00029 * Status: $State: Exp $ 00030 * 00031 * CVS/RCS Log at end of file 00032 * 00033 */ 00034 00035 00036 #ifndef DCOBJECT_H 00037 #define DCOBJECT_H 00038 00039 #include "dcmtk/config/osconfig.h" /* make sure OS specific configuration is included first */ 00040 00041 #include "dcmtk/ofstd/ofconsol.h" 00042 #include "dcmtk/ofstd/ofglobal.h" 00043 #include "dcmtk/dcmdata/dcerror.h" 00044 #include "dcmtk/dcmdata/dctypes.h" 00045 #include "dcmtk/dcmdata/dcxfer.h" 00046 #include "dcmtk/dcmdata/dctag.h" 00047 #include "dcmtk/dcmdata/dclist.h" 00048 #include "dcmtk/dcmdata/dcstack.h" 00049 00050 00051 // forward declarations 00052 class DcmOutputStream; 00053 class DcmInputStream; 00054 00055 00056 // Undefined Length Identifier now defined in dctypes.h 00057 00058 // Maxinum number of read bytes for a Value Element 00059 const Uint32 DCM_MaxReadLength = 4096; 00060 00061 // Maximum length of tag and length in a DICOM element 00062 const Uint32 DCM_TagInfoLength = 12; 00063 00064 // Optimum line length if not all data printed 00065 const Uint32 DCM_OptPrintLineLength = 70; 00066 00067 // Optimum value length if not all data printed 00068 const Uint32 DCM_OptPrintValueLength = 40; 00069 00070 00075 extern OFGlobal<OFBool> dcmEnableAutomaticInputDataCorrection; /* default OFTrue */ 00076 00086 extern OFGlobal<OFBool> dcmAcceptOddAttributeLength; /* default OFTrue */ 00087 00100 extern OFGlobal<OFBool> dcmEnableCP246Support; /* default OFTrue */ 00101 00110 extern OFGlobal<OFBool> dcmEnableOldSignatureFormat; /* default OFFalse */ 00111 00117 extern OFGlobal<OFBool> dcmAutoDetectDatasetXfer; /* default OFFalse */ 00118 00121 class DcmObject 00122 { 00123 00124 public: 00125 00131 DcmObject(const DcmTag &tag, 00132 const Uint32 len = 0); 00133 00137 DcmObject(const DcmObject &obj); 00138 00141 virtual ~DcmObject(); 00142 00146 virtual DcmObject *clone() const = 0; 00147 00152 DcmObject &operator=(const DcmObject &obj); 00153 00157 virtual DcmEVR ident() const = 0; 00158 00159 // current value representation. If object was read from a stream 00160 // getVR returns the read value representation. It is possible that 00161 // this vr is not the same as mentioned in the data dictionary 00162 // (e.g. private tags, encapsulated data ...) 00163 inline DcmEVR getVR() const { return Tag.getEVR(); } 00164 00165 inline OFBool isaString() const { return Tag.getVR().isaString(); } 00166 00167 virtual OFBool isLeaf() const = 0; 00168 00176 virtual void print(ostream &out, 00177 const size_t flags = 0, 00178 const int level = 0, 00179 const char *pixelFileName = NULL, 00180 size_t *pixelCounter = NULL) = 0; 00181 00182 inline OFCondition error() const { return errorFlag; } 00183 00184 inline E_TransferState transferState() const { return fTransferState; } 00185 virtual void transferInit(void); 00186 virtual void transferEnd(void); 00187 00188 inline Uint16 getGTag() const { return Tag.getGTag(); } 00189 inline Uint16 getETag() const { return Tag.getETag(); } 00190 inline const DcmTag &getTag() const { return Tag; } 00191 inline void setGTag(Uint16 gtag) { Tag.setGroup(gtag); } 00192 00193 virtual OFCondition setVR(DcmEVR /*vr*/) { return EC_IllegalCall; } 00194 virtual unsigned long getVM() = 0; 00195 00196 // calculate length of Dicom element 00197 virtual Uint32 calcElementLength(const E_TransferSyntax xfer, 00198 const E_EncodingType enctype) = 0; 00199 00200 // returns value length 00201 virtual Uint32 getLength(const E_TransferSyntax xfer = EXS_LittleEndianImplicit, 00202 const E_EncodingType enctype = EET_UndefinedLength) = 0; 00203 00204 virtual OFBool canWriteXfer(const E_TransferSyntax newXfer, 00205 const E_TransferSyntax oldXfer) = 0; 00206 00207 virtual OFCondition read(DcmInputStream &inStream, 00208 const E_TransferSyntax ixfer, 00209 const E_GrpLenEncoding glenc = EGL_noChange, 00210 const Uint32 maxReadLength = DCM_MaxReadLength) = 0; 00211 00218 virtual OFCondition write(DcmOutputStream &outStream, 00219 const E_TransferSyntax oxfer, 00220 const E_EncodingType enctype = EET_UndefinedLength) = 0; 00221 00227 virtual OFCondition writeXML(ostream &out, 00228 const size_t flags = 0); 00229 00236 virtual OFCondition writeSignatureFormat(DcmOutputStream &outStream, 00237 const E_TransferSyntax oxfer, 00238 const E_EncodingType enctype = EET_UndefinedLength) = 0; 00239 00243 virtual OFBool isSignable() const; 00244 00248 virtual OFBool containsUnknownVR() const; 00249 00250 virtual OFCondition clear() = 0; 00251 virtual OFCondition verify(const OFBool autocorrect = OFFalse) = 0; 00252 00253 virtual DcmObject *nextInContainer(const DcmObject *obj); 00254 00255 virtual OFCondition nextObject(DcmStack &stack, 00256 const OFBool intoSub); 00257 00258 virtual OFCondition search(const DcmTagKey &xtag, // in 00259 DcmStack &resultStack, // inout 00260 E_SearchMode mode = ESM_fromHere, // in 00261 OFBool searchIntoSub = OFTrue); // in 00262 00263 virtual OFCondition searchErrors(DcmStack &resultStack); // inout 00264 00265 virtual OFCondition loadAllDataIntoMemory() = 0; 00266 00267 00268 protected: 00269 00276 void printNestingLevel(ostream &out, 00277 const size_t flags, 00278 const int level); 00279 00288 void printInfoLineStart(ostream &out, 00289 const size_t flags, 00290 const int level, 00291 DcmTag *tag = NULL); 00292 00302 void printInfoLineEnd(ostream &out, 00303 const size_t flags, 00304 const unsigned long printedLength = 0xffffffff /*no padding*/, 00305 DcmTag *tag = NULL); 00306 00316 virtual void printInfoLine(ostream &out, 00317 const size_t flags, 00318 const int level = 0, 00319 const char *info = NULL, 00320 DcmTag *tag = NULL); 00321 00322 static OFCondition writeTag(DcmOutputStream &outStream, 00323 const DcmTag &tag, 00324 const E_TransferSyntax oxfer); // in 00325 00326 virtual OFCondition writeTagAndLength(DcmOutputStream &outStream, 00327 const E_TransferSyntax oxfer, // in 00328 Uint32 &writtenBytes) const; // out 00329 00336 virtual Uint32 getTagAndLengthSize(const E_TransferSyntax oxfer) const; 00337 00338 /* member variables */ 00339 DcmTag Tag; 00340 Uint32 Length; 00341 E_TransferState fTransferState; 00342 OFCondition errorFlag; // defined after fTransferState to workaround 00343 // memory layout problem with Borland C++ 00344 Uint32 fTransferredBytes; 00345 }; // class DcmObject 00346 00347 00348 #endif // DCOBJECT_H 00349 00350 00351 /* 00352 * CVS/RCS Log: 00353 * $Log: dcobject.h,v $ 00354 * Revision 1.41 2005/12/08 16:28:22 meichel 00355 * Changed include path schema for all DCMTK header files 00356 * 00357 * Revision 1.40 2005/12/02 08:49:17 joergr 00358 * Changed macro NO_XFER_DETECTION_FOR_DATASETS into a global option that can 00359 * be enabled and disabled at runtime. 00360 * 00361 * Revision 1.39 2005/11/24 12:50:57 meichel 00362 * Fixed bug in code that prepares a byte stream that is fed into the MAC 00363 * algorithm when creating or verifying a digital signature. The previous 00364 * implementation was non-conformant when signatures included compressed 00365 * (encapsulated) pixel data because the item length was included in the byte 00366 * stream, while it should not. The global variable dcmEnableOldSignatureFormat 00367 * and a corresponding command line option in dcmsign allow to re-enable the old 00368 * implementation. 00369 * 00370 * Revision 1.38 2005/05/10 15:27:14 meichel 00371 * Added support for reading UN elements with undefined length according 00372 * to CP 246. The global flag dcmEnableCP246Support allows to revert to the 00373 * prior behaviour in which UN elements with undefined length were parsed 00374 * like a normal explicit VR SQ element. 00375 * 00376 * Revision 1.37 2004/07/01 12:28:25 meichel 00377 * Introduced virtual clone method for DcmObject and derived classes. 00378 * 00379 * Revision 1.36 2004/04/27 09:21:01 wilkens 00380 * Fixed a bug in dcelem.cc which occurs when one is serializing a dataset 00381 * (that contains an attribute whose length value is coded with 2 bytes) into 00382 * a given buffer. Although the number of available bytes in the buffer was 00383 * sufficient, the dataset->write(...) method would always return 00384 * EC_StreamNotifyClient to indicate that there are not sufficient bytes 00385 * available in the buffer. This code modification fixes the problem. 00386 * 00387 * Revision 1.35 2003/06/12 13:33:21 joergr 00388 * Fixed inconsistent API documentation reported by Doxygen. 00389 * 00390 * Revision 1.34 2002/12/06 12:49:11 joergr 00391 * Enhanced "print()" function by re-working the implementation and replacing 00392 * the boolean "showFullData" parameter by a more general integer flag. 00393 * Added doc++ documentation. 00394 * Made source code formatting more consistent with other modules/files. 00395 * 00396 * Revision 1.33 2002/08/27 16:55:35 meichel 00397 * Initial release of new DICOM I/O stream classes that add support for stream 00398 * compression (deflated little endian explicit VR transfer syntax) 00399 * 00400 * Revision 1.32 2002/08/20 12:18:35 meichel 00401 * Changed parameter list of loadFile and saveFile methods in class 00402 * DcmFileFormat. Removed loadFile and saveFile from class DcmObject. 00403 * 00404 * Revision 1.31 2002/07/08 14:45:20 meichel 00405 * Improved dcmdata behaviour when reading odd tag length. Depending on the 00406 * global boolean flag dcmAcceptOddAttributeLength, the parser now either accepts 00407 * odd length attributes or implements the old behaviour, i.e. assumes a real 00408 * length larger by one. 00409 * 00410 * Revision 1.30 2002/04/25 09:38:47 joergr 00411 * Added support for XML output of DICOM objects. 00412 * 00413 * Revision 1.29 2002/04/11 12:23:46 joergr 00414 * Added new methods for loading and saving DICOM files. 00415 * 00416 * Revision 1.28 2001/11/16 15:54:39 meichel 00417 * Adapted digital signature code to final text of supplement 41. 00418 * 00419 * Revision 1.27 2001/09/25 17:19:27 meichel 00420 * Adapted dcmdata to class OFCondition 00421 * 00422 * Revision 1.26 2001/06/01 15:48:41 meichel 00423 * Updated copyright header 00424 * 00425 * Revision 1.25 2000/11/07 16:56:07 meichel 00426 * Initial release of dcmsign module for DICOM Digital Signatures 00427 * 00428 * Revision 1.24 2000/04/14 16:02:39 meichel 00429 * Global flag dcmEnableAutomaticInputDataCorrection now derived from OFGlobal 00430 * and, thus, safe for use in multi-thread applications. 00431 * 00432 * Revision 1.23 2000/03/08 16:26:16 meichel 00433 * Updated copyright header. 00434 * 00435 * Revision 1.22 2000/03/03 14:05:24 meichel 00436 * Implemented library support for redirecting error messages into memory 00437 * instead of printing them to stdout/stderr for GUI applications. 00438 * 00439 * Revision 1.21 2000/02/10 10:50:52 joergr 00440 * Added new feature to dcmdump (enhanced print method of dcmdata): write 00441 * pixel data/item value fields to raw files. 00442 * 00443 * Revision 1.20 2000/02/01 10:12:02 meichel 00444 * Avoiding to include <stdlib.h> as extern "C" on Borland C++ Builder 4, 00445 * workaround for bug in compiler header files. 00446 * 00447 * Revision 1.19 1999/03/31 09:24:42 meichel 00448 * Updated copyright header in module dcmdata 00449 * 00450 * 00451 */