3
* $Id: i2d.h 3066 2010-12-21 10:10:14Z carlos $
6
* Code addapted from DCMTK
9
* Copyright (C) 2001-2007, OFFIS
11
* This software and supporting documentation were developed by
13
* Kuratorium OFFIS e.V.
14
* Healthcare Information and Communication Systems
16
* D-26121 Oldenburg, Germany
18
* THIS SOFTWARE IS MADE AVAILABLE, AS IS, AND OFFIS MAKES NO WARRANTY
19
* REGARDING THE SOFTWARE, ITS PERFORMANCE, ITS MERCHANTABILITY OR
20
* FITNESS FOR ANY PARTICULAR USE, FREEDOM FROM ANY COMPUTER DISEASES OR
21
* ITS CONFORMITY TO ANY SPECIFICATION. THE ENTIRE RISK AS TO QUALITY AND
22
* PERFORMANCE OF THE SOFTWARE IS WITH THE USER.
28
#include <dcmtk/config/osconfig.h>
29
#include <dcmtk/dcmdata/dctk.h>
39
/** Constructor, initializes command line options
44
/** Start the conversion. Needs a fully configured input plugin
45
* and a fully configured output plugin to operate. Returns
46
* a dataset with the resulting DICOM object.
47
* @param inputPlug - [in] The input plugin to read pixel data
48
* @param outPlug - [in] The output plugin for specific SOP class output
49
* @param resultDset - [out] The DICOM object resulting from the conversion
50
* @param proposedTS - [out] The proposed transfer syntax (needed e. g.
51
* by JPEG input plugin)
52
* @return EC_Normal, if successfull, error otherwise
54
OFCondition convert(I2DImgSource *inputPlug,
55
I2DOutputPlug *outPlug,
56
DcmDataset*& resultDset,
57
E_TransferSyntax& proposedTS);
59
OFCondition updateOverrideKeys(DcmDataset* dset);
61
/** Sets a DICOM file that should serve as a template for the resulting
62
* DICOM object. Only the dataset of the given file is imported.
63
* @param file - [in] The filename of the template DICOM file
66
void setTemplateFile(const OFString& file);
68
/** Set file from which patient/study/series data should be imported from.
69
* @param file - [in] The DICOM file to read from
72
void setSeriesFrom(const OFString& file);
74
/** Set file from which patient/study/series data should be imported from.
75
* @param file - [in] The DICOM file to read from
78
void setStudyFrom(const OFString& file);
80
/** Enables/Disables incrementing instance number taken over from DICOM file.
81
* This can either be a the study/series file or the template file
83
* @param incInstNo - [in] If true, the instance number will be incremented
86
void setIncrementInstanceNumber(OFBool incInstNo);
88
/** Enables/disables autotmatic insertion of the value "ISO_IR100" as
89
* a value for the Specific Character Set attribute. If disabled,
90
* no value is inserted for Specifific Character Set but instead
91
* must be provided by other means (see setTemplateFile(), setSeriesFrom(),
92
* setStudyFrom(), setOverrideKeys()). The insertion is applied after
93
* loading the (optional) template file; the value might be overwritten
94
* by the value copied by setStudy/Series/OverrideKeys.
95
* @param insertLatin1 - [in] Enable/disable insertion of Iso Latin 1
98
void setISOLatin1(OFBool insertLatin1);
100
void setUTF8(OFBool insertUTF8);
102
/** Specifies some attributes that should be inserted after conversion.
103
* They will override any identical attributes already existing in the
104
* converted result DICOM object. The override keys are applied at the very
105
* end of the conversion and do not undergoe any validity checking.
106
* @param dset - [in] The dataset with override attributes
109
void setOverrideKeys(DcmDataset* dset);
111
DcmDataset* getOverrideKeys() {
112
if (m_overrideKeys == NULL) {
113
m_overrideKeys = new DcmDataset();
115
return m_overrideKeys;
118
/** Enable/Disable basic validity checks for output dataset
119
* @param doChecks - [in] OFTrue enables checking, OFFalse turns it off.
120
* @param insertMissingType2 - [in] If true (default), missing type 2
121
* attributes are inserted automatically
122
* @param inventMissingType1 - [in] If true , missing type 1
123
* attributes are inserted automatically with a predefined
124
* value (if possible). An existing empty type 1 attribute is
125
* assigned a value, too.
128
void setValidityChecking(OFBool doChecks,
129
OFBool insertMissingType2 = OFTrue,
130
OFBool inventMissingType1 = OFTrue);
132
/** Sets the log stream
133
* The log stream is used to report any warnings and error messages.
134
* @param stream - [out] pointer to the log stream (might be NULL = no messages)
137
void setLogStream(OFConsole *stream)
139
m_logStream = stream;
142
/** Sets the debug mode
143
* @param debugMode - [in] New status for debug mode
146
void setDebugMode(const OFBool& debugMode) { m_debug = debugMode; };
148
/** Prints a message to the given stream.
149
** @param stream - [out] output stream to which the message is printed
150
* @param message1 - [in] first part of message to be printed
151
* @param message2 - [in] second part of message to be printed
154
static void printMessage(OFConsole *stream,
155
const OFString& message1,
156
const OFString& message2 = "")
160
stream->lockCerr() << message1 << message2 << std::endl;
161
stream->unlockCerr();
166
/** Destructor, frees plugin memory
173
/** Cleans up template for future insertion of pixel data information, ie
174
* generally removes attributes from image pixel module
175
* @param targetDset - [out] The dataset that should be cleand up
178
void cleanupTemplate(DcmDataset *targetDset);
180
/** Parses patient/study/series level attributes from file as defined
181
* on command line and fills internal attributes accordingly.
182
* @param targetDset - [out] The dataset to write the attributes to
183
* @return EC_Normal, if successful, error otherwise
185
OFCondition applyStudyOrSeriesFromFile(DcmDataset *targetDset);
187
/** Increments instance number in given dataset
188
* @param targetDset - [in/out] Dataset to increment instance number in
189
* @return EC_Normal, if successful, error otherwise
191
OFCondition incrementInstanceNumber(DcmDataset *targetDset);
193
/** Generates and inserts missing UIDs, ie UIDs not taken over
194
* from --dataset-from --study from and --series-from options
195
* @param dset - [in] The dataset to write the UIDs to
196
* @return EC_Normal, if successful, error otherwise
198
OFCondition generateUIDs(DcmDataset *dset);
200
/** Reads pixel data and corresponding attributes like rows etc. from image
201
* file and inserts them into dataset.
202
* @param imageSource - [in] The input plugin that actually reads the pixel data
203
* @param dset - [out] The dataset to export the pixel data attributes to
204
* @param outputTS - [out] The proposed transfex syntax of the dataset
205
* @return EC_Normal, if successful, error otherwise
207
OFCondition readAndInsertPixelData( I2DImgSource* imageSource,
209
E_TransferSyntax& outputTS);
211
/** Do some completeness / validity checks. Should be called when
212
* dataset is completed and is about to be saved.
213
* @param dataset - [in] The dataset to check
214
* @return Error string if error occurs, empty string otherwise
216
OFString isValid(DcmDataset& dataset) const;
218
/** Copy override keys over existing keys in given dataset.
219
* @param outputDset - [out] dataset to which the override keys are copied
221
void applyOverrideKeys(DcmDataset *outputDset);
223
/** Inserts "ISO_IR100" in the attribute "Specific Character Set".
224
* Overwrites any existing value.
225
* @param outputDset - [out] The dataset to write to
226
* @return EC_Normal if insertion is successfull, error code otherwise
228
OFCondition insertLatin1(DcmDataset *outputDset);
230
OFCondition insertUTF8(DcmDataset *outputDset);
232
/** Check whether given type 1 attribute is present and has a length > 0.
233
* @param key - [in] The attribute tag check
234
* @param targetDset - [out] targetDset
235
* @param defaultValue - [in] value to be inserted if attribute is missing
236
* (needs invent option for type 1 attributes enabled)
237
* @return A string with an error message if attribute is not present
240
OFString checkAndInventType1Attrib(const DcmTagKey& key,
241
DcmDataset* targetDset,
242
const OFString& defaultValue = "") const;
245
/** Inserts an empty element with the given tag into a dataset
246
* @param key - [in] The attribute tag to check
247
* @param targetDset - [out] targetDset
248
* @return A string with an error message if attribute is not present
249
* nor gets inserted automatically (see m_inventMissingType2Attribs)
251
OFString checkAndInventType2Attrib(const DcmTagKey& key,
252
DcmDataset* targetDset) const;
256
/* Attributes for writing DICOM dataset */
258
/// These attributes are applied to the dataset after conversion
259
/// (and are not checked by the isValid() function)
260
DcmDataset *m_overrideKeys;
262
/// If not empty, the DICOM file specified in this variable is used
263
/// as a base for the DICOM image file to be created, ie. all attributes
264
/// are taken over from this template file
265
OFString m_templateFile;
267
/// If true, patient and study data is read from file
268
OFBool m_readStudyLevel;
270
/// If true, patient, study and series data is read from file
271
OFBool m_readSeriesLevel;
273
/// File to read study and series from
274
OFString m_studySeriesFile;
276
/// If true, Instance Number ist read from file and incremented by 1
277
OFBool m_incInstNoFromFile;
279
/// If true, some simple attribute checks (missing type 2 attributes or
280
/// missing type 1 values) are omitted
281
OFBool m_disableAttribChecks;
283
/// If true, missing type 2 elements are inserted automatically (empty value).
284
/// Enabled per default.
285
OFBool m_inventMissingType2Attribs;
287
/// If true, missing type 1 elements are inserted automatically with a
288
/// predefined value, if possible. Disabled per default.
289
OFBool m_inventMissingType1Attribs;
291
/// If enabled, ISO_IR100 (ISO Latin 1) is inserted as a standard value
292
/// for attribute "Specific Character Set". Insertion takes place after
293
/// loading (optional) template file.
294
OFBool m_insertLatin1;
298
/// If true, debug output is enabled
301
/// stream where warning/error message are sent to.
302
/// can be NULL (default, no output).
303
OFConsole *m_logStream;