23 #include <itksys/SystemTools.hxx>
49 const char *
const NI =
"##$NI";
50 const char *
const NR =
"##$NR";
59 #define FORWARDSLASH_DIRECTORY_SEPARATOR '/'
61 #define RECO_FILE "reco"
62 #define ACQP_FILE "acqp"
63 #define DTHREEPROC_FILE "d3proc"
64 #define RECO_byte_order "##$RECO_byte_order="
65 #define BRUKER_LITTLE_ENDIAN "littleEndian"
66 #define BRUKER_BIG_ENDIAN "bigEndian"
67 #define RECO_fov "##$RECO_fov=("
68 #define RECO_size "##$RECO_size=("
69 #define RECO_wordtype "##$RECO_wordtype="
70 #define RECO_image_type "##$RECO_image_type="
71 #define RECO_transposition "##$RECO_transposition=("
72 #define MAGNITUDE_IMAGE "MAGNITUDE_IMAGE"
73 #define REAL_IMAGE "REAL_IMAGE"
74 #define IMAGINARY_IMAGE "IMAGINARY_IMAGE"
75 #define COMPLEX_IMAGE "COMPLEX_IMAGE"
76 #define PHASE_IMAGE "PHASE_IMAGE"
77 #define IR_IMAGE "IR_IMAGE"
78 #define ACQ_dim "##$ACQ_dim="
81 #define Nechoes "##$NECHOES="
82 #define ACQ_slice_thick "##$ACQ_slice_thick="
83 #define ACQ_slice_sepn "##$ACQ_slice_sepn=("
84 #define ACQ_slice_sepn_mode "##$ACQ_slice_sepn_mode="
85 #define BRUKER_SIGNED_CHAR "_8BIT_SGN_INT"
86 #define BRUKER_UNSIGNED_CHAR "_8BIT_UNSGN_INT"
87 #define BRUKER_SIGNED_SHORT "_16BIT_SGN_INT"
88 #define BRUKER_SIGNED_INT "_32BIT_SGN_INT"
89 #define BRUKER_FLOAT "_32BIT_FLOAT"
90 #define ACQ_echo_time "##$ACQ_echo_time=("
91 #define ACQ_repetition_time "##$ACQ_repetition_time=("
92 #define ACQ_inversion_time "##$ACQ_inversion_time=("
93 #define ACQ_grad_matrix "##$ACQ_grad_matrix=("
94 #define DATTYPE "##$DATTYPE="
95 #define IM_SIX "##$IM_SIX="
96 #define IM_SIY "##$IM_SIY="
97 #define IM_SIZ "##$IM_SIZ="
98 #define IP_CHAR "ip_char"
99 #define IP_SHORT "ip_short"
100 #define IP_INT "ip_int"
104 unsigned long numberOfPixels )
112 ((
char*)buffer, numberOfPixels );
116 ((
unsigned char*)buffer, numberOfPixels );
120 ((
short*)buffer, numberOfPixels );
124 ((
unsigned short*)buffer, numberOfPixels );
128 ((
int*)buffer, numberOfPixels );
132 ((
unsigned int*)buffer, numberOfPixels );
136 ((
long*)buffer, numberOfPixels );
140 ((
unsigned long*)buffer, numberOfPixels );
144 ((
float*)buffer, numberOfPixels );
148 ((
double*)buffer, numberOfPixels );
152 "Component Type Unknown",
163 ((
char *)buffer, numberOfPixels );
167 ((
unsigned char *)buffer, numberOfPixels );
171 ((
short *)buffer, numberOfPixels );
175 ((
unsigned short *)buffer, numberOfPixels );
179 ((
int *)buffer, numberOfPixels );
183 ((
unsigned int *)buffer, numberOfPixels );
187 ((
long *)buffer, numberOfPixels );
191 ((
unsigned long *)buffer, numberOfPixels );
195 ((
float *)buffer, numberOfPixels );
199 ((
double *)buffer, numberOfPixels );
203 "Component Type Unknown",
247 unsigned int numberOfPixels = 1;
248 char *
const p =
static_cast<char *
>(buffer);
250 for(dim=0; dim< dimensions; dim++ )
257 std::string file2Dseq =
258 itksys::SystemTools::CollapseFullPath(this->
m_FileName.c_str());
259 itksys::SystemTools::ConvertToUnixSlashes(file2Dseq);
261 std::ifstream twodseq_InputStream;
262 twodseq_InputStream.imbue(std::locale::classic());
263 twodseq_InputStream.open( file2Dseq.c_str(), std::ios::in | std::ios::binary );
265 if( twodseq_InputStream.fail() )
267 OStringStream message;
268 message <<
"The Brucker2DSEG Data File can not be opened. "
269 <<
"The following file was attempted:" << std::endl
277 twodseq_InputStream.read(p, Math::CastWithRangeCheck< std::streamsize, SizeType >( this->
GetImageSizeInBytes() ) );
279 if( twodseq_InputStream.fail() )
281 OStringStream message;
282 message <<
"The Brucker2DSEG Data File can not be read. "
283 <<
"The following file was attempted:" << std::endl
290 twodseq_InputStream.close();
296 std::string file2Dseq = itksys::SystemTools::CollapseFullPath(FileNameToRead);
297 itksys::SystemTools::ConvertToUnixSlashes(file2Dseq);
298 std::string path = itksys::SystemTools::GetFilenamePath(file2Dseq);
303 std::vector<std::string> pathComponents;
304 itksys::SystemTools::SplitPath(path.c_str(), pathComponents);
305 if(pathComponents.size() < 3)
310 pathComponents.pop_back();pathComponents.pop_back();
311 path = itksys::SystemTools::JoinPath(pathComponents);
314 std::string readFileBufferString =
"";
315 char readFileBuffer[512] =
"";
316 std::string::size_type index;
317 unsigned long length2DSEQ = 0;
318 unsigned long calcLength = 1;
321 if( !itksys::SystemTools::FileExists(file2Dseq.c_str()) )
327 length2DSEQ = itksys::SystemTools::FileLength(file2Dseq.c_str());
331 std::ifstream reco_InputStream;
332 reco_InputStream.open( filereco.c_str(),
334 if( reco_InputStream.fail() )
338 reco_InputStream.imbue(std::locale::classic());
339 while( !reco_InputStream.eof() )
341 reco_InputStream.getline(readFileBuffer,
sizeof(readFileBuffer));
342 readFileBufferString = readFileBuffer;
346 if( index != std::string::npos )
349 std::string dattypeString =
350 readFileBufferString.substr(index+tempString.length());
353 calcLength *= (
unsigned long)
sizeof(
char);
357 calcLength *= (
unsigned long)
sizeof(
unsigned char);
361 calcLength *= (
unsigned long)
sizeof(
short);
365 calcLength *= (
unsigned long)
sizeof(
int);
367 else if( dattypeString.find(
BRUKER_FLOAT) != std::string::npos )
369 calcLength *= (
unsigned long)
sizeof(
float);
373 reco_InputStream.close();
379 reco_InputStream.close();
383 if( !itksys::SystemTools::FileExists(fileacqp.c_str()) )
389 std::ifstream d3proc_InputStream;
390 d3proc_InputStream.open( filed3proc.c_str(),
392 if( d3proc_InputStream.fail() )
396 d3proc_InputStream.imbue(std::locale::classic());
397 while( !d3proc_InputStream.eof() )
399 d3proc_InputStream.getline(readFileBuffer,
sizeof(readFileBuffer));
400 readFileBufferString = readFileBuffer;
434 index = readFileBufferString.find(
IM_SIX);
435 if( index != std::string::npos )
437 unsigned long xDim = 0;
438 std::string tempString =
IM_SIX;
439 std::istringstream im_sixString(readFileBufferString.substr(
440 index+tempString.length()));
443 d3proc_InputStream.close();
446 im_sixString >> xDim;
453 index = readFileBufferString.find(
IM_SIY);
454 if( index != std::string::npos )
456 unsigned long yDim = 0;
457 std::string tempString =
IM_SIY;
458 std::istringstream im_siyString(readFileBufferString.substr(
459 index+tempString.length()));
462 d3proc_InputStream.close();
465 im_siyString >> yDim;
472 index = readFileBufferString.find(
IM_SIZ);
473 if( index != std::string::npos )
475 unsigned long zDim = 0;
476 std::string tempString =
IM_SIZ;
477 std::istringstream im_sizString(readFileBufferString.substr(
478 index+tempString.length()));
481 d3proc_InputStream.close();
484 im_sizString >> zDim;
491 d3proc_InputStream.close();
495 if( calcLength != length2DSEQ )
506 std::string file2Dseq =
507 itksys::SystemTools::CollapseFullPath(this->
m_FileName.c_str());
508 itksys::SystemTools::ConvertToUnixSlashes(file2Dseq);
509 std::string path = itksys::SystemTools::GetFilenamePath(file2Dseq);
514 std::vector<std::string> pathComponents;
515 itksys::SystemTools::SplitPath(path.c_str(), pathComponents);
516 if(pathComponents.size() < 3)
518 OStringStream message;
519 message <<
"Cannot create path for acqp file: "
521 <<
"Path Components: ";
522 for (
unsigned int i = 0; i < pathComponents.size(); i++)
524 message << pathComponents[i] <<
"' ";
532 pathComponents.pop_back();pathComponents.pop_back();
533 path = itksys::SystemTools::JoinPath(pathComponents);
536 std::string readFileBufferString =
"";
537 char readFileBuffer[512] =
"";
538 std::string::size_type index;
539 std::string::size_type tempIndex = 0;
540 std::vector<double> imageFOV(3);
541 std::vector<unsigned int> imageDim(3);
542 bool numDimensions =
false;
543 bool byteOrder =
false;
544 bool slicesNotInSameOrientation =
false;
545 bool echoTime =
false;
546 bool repetitionTime =
false;
547 bool inversionTime =
false;
550 unsigned int numEchoImages = 0;
551 bool sliceThickness =
false;
552 bool sliceSeperation =
false;
553 int numSeperation = 0;
554 int numRecoTranspose = -1;
555 double sliceThick = 0;
556 std::string seperationMode =
"";
557 std::vector<double> dirx(3,0),diry(3,0),dirz(3,0);
558 std::vector<int> recoTransposition;
567 std::ifstream d3proc_InputStream;
568 d3proc_InputStream.open( filed3proc.c_str(),
570 if( d3proc_InputStream.fail() )
572 OStringStream message;
573 message <<
"d3proc file: " << filed3proc <<
" cannot be opened.";
579 d3proc_InputStream.imbue(std::locale::classic());
580 while( !d3proc_InputStream.eof() )
582 d3proc_InputStream.getline(readFileBuffer,
sizeof(readFileBuffer));
583 readFileBufferString = readFileBuffer;
621 index = readFileBufferString.find(
IM_SIX);
622 if( index != std::string::npos )
624 std::string tempString =
IM_SIX;
625 std::istringstream im_sixString(readFileBufferString.substr(
626 index+tempString.length()));
629 d3proc_InputStream.close();
630 OStringStream message;
631 message <<
"Could not create std::istringstream for "
632 <<
"##$IM_SIX" << std::endl
640 im_sixString >> imageDim[0];
644 index = readFileBufferString.find(
IM_SIY);
645 if( index != std::string::npos )
647 std::string tempString =
IM_SIY;
648 std::istringstream im_siyString(readFileBufferString.substr(
649 index+tempString.length()));
652 d3proc_InputStream.close();
653 OStringStream message;
654 message <<
"Could not create std::istringstream for "
655 <<
"##$IM_SIY" << std::endl
663 im_siyString >> imageDim[1];
667 index = readFileBufferString.find(
IM_SIZ);
668 if( index != std::string::npos )
670 std::string tempString =
IM_SIZ;
671 std::istringstream im_sizString(readFileBufferString.substr(
672 index+tempString.length()));
675 d3proc_InputStream.close();
676 OStringStream message;
677 message <<
"Could not create std::istringstream for "
678 <<
"##$IM_SIZ" << std::endl
686 im_sizString >> imageDim[2];
690 d3proc_InputStream.close();
692 std::ifstream reco_InputStream;
693 reco_InputStream.open(filereco.c_str(),
695 if( reco_InputStream.fail())
697 OStringStream message;
698 message <<
"reco file: " << filereco <<
" cannot be opened";
704 reco_InputStream.imbue(std::locale::classic());
705 while( !reco_InputStream.eof() )
707 reco_InputStream.getline(readFileBuffer,
sizeof(readFileBuffer));
708 readFileBufferString = readFileBuffer;
711 index = readFileBufferString.find(
RECO_fov);
712 if( index != std::string::npos )
715 tempIndex = readFileBufferString.find(
"2");
716 if( tempIndex != std::string::npos )
718 reco_InputStream >> imageFOV[0] >> imageFOV[1];
720 tempRecoFOV->resize(2);
721 tempRecoFOV->SetElement(0, imageFOV[0]);
722 tempRecoFOV->SetElement(1, imageFOV[1]);
723 numDimensions =
true;
727 tempIndex = readFileBufferString.find(
"3");
728 if( tempIndex != std::string::npos )
730 reco_InputStream >> imageFOV[0] >> imageFOV[1] >> imageFOV[2];
731 tempRecoFOV->resize(3);
732 tempRecoFOV->SetElement(0, imageFOV[0]);
733 tempRecoFOV->SetElement(1, imageFOV[1]);
734 tempRecoFOV->SetElement(2, imageFOV[2]);
735 numDimensions =
true;
739 reco_InputStream.close();
740 OStringStream message;
741 message <<
"Invalid reco file: Couldn't locate proper "
742 <<
"fov parameters" << std::endl
751 EncapsulateMetaData<RECOFOVContainerType::Pointer>(
756 index = readFileBufferString.find(
RECO_size);
757 if( index != std::string::npos )
759 unsigned int tempRecoSize = 2;
760 tempIndex = readFileBufferString.find(
"2");
761 if( tempIndex == std::string::npos )
763 tempIndex = readFileBufferString.find(
"3");
765 if( tempIndex == std::string::npos )
767 reco_InputStream.close();
768 OStringStream message;
769 message <<
"Invalid reco file: Couldn't locate proper "
770 <<
"dimension parameters" << std::endl
779 EncapsulateMetaData<unsigned int>(thisDic,
RECO_SIZE,tempRecoSize);
784 if( index != std::string::npos )
788 if( tempIndex != std::string::npos )
792 EncapsulateMetaData<std::string>(
798 if( tempIndex != std::string::npos )
802 EncapsulateMetaData<std::string>(
808 if( tempIndex != std::string::npos )
812 EncapsulateMetaData<std::string>(
818 if( tempIndex != std::string::npos )
822 EncapsulateMetaData<std::string>(
828 if( tempIndex != std::string::npos )
832 EncapsulateMetaData<std::string>(
837 reco_InputStream.close();
838 OStringStream message;
839 message <<
"Invalid reco file: Couldn't locate proper "
840 <<
"wordtype parameter" << std::endl
856 if( index != std::string::npos )
859 std::istringstream recoTransposeString(readFileBufferString.substr(
860 index+tempString.length()));
861 if (!recoTransposeString)
863 reco_InputStream.close();
864 OStringStream message;
865 message <<
"Could not create std::istringstream for "
866 <<
"##$RECO_transposition" << std::endl
874 recoTransposeString >> numRecoTranspose;
876 if( numRecoTranspose > 0 )
880 recoTransposition.resize(numRecoTranspose);
881 tempRecoTransposition->resize(numRecoTranspose);
882 for(
unsigned int i=0; i<(
unsigned int)numRecoTranspose; i++)
884 reco_InputStream >> recoTransposition[i];
885 tempRecoTransposition->SetElement(i,recoTransposition[i]);
887 EncapsulateMetaData<RECOTranspositionContainerType::Pointer>(
894 if( index != std::string::npos )
897 std::string recoType =
"";
898 recoType = readFileBufferString.substr(index+tempString.length());
901 EncapsulateMetaData<std::string>(
904 else if( recoType.find(
REAL_IMAGE) != std::string::npos )
906 EncapsulateMetaData<std::string>(
911 EncapsulateMetaData<std::string>(
916 EncapsulateMetaData<std::string>(
919 else if( recoType.find(
PHASE_IMAGE) != std::string::npos )
921 EncapsulateMetaData<std::string>(
924 else if( recoType.find(
IR_IMAGE) != std::string::npos )
926 EncapsulateMetaData<std::string>(
931 reco_InputStream.close();
932 OStringStream message;
933 message <<
"Invalid reco file: Couldn't locate proper"
934 <<
"datatype parameter" << std::endl
946 if( index != std::string::npos )
949 if( tempIndex != std::string::npos )
953 EncapsulateMetaData<std::string>(
959 if( tempIndex != std::string::npos )
963 EncapsulateMetaData<std::string>(
968 reco_InputStream.close();
969 OStringStream message;
970 message <<
"Invalid reco file: Couldn't locate proper"
971 <<
"byte order parameter" << std::endl
982 reco_InputStream.close();
986 OStringStream message;
987 message <<
"Invalid reco file: Couldn't locate "
988 <<
"'##$RECO_fov=(' tag" << std::endl
998 OStringStream message;
999 message <<
"Invalid reco file: Couldn't locate "
1000 <<
"'##$RECO_byte_order=' tag" << std::endl
1008 if( numRecoTranspose < 0 )
1010 OStringStream message;
1011 message <<
"Invalid reco file: Couldn't locate "
1012 <<
"'##$RECO_transposition=(' tag" << std::endl
1022 std::ifstream acqp_InputStream;
1023 std::string acqpFileString =
"";
1024 acqp_InputStream.open(fileacqp.c_str(),
1027 if( acqp_InputStream.fail() )
1029 OStringStream message;
1030 message <<
"acqp file cannot be opened. "
1038 acqp_InputStream.imbue(std::locale::classic());
1039 while( !acqp_InputStream.eof() )
1042 int numRepetitions = 0;
1043 int numInversionTimes = 0;
1044 acqp_InputStream.getline(readFileBuffer,
sizeof(readFileBuffer));
1046 acqpFileString = readFileBuffer;
1049 index = acqpFileString.find(
ACQ_dim);
1050 if( index != std::string::npos )
1052 std::string tempString =
ACQ_dim;
1053 std::istringstream acqDimString(acqpFileString.substr(
1054 index+tempString.length()));
1057 acqp_InputStream.close();
1058 OStringStream message;
1059 message <<
"Could not create std::istringstream for "
1068 acqDimString >> acq_dim;
1070 EncapsulateMetaData<int>(thisDic,
ACQ_DIM,acq_dim);
1075 index = acqpFileString.find(
Ni);
1076 if( index != std::string::npos )
1078 std::string tempString =
Ni;
1079 std::istringstream niString(acqpFileString.substr(
1080 index+tempString.length()));
1083 acqp_InputStream.close();
1084 OStringStream message;
1085 message <<
"Could not create std::istringstream for "
1086 <<
"##$NI" << std::endl
1096 EncapsulateMetaData<int>(thisDic,
NI,ni);
1100 index = acqpFileString.find(
Nr);
1101 if( index != std::string::npos )
1103 std::string tempString =
Nr;
1104 std::istringstream nrString(acqpFileString.substr(
1105 index+tempString.length()));
1108 acqp_InputStream.close();
1109 OStringStream message;
1110 message <<
"Could not create std::istringstream for "
1111 <<
"##$NR" << std::endl
1121 EncapsulateMetaData<int>(thisDic,
NR,nr);
1125 index = acqpFileString.find(
Nechoes);
1126 if( index != std::string::npos )
1128 std::string tempString =
Nechoes;
1129 std::istringstream dimString(acqpFileString.substr(
1130 index+tempString.length()));
1133 acqp_InputStream.close();
1134 OStringStream message;
1135 message <<
"Could not create std::istringstream for "
1136 <<
"##$NECHOES" << std::endl
1144 dimString >> numEchoImages;
1146 EncapsulateMetaData<unsigned int>(thisDic,
NECHOES,numEchoImages);
1151 if( index != std::string::npos )
1154 std::istringstream sliceThickString(acqpFileString.substr(
1155 index+tempString.length()));
1156 if (!sliceThickString)
1158 acqp_InputStream.close();
1159 OStringStream message;
1160 message <<
"Could not create std::istringstream for "
1161 <<
"##$ACQ_slice_thick" << std::endl
1169 sliceThickString >> sliceThick;
1171 sliceThickness =
true;
1177 if( index != std::string::npos )
1180 std::istringstream sliceSepString(acqpFileString.substr(
1181 index+tempString.length()));
1182 if (!sliceSepString)
1184 acqp_InputStream.close();
1185 OStringStream message;
1186 message <<
"Could not create std::istringstream for "
1187 <<
"##$ACQ_slice_sepn" << std::endl
1195 sliceSepString >> numSeperation;
1197 if( numSeperation > 0 )
1199 std::vector<double> imageSliceSeperation(numSeperation);
1202 sliceSepn->resize(numSeperation);
1203 for(
unsigned int i=0; i<(
unsigned int)numSeperation; i++)
1205 acqp_InputStream >> imageSliceSeperation[i];
1206 sliceSepn->SetElement(i,imageSliceSeperation[i]);
1208 EncapsulateMetaData<ACQSliceSepnContainerType::Pointer>(
1210 sliceSeperation =
true;
1216 if( index != std::string::npos )
1219 seperationMode = acqpFileString.substr(index+tempString.length());
1221 EncapsulateMetaData<std::string>(
1227 if( index != std::string::npos )
1230 std::istringstream echoTimeString(acqpFileString.substr(
1231 index+tempString.length()));
1232 if (!echoTimeString)
1234 acqp_InputStream.close();
1235 OStringStream message;
1236 message <<
"Could not create std::istringstream for "
1237 <<
"##$ACQ_echo_time" << std::endl
1245 echoTimeString >> numEchoes;
1249 std::vector<double> Echo_time(numEchoes);
1252 echoTimes->resize(numEchoes);
1253 for(
unsigned int i=0; i<(
unsigned int)numEchoes; i++)
1255 acqp_InputStream >> Echo_time[i];
1256 echoTimes->SetElement(i,Echo_time[i]);
1258 EncapsulateMetaData<ACQEchoTimeContainerType::Pointer>(
1264 acqp_InputStream.close();
1265 OStringStream message;
1266 message <<
"Could not retrieve ##$ACQ_echo_times" << std::endl
1278 if( index != std::string::npos )
1281 std::istringstream reptitionTimeString(acqpFileString.substr(
1282 index+tempString.length()));
1283 if (!reptitionTimeString)
1285 acqp_InputStream.close();
1286 OStringStream message;
1287 message <<
"Could not create std::istringstream for "
1288 <<
"##$ACQ_repetition_time" << std::endl
1296 reptitionTimeString >> numRepetitions;
1298 if( numRepetitions > 0 )
1300 std::vector<double> Repetition_time(numRepetitions);
1303 repetitionTimes->resize(numRepetitions);
1304 for(
unsigned int i=0; i<(
unsigned int)numRepetitions; i++)
1306 acqp_InputStream >> Repetition_time[i];
1307 repetitionTimes->SetElement(i,Repetition_time[i]);
1309 EncapsulateMetaData<ACQRepetitionTimeContainerType::Pointer>(
1311 repetitionTime =
true;
1315 acqp_InputStream.close();
1316 OStringStream message;
1317 message <<
"Could not retrieve ##$ACQ_repetition_time" << std::endl
1329 if( index != std::string::npos )
1332 std::istringstream inversionTimeString(acqpFileString.substr(
1333 index+tempString.length()));
1334 if (!inversionTimeString)
1336 acqp_InputStream.close();
1337 OStringStream message;
1338 message <<
"Could not create std::istringstream for "
1339 <<
"##$ACQ_inversion_time" << std::endl
1347 inversionTimeString >> numInversionTimes;
1349 if( numInversionTimes > 0 )
1351 std::vector<double> Inversion_time(numInversionTimes);
1354 inversionTimes->resize(numInversionTimes);
1355 for(
unsigned int i=0; i<(
unsigned int)numInversionTimes; i++)
1357 acqp_InputStream >> Inversion_time[i];
1358 inversionTimes->SetElement(i,Inversion_time[i]);
1360 EncapsulateMetaData<ACQInversionTimeContainerType::Pointer>(
1362 inversionTime =
true;
1366 acqp_InputStream.close();
1367 OStringStream message;
1368 message <<
"Could not retrieve ##$ACQ_inversion_time" << std::endl
1380 if( index != std::string::npos )
1383 int numMatrix=0, dim1=0, dim2=0;
1384 tempString = acqpFileString.substr(index+tempString.length());
1386 for(std::string::iterator iter = tempString.begin();
1387 iter != tempString.end(); iter++ )
1394 std::istringstream gradMatrixString(tempString);
1395 if (!gradMatrixString)
1397 acqp_InputStream.close();
1398 OStringStream message;
1399 message <<
"Could not create std::istringstream for "
1400 <<
"##$ACQ_grad_matrix" << std::endl
1408 gradMatrixString >> numMatrix >> dim1 >> dim2;
1412 if( numMatrix && (dim1 == 3) && (dim2 == 3) )
1418 acqp_InputStream.close();
1419 OStringStream message;
1420 message <<
"Invalid acqp file: Couldn't locate "
1421 <<
"'##$ACQ_dim=' tag" << std::endl
1432 acqp_InputStream >> dirx[i];
1441 acqp_InputStream >> diry[i];
1450 acqp_InputStream >> dirz[i];
1458 if( (acq_dim == 2) &&
1459 (numRecoTranspose == numMatrix) &&
1460 recoTransposition[0] )
1464 std::vector<double> temp(3,0);
1472 else if( recoTransposition[0] == 1 )
1476 std::vector<double> temp(3,0);
1484 else if( recoTransposition[0] == 2 )
1488 std::vector<double> temp(3,0);
1496 else if( recoTransposition[0] == 3 )
1500 std::vector<double> temp(3,0);
1510 if( (numMatrix-1) > 0 )
1512 std::vector<double> gradMatrixX(3,0);
1513 std::vector<double> gradMatrixY(3,0);
1514 std::vector<double> gradMatrixZ(3,0);
1515 for(
int j=0; j<(numMatrix-1); j++)
1520 acqp_InputStream >> gradMatrixX[l];
1521 if( gradMatrixX[l] == -0 )
1528 acqp_InputStream >> gradMatrixY[l];
1529 if( gradMatrixY[l] == -0 )
1536 acqp_InputStream >> gradMatrixZ[l];
1537 if( gradMatrixZ[l] == -0 )
1543 if( (acq_dim == 2) && recoTransposition[j+1] )
1546 std::vector<double> temp(3,0);
1549 temp[i] = gradMatrixX[i];
1550 gradMatrixX[i] = gradMatrixY[i];
1551 gradMatrixY[i] = temp[i];
1554 else if( recoTransposition[j+1] == 1 )
1557 std::vector<double> temp(3,0);
1560 temp[i] = gradMatrixX[i];
1561 gradMatrixX[i] = gradMatrixY[i];
1562 gradMatrixY[i] = temp[i];
1565 else if( recoTransposition[j+1] == 2 )
1568 std::vector<double> temp(3,0);
1571 temp[i] = gradMatrixY[i];
1572 gradMatrixY[i] = gradMatrixZ[i];
1573 gradMatrixZ[i] = temp[i];
1576 else if( recoTransposition[j+1] == 3 )
1579 std::vector<double> temp(3,0);
1582 temp[i] = gradMatrixX[i];
1583 gradMatrixX[i] = gradMatrixZ[i];
1584 gradMatrixZ[i] = temp[i];
1588 if( !std::equal(dirx.begin(),dirx.end(),gradMatrixX.begin()) ||
1589 !std::equal(diry.begin(),diry.end(),gradMatrixY.begin()) ||
1590 !std::equal(dirz.begin(),dirz.end(),gradMatrixZ.begin()) )
1592 slicesNotInSameOrientation =
true;
1600 acqp_InputStream.close();
1601 OStringStream message;
1602 message <<
"Could not retrieve ##$ACQ_grad_matrix" << std::endl
1612 acqp_InputStream.close();
1616 OStringStream message;
1617 message <<
"Invalid acqp file: Couldn't locate "
1618 <<
"'##$ACQ_echo_time=( ' tag" << std::endl
1627 if( !sliceThickness )
1629 OStringStream message;
1630 message <<
"Invalid acqp file: Couldn't locate "
1631 <<
"'##$ACQ_slice_thick=' tag" << std::endl
1640 if( !sliceSeperation )
1642 OStringStream message;
1643 message <<
"Invalid acqp file: Couldn't locate "
1644 <<
"'##$ACQ_slice_sepn=(' tag" << std::endl
1655 OStringStream message;
1656 message <<
"Invalid acqp file: Couldn't locate "
1657 <<
"'##$NR=' tag" << std::endl
1668 OStringStream message;
1669 message <<
"Invalid acqp file: Couldn't locate "
1670 <<
"'##$NI=' tag" << std::endl
1681 OStringStream message;
1682 message <<
"Invalid acqp file: Couldn't locate "
1683 <<
"'##$ACQ_echo_time=( ' tag" << std::endl
1692 if( !repetitionTime )
1694 OStringStream message;
1695 message <<
"Invalid acqp file: Couldn't locate "
1696 <<
"'##$ACQ_repetition_time=( ' tag" << std::endl
1705 if( !inversionTime )
1707 OStringStream message;
1708 message <<
"Invalid acqp file: Couldn't locate "
1709 <<
"'##$ACQ_inversion_time=( ' tag" << std::endl
1720 if( imageFOV[2] == 0 )
1722 imageFOV[2] = imageDim[2]*sliceThick;
1723 imageFOV[2] /= 10.0f;
1726 if( slicesNotInSameOrientation )
1731 EncapsulateMetaData<unsigned int>(
1741 unsigned int tempDim;
1742 tempFOV = imageFOV[0];
1743 imageFOV[0] = imageFOV[1];
1744 imageFOV[1] = tempFOV;
1745 tempDim = imageDim[0];
1746 imageDim[0] = imageDim[1];
1747 imageDim[1] = tempDim;
1753 unsigned int tempDim;
1754 tempFOV = imageFOV[1];
1755 imageFOV[1] = imageFOV[2];
1756 imageFOV[2] = tempFOV;
1757 tempDim = imageDim[1];
1758 imageDim[1] = imageDim[2];
1759 imageDim[2] = tempDim;
1765 unsigned int tempDim;
1766 tempFOV = imageFOV[0];
1767 imageFOV[0] = imageFOV[2];
1768 imageFOV[2] = tempFOV;
1769 tempDim = imageDim[0];
1770 imageDim[0] = imageDim[2];
1771 imageDim[2] = tempDim;
1781 imageFOV[dim] *= 10.0f;
1782 this->
SetSpacing(dim, imageFOV[dim]/(
double)imageDim[dim]);
1783 this->
SetOrigin(dim, -imageFOV[dim]/2.0f);