forked from pixmeo/osirix
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDicomSeries.m
750 lines (618 loc) · 22.6 KB
/
DicomSeries.m
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
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
/*=========================================================================
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 "DicomSeries.h"
#import "DicomStudy.h"
#import "DicomImage.h"
#import <OsiriX/DCMAbstractSyntaxUID.h>
#import <OsiriX/DCM.h>
#import "NSImage+OsiriX.h"
#import "DCMPix.h"
#import "BrowserController.h"
#import "MutableArrayCategory.h"
#import "N2Debug.h"
#import "N2Stuff.h"
#ifdef OSIRIX_VIEWER
#import "DicomFileDCMTKCategory.h"
#import "DICOMToNSString.h"
#import "XMLControllerDCMTKCategory.h"
#import "ThreadsManager.h"
#import "NSThread+N2.h"
#import "VRController.h"
#endif
@implementation DicomSeries
@synthesize dicomTime;
@dynamic comment, comment2, comment3, comment4;
@dynamic date;
@dynamic dateAdded;
@dynamic dateOpened;
@dynamic displayStyle;
@dynamic id;
@dynamic modality;
@dynamic mountedVolume;
@dynamic name;
@dynamic numberOfImages;
@dynamic numberOfKeyImages;
@dynamic rotationAngle;
@dynamic scale;
@dynamic seriesDescription;
@dynamic seriesDICOMUID;
@dynamic seriesInstanceUID;
@dynamic seriesSOPClassUID;
@dynamic stateText;
@dynamic thumbnail;
@dynamic windowLevel;
@dynamic windowWidth;
@dynamic xFlipped;
@dynamic xOffset;
@dynamic yFlipped;
@dynamic yOffset;
@dynamic images;
@dynamic study;
- (BOOL) isDistant
{
return NO;
}
- (void) dealloc
{
[dicomTime release];
[super dealloc];
}
- (void)setValue:(id)value forUndefinedKey:(NSString *)key
{
}
- (id) valueForUndefinedKey:(NSString *)key
{
NSArray* files = [self sortedImages];
if( files.count)
{
DicomImage* image = [files objectAtIndex:[files count]/2];
@try {
id value = [image valueForKey:key];
if (value)
return value;
}
@catch (NSException *exception) {
// do nothing
}
id value = [DicomFile getDicomField: key forFile: image.completePath];
if( value)
return value;
}
return [super valueForUndefinedKey: key];
}
- (void) dcmodifyThread: (NSDictionary*) dict
{
#ifdef OSIRIX_VIEWER
#ifndef OSIRIX_LIGHT
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
[[DicomStudy dbModifyLock] lock];
@try {
NSMutableArray *params = [NSMutableArray arrayWithObjects:@"dcmodify", @"--ignore-errors", nil];
if( [dict objectForKey: @"value"] == nil || [(NSString*)[dict objectForKey: @"value"] length] == 0)
[params addObjectsFromArray: [NSArray arrayWithObjects: @"-e", [dict objectForKey: @"field"], nil]];
else
[params addObjectsFromArray: [NSArray arrayWithObjects: @"-i", [NSString stringWithFormat: @"%@=%@", [dict objectForKey: @"field"], [dict objectForKey: @"value"]], nil]];
NSMutableArray *files = [NSMutableArray arrayWithArray: [dict objectForKey: @"files"]];
if( files)
{
[files removeDuplicatedStrings];
[params addObjectsFromArray: files];
@try
{
NSStringEncoding encoding = [NSString encodingForDICOMCharacterSet: [[DicomFile getEncodingArrayForFile: [files lastObject]] objectAtIndex: 0]];
[XMLController modifyDicom: params encoding: encoding];
for( id loopItem in files)
[[NSFileManager defaultManager] removeFileAtPath: [loopItem stringByAppendingString:@".bak"] handler:nil];
}
@catch (NSException * e)
{
NSLog(@"**** DicomStudy setComment: %@", e);
}
}
}
@catch (NSException* e) {
N2LogExceptionWithStackTrace(e);
}
@finally {
[[DicomStudy dbModifyLock] unlock];
[pool release];
}
#endif
#endif
}
- (void) setComment: (NSString*) c
{
#ifdef OSIRIX_VIEWER
#ifndef OSIRIX_LIGHT
@try
{
if( [self.study.hasDICOM boolValue] == YES && [[NSUserDefaults standardUserDefaults] boolForKey: @"savedCommentsAndStatusInDICOMFiles"] && [[BrowserController currentBrowser] isBonjour: [self managedObjectContext]] == NO)
{
if( c == nil)
c = @"";
if( [(NSString*)[self primitiveValueForKey: @"comment"] length] != 0 || [c length] != 0)
{
if( [c isEqualToString: [self primitiveValueForKey: @"comment"]] == NO)
{
NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys: [[self paths] allObjects], @"files", @"(0020,4000)", @"field", c, @"value", nil];
NSThread *t = [[[NSThread alloc] initWithTarget:self selector:@selector(dcmodifyThread:) object: dict] autorelease];
t.name = NSLocalizedString( @"Updating DICOM files...", nil);
t.status = N2LocalizedSingularPluralCount( [[dict objectForKey: @"files"] count], NSLocalizedString(@"file", nil), NSLocalizedString(@"files", nil));
[[ThreadsManager defaultManager] addThreadAndStart: t];
}
}
}
}
@catch (NSException * e)
{
N2LogExceptionWithStackTrace(e);
}
#endif
#endif
NSString *previousValue = [self primitiveValueForKey: @"comment"];
[self willChangeValueForKey: @"comment"];
[self setPrimitiveValue: c forKey: @"comment"];
[self didChangeValueForKey: @"comment"];
if( [previousValue length] != 0 || [c length] != 0)
{
if( [c isEqualToString: previousValue] == NO)
[self.study archiveAnnotationsAsDICOMSR];
}
}
- (void) setComment2: (NSString*) c
{
NSString *previousValue = [self primitiveValueForKey: @"comment2"];
[self willChangeValueForKey: @"comment2"];
[self setPrimitiveValue: c forKey: @"comment2"];
[self didChangeValueForKey: @"comment2"];
if( [previousValue length] != 0 || [c length] != 0)
{
if( [c isEqualToString: previousValue] == NO)
[self.study archiveAnnotationsAsDICOMSR];
}
}
- (void) setComment3: (NSString*) c
{
NSString *previousValue = [self primitiveValueForKey: @"comment3"];
[self willChangeValueForKey: @"comment3"];
[self setPrimitiveValue: c forKey: @"comment3"];
[self didChangeValueForKey: @"comment3"];
if( [previousValue length] != 0 || [c length] != 0)
{
if( [c isEqualToString: previousValue] == NO)
[self.study archiveAnnotationsAsDICOMSR];
}
}
- (void) setComment4: (NSString*) c
{
NSString *previousValue = [self primitiveValueForKey: @"comment4"];
[self willChangeValueForKey: @"comment4"];
[self setPrimitiveValue: c forKey: @"comment4"];
[self didChangeValueForKey: @"comment4"];
if( [previousValue length] != 0 || [c length] != 0)
{
if( [c isEqualToString: previousValue] == NO)
[self.study archiveAnnotationsAsDICOMSR];
}
}
- (void) setStateText: (NSNumber*) c
{
NSNumber *previousState = [self primitiveValueForKey: @"stateText"];
[self willChangeValueForKey: @"stateText"];
[self setPrimitiveValue: c forKey: @"stateText"];
[self didChangeValueForKey: @"stateText"];
if( [c intValue] != [previousState intValue])
[self.study archiveAnnotationsAsDICOMSR];
}
- (void) didTurnIntoFault
{
[dicomTime release];
dicomTime = nil;
}
- (void) setDate:(NSDate*) date
{
@synchronized (self)
{
[dicomTime release];
dicomTime = nil;
[self willChangeValueForKey: @"date"];
[self setPrimitiveValue:date forKey:@"date"];
[self didChangeValueForKey: @"date"];
}
}
- (NSNumber*)dicomTime
{
@synchronized (self) {
if (!dicomTime)
dicomTime = [[[DCMCalendarDate dicomTimeWithDate:self.date] timeAsNumber] retain];
return dicomTime;
}
return nil;
}
//- (void) setThumbnail:(NSData *)thumbnail
//{
//
// // [img setScalesWhenResized: YES];
// // [img setSize:NSMakeSize(fillWidth, [fillImage size].height)];
//
//#ifndef NDEBUG
// NSImageRep* rep = [[[NSBitmapImageRep alloc] initWithData: thumbnail] autorelease];
// NSImage* img = [[[NSImage alloc] initWithSize:[rep size]] autorelease];
// [img addRepresentation:rep];
//
// if( img.size.width > THUMBNAILSIZE || img.size.height > THUMBNAILSIZE)
// NSLog( @"img: %f %f", img.size.width, img.size.height);
//#endif
//
// [self willChangeValueForKey: @"thumbnail"];
// [self setPrimitiveValue:thumbnail forKey:@"thumbnail"];
// [self didChangeValueForKey: @"thumbnail"];
//}
-(NSData*)thumbnail
{
NSData* thumbnailData = nil;
[self.managedObjectContext lock];
@try
{
thumbnailData = [[self primitiveValueForKey:@"thumbnail"] retain]; // autoreleased when returning
if( !thumbnailData)
{
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
@try
{
NSArray* files = [self sortedImages];
if (files.count)
{
DicomImage* image = [files objectAtIndex:[files count]/2];
NSImage* thumbAv = [image thumbnailIfAlreadyAvailable];
if (thumbAv) {
NSImage* thumbnail = [[[NSImage alloc] initWithSize: NSMakeSize(THUMBNAILSIZE, THUMBNAILSIZE)] autorelease];
[thumbnail lockFocus];
[thumbAv drawInRect:NSMakeRect(0,0,THUMBNAILSIZE,THUMBNAILSIZE) fromRect:[thumbAv alignmentRect] operation:NSCompositeCopy fraction:1.0];
[thumbnail unlockFocus];
thumbnailData = [[thumbnail TIFFRepresentation] retain]; // autoreleased when returning
}
else
if ([[NSFileHandle fileHandleForReadingAtPath: image.completePath] readDataOfLength: 100]) // This means the file is readable...
{
int frame = 0;
if (files.count == 1 && image.numberOfFrames.intValue > 1)
frame = [image.numberOfFrames intValue]/2;
if (image.frameID)
frame = image.frameID.intValue;
NSString *recoveryPath = [[[BrowserController currentBrowser] documentsDirectory] stringByAppendingPathComponent:@"/ThumbnailPath"];
[[NSFileManager defaultManager] removeFileAtPath: recoveryPath handler: nil];
[[[[self.study objectID] URIRepresentation] absoluteString] writeToFile: recoveryPath atomically: YES encoding: NSASCIIStringEncoding error: nil];
NSImage *thumbnail = nil;
NSString *seriesSOPClassUID = self.seriesSOPClassUID;
if( [[DCMAbstractSyntaxUID RTStructureSetStorage] isEqualToString: seriesSOPClassUID])
{
thumbnail = [NSImage imageNamed: @"RTStructIcon.jpg"];
thumbnailData = [[thumbnail TIFFRepresentation] retain]; // autoreleased when returning
}
else if( [DCMAbstractSyntaxUID isSpectroscopy: seriesSOPClassUID])
{
thumbnail = [NSImage imageNamed: @"SpectroIcon.jpg"];
thumbnailData = [[thumbnail TIFFRepresentation] retain]; // autoreleased when returning
}
else if( [DCMAbstractSyntaxUID isStructuredReport: seriesSOPClassUID] || [DCMAbstractSyntaxUID isPDF: seriesSOPClassUID])
{
NSImage *icon = [[NSWorkspace sharedWorkspace] iconForFileType: @"txt"];
thumbnail = [[[NSImage alloc] initWithSize: NSMakeSize( THUMBNAILSIZE, THUMBNAILSIZE)] autorelease];
[thumbnail lockFocus];
[icon drawInRect: NSMakeRect( 0, 0, THUMBNAILSIZE, THUMBNAILSIZE) fromRect: [icon alignmentRect] operation: NSCompositeCopy fraction: 1.0];
[thumbnail unlockFocus];
thumbnailData = [[thumbnail TIFFRepresentation] retain]; // autoreleased when returning
}
else if( [DCMAbstractSyntaxUID isImageStorage: seriesSOPClassUID] || [DCMAbstractSyntaxUID isRadiotherapy: seriesSOPClassUID] || [seriesSOPClassUID length] == 0)
{
DCMPix* dcmPix = [[DCMPix alloc] initWithPath: image.completePath :0 :1 :nil :frame :self.id.intValue isBonjour: [[BrowserController currentBrowser] isBonjour: [self managedObjectContext]] imageObj:image];
[dcmPix CheckLoad];
//Set the default series level window-width&level
if( image.series.windowWidth == nil && image.series.windowLevel == nil)
{
if( dcmPix.ww != 0 && dcmPix.wl != 0)
{
image.series.windowWidth = [NSNumber numberWithFloat: dcmPix.ww];
image.series.windowLevel = [NSNumber numberWithFloat: dcmPix.wl];
}
}
thumbnail = [dcmPix generateThumbnailImageWithWW: [image.series.windowWidth floatValue] WL: [image.series.windowLevel floatValue]];
if (!dcmPix.notAbleToLoadImage)
thumbnailData = [[thumbnail JPEGRepresentationWithQuality:0.3] retain]; // autoreleased when returning
[dcmPix release];
}
else
{
thumbnail = [NSImage imageNamed: @"FileNotFound.tif"];
thumbnailData = [[thumbnail TIFFRepresentation] retain]; // autoreleased when returning
}
[[NSFileManager defaultManager] removeFileAtPath: recoveryPath handler: nil];
}
}
if (thumbnailData)
{
[self willChangeValueForKey: @"thumbnail"];
[self setPrimitiveValue:thumbnailData forKey:@"thumbnail"];
[self didChangeValueForKey: @"thumbnail"];
}
}
@catch (NSException * e)
{
N2LogExceptionWithStackTrace(e);
}
[pool release];
}
}
@catch (NSException * e)
{
thumbnailData = [[[NSImage imageNamed: @"FileNotFound.tif"] TIFFRepresentation] retain];
}
@finally
{
[self.managedObjectContext unlock];
}
return [thumbnailData autorelease];
}
- (NSString*) modalities
{
return self.modality;
}
- (NSString*) type
{
return @"Series";
}
- (NSString *) localstring
{
BOOL local = YES;
[self.managedObjectContext lock];
@try {
NSManagedObject *obj = [self.images anyObject];
local = [[obj valueForKey:@"inDatabaseFolder"] boolValue];
}
@catch (NSException* e) {
N2LogExceptionWithStackTrace(e);
}
@finally {
[self.managedObjectContext unlock];
}
if (local)
return @"L";
else return @"";
}
- (NSNumber *) rawNoFiles
{
NSNumber* no = nil;
[self.managedObjectContext lock];
@try
{
int v = [[[self.images anyObject] valueForKey:@"numberOfFrames"] intValue];
if( v > 1)
no = [NSNumber numberWithInt: [self.images count] - v + 1];
else
no = [NSNumber numberWithInt: [self.images count]];
}
@catch (NSException* e) {
N2LogExceptionWithStackTrace(e);
}
@finally {
[self.managedObjectContext unlock];
}
return no;
}
- (NSSet*) images
{
if( self.managedObjectContext.deletedObjects.count == 0)
return [self primitiveValueForKey: @"images"];
else
{
NSSet *s = nil;
@autoreleasepool
{
s = [[[self primitiveValueForKey: @"images"] objectsWithOptions: NSEnumerationConcurrent passingTest:^BOOL(DicomImage *obj, BOOL *stop)
{
if( obj.isDeleted)
return NO;
return YES;
}] retain];
}
return [s autorelease];
}
}
- (NSNumber *) noFiles
{
@try {
int n = [[self primitiveValueForKey:@"numberOfImages"] intValue];
if( n == 0)
{
NSNumber* no = nil;
[self.managedObjectContext lock];
@try {
NSString *sopClassUID = self.seriesSOPClassUID;
if( [DCMAbstractSyntaxUID isStructuredReport: sopClassUID] == NO && [DCMAbstractSyntaxUID isPresentationState: sopClassUID] == NO && [DCMAbstractSyntaxUID isSupportedPrivateClasses: sopClassUID] == NO)
{
int v = [[[self.images anyObject] valueForKey:@"numberOfFrames"] intValue];
int count = [self.images count];
if( v > 1) // There are frames !
no = [NSNumber numberWithInt: -count];
else
no = [NSNumber numberWithInt: count];
[self willChangeValueForKey: @"numberOfImages"];
[self setPrimitiveValue:no forKey:@"numberOfImages"];
[self didChangeValueForKey: @"numberOfImages"];
if( v > 1)
no = [NSNumber numberWithInt: count]; // For the return
}
else no = [NSNumber numberWithInt: 0];
}
@catch (NSException* e) {
N2LogExceptionWithStackTrace(e);
}
@finally {
[self.managedObjectContext unlock];
}
return no;
}
else
{
if( n < 0) // There are frames !
return [NSNumber numberWithInt: -n];
else
return [self primitiveValueForKey:@"numberOfImages"];
}
}
@catch (NSException *exception) {
N2LogException( exception);
}
return [NSNumber numberWithInt: 0];
}
- (NSNumber *) noFilesExcludingMultiFrames
{
if( [[self primitiveValueForKey:@"numberOfImages"] intValue] <= 0) // There are frames !
{
int v = [[[self.images anyObject] valueForKey:@"numberOfFrames"] intValue];
NSNumber *no;
if( v > 1)
no = [NSNumber numberWithInt: [self.images count] - v + 1];
else
no = [self noFiles];
return no;
}
else
return [self noFiles];
}
- (DicomSeries*) previousSeries
{
NSArray *series = self.study.imageSeries;
NSUInteger index = [series indexOfObject: self];
if( index != NSNotFound && index > 0)
return [series objectAtIndex: index-1];
return nil;
}
- (DicomSeries*) nextSeries
{
NSArray *series = self.study.imageSeries;
NSUInteger index = [series indexOfObject: self];
if( index != NSNotFound && index < (long)series.count-1)
return [series objectAtIndex: index+1];
return nil;
}
- (void) setStudy:(DicomStudy *)study
{
[self willChangeValueForKey:@"study"];
[self setPrimitiveValue: study forKey: @"study"];
[self didChangeValueForKey:@"study"];
[self.study setNumberOfImages: nil];
}
- (NSSet *)paths
{
[self.managedObjectContext lock];
@try {
return [self valueForKeyPath:@"images.completePath"];
}
@catch (NSException* e) {
N2LogExceptionWithStackTrace(e);
}
@finally {
[self.managedObjectContext unlock];
}
return nil;
}
- (NSSet *)pathsForForkedProcess
{
[self.managedObjectContext lock];
@try {
return [self valueForKeyPath:@"images.completePathWithNoDownloadAndLocalOnly"];
}
@catch (NSException* e) {
N2LogExceptionWithStackTrace(e);
}
@finally {
[self.managedObjectContext unlock];
}
return nil;
}
- (NSSet *)keyImages
{
[self.managedObjectContext lock];
@try {
NSArray *imageArray = [self.images allObjects];
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"isKeyImage == YES"];
return [NSSet setWithArray:[imageArray filteredArrayUsingPredicate:predicate]];
}
@catch (NSException* e) {
N2LogExceptionWithStackTrace(e);
}
@finally {
[self.managedObjectContext unlock];
}
return nil;
}
- (NSArray*) sortDescriptorsForImages
{
int sortSeriesBySliceLocation = [[NSUserDefaults standardUserDefaults] integerForKey: @"sortSeriesBySliceLocation"];
NSSortDescriptor *sortInstance = nil, *sortLocation = nil, *sortDate = nil;
sortDate = [NSSortDescriptor sortDescriptorWithKey: @"date" ascending: (sortSeriesBySliceLocation > 0) ? YES : NO];
sortInstance = [NSSortDescriptor sortDescriptorWithKey: @"instanceNumber" ascending: YES];
sortLocation = [NSSortDescriptor sortDescriptorWithKey: @"sliceLocation" ascending: (sortSeriesBySliceLocation > 0) ? YES : NO];
NSArray *sortDescriptors = nil;
if( sortSeriesBySliceLocation == 0)
sortDescriptors = [NSArray arrayWithObjects: sortInstance, sortLocation, nil];
else
{
if( sortSeriesBySliceLocation == 2 || sortSeriesBySliceLocation == -2)
sortDescriptors = [NSArray arrayWithObjects: sortDate, sortLocation, sortInstance, nil];
else
sortDescriptors = [NSArray arrayWithObjects: sortLocation, sortInstance, nil];
}
return sortDescriptors;
}
- (NSArray *)sortedImages
{
@try {
return [self.images.allObjects sortedArrayUsingDescriptors: self.sortDescriptorsForImages];
}
@catch (NSException* e) {
N2LogExceptionWithStackTrace(e);
}
@finally {
}
return nil;
}
-(NSString*) uniqueFilename // Return a 'unique' filename that identify this series
{
return [NSString stringWithFormat:@"%@ %ld", self.seriesInstanceUID, (long) [self.date timeIntervalSinceReferenceDate]];
}
- (BOOL)validateForDelete:(NSError **)error
{
BOOL delete = [super validateForDelete: error];
@synchronized (self)
{
if (delete)
{
#ifndef OSIRIX_LIGHT
NSString *vrFile = [VRController getUniqueFilenameScissorStateFor: self];
if( vrFile && [[NSFileManager defaultManager] fileExistsAtPath: vrFile])
[[NSFileManager defaultManager] removeFileAtPath: vrFile handler: nil];
#endif
}
}
return delete;
}
- (NSComparisonResult)compareName:(DicomSeries*)series;
{
return [self.name caseInsensitiveCompare:[series valueForKey:@"name"]];
}
- (NSString*) albumsNames
{
return [self.study valueForKey: @"albumsNames"];
}
@end