00001 /* 00002 * 00003 * Copyright (C) 2001-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: dcmdata 00015 * 00016 * Author: Michael Onken 00017 * 00018 * Purpose: Base class for converter from image file to DICOM 00019 * 00020 * Last Update: $Author: uli $ 00021 * Update Date: $Date: 2010-11-01 10:42:44 $ 00022 * CVS/RCS Revision: $Revision: 1.11 $ 00023 * Status: $State: Exp $ 00024 * 00025 * CVS/RCS Log at end of file 00026 * 00027 */ 00028 00029 #ifndef I2DOUTPL_H 00030 #define I2DOUTPL_H 00031 00032 #include "dcmtk/config/osconfig.h" 00033 #include "dcmtk/dcmdata/dcdatset.h" 00034 #include "dcmtk/dcmdata/dcelem.h" 00035 #include "dcmtk/oflog/oflog.h" 00036 00037 00038 OFLogger DCM_dcmdataLibi2dGetLogger(); 00039 00040 #define DCMDATA_LIBI2D_TRACE(msg) OFLOG_TRACE(DCM_dcmdataLibi2dGetLogger(), msg) 00041 #define DCMDATA_LIBI2D_DEBUG(msg) OFLOG_DEBUG(DCM_dcmdataLibi2dGetLogger(), msg) 00042 #define DCMDATA_LIBI2D_INFO(msg) OFLOG_INFO(DCM_dcmdataLibi2dGetLogger(), msg) 00043 #define DCMDATA_LIBI2D_WARN(msg) OFLOG_WARN(DCM_dcmdataLibi2dGetLogger(), msg) 00044 #define DCMDATA_LIBI2D_ERROR(msg) OFLOG_ERROR(DCM_dcmdataLibi2dGetLogger(), msg) 00045 #define DCMDATA_LIBI2D_FATAL(msg) OFLOG_FATAL(DCM_dcmdataLibi2dGetLogger(), msg) 00046 00047 00048 class I2DOutputPlug 00049 { 00050 00051 public: 00052 00056 I2DOutputPlug() : m_doAttribChecking(OFTrue), m_inventMissingType2Attribs(OFTrue), 00057 m_inventMissingType1Attribs(OFTrue) 00058 {}; 00059 00063 virtual OFString ident() =0; 00064 00069 virtual void supportedSOPClassUIDs(OFList<OFString> suppSOPs) =0; 00070 00075 virtual OFCondition convert(DcmDataset &dataset) const =0; 00076 00082 virtual OFString isValid(DcmDataset& dataset) const = 0; 00083 00087 virtual ~I2DOutputPlug() {}; 00088 00099 virtual void setValidityChecking(OFBool doChecks, 00100 OFBool insertMissingType2 = OFTrue, 00101 OFBool inventMissingType1 = OFTrue) 00102 { 00103 m_doAttribChecking = doChecks; 00104 m_inventMissingType2Attribs = insertMissingType2; 00105 m_inventMissingType1Attribs = inventMissingType1; 00106 }; 00107 00108 protected: 00109 00118 virtual OFString checkAndInventType1Attrib(const DcmTagKey& key, 00119 DcmDataset* targetDset, 00120 const OFString& defaultValue ="") const 00121 { 00122 OFBool exists = targetDset->tagExists(key); 00123 if (!exists && !m_inventMissingType1Attribs) 00124 { 00125 OFString err = "I2DOutputPlug: Missing type 1 attribute: "; err += DcmTag(key).getTagName(); err += "\n"; 00126 return err; 00127 } 00128 DcmElement *elem; 00129 OFCondition cond = targetDset->findAndGetElement(key, elem); 00130 if (cond.bad() || !elem || (elem->getLength() == 0)) 00131 { 00132 if (!m_inventMissingType1Attribs) 00133 { 00134 OFString err; 00135 err += "I2DOutputPlug: Empty value for type 1 attribute: "; 00136 err += DcmTag(key).getTagName(); 00137 err += "\n"; 00138 return err; 00139 } 00140 //holds element to insert in item 00141 elem = NULL; 00142 DcmTag tag(key); OFBool wasError = OFFalse; 00143 //if dicom element could be created, insert in to item and modify to value 00144 if ( newDicomElement(elem, tag).good()) 00145 { 00146 if (targetDset->insert(elem, OFTrue).good()) 00147 { 00148 if (elem->putString(defaultValue.c_str()).good()) 00149 { 00150 DCMDATA_LIBI2D_DEBUG("I2DOutputPlug: Inserting missing type 1 attribute: " << tag.getTagName() << " with value " << defaultValue); 00151 } else wasError = OFTrue; 00152 } else wasError = OFTrue; 00153 } else wasError = OFTrue; 00154 if (wasError) 00155 { 00156 OFString err = "Unable to insert type 1 attribute "; 00157 err += tag.getTagName(); err += " with value "; err += defaultValue; err += "\n"; 00158 return err; 00159 } 00160 } 00161 return ""; 00162 }; 00163 00164 00171 virtual OFString checkAndInventType2Attrib(const DcmTagKey& key, 00172 DcmDataset* targetDset, 00173 const OFString& defaultValue ="") const 00174 { 00175 OFString err; 00176 OFBool exists = targetDset->tagExists(key); 00177 if (!exists) 00178 { 00179 if (m_inventMissingType2Attribs) 00180 { 00181 //holds element to insert in item 00182 DcmElement *elem = NULL; 00183 DcmTag tag(key); OFBool wasError = OFFalse; 00184 //if dicom element could be created, insert in to item and modify to value 00185 if ( newDicomElement(elem, tag).good()) 00186 { 00187 if (targetDset->insert(elem, OFTrue).good()) 00188 { 00189 OFCondition result; 00190 if (!defaultValue.empty()) // only insert value if not empty(e. g. empty type 2 sequences) 00191 { 00192 result = elem->putString(defaultValue.c_str()); 00193 } 00194 if (result.good()) 00195 { 00196 DCMDATA_LIBI2D_DEBUG("I2DOutputPlug: Inserting missing type 2 attribute: " << tag.getTagName() << " with value " << (defaultValue.empty() ? "<empty>" : defaultValue)); 00197 } else wasError = OFTrue; 00198 } else wasError = OFTrue; 00199 } else wasError = OFTrue; 00200 if (wasError) 00201 { 00202 err += "Unable to insert type 2 attribute "; err += tag.getTagName(); err += " with value "; err += defaultValue; err += "\n"; 00203 } 00204 } 00205 else 00206 { 00207 err = "Image2Dcm: Missing type 2 attribute: "; err += DcmTag(key).getTagName(); err += "\n"; 00208 return err; 00209 } 00210 } 00211 return err; 00212 }; 00213 00216 OFBool m_doAttribChecking; 00217 00220 OFBool m_inventMissingType2Attribs; 00221 00224 OFBool m_inventMissingType1Attribs; 00225 00226 }; 00227 00228 #endif // #ifndef I2DOUTPL_H 00229 00230 /* 00231 * CVS/RCS Log: 00232 * $Log: i2doutpl.h,v $ 00233 * Revision 1.11 2010-11-01 10:42:44 uli 00234 * Fixed some compiler warnings reported by gcc with additional flags. 00235 * 00236 * Revision 1.10 2010-10-14 13:15:46 joergr 00237 * Updated copyright header. Added reference to COPYRIGHT file. 00238 * 00239 * Revision 1.9 2010-03-01 09:08:45 uli 00240 * Removed some unnecessary include directives in the headers. 00241 * 00242 * Revision 1.8 2009-11-04 09:58:08 uli 00243 * Switched to logging mechanism provided by the "new" oflog module 00244 * 00245 * Revision 1.7 2009-09-30 08:05:25 uli 00246 * Stop including dctk.h in libi2d's header files. 00247 * 00248 * Revision 1.6 2009-03-31 11:31:05 onken 00249 * Corrected commit message. 00250 * 00251 * Revision 1.5 2009-03-31 11:29:54 onken 00252 * Added possibility to also insert type 2 elements with a default value 00253 * when automatically inserting missing values (feature currently not in use). 00254 * 00255 * Revision 1.4 2009-01-16 09:51:55 onken 00256 * Completed doxygen documentation for libi2d. 00257 * 00258 * Revision 1.3 2008-01-16 16:32:23 onken 00259 * Fixed some empty or doubled log messages in libi2d files. 00260 * 00261 * Revision 1.2 2008-01-16 15:10:20 onken 00262 * Moved library "i2dlib" from /dcmdata/libsrc/i2dlib to /dcmdata/libi2d 00263 * 00264 * Revision 1.2 2008-01-11 14:17:53 onken 00265 * Added various options to i2dlib. Changed logging to use a configurable 00266 * logstream. Added output plugin for the new Multiframe Secondary Capture SOP 00267 * Classes. Added mode for JPEG plugin to copy exsiting APPn markers (except 00268 * JFIF). Changed img2dcm default behaviour to invent type1/type2 attributes (no 00269 * need for templates any more). Added some bug fixes. 00270 * 00271 * Revision 1.1 2007/11/08 15:58:55 onken 00272 * Initial checkin of img2dcm application and corresponding library i2dlib. 00273 * 00274 * 00275 */ 00276