-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathitkPhilipsPAR.cxx
2583 lines (2526 loc) · 90.9 KB
/
itkPhilipsPAR.cxx
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
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*=========================================================================
Program: Insight Segmentation & Registration Toolkit
Module: $RCSfile: itkPhilipsPAR.cxx,v $
Language: C++
Date: $Date: 2008-06-23 22:04:35 $
Version: $Revision: 1.7 $
Copyright (c) Insight Software Consortium. All rights reserved.
See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
#include "itkPhilipsPAR.h"
#include <fstream>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <string.h>
/**
* \author Don C. Bigler
* The Pennsylvania State University 2005
*
* This implementation was contributed as a paper to the Insight Journal
* http://insight-journal.org/midas/handle.php?handle=1926/1381
*
*/
namespace itk
{
/*# === IMAGE INFORMATION DEFINITION ============================================
#
# The rest of this file contains ONE line per image, this line contains the
# following information:
#
# slice number (integer)
# echo number (integer)
# dynamic scan number (integer)
# cardiac phase number (integer)
# image_type_mr (integer)
# scanning sequence (integer)
# index in REC file (in images) (integer)
# rescale intercept (float)
# rescale slope (float)
# scale slope (float)
# window center (integer)
# window width (integer)
# image angulation (ap,fh,rl in degrees ) (3*float)
# image offcentre (ap,fh,rl in mm ) (3*float)
# image_display_orientation (integer)
# slice orientation ( TRA/SAG/COR ) (integer)
# fmri_status_indication (integer)
# image_type_ed_es (end diast/end syst) (integer)
# pixel spacing (x,y) (in mm) (2*float)
# echo_time (float)
# dyn_scan_begin_time (float)
# trigger_time (float)
# diffusion_b_factor (float)
# image_flip_angle (in degrees) (float)
#
# === IMAGE INFORMATION =======================================================*/
/**
* \struct image_info_defV3
*/
struct image_info_defV3
{
int problemreading;
int slice;
int echo;
int dynamic;
int cardiac;
int image_type_mr;
int scan_sequence;
int index;
float rescale_int;
float rescale_slope;
float scale_slope;
int window_center;
int window_width;
float angAP;
float angFH;
float angRL;
float offAP;
float offFH;
float offRL;
int display_orientation;
int slice_orientation;
int fmri_status_indication;
int image_type_ed_es;
float spacingx;
float spacingy;
float echo_time;
float dyn_scan_begin_time;
float trigger_time;
float diffusion_b_factor;
float image_flip_angle;
};
/*# === IMAGE INFORMATION DEFINITION ============================================
# The rest of this file contains ONE line per image, this line contains the
# following information:
#
# slice number (integer)
# echo number (integer)
# dynamic scan number (integer)
# cardiac phase number (integer)
# image_type_mr (integer)
# scanning sequence (integer)
# index in REC file (in images) (integer)
# image pixel size (in bits) (integer)
# scan percentage (integer)
# recon resolution (x y) (2*integer)
# rescale intercept (float)
# rescale slope (float)
# scale slope (float)
# window center (integer)
# window width (integer)
# image angulation (ap,fh,rl in degrees ) (3*float)
# image offcentre (ap,fh,rl in mm ) (3*float)
# slice thickness (in mm ) (float)
# slice gap (in mm ) (float)
# image_display_orientation (integer)
# slice orientation ( TRA/SAG/COR ) (integer)
# fmri_status_indication (integer)
# image_type_ed_es (end diast/end syst) (integer)
# pixel spacing (x,y) (in mm) (2*float)
# echo_time (float)
# dyn_scan_begin_time (float)
# trigger_time (float)
# diffusion_b_factor (float)
# number of averages (integer)
# image_flip_angle (in degrees) (float)
# cardiac frequency (bpm) (integer)
# minimum RR-interval (in ms) (integer)
# maximum RR-interval (in ms) (integer)
# TURBO factor <0=no turbo> (integer)
# Inversion delay (in ms) (float)
#
# === IMAGE INFORMATION =======================================================*/
/**
* \struct image_info_defV4
*/
struct image_info_defV4
{
int problemreading;
int slice;
int echo;
int dynamic;
int cardiac;
int image_type_mr;
int scan_sequence;
int index;
int image_bits;
int scan_percent;
int recon_dimx;
int recon_dimy;
float rescale_int;
float rescale_slope;
float scale_slope;
int window_center;
int window_width;
float angAP;
float angFH;
float angRL;
float offAP;
float offFH;
float offRL;
float slice_thick;
float slice_gap;
int display_orientation;
int slice_orientation;
int fmri_status_indication;
int image_type_ed_es;
float spacingx;
float spacingy;
float echo_time;
float dyn_scan_begin_time;
float trigger_time;
float diffusion_b_factor;
int num_averages;
float image_flip_angle;
int cardiac_freq;
int min_rr_int;
int max_rr_int;
int turbo_factor;
float inversion_delay;
};
/*# === IMAGE INFORMATION DEFINITION ============================================
# The rest of this file contains ONE line per image, this line contains the
# following information:
#
# slice number (integer)
# echo number (integer)
# dynamic scan number (integer)
# cardiac phase number (integer)
# image_type_mr (integer)
# scanning sequence (integer)
# index in REC file (in images) (integer)
# image pixel size (in bits) (integer)
# scan percentage (integer)
# recon resolution (x y) (2*integer)
# rescale intercept (float)
# rescale slope (float)
# scale slope (float)
# window center (integer)
# window width (integer)
# image angulation (ap,fh,rl in degrees ) (3*float)
# image offcentre (ap,fh,rl in mm ) (3*float)
# slice thickness (in mm ) (float)
# slice gap (in mm ) (float)
# image_display_orientation (integer)
# slice orientation ( TRA/SAG/COR ) (integer)
# fmri_status_indication (integer)
# image_type_ed_es (end diast/end syst) (integer)
# pixel spacing (x,y) (in mm) (2*float)
# echo_time (float)
# dyn_scan_begin_time (float)
# trigger_time (float)
# diffusion_b_factor (float)
# number of averages (integer)
# image_flip_angle (in degrees) (float)
# cardiac frequency (bpm) (integer)
# minimum RR-interval (in ms) (integer)
# maximum RR-interval (in ms) (integer)
# TURBO factor <0=no turbo> (integer)
# Inversion delay (in ms) (float)
# diffusion b value number (imagekey!) (integer)
# gradient orientation number (imagekey!) (integer)
# contrast type (string)
# diffusion anisotropy type (string)
# diffusion (ap, fh, rl) (3*float)
#
# === IMAGE INFORMATION =======================================================*/
/**
* \struct image_info_defV41
*/
struct image_info_defV41
{
int problemreading;
int slice;
int echo;
int dynamic;
int cardiac;
int image_type_mr;
int scan_sequence;
int index;
int image_bits;
int scan_percent;
int recon_dimx;
int recon_dimy;
float rescale_int;
float rescale_slope;
float scale_slope;
int window_center;
int window_width;
float angAP;
float angFH;
float angRL;
float offAP;
float offFH;
float offRL;
float slice_thick;
float slice_gap;
int display_orientation;
int slice_orientation;
int fmri_status_indication;
int image_type_ed_es;
float spacingx;
float spacingy;
float echo_time;
float dyn_scan_begin_time;
float trigger_time;
float diffusion_b_factor;
int num_averages;
float image_flip_angle;
int cardiac_freq;
int min_rr_int;
int max_rr_int;
int turbo_factor;
float inversion_delay;
int diffusion_b_value_number;
int gradient_orientation_number;
int contrast_type;
int diffusion_anisotropy_type;
float diffusion_ap;
float diffusion_fh;
float diffusion_rl;
};
static std::string GetLineNumber(std::string file, int lineNum)
{
std::string line = "";
int lineCount = 0;
char readFileBuffer[512] = "";
if( lineNum <= 0 )
{
return line;
}
// Try to read the text file.
std::ifstream local_InputStream;
local_InputStream.open( file.c_str(),
std::ios::in );
if( local_InputStream.fail() )
{
return line;
}
while( (!local_InputStream.eof()) && (lineCount != lineNum) )
{
local_InputStream.getline(readFileBuffer, sizeof(readFileBuffer));
++lineCount;
}
local_InputStream.close();
if( lineCount == lineNum )
{
line = readFileBuffer;
}
return line;
}
static std::string GetGeneralInfoString(std::string file, int lineNum)
{
std::string currentLine = "";
std::string::size_type index;
std::string outString = "";
if( (lineNum < 12) && (lineNum > 51) )
{
return outString;
}
currentLine = GetLineNumber(file,lineNum);
index = currentLine.find(":");
if( index != std::string::npos )
{
std::string tempString = ":";
outString = currentLine.substr(index+tempString.length());
}
return outString;
}
static struct image_info_defV3 GetImageInformationDefinitionV3(std::string file,
int lineNum)
{
struct image_info_defV3 tempInfo;
std::string currentLine = "";
memset((void*)&tempInfo,0,sizeof(struct image_info_defV3));
if( lineNum < 89 )
{
tempInfo.problemreading = 1;
return tempInfo;
}
currentLine = GetLineNumber(file,lineNum);
if( (currentLine == "") ||
(currentLine == "\n") ||
(currentLine == "\r\n") ||
(currentLine == "\r") ||
(currentLine == "# === END OF DATA DESCRIPTION FILE ======================"
"=========================") ||
(currentLine == "# === END OF DATA DESCRIPTION FILE ======================"
"=========================\r"))
{
tempInfo.problemreading = 1;
return tempInfo;
}
std::istringstream inString(currentLine);
if( !inString )
{
tempInfo.problemreading = 1;
return tempInfo;
}
inString >> tempInfo.slice >> tempInfo.echo >> tempInfo.dynamic;
inString >> tempInfo.cardiac >> tempInfo.image_type_mr
>> tempInfo.scan_sequence;
inString >> tempInfo.index >> tempInfo.rescale_int >> tempInfo.rescale_slope;
inString >> tempInfo.scale_slope >> tempInfo.window_center
>> tempInfo.window_width;
inString >> tempInfo.angAP >> tempInfo.angFH >> tempInfo.angRL;
inString >> tempInfo.offAP >> tempInfo.offFH >> tempInfo.offRL;
inString >> tempInfo.display_orientation >> tempInfo.slice_orientation
>> tempInfo.fmri_status_indication;
inString >> tempInfo.image_type_ed_es >> tempInfo.spacingx
>> tempInfo.spacingy;
inString >> tempInfo.echo_time >> tempInfo.dyn_scan_begin_time
>> tempInfo.trigger_time;
inString >> tempInfo.diffusion_b_factor >> tempInfo.image_flip_angle;
return tempInfo;
}
struct image_info_defV4 GetImageInformationDefinitionV4(std::string file,
int lineNum)
{
struct image_info_defV4 tempInfo;
std::string currentLine = "";
memset((void*)&tempInfo,0,sizeof(struct image_info_defV4));
if( lineNum < 92 )
{
tempInfo.problemreading = 1;
return tempInfo;
}
currentLine = GetLineNumber(file,lineNum);
if( (currentLine == "") ||
(currentLine == "\n") ||
(currentLine == "\r\n") ||
(currentLine == "\r") ||
(currentLine == "# === END OF DATA DESCRIPTION FILE ======================"
"=========================") ||
(currentLine == "# === END OF DATA DESCRIPTION FILE ======================"
"=========================\r"))
{
tempInfo.problemreading = 1;
return tempInfo;
}
std::istringstream inString(currentLine);
if( !inString )
{
tempInfo.problemreading = 1;
return tempInfo;
}
inString >> tempInfo.slice >> tempInfo.echo >> tempInfo.dynamic;
inString >> tempInfo.cardiac >> tempInfo.image_type_mr
>> tempInfo.scan_sequence;
inString >> tempInfo.index >> tempInfo.image_bits >> tempInfo.scan_percent;
inString >> tempInfo.recon_dimx >> tempInfo.recon_dimy;
inString >> tempInfo.rescale_int >> tempInfo.rescale_slope;
inString >> tempInfo.scale_slope >> tempInfo.window_center
>> tempInfo.window_width;
inString >> tempInfo.angAP >> tempInfo.angFH >> tempInfo.angRL;
inString >> tempInfo.offAP >> tempInfo.offFH >> tempInfo.offRL;
inString >> tempInfo.slice_thick >> tempInfo.slice_gap;
inString >> tempInfo.display_orientation >> tempInfo.slice_orientation
>> tempInfo.fmri_status_indication;
inString >> tempInfo.image_type_ed_es >> tempInfo.spacingx
>> tempInfo.spacingy;
inString >> tempInfo.echo_time >> tempInfo.dyn_scan_begin_time
>> tempInfo.trigger_time;
inString >> tempInfo.diffusion_b_factor >> tempInfo.num_averages
>> tempInfo.image_flip_angle;
inString >> tempInfo.cardiac_freq >> tempInfo.min_rr_int
>> tempInfo.max_rr_int;
inString >> tempInfo.turbo_factor >> tempInfo.inversion_delay;
return tempInfo;
}
struct image_info_defV41 GetImageInformationDefinitionV41(std::string file,
int lineNum)
{
struct image_info_defV41 tempInfo;
std::string currentLine = "";
memset((void*)&tempInfo,0,sizeof(struct image_info_defV41));
if( lineNum < 99 )
{
tempInfo.problemreading = 1;
return tempInfo;
}
currentLine = GetLineNumber(file,lineNum);
if( (currentLine == "") ||
(currentLine == "\n") ||
(currentLine == "\r\n") ||
(currentLine == "\r") ||
(currentLine == "# === END OF DATA DESCRIPTION FILE ======================"
"=========================") ||
(currentLine == "# === END OF DATA DESCRIPTION FILE ======================"
"=========================\r"))
{
tempInfo.problemreading = 1;
return tempInfo;
}
std::istringstream inString(currentLine);
if( !inString )
{
tempInfo.problemreading = 1;
return tempInfo;
}
inString >> tempInfo.slice >> tempInfo.echo >> tempInfo.dynamic;
inString >> tempInfo.cardiac >> tempInfo.image_type_mr
>> tempInfo.scan_sequence;
inString >> tempInfo.index >> tempInfo.image_bits >> tempInfo.scan_percent;
inString >> tempInfo.recon_dimx >> tempInfo.recon_dimy;
inString >> tempInfo.rescale_int >> tempInfo.rescale_slope;
inString >> tempInfo.scale_slope >> tempInfo.window_center
>> tempInfo.window_width;
inString >> tempInfo.angAP >> tempInfo.angFH >> tempInfo.angRL;
inString >> tempInfo.offAP >> tempInfo.offFH >> tempInfo.offRL;
inString >> tempInfo.slice_thick >> tempInfo.slice_gap;
inString >> tempInfo.display_orientation >> tempInfo.slice_orientation
>> tempInfo.fmri_status_indication;
inString >> tempInfo.image_type_ed_es >> tempInfo.spacingx
>> tempInfo.spacingy;
inString >> tempInfo.echo_time >> tempInfo.dyn_scan_begin_time
>> tempInfo.trigger_time;
inString >> tempInfo.diffusion_b_factor >> tempInfo.num_averages
>> tempInfo.image_flip_angle;
inString >> tempInfo.cardiac_freq >> tempInfo.min_rr_int
>> tempInfo.max_rr_int;
inString >> tempInfo.turbo_factor >> tempInfo.inversion_delay;
inString >> tempInfo.diffusion_b_value_number
>> tempInfo.gradient_orientation_number;
inString >> tempInfo.contrast_type >> tempInfo.contrast_type;
inString >> tempInfo.diffusion_ap >> tempInfo.diffusion_fh
>> tempInfo.diffusion_rl;
return tempInfo;
}
#define UNDEFINED "Undefined"
// Adapted from r2agui.m
bool ReadPAR(std::string parFile, struct par_parameter* pPar)
{
//read version number of Philips research tools
//Research tools are used to extract data from database; data formats differ
//considerably between versions. Handles V3, V4, and V4.1
std::string currentLine = "";
std::string temp = "";
std::string::size_type index = 0;
std::istringstream inString;
if( pPar == nullptr )
{
std::cerr << "ReadPAR: pPar == NULL" << std::endl;
return false;
}
// Zero out struct.
memset((void *)pPar,0,sizeof(struct par_parameter));
// Need to set strings to UNDEFINED to avoid segmentation faults.
strcpy(pPar->patient_name, UNDEFINED);
strcpy(pPar->exam_name, UNDEFINED);
strcpy(pPar->protocol_name, UNDEFINED);
strcpy(pPar->exam_date, UNDEFINED);
strcpy(pPar->exam_time, UNDEFINED);
strcpy(pPar->series_type, UNDEFINED);
strcpy(pPar->patient_position, UNDEFINED);
strcpy(pPar->prep_direction, UNDEFINED);
strcpy(pPar->technique, UNDEFINED);
strcpy(pPar->scan_mode, UNDEFINED);
// Set image types index to -1.
memset((void *)pPar->image_types,-1,sizeof(pPar->image_types));
// Set num_slice_repetitions to 1 to avoid divide by zero.
pPar->num_slice_repetitions = 1;
// Check version of PAR file.
currentLine = GetLineNumber(parFile,8);
//std::cout << currentLine << std::endl;
index = currentLine.find("V3");
if( index != std::string::npos )
{
pPar->ResToolsVersion = RESEARCH_IMAGE_EXPORT_TOOL_V3;
}
else
{
index = currentLine.find("V4.1");
if( index != std::string::npos )
{
pPar->ResToolsVersion = RESEARCH_IMAGE_EXPORT_TOOL_V4_1;
}
else
{
index = currentLine.find("V4");
if( index != std::string::npos )
{
pPar->ResToolsVersion = RESEARCH_IMAGE_EXPORT_TOOL_V4;
}
else
{
pPar->problemreading = 1;
std::cerr << "ReadPAR: Unknown PAR version?" << std::endl;
return false;
}
}
}
switch( pPar->ResToolsVersion )
{
case RESEARCH_IMAGE_EXPORT_TOOL_V3:
{
struct image_info_defV3 tempInfo;
struct image_info_defV3 tempInfo1;
float fovAP, fovFH, fovRL;
strncpy(pPar->patient_name,GetGeneralInfoString(parFile,12).c_str(),
sizeof(pPar->patient_name));
strncpy(pPar->exam_name,GetGeneralInfoString(parFile,13).c_str(),
sizeof(pPar->exam_name));
strncpy(pPar->protocol_name,GetGeneralInfoString(parFile,14).c_str(),
sizeof(pPar->protocol_name));
strncpy(pPar->exam_date,GetGeneralInfoString(parFile,15).c_str(),
GetGeneralInfoString(parFile,15).find("/"));
strncpy(pPar->exam_time,
GetGeneralInfoString(parFile,15).substr(
GetGeneralInfoString(parFile,15).find("/")+1).c_str(),
sizeof(pPar->exam_time));
inString.str(GetGeneralInfoString(parFile,16));
inString >> pPar->scno;
inString.clear();
inString.str(GetGeneralInfoString(parFile,17));
inString >> pPar->recno;
inString.clear();
inString.str(GetGeneralInfoString(parFile,18));
inString >> pPar->scan_duration;
inString.clear();
inString.str(GetGeneralInfoString(parFile,19));
inString >> pPar->cardiac_phases;
inString.clear();
inString.str(GetGeneralInfoString(parFile,20));
inString >> pPar->echoes;
inString.clear();
inString.str(GetGeneralInfoString(parFile,21));
inString >> pPar->slice;
inString.clear();
inString.str(GetGeneralInfoString(parFile,22));
inString >> pPar->dyn;
inString.clear();
inString.str(GetGeneralInfoString(parFile,23));
inString >> pPar->mixes;
inString.clear();
inString.str(GetGeneralInfoString(parFile,24));
inString >> pPar->bit;
inString.clear();
strncpy(pPar->technique,GetGeneralInfoString(parFile,25).c_str(),
sizeof(pPar->technique));
strncpy(pPar->scan_mode,GetGeneralInfoString(parFile,26).c_str(),
sizeof(pPar->scan_mode));
inString.str(GetGeneralInfoString(parFile,27));
inString >> pPar->scan_resolution[0];
inString >> pPar->scan_resolution[1];
inString.clear();
inString.str(GetGeneralInfoString(parFile,28));
inString >> pPar->scan_percent;
inString.clear();
inString.str(GetGeneralInfoString(parFile,29));
inString >> pPar->dim[0] >> pPar->dim[1];
pPar->dim[2] = pPar->slice;
inString.clear();
inString.str(GetGeneralInfoString(parFile,30));
inString >> pPar->num_averages;
inString.clear();
// It appears that the max number of mixes
// parameter indicates the number of experiment
// repititions. This assumption is based on
// the T1 mapping images that use the look-locker
// sequence.
inString.str(GetGeneralInfoString(parFile,31));
for(int repTime=0; repTime<pPar->mixes; repTime++)
{
inString >> pPar->repetition_time[repTime];
}
inString.clear();
tempInfo = GetImageInformationDefinitionV3(parFile, 89);
if( tempInfo.problemreading )
{
pPar->problemreading = 1;
std::cerr << "ReadPAR: GetImageInformationDefinitionV3(parFile, 89)"
<< std::endl;
return false;
}
pPar->sliceorient = tempInfo.slice_orientation;
int echoNumber = tempInfo.echo;
pPar->echo_times[0] = tempInfo.echo_time;
int cardiacPhase = tempInfo.cardiac;
pPar->trigger_times[0] = tempInfo.trigger_time;
pPar->vox[0] = tempInfo.spacingx;
pPar->vox[1] = tempInfo.spacingy;
inString.str(GetGeneralInfoString(parFile,32));
inString >> fovAP >> fovFH >> fovRL;
inString.clear();
// slice orientation: transversal
if( pPar->sliceorient == PAR_SLICE_ORIENTATION_TRANSVERSAL )
{
pPar->fov[0] = fovAP;
pPar->fov[1] = fovRL;
}
// slice orientation: sagittal
if( pPar->sliceorient == PAR_SLICE_ORIENTATION_SAGITTAL )
{
pPar->fov[0] = fovFH;
pPar->fov[1] = fovAP;
}
// slice orientation: coronal
if( pPar->sliceorient == PAR_SLICE_ORIENTATION_CORONAL )
{
pPar->fov[0] = fovRL;
pPar->fov[1] = fovFH;
}
inString.str(GetGeneralInfoString(parFile,33));
inString >> pPar->slth;
inString.clear();
inString.str(GetGeneralInfoString(parFile,34));
inString >> pPar->gap;
inString.clear();
pPar->fov[2] = (pPar->gap + pPar->slth)*pPar->slice;
pPar->vox[2] = pPar->slth + pPar->gap;
inString.str(GetGeneralInfoString(parFile,35));
inString >> pPar->water_fat_shift;
inString.clear();
inString.str(GetGeneralInfoString(parFile,36));
inString >> pPar->angAP;
inString >> pPar->angFH;
inString >> pPar->angRL;
inString.clear();
inString.str(GetGeneralInfoString(parFile,37));
inString >> pPar->offAP;
inString >> pPar->offFH;
inString >> pPar->offRL;
inString.clear();
inString.str(GetGeneralInfoString(parFile,38));
inString >> pPar->flow_comp;
inString.clear();
inString.str(GetGeneralInfoString(parFile,39));
inString >> pPar->presaturation;
inString.clear();
inString.str(GetGeneralInfoString(parFile,40));
inString >> pPar->cardiac_freq;
inString.clear();
inString.str(GetGeneralInfoString(parFile,41));
inString >> pPar->min_rr_int;
inString.clear();
inString.str(GetGeneralInfoString(parFile,42));
inString >> pPar->max_rr_int;
inString.clear();
inString.str(GetGeneralInfoString(parFile,43));
inString >> pPar->phase_encode_vel[0];
inString >> pPar->phase_encode_vel[1];
inString >> pPar->phase_encode_vel[2];
inString.clear();
inString.str(GetGeneralInfoString(parFile,44));
inString >> pPar->mtc;
inString.clear();
inString.str(GetGeneralInfoString(parFile,45));
inString >> pPar->spir;
inString.clear();
inString.str(GetGeneralInfoString(parFile,46));
inString >> pPar->epi;
inString.clear();
inString.str(GetGeneralInfoString(parFile,47));
inString >> pPar->turbo;
inString.clear();
inString.str(GetGeneralInfoString(parFile,48));
inString >> pPar->dynamic_scan;
inString.clear();
inString.str(GetGeneralInfoString(parFile,49));
inString >> pPar->diffusion;
inString.clear();
inString.str(GetGeneralInfoString(parFile,50));
inString >> pPar->diff_echo;
inString.clear();
inString.str(GetGeneralInfoString(parFile,51));
inString >> pPar->inversion_delay;
inString.clear();
// OK, need to figure out how many images are stored in the REC file
// and whether or not the images are sorted by slice or by image blocks.
// Also get echo times and trigger_times.
if( pPar->slice > 1 )
{
int lineIncrement = 89;
int echoIndex = 0;
int cardiacIndex = 0;
tempInfo1 = GetImageInformationDefinitionV3(parFile, 90);
if( tempInfo1.problemreading )
{
pPar->problemreading = 1;
std::cerr << "ReadPAR: GetImageInformationDefinitionV3(parFile, 90)"
<< std::endl;
return false;
}
if ((tempInfo1.slice-tempInfo.slice) > 0 )
{
pPar->slicessorted = 1;
}
// If slices are sorted I only need to calculate the number of
// image blocks (if more than 1) and store the echo times.
if( pPar->slicessorted )
{
++pPar->image_blocks;
++pPar->num_image_types;
pPar->image_types[0] = tempInfo.image_type_mr;
++pPar->num_scanning_sequences;
pPar->scanning_sequences[0] = tempInfo.scan_sequence;
lineIncrement += pPar->slice;
tempInfo1 = GetImageInformationDefinitionV3(parFile, lineIncrement);
while( !tempInfo1.problemreading && tempInfo1.slice )
{
int isUnique = 1;
// Find unique image types in REC.
for(int i=0; i<pPar->num_image_types; i++)
{
if( pPar->image_types[i] == tempInfo1.image_type_mr )
{
isUnique = 0;
break;
}
}
if( isUnique )
{
++pPar->num_image_types;
pPar->image_types[pPar->num_image_types-1] =
tempInfo1.image_type_mr;
}
isUnique = 1;
// Find all of the scanning sequences.
for(int i=0; i<pPar->num_scanning_sequences; i++)
{
if( pPar->scanning_sequences[i] == tempInfo1.scan_sequence )
{
isUnique = 0;
break;
}
}
if( isUnique )
{
++pPar->num_scanning_sequences;
pPar->scanning_sequences[pPar->num_scanning_sequences-1] =
tempInfo1.scan_sequence;
}
++pPar->image_blocks;
lineIncrement += pPar->slice;
// Get the echo times.
if( echoNumber != tempInfo1.echo )
{
++echoIndex;
pPar->echo_times[echoIndex] = tempInfo1.echo_time;
echoNumber = tempInfo1.echo;
}
// Get the trigger times
if( cardiacPhase != tempInfo1.cardiac )
{
++cardiacIndex;
pPar->trigger_times[cardiacIndex] = tempInfo1.trigger_time;
cardiacPhase = tempInfo1.cardiac;
}
tempInfo1 = GetImageInformationDefinitionV3(parFile, lineIncrement);
}
}
// Slices are not sorted.
else
{
int slice = tempInfo.slice;
++pPar->image_blocks;
++pPar->num_image_types;
pPar->image_types[0] = tempInfo.image_type_mr;
++pPar->num_scanning_sequences;
pPar->scanning_sequences[0] = tempInfo.scan_sequence;
++lineIncrement;
tempInfo1 = GetImageInformationDefinitionV3(parFile, lineIncrement);
while( !tempInfo1.problemreading && tempInfo1.slice )
{
if( slice == tempInfo1.slice )
{
int isUnique = 1;
// Find unique image types in REC.
for(int i=0; i<pPar->num_image_types; i++)
{
if( pPar->image_types[i] == tempInfo1.image_type_mr )
{
isUnique = 0;
break;
}
}
if( isUnique )
{
++pPar->num_image_types;
pPar->image_types[pPar->num_image_types-1] =
tempInfo1.image_type_mr;
}
isUnique = 1;
// Find all of the scanning sequences.
for(int i=0; i<pPar->num_scanning_sequences; i++)
{
if( pPar->scanning_sequences[i] == tempInfo1.scan_sequence )
{
isUnique = 0;
break;
}
}
if( isUnique )
{
++pPar->num_scanning_sequences;
pPar->scanning_sequences[pPar->num_scanning_sequences-1] =
tempInfo1.scan_sequence;
}
++pPar->image_blocks;
// Get the echo times.
if( echoNumber != tempInfo1.echo )
{
++echoIndex;
pPar->echo_times[echoIndex] = tempInfo1.echo_time;
echoNumber = tempInfo1.echo;
}
// Get the trigger times
if( cardiacPhase != tempInfo1.cardiac )
{
++cardiacIndex;
pPar->trigger_times[cardiacIndex] = tempInfo1.trigger_time;
cardiacPhase = tempInfo1.cardiac;
}
}
else
{
lineIncrement = 89;
// OK, I need to determine if there are more image blocks, only
// if pPar->num_image_types or pPar->num_scanning_sequences > 1
if( (pPar->num_image_types > 1) ||
(pPar->num_scanning_sequences > 1) )
{
pPar->num_slice_repetitions = pPar->image_blocks;
lineIncrement += (pPar->slice*pPar->num_slice_repetitions);
tempInfo1 = GetImageInformationDefinitionV3(parFile,
lineIncrement);
while( !tempInfo1.problemreading && tempInfo1.slice )
{
// Get the echo times.
if( echoNumber != tempInfo1.echo )
{
++echoIndex;
pPar->echo_times[echoIndex] = tempInfo1.echo_time;
echoNumber = tempInfo1.echo;
}
// Get the trigger times
if( cardiacPhase != tempInfo1.cardiac )
{
++cardiacIndex;
pPar->trigger_times[cardiacIndex] = tempInfo1.trigger_time;
cardiacPhase = tempInfo1.cardiac;
}
pPar->image_blocks += pPar->num_slice_repetitions;
lineIncrement += (pPar->slice*pPar->num_slice_repetitions);
tempInfo1 = GetImageInformationDefinitionV3(parFile,
lineIncrement);
}
}
break;
}
++lineIncrement;
tempInfo1 = GetImageInformationDefinitionV3(parFile, lineIncrement);
}
}
// This is a sanity check. The echoIndex should match
// (pPar->echoes-1).
if( (pPar->echoes-1) != echoIndex )
{
pPar->problemreading = 1;
std::cerr << "ReadPAR: (pPar->echoes-1) != echoIndex" << std::endl;
std::cerr << "pPar->echoes-1 = " << pPar->echoes-1 << std::endl;
std::cerr << "echoIndex = " << echoIndex << std::endl;
return false;
}
// Another sanity check. The cardiacIndex should match
// (pPar->cardiac_phases-1).
if( (pPar->cardiac_phases-1) != cardiacIndex )
{
pPar->problemreading = 1;
std::cerr << "ReadPAR: (pPar->cardiac_phases-1) != cardiacIndex"
<< std::endl;
std::cerr << "pPar->cardiac_phases-1 = " << pPar->cardiac_phases-1
<< std::endl;
std::cerr << "cardiacIndex = " << cardiacIndex << std::endl;
return false;
}
}
// Only 1 slice, but how many repetitions of that slice?
else
{
int lineIncrement = 89;
int echoIndex = 0;
int cardiacIndex = 0;
int slice = tempInfo.slice;
int firstEchoNumber = echoNumber;
int firstCardiacPhase = cardiacPhase;
int firstDynamic = tempInfo.dynamic;
++pPar->image_blocks;
++pPar->num_image_types;
pPar->image_types[0] = tempInfo.image_type_mr;
++pPar->num_scanning_sequences;
pPar->scanning_sequences[0] = tempInfo.scan_sequence;
++lineIncrement;
tempInfo1 = GetImageInformationDefinitionV3(parFile, lineIncrement);
while( !tempInfo1.problemreading && tempInfo1.slice )
{
if( slice == tempInfo1.slice )
{
int isUnique = 1;
// Find unique image types in REC.
for(int i=0; i<pPar->num_image_types; i++)
{
if( pPar->image_types[i] == tempInfo1.image_type_mr )
{
isUnique = 0;
break;
}
}
if( isUnique )
{
++pPar->num_image_types;