-
Notifications
You must be signed in to change notification settings - Fork 218
/
Copy pathDCMObject.h
365 lines (283 loc) · 14.2 KB
/
DCMObject.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
/*=========================================================================
Program: OsiriX
Copyright (c) OsiriX Team
All rights reserved.
Distributed under GNU - LGPL
See http://www.osirix-viewer.com/copyright.html for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE.
=========================================================================*/
#import <Foundation/Foundation.h>
@class DCMAttribute;
@class DCMAttributeTag;
@class DCMDataContainer;
@class DCMCharacterSet;
@class DCMTagDictionary ;
@class DCMTagForNameDictionary;
@class DCMTransferSyntax;
/** \brief This is the main object representaing a Dicom File or as a list of Attributes for networking
*
* DCMObject is the main representation of a DICOM file or attribute list for networking. The object can be
* an image, Structured Report, Presentation State, etc
*/
@interface DCMObject : NSObject {
NSMutableDictionary *attributes;
NSDictionary *dicomDict;
DCMTagDictionary *sharedTagDictionary;
DCMTagForNameDictionary *sharedTagForNameDictionary;
DCMCharacterSet *specificCharacterSet;
DCMTransferSyntax *transferSyntax;
BOOL _decodePixelData;
BOOL isSequence;
}
@property(readonly) NSMutableDictionary *attributes; /**< Attributes as an NSDictionary */
@property(readonly) BOOL pixelDataIsDecoded; /**< Returns whether the pixel data has been converted to host endian transfer syntax */
@property(readonly) DCMTransferSyntax *transferSyntax;/**< The current transferSyntax */
@property(readonly) DCMCharacterSet *specificCharacterSet; /**< Encoding character set */
@property(readonly) NSXMLDocument *xmlDocument; /**< The object as an xml document */
@property(readonly) NSXMLNode *xmlNode; /**< The object as an xml node */
@property(readonly) NSString *description; /**< Human readable description */
@property BOOL isSequence;
+ (NSString*) globallyUniqueString;
/** Quick test to see if data is a DICOM/ACR file. First looks for the DICM at 128. If that isn't there looks for valid DICOM 3 elements at the start */
+ (BOOL)isDICOM:(NSData *)data;
/** Returns to rootUID for files created used by OsiriX */
+ (NSString *)rootUID;
/** Returns the MACAddress of the computer which generated the image */
+ (NSString*) MACAddress;
/** Returns to implementationClassUID for files created used by OsiriX */
+ (NSString *)implementationClassUID;
/** Returns to implementationClassUID for files created used by OsiriX */
+ (NSString *)implementationVersionName;
/** Create an empty DICOM object */
+ (id)dcmObject;
/** Anonymize a DICOM file
* @param file Path to the file to anonymize
* @param tags Array of tags to anonymize with the replacement values. Each object in tags is an array.
* The first object is a DCMAttributeTag..
* The second object is the replacement value if there is one.
* @param destination Path to save the anonymized file at
*/
+ (BOOL)anonymizeContentsOfFile:(NSString *)file tags:(NSArray *)tags writingToFile:(NSString *)destination;
/** Create a secondary caputure object.
* The patient name, patient ID, Study ID, and other necessary information us extracted from the template object
* @param object The template object to extract information from
*/
+ (id)secondaryCaptureObjectFromTemplate:(DCMObject *)object;
/** Create a seocndary capture object
* @param bitDepth Bit depth of object ususally 8 or 16
* @param spp Samples per pixel is the number of color channels. 1 for monochrome. 3 for RGB
* @param nff Number of frames
*/
+ (id)secondaryCaptureObjectWithBitDepth:(int)bitDepth samplesPerPixel:(int)spp numberOfFrames:(int)nff;
/** Create a DICOM object with data
* @param data Data to create the object with.
* @param decodePixelData If YES the pixel data will be decompressed if needed and converted to host byte order.
*/
+ (id)objectWithData:(NSData *)data decodingPixelData:(BOOL)decodePixelData;
/** Create a DICOM object from a file
* @param file Path to the file.
* @param decodePixelData If YES the pixel data will be decompressed if needed and converted to host byte order.
*/
+ (id)objectWithContentsOfFile:(NSString *)file decodingPixelData:(BOOL)decodePixelData;
/** Create a DICOM object from a URL
* @param aURL Absolute URL to the file.
* @param decodePixelData If YES the pixel data will be decompressed if needed and converted to host byte order.
*/
+ (id)objectWithContentsOfURL:(NSURL *)aURL decodingPixelData:(BOOL)decodePixelData;
/** Create a copy of a DICOM object
* @param object Original object.
*/
+ (id)objectWithObject:(DCMObject *)object;
/** Initialize a DICOM object with data
* @param data Data to create the object with.
* @param decodePixelData If YES the pixel data will be decompressed if needed and converted to host byte order.
*/
- (id)initWithData:(NSData *)data decodingPixelData:(BOOL)decodePixelData;
/** Initialize a DICOM object with data
* @param data Data to create the object with.
* @param syntax The encoding transfer syntax.
*/
- (id)initWithData:(NSData *)data transferSyntax:(DCMTransferSyntax *)syntax;
/** Initialize a DICOM object from a file
* @param file Path to the file.
* @param decodePixelData If YES the pixel data will be decompressed if needed and converted to host byte order.
*/
- (id)initWithContentsOfFile:(NSString *)file decodingPixelData:(BOOL)decodePixelData;
/** Initialize a DICOM object from a URL
* @param aURL Absolute URL to the file.
* @param decodePixelData If YES the pixel data will be decompressed if needed and converted to host byte order.
*/
- (id)initWithContentsOfURL:(NSURL *)aURL decodingPixelData:(BOOL)decodePixelData;
/** Initialize a copy of a DICOM object
* @param object Original object.
*/
- (id)initWithObject:(DCMObject *)object;
/** Initialize with a DCMDataContainer.\n
* Used when parsing a sequence
* @param data The DCMDataContainer
* @param lengthToRead Length to read from data
* @param byteOffset Byte offset to start of the object
* @param characterSet The DCMCharacterSet used for decoding
* @param decodePixelData Flag to decode contained pixelData
*/
- (id)initWithDataContainer:(DCMDataContainer *)data lengthToRead:(int)lengthToRead byteOffset:(int *)byteOffset characterSet:(DCMCharacterSet *)characterSet decodingPixelData:(BOOL)decodePixelData;
/** Empty initializer */
- (id)init;
//Dicom Parsing
/** Extract group from the dicomData at the current position.\n
* Used when parsing the DICOM data. */
- (int)getGroup:(DCMDataContainer *)dicomData;
/** Extract element from the dicomData at the current position.\n
* Used when parsing the DICOM data. */
- (int)getElement:(DCMDataContainer *)dicomData;
/** Extract length of the current element.\n
* Used when parsing the DICOM data. */
- (int)length:(DCMDataContainer *)dicomData;
/** Extract VR from the dicomData for DCMAttributeTag.\n
* Used when parsing the DICOM data. */
- (NSString *)getvr:(DCMDataContainer *)dicomData forTag:(DCMAttributeTag *)tag isExplicit:(BOOL)isExplicit;
/** Extract values for DCMAttribute.\n
* Used when parsing the DICOM data. */
- (NSMutableArray *)getValues:(DCMDataContainer *)dicomData;
/** Parse the dataset\n
* Used when parsing the DICOM data. */
- (int)readDataSet:(DCMDataContainer *)dicomData lengthToRead:(int)lengthToRead byteOffset:(int *)byteOffset;
/** Parse of Sequence attribute\n
* Used when parsing the DICOM data. */
- (int)readNewSequenceAttribute:(DCMAttribute *)attr dicomData:(DCMDataContainer *)dicomData byteOffset:(int *)byteOffset lengthToRead:(int)lengthToRead specificCharacterSet:(DCMCharacterSet *)specificCharacterSet;
/** Create a DCMAttribute\n
* Used when parsing the DICOM data. */
- (DCMAttribute *) newAttributeForAttributeTag:(DCMAttributeTag *)tag
vr:(NSString *)vr
length:(int) vl
data:(DCMDataContainer *)dicomData
specificCharacterSet:(DCMCharacterSet *)specificCharacterSet
isExplicit:(BOOL) explicitTS
forImplicitUseOW:(BOOL)forImplicitUseOW;
/** Remove the metainformation. This is all elements for group 0x0002*/
- (void)removeMetaInformation;
/** Update the metainformation\n
* mandatory attributes:\n
* FileMetaInformationVersion\n
* MediaStorageSOPClassUID\n
* MediaStorageSOPInstanceUID\n
* TransferSyntaxUID\n
* ImplementationClassUID\n
* SourceApplicationEntityTitle\n
* groupLengthTag\n
*/
- (void)updateMetaInformationWithTransferSyntax: (DCMTransferSyntax *)ts aet:(NSString *)aet;
/** Remove group lengths */
- (void)removeGroupLengths;
/** Remove private tags */
- (void)removePrivateTags;
/** Remove planar and rescale attributes.\n
* Used when changing the pixelData encapsulation or rescaling pixelData
*/
- (void)removePlanarAndRescaleAttributes;
/** Anonymize DCMAttributeTag or replace with aValue if present */
- (void)anonymizeAttributeForTag:(DCMAttributeTag *)tag replacingWith:(id)aValue;
/** Create a new study instance UID */
- (void)newStudyInstanceUID;
/** Create a new series instance UID */
- (void)newSeriesInstanceUID;
/** Create a new SOP Instance UID */
- (void)newSOPInstanceUID;
/** Anonymize the given string */
- (NSString *)anonymizeString:(NSString *)string;
/** Set the Specific character set
* @param characterSet The new DCMCharacterSet
*/
- (void)setCharacterSet:(DCMCharacterSet *)characterSet;
/** Return the DCMAttribute for the given DCMAttributeTag */
- (DCMAttribute *)attributeForTag:(DCMAttributeTag *)tag;
/** Return the first value for the named attribute. */
- (id)attributeValueWithName:(NSString *)name;
/** Return the first value for the attribute with the key
* @param key The element as a string 0XGGGGWWWW */
- (id)attributeValueForKey:(NSString *)key;
/** Return the named attribute . */
- (DCMAttribute *)attributeWithName:(NSString *)name;
/** Return the array of values for the named attribute */
- (NSArray *)attributeArrayWithName:(NSString *)name;
/** Set the DCMAttribute */
- (void)setAttribute:(DCMAttribute *)attr;
/** add a value to the named attribute*/
- (void)addAttributeValue:(id)value forName:(NSString *)name;
/** Set the array of values for the named attribute */
- (void)setAttributeValues:(NSMutableArray *)values forName:(NSString *)name;
/** Write to a DCMDataContainer
* @param container DCMDataContainer to write to
* @param ts DCMTransferSyntax for writing
* @param aet Application Entity Title for the device doing the writing
* @param flag Write as DICOM3. Add metainformation and DICM at offset 128.
*/
- (BOOL)writeToDataContainer:(DCMDataContainer *)container withTransferSyntax:(DCMTransferSyntax *)ts AET:(NSString *)aet asDICOM3:(BOOL)flag;
- (BOOL)writeToDataContainer:(DCMDataContainer *)container withTransferSyntax:(DCMTransferSyntax *)ts AET:(NSString *)aet asDICOM3:(BOOL)flag implicitForPixelData: (BOOL) ipd;
/** Write to a DCMDataContainer
* @param container DCMDataContainer to write to
* @param ts DCMTransferSyntax for writing
* @param quality The quality for lossy syntaxes
* @param flag Write as DICOM3. Add metainformation and DICM at offset 128.
* @param aet Application Entity Title for the device doing the writing
* @param stripGroupLength Remove group length when writing
*/
- (BOOL)writeToDataContainer:(DCMDataContainer *)container
withTransferSyntax:(DCMTransferSyntax *)ts
quality:(int)quality
asDICOM3:(BOOL)flag
AET:(NSString *)aet
strippingGroupLengthLength:(BOOL)stripGroupLength;
/** Write to a file
* @param path Path to the file
* @param ts DCMTransferSyntax for writing
* @param quality The quality for lossy syntaxes
* @param aet Application Entity Title for the device doing the writing
* @param atomically If YES, the data is written to a backup file, and thenÑassuming no errors occurÑthe backup file is renamed to the name specified by path; otherwise, the data is written directly to path.
*/
- (BOOL)writeToFile:(NSString *)path withTransferSyntax:(DCMTransferSyntax *)ts quality:(int)quality AET:(NSString *)aet atomically:(BOOL)atomically;
/** Write to a url
* @param aURL URL to the file
* @param ts DCMTransferSyntax for writing
* @param quality The quality for lossy syntaxes
* @param aet Application Entity Title for the device doing the writing
* @param atomically If YES, the data is written to a backup file, and thenÑassuming no errors occurÑthe backup file is renamed to the name specified by path; otherwise, the data is written directly to path.
* If YES, the data is written to a backup location, and thenÑassuming no errors occurÑthe backup location is renamed to the name specified by aURL; otherwise, the data is written directly to aURL. atomically is ignored if aURL is not of a type the supports atomic writes.
*/
- (BOOL)writeToURL:(NSURL *)aURL withTransferSyntax:(DCMTransferSyntax *)ts quality:(int)quality AET:(NSString *)aet atomically:(BOOL)atomically;
/** Write to NSData
* @param ts DCMTransferSyntax for writing
* @param quality The quality for lossy syntaxes
*/
- (NSData *)writeDatasetWithTransferSyntax:(DCMTransferSyntax *)ts quality:(int)quality;
/** Returns YES if the tag string is a needed attribute */
- (BOOL)isNeededAttribute:(char *)tagString;
//deprecated methods
/** Deprecated */
- (BOOL)writeToDataContainer:(DCMDataContainer *)container withTransferSyntax:(DCMTransferSyntax *)ts quality:(int)quality;
/** Deprecated */
- (BOOL)writeToDataContainer:(DCMDataContainer *)container withTransferSyntax:(DCMTransferSyntax *)ts asDICOM3:(BOOL)flag;
/** Deprecated */
- (BOOL)writeToDataContainer:(DCMDataContainer *)container
withTransferSyntax:(DCMTransferSyntax *)ts
quality:(int)quality
asDICOM3:(BOOL)flag
strippingGroupLengthLength:(BOOL)stripGroupLength;
/** Deprecated */
- (BOOL)writeToDataContainer:(DCMDataContainer *)container withTransferSyntax:(DCMTransferSyntax *)ts quality:(int)quality asDICOM3:(BOOL)flag;
/** Deprecated */
- (BOOL)writeToFile:(NSString *)path withTransferSyntax:(DCMTransferSyntax *)ts quality:(int)quality atomically:(BOOL)flag;
/** Deprecated */
- (BOOL)writeToURL:(NSURL *)aURL withTransferSyntax:(DCMTransferSyntax *)ts quality:(int)quality atomically:(BOOL)flag;
//sequences
/** return a sequence as an NSArray */
- (NSArray *)referencedSeriesSequence;
/** returns the referenced Image Sequence for object */
- (NSArray *)referencedImageSequenceForObject:(DCMObject *)object;
/** Create a Structured Report Object */
+ (id)objectWithCodeValue:(NSString *)codeValue
codingSchemeDesignator:(NSString *)codingSchemeDesignator
codeMeaning:(NSString *)codeMeaning;
@end