~ubuntu-branches/ubuntu/wily/ginkgocadx/wily-proposed

« back to all changes in this revision

Viewing changes to src/cadxcore/main/controllers/dcmtk/libi2d/i2d.h

  • Committer: Bazaar Package Importer
  • Author(s): Andreas Tille
  • Date: 2011-05-02 08:09:26 UTC
  • Revision ID: james.westby@ubuntu.com-20110502080926-bql5wep49c7hg91t
Tags: upstream-2.4.1.1
ImportĀ upstreamĀ versionĀ 2.4.1.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *  
 
3
 *  $Id: i2d.h 3066 2010-12-21 10:10:14Z carlos $
 
4
 *  Ginkgo CADx Project
 
5
 *
 
6
 *  Code addapted from DCMTK
 
7
 *
 
8
 *
 
9
 *  Copyright (C) 2001-2007, OFFIS
 
10
 *
 
11
 *  This software and supporting documentation were developed by
 
12
 *
 
13
 *    Kuratorium OFFIS e.V.
 
14
 *    Healthcare Information and Communication Systems
 
15
 *    Escherweg 2
 
16
 *    D-26121 Oldenburg, Germany
 
17
 *
 
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.
 
23
 *
 
24
 *
 
25
 */
 
26
#pragma once
 
27
 
 
28
#include <dcmtk/config/osconfig.h>
 
29
#include <dcmtk/dcmdata/dctk.h>
 
30
#include "i2doutpl.h"
 
31
#include "i2dplvlp.h"
 
32
#include "i2dplsc.h"
 
33
#include "i2djpgs.h"
 
34
 
 
35
class Image2Dcm {
 
36
        
 
37
public:
 
38
        
 
39
        /** Constructor, initializes command line options
 
40
         *  @return none
 
41
         */
 
42
        Image2Dcm();
 
43
        
 
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
 
53
         */
 
54
        OFCondition convert(I2DImgSource *inputPlug,
 
55
                                                I2DOutputPlug *outPlug,
 
56
                                                DcmDataset*& resultDset,
 
57
                                                E_TransferSyntax& proposedTS);
 
58
        
 
59
        OFCondition updateOverrideKeys(DcmDataset* dset);
 
60
        
 
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
 
64
         * @return none
 
65
         */
 
66
        void setTemplateFile(const OFString& file);
 
67
        
 
68
        /** Set file from which patient/study/series data should be imported from.
 
69
         *  @param file - [in] The DICOM file to read from
 
70
         *  @return none
 
71
         */
 
72
        void setSeriesFrom(const OFString& file);
 
73
        
 
74
        /** Set file from which patient/study/series data should be imported from.
 
75
         *  @param file - [in] The DICOM file to read from
 
76
         *  @return none
 
77
         */
 
78
        void setStudyFrom(const OFString& file);
 
79
        
 
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
 
82
         *  provided.
 
83
         *  @param incInstNo - [in] If true, the instance number will be incremented
 
84
         *  @return none
 
85
         */
 
86
        void setIncrementInstanceNumber(OFBool incInstNo);
 
87
        
 
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
 
96
         * @return none;
 
97
         */
 
98
        void setISOLatin1(OFBool insertLatin1);
 
99
        
 
100
        void setUTF8(OFBool insertUTF8);
 
101
        
 
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
 
107
         *  @return none
 
108
         */
 
109
        void setOverrideKeys(DcmDataset* dset);
 
110
        
 
111
        DcmDataset* getOverrideKeys() {
 
112
                if (m_overrideKeys == NULL) {
 
113
                        m_overrideKeys = new DcmDataset();
 
114
                }
 
115
                return m_overrideKeys;
 
116
        };
 
117
        
 
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.
 
126
         *  @return none
 
127
         */
 
128
        void setValidityChecking(OFBool doChecks,
 
129
                                                         OFBool insertMissingType2 = OFTrue,
 
130
                                                         OFBool inventMissingType1 = OFTrue);
 
131
        
 
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)
 
135
         *  @return none
 
136
         */
 
137
        void setLogStream(OFConsole *stream)
 
138
        {
 
139
                m_logStream = stream;
 
140
        }
 
141
        
 
142
        /** Sets the debug mode
 
143
         *  @param debugMode - [in] New status for debug mode
 
144
         *  @return none
 
145
         */
 
146
        void setDebugMode(const OFBool& debugMode) { m_debug = debugMode; };
 
147
        
 
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
 
152
         *  @return none
 
153
         */
 
154
        static void printMessage(OFConsole *stream,
 
155
                                                         const OFString& message1,
 
156
                                                         const OFString& message2 = "")
 
157
        {
 
158
                if (stream != NULL)
 
159
                {
 
160
                        stream->lockCerr() << message1 << message2 << std::endl;
 
161
                        stream->unlockCerr();
 
162
                }
 
163
        }
 
164
        
 
165
        
 
166
        /** Destructor, frees plugin memory
 
167
         *  @return none
 
168
         */
 
169
        ~Image2Dcm();
 
170
        
 
171
protected:
 
172
        
 
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
 
176
         * @return none
 
177
         */
 
178
        void cleanupTemplate(DcmDataset *targetDset);
 
179
        
 
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
 
184
         */
 
185
        OFCondition applyStudyOrSeriesFromFile(DcmDataset *targetDset);
 
186
        
 
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
 
190
         */
 
191
        OFCondition incrementInstanceNumber(DcmDataset *targetDset);
 
192
        
 
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
 
197
         */
 
198
        OFCondition generateUIDs(DcmDataset *dset);
 
199
        
 
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
 
206
         */
 
207
        OFCondition readAndInsertPixelData( I2DImgSource* imageSource,
 
208
                                                                           DcmDataset* dset,
 
209
                                                                           E_TransferSyntax& outputTS);
 
210
        
 
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
 
215
         */
 
216
        OFString isValid(DcmDataset& dataset) const;
 
217
        
 
218
        /** Copy override keys over existing keys in given dataset.
 
219
         *  @param outputDset - [out] dataset to which the override keys are copied
 
220
         */
 
221
        void applyOverrideKeys(DcmDataset *outputDset);
 
222
        
 
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
 
227
         */
 
228
        OFCondition insertLatin1(DcmDataset *outputDset);
 
229
        
 
230
        OFCondition insertUTF8(DcmDataset *outputDset);
 
231
        
 
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
 
238
         *          or has length of 0
 
239
         */
 
240
        OFString checkAndInventType1Attrib(const DcmTagKey& key,
 
241
                                                                           DcmDataset* targetDset,
 
242
                                                                           const OFString& defaultValue = "") const;
 
243
        
 
244
        
 
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)
 
250
         */
 
251
        OFString checkAndInventType2Attrib(const DcmTagKey& key,
 
252
                                                                           DcmDataset* targetDset) const;
 
253
        
 
254
private:
 
255
        
 
256
        /* Attributes for writing DICOM dataset */
 
257
        
 
258
        /// These attributes are applied to the dataset after conversion
 
259
        /// (and are not checked by the isValid() function)
 
260
        DcmDataset *m_overrideKeys;
 
261
        
 
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;
 
266
        
 
267
        /// If true, patient and study data is read from file
 
268
        OFBool m_readStudyLevel;
 
269
        
 
270
        /// If true, patient, study and series data is read from file
 
271
        OFBool m_readSeriesLevel;
 
272
        
 
273
        /// File to read study and series from
 
274
        OFString m_studySeriesFile;
 
275
        
 
276
        /// If true, Instance Number ist read from file and incremented by 1
 
277
        OFBool m_incInstNoFromFile;
 
278
        
 
279
        ///  If true, some simple attribute checks (missing type 2 attributes or
 
280
        ///  missing type 1 values) are omitted
 
281
        OFBool m_disableAttribChecks;
 
282
        
 
283
        /// If true, missing type 2 elements are inserted automatically (empty value).
 
284
        /// Enabled per default.
 
285
        OFBool m_inventMissingType2Attribs;
 
286
        
 
287
        /// If true, missing type 1 elements are inserted automatically with a
 
288
        /// predefined value, if possible. Disabled per default.
 
289
        OFBool m_inventMissingType1Attribs;
 
290
        
 
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;
 
295
        
 
296
        OFBool m_insertUTF8;
 
297
        
 
298
        /// If true, debug output is enabled
 
299
        OFBool m_debug;
 
300
        
 
301
        /// stream where warning/error message are sent to.
 
302
        /// can be NULL (default, no output).
 
303
        OFConsole *m_logStream;
 
304
        
 
305
};