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 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537
|
/*LICENSE_START*/
/*
* Copyright 1995-2002 Washington University School of Medicine
*
* http://brainmap.wustl.edu
*
* This file is part of CARET.
*
* CARET is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* CARET is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with CARET; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
/*LICENSE_END*/
#include <QFileInfo>
#include "AreaColorFile.h"
#include "BrainSet.h"
#include "BrainModelContours.h"
#include "CommandFileConvert.h"
#include "ContourCellFile.h"
#include "ContourFile.h"
#include "FileFilters.h"
#include "FileUtilities.h"
#include "FreeSurferCurvatureFile.h"
#include "FreeSurferFunctionalFile.h"
#include "FreeSurferSurfaceFile.h"
#include "GiftiDataArrayFile.h"
#include "MetricFile.h"
#include "PaintFile.h"
#include "ProgramParameters.h"
#include "ScriptBuilderParameters.h"
#include "SpecFile.h"
#include "SurfaceShapeFile.h"
#include "TopologyFile.h"
#include "vtkPolyData.h"
#include "vtkPolyDataReader.h"
/**
* constructor.
*/
CommandFileConvert::CommandFileConvert()
: CommandBase("-file-convert",
"FILE CONVERSION")
{
brainSet = NULL;
fileWriteType = AbstractFile::FILE_FORMAT_ASCII;
mode = MODE_NONE;
}
/**
* destructor.
*/
CommandFileConvert::~CommandFileConvert()
{
if (brainSet != NULL) {
delete brainSet;
brainSet = NULL;
}
}
/**
* get the script builder parameters.
*/
void
CommandFileConvert::getScriptBuilderParameters(ScriptBuilderParameters& paramsOut) const
{
paramsOut.clear();
paramsOut.addVariableListOfParameters("commands");
}
/**
* get full help information.
*/
QString
CommandFileConvert::getHelpInformation() const
{
std::vector<AbstractFile::FILE_FORMAT> fileFormats;
std::vector<QString> fileFormatNames;
AbstractFile::getFileFormatTypesAndNames(fileFormats, fileFormatNames);
const QString cmdSwitch(getOperationSwitch());
QString helpInfo =
(indent3 + getShortDescription() + "\n"
+ indent6 + parameters->getProgramNameWithoutPath() + " " + getOperationSwitch() + " \n"
+ indent9 + "\n"
+ indent9 + "---------------------------------------------------------------------- \n"
+ indent9 + "SYNOPSIS for Caret File Format Conversion \n"
+ indent9 + " " + cmdSwitch + " [options] -format-convert <file-format> \\ \n"
+ indent9 + " <one-or-more-file-names> \n"
+ indent9 + " \n"
+ indent9 + "DESCRIPTION for Caret File Format Conversion \n"
+ indent9 + " Convert Caret data files to the specified formats. \n"
+ indent9 + " \n"
+ indent9 + " REQUIRED PARAMETERS \n"
+ indent9 + " <file-format> is any combination of the following\n"
+ indent9 + " separated by a colon:\n");
for (unsigned int i = 0; i < fileFormatNames.size(); i++) {
helpInfo +=
(indent9 + " " + fileFormatNames[i] + "\n");
}
helpInfo += (""
+ indent9 + " \n"
+ indent9 + " OPTIONS\n"
+ indent9 + " [-area-color-file filename]\n"
+ indent9 + " \n"
+ indent9 + " Use the area color file option when converting\n"
+ indent9 + " paint files to GIFTI format. When the LabelTable \n"
+ indent9 + " in the output GIFTI file is created, color components\n"
+ indent9 + " will be assigned using the colors in the area color\n"
+ indent9 + " file. If there is more than one area color file,\n"
+ indent9 + " precede each of the them with the \"-area-color-file\"\n"
+ indent9 + " option.\n"
+ indent9 + " \n"
+ indent9 + "---------------------------------------------------------------------- \n"
+ indent9 + "SYNOPSIS for Caret File Format Information \n"
+ indent9 + " " + cmdSwitch + " -format-info <one-or-more-file-names> \n"
+ indent9 + " \n"
+ indent9 + "DESCRIPTION for Caret File Format Information \n"
+ indent9 + " Display the file format of each of the specified files. \n"
+ indent9 + " \n"
+ indent9 + "---------------------------------------------------------------------- \n"
+ indent9 + "SYNOPSIS for Converting Data Files in a Spec File \n"
+ indent9 + " " + cmdSwitch + " -spec-convert <file-format> spec-file-name \n"
+ indent9 + " \n"
+ indent9 + "DESCRIPTION for Converting Data Files in a Spec File \n"
+ indent9 + " Converts all of the data files listed in a spec file to the \n"
+ indent9 + " specified formats. \n"
+ indent9 + " \n"
+ indent9 + " REQUIRED PARAMETERS \n"
+ indent9 + " <file-format> is any combination of the following\n"
+ indent9 + " separated by a colon:\n");
for (unsigned int i = 0; i < fileFormatNames.size(); i++) {
helpInfo +=
(indent9 + " " + fileFormatNames[i] + "\n");
}
helpInfo += (""
+ indent9 + " \n"
+ indent9 + "---------------------------------------------------------------------- \n"
+ indent9 + "SYNOPSIS for Surface File Conversion \n"
+ indent9 + " " + cmdSwitch + " -sc -is <type> <name> [name2] \\ \n"
+ indent9 + " -os <type> <name> [name2] [coord-type] [topo-type] \\ \n"
+ indent9 + " [-outbin -outtext] \\ \n"
+ indent9 + " [-spec spec-file-name] [-struct structure] \n"
+ indent9 + " \n"
+ indent9 + "DESCRIPTION for Convert surface file formats. \n"
+ indent9 + " \n"
+ indent9 + " REQUIRED PARAMETERS \n"
+ indent9 + " -sc Specifies surface format conversion. \n"
+ indent9 + " \n"
+ indent9 + " -is <type> <name> [name2] Specifies the input surface. \n"
+ indent9 + " type is one of: \n"
+ indent9 + " BYU input surface is a BYU surface file \n"
+ indent9 + " This type is followed by the name of the BYU surface\n"
+ indent9 + " file.\n"
+ indent9 + " \n"
+ indent9 + " CARET input surface is Caret Coordinate and Topology \n"
+ indent9 + " files. This type is followed by the names of the \n"
+ indent9 + " Caret Coordinatefile, the Caret Topology file. \n"
+ indent9 + " \n"
+ indent9 + " FSS input surface is a FreeSurfer surface surface file. \n"
+ indent9 + " This type is followed by the name of the FreeSurfer \n"
+ indent9 + " surface file. \n"
+ indent9 + " \n"
+ indent9 + " FSP input surface is a FreeSurfer surface patch file. \n"
+ indent9 + " This type is followed by the name of the FreeSurfer \n"
+ indent9 + " patch file and the name of a corresponding FreeSurfer \n"
+ indent9 + " surface file. \n"
+ indent9 + " \n"
+ indent9 + " GS input surface is a GIFTI XML surface file.\n"
+ indent9 + " This type is followed by the name of the GIFTI\n"
+ indent9 + " surface file.\n"
+ indent9 + " \n"
+ indent9 + " MNIOBJ input surface is a MNI OBJ surface file.\n"
+ indent9 + " This type is followed by the name of the MNI\n"
+ indent9 + " surface file.\n"
+ indent9 + " http://www.bic.mni.mcgill.ca/~david/FAQ/FAQ.html#9 \n"
+ indent9 + " \n"
+ indent9 + " STL input surface is a BYU surface file \n"
+ indent9 + " This type is followed by the name of the STL surface \n"
+ indent9 + " file.\n"
+ indent9 + " \n"
+ indent9 + " VTKP input surface is a VTK PolyData file. \n"
+ indent9 + " This type is followed by the name of the VTK PolyData \n"
+ indent9 + " file.\n"
+ indent9 + " \n"
+ indent9 + " VTKXP input surface is an XML VTK PolyData file. \n"
+ indent9 + " This type is followed by the name of the XML VTK \n"
+ indent9 + " PolyData file.\n"
+ indent9 + " \n"
+ indent9 + " -os <type> <name> [name2] [coord-type] [topo-type] \n"
+ indent9 + " Specifies the output surface. \n"
+ indent9 + " \n"
+ indent9 + " This option's type name and name2 parameters are the same as\n"
+ indent9 + " for the \"-is\" option. \n"
+ indent9 + " \n"
+ indent9 + " The third and forth parameters are the \n"
+ indent9 + " coordinate file type and the topology file type. \n"
+ indent9 + " \n"
+ indent9 + " In addition to the types listed for input, an\n"
+ indent9 + " output only type is one of: \n"
+ indent9 + " OI Output surface is an Open Inventor file. \n"
+ indent9 + " \n"
+ indent9 + " Valid topology file types: \n"
+ indent9 + " CLOSED \n"
+ indent9 + " OPEN \n"
+ indent9 + " CUT \n"
+ indent9 + " LOBAR_CUT \n"
+ indent9 + " UNKNOWN \n"
+ indent9 + " \n"
+ indent9 + " Valid coordinate file types \n"
+ indent9 + " RAW \n"
+ indent9 + " FIDUCIAL \n"
+ indent9 + " INFLATED \n"
+ indent9 + " VERY_INFLATED \n"
+ indent9 + " SPHERICAL \n"
+ indent9 + " ELLIPSOIDAL \n"
+ indent9 + " CMW \n"
+ indent9 + " FLAT \n"
+ indent9 + " FLAT_LOBAR \n"
+ indent9 + " UNKNOWN \n"
+ indent9 + " \n"
+ indent9 + " OPTIONAL PARAMETERS \n"
+ indent9 + " -outbin Indicates that output Caret files are to be written in \n"
+ indent9 + " binary format. \n"
+ indent9 + " \n"
+ indent9 + " -outtext Indicates that output Caret files are to be written in \n"
+ indent9 + " text (ascii) format. \n"
+ indent9 + " \n"
+ indent9 + " -spec spec-file-name Indicates that output Caret files are to \n"
+ indent9 + " be written to the spec file <spec-file-name>. If the spec \n"
+ indent9 + " file does not exist, it will be created. \n"
+ indent9 + " \n"
+ indent9 + " -struct structure Indicates the structure that should be \n"
+ indent9 + " placed into the spec file when writing Caret files. \n"
+ indent9 + " Valid structure types \n"
+ indent9 + " right \n"
+ indent9 + " left \n"
+ indent9 + " cerebellum \n"
+ indent9 + " \n"
+ indent9 + "---------------------------------------------------------------------- \n"
+ indent9 + "SYNOPSIS for FreeSurfer Data File / Caret Conversion \n"
+ indent9 + " " + cmdSwitch + " -fsc2c free-surfer-curvature \\ \n"
+ indent9 + " free-surfer-surface output-surface-shape \\ \n"
+ indent9 + " [-outbin -outtext] \\ \n"
+ indent9 + " [-spec spec-file-name] [-struct structure] \n"
+ indent9 + " \n"
+ indent9 + " " + cmdSwitch + " -fsf2c free-surfer-functional \\ \n"
+ indent9 + " free-surfer-surface output-metric \\ \n"
+ indent9 + " [-outbin -outtext] \\ \n"
+ indent9 + " [-spec spec-file-name] [-struct structure] \n"
+ indent9 + " \n"
+ indent9 + " " + cmdSwitch + " -cp2fsl caret-paint-file \\ \n"
+ indent9 + " caret-fiducial-coord-file \n"
+ indent9 + " \n"
+ indent9 + " " + cmdSwitch + " -cs2fsc caret-shape-file \\ \n"
+ indent9 + " shape-column \\ \n"
+ indent9 + " caret-fiducial-coord-file \\ \n"
+ indent9 + " free-surfer-curvature-file\n"
+ indent9 + " \n"
+ indent9 + "DESCRIPTION for FreeSurfer Data File / Caret Conversion \n"
+ indent9 + " Convert free surfer data files to Caret format. \n"
+ indent9 + " \n"
+ indent9 + " REQUIRED PARAMETERS \n"
+ indent9 + " \n"
+ indent9 + " Note: You must specify one of the following: \n"
+ indent9 + " \n"
+ indent9 + " " + cmdSwitch + " -fsc2c \n"
+ indent9 + " Converts a free surfer curvature file into a Caret surface\n"
+ indent9 + " shape file. This option is followed by the name of the \n"
+ indent9 + " Free Surfer curvature file, the name of a Free Surfer \n"
+ indent9 + " surfacefile (used to get number of nodes), and the output \n"
+ indent9 + " Caret surface shape file. \n"
+ indent9 + " \n"
+ indent9 + " " + cmdSwitch + " -fsf2c \n"
+ indent9 + " Converts a free surfer functional file into a Caret metric\n"
+ indent9 + " file. This option is followed by the name of the Free \n"
+ indent9 + " Surfer functional file, the name of a Free Surfer surface \n"
+ indent9 + " file (used to get number of nodes), and the output Caret \n"
+ indent9 + " metric file. \n"
+ indent9 + " \n"
+ indent9 + " " + cmdSwitch + " -fsl2c \n"
+ indent9 + " Converts all free surfer label files in the specified \n"
+ indent9 + " directory into a paint file. This option is followed by \n"
+ indent9 + " the directory containing the label files, the name of a \n"
+ indent9 + " Free Surfer surface file (used to get number of nodes), \n"
+ indent9 + " and the output Caret paint file. \n"
+ indent9 + " \n"
+ indent9 + " " + cmdSwitch + " -cp2fsl \n"
+ indent9 + " Convert a paint file into free surfer label files. No \n"
+ indent9 + " output name is needed since free surfer uses on file per \n"
+ indent9 + " paint ID with the name of the file being \"paintID\" \n"
+ indent9 + " label. \n"
+ indent9 + " \n"
+ indent9 + " " + cmdSwitch + " -cs2fsc \n"
+ indent9 + " Convert a Caret shape file column into a free\n"
+ indent9 + " surfer curvature file.\n"
+ indent9 + " \n"
+ indent9 + " OPTIONAL PARAMETERS for FreeSurfer Data File to Caret Conversion \n"
+ indent9 + " \n"
+ indent9 + " See the surface conversion options for explanation. \n"
+ indent9 + " \n"
+ indent9 + "---------------------------------------------------------------------- \n"
+ indent9 + "SYNOPSIS for Converting Volume Files \n"
+ indent9 + " " + cmdSwitch + " -vc <input-volume> <output-volume> \n"
+ indent9 + " \n"
+ indent9 + "DESCRIPTION for Converting Volume Files \n"
+ indent9 + " The extension of the output volume file name determines the type of \n"
+ indent9 + " of volume file. \n"
+ indent9 + " \n"
+ indent9 + " Extension Type of Volume File \n"
+ indent9 + " --------- ------------------- \n"
+ indent9 + " HEAD AFNI Volume File \n"
+ indent9 + " ifh Washington University Volume File \n"
+ indent9 + " nii NIFTI Volume File \n"
+ indent9 + " nii.gz Compressed NIFTI Volume File \n"
+ indent9 + " \n"
+ indent9 + " \n"
+ indent9 + "For best results, run this program from the directory containing \n"
+ indent9 + "the files \n"
+ indent9 + " \n"
+ indent9 + "---------------------------------------------------------------------- \n"
+ indent9 + "SYNOPSIS for importing contour files \n"
+ indent9 + " " + cmdSwitch + " -ic <CONTOUR_TYPE> <input-file-name \n"
+ indent9 + " <caret-contour-file-name> [caret-contour-cell-file-name] \n"
+ indent9 + " \n"
+ indent9 + "DESCRIPTION for Importing Contour Files \n"
+ indent9 + " \n"
+ indent9 + " CONTOUR_TYPE Type of Contour File\n"
+ indent9 + " ------------ --------------------\n"
+ indent9 + " MDPLOT MDPLOT .mdo contour file\n"
+ indent9 + " NEURO Neurolucida XML contour file\n"
+ indent9 + " \n"
+ indent9 + " The \"caret-contour-cell-file-name\" is optional. If \n"
+ indent9 + " there are no contour cells, it is not written.\n"
+ indent9 + " \n"
+ indent9 + "---------------------------------------------------------------------- \n"
+ indent9 + "---------------------------------------------------------------------- \n"
+ indent9 + "EXAMPLES \n"
+ indent9 + " \n"
+ indent9 + " Convert all Caret data files in the current directory that support \n"
+ indent9 + " binary format into the binary format. If the file does not \n"
+ indent9 + " support binary, convert the file to XML format. If the file \n"
+ indent9 + " supports neither binary nor XML format, do not change the file:\n"
+ indent9 + " " + cmdSwitch + " -format-convert BINARY:XML * \n"
+ indent9 + " \n"
+ indent9 + " Convert all files in the current directory that can be\n"
+ indent9 + " written in GIFTI XML-GZIP format to that format. An\n"
+ indent9 + " area color file is included so that any paint files \n"
+ indent9 + " that are converted to GIFTI label files, receive color\n"
+ indent9 + " assignments in their LabelTables.\n"
+ indent9 + " " + cmdSwitch + " -area-color-file Human.labels.areacolor \\\n"
+ indent9 + " -format-convert XML_BASE64_GZIP * \n"
+ indent9 + " \n"
+ indent9 + " Convert the two Caret files into ascii format Caret files: \n"
+ indent9 + " " + cmdSwitch + " -format-convert ASCII file1.top \\ \n"
+ indent9 + " file3.coord \n"
+ indent9 + " \n"
+ indent9 + " List the data type (text or binary) of all Caret files in the \n"
+ indent9 + " current directory: \n"
+ indent9 + " " + cmdSwitch + " -format-info * \n"
+ indent9 + " \n"
+ indent9 + " Convert the free surfer surface into closed topology and fiducial \n"
+ indent9 + " coordinate files. Create a spec file for a left cortex. \n"
+ indent9 + " " + cmdSwitch + " -sc -is FSS lh.orig.asc -os CARET fiducial.coord \\\n"
+ indent9 + " closed.topo FIDUCIAL CLOSED -spec file.spec -struct LEFT \n"
+ indent9 + " \n"
+ indent9 + " Convert the free surfer patch into cut topology and flat \n"
+ indent9 + " coordinate files. Create or add to the spec file as left cortex. \n"
+ indent9 + " Write the coord and topo files in text format. \n"
+ indent9 + " " + cmdSwitch + " -sc -is FSP lh.oc.flat.asc lh.orig.asc \\ \n"
+ indent9 + " -os CARET flat.coord cut.topo FLAT CUT -spec file.spec \\ \n"
+ indent9 + " -struct LEFT -outtext \n"
+ indent9 + " \n"
+ indent9 + " Convert the free surfer curvature file to a Caret surface shape \n"
+ indent9 + " file.\n"
+ indent9 + " " + cmdSwitch + " -fsc2c lh.curv.asc lh.pial.asc \\ \n"
+ indent9 + " shape.surface_shape -spec file.spec \n"
+ indent9 + " \n"
+ indent9 + " Convert the free surfer functional file to a Caret metric file. \n"
+ indent9 + " " + cmdSwitch + " -fsf2c pho-lh.5.w.asc lh.pial.asc \\ \n"
+ indent9 + " func.metric -spec file.spec \n"
+ indent9 + " \n"
+ indent9 + " Convert the free surfer label files in current directory to a Caret \n"
+ indent9 + " paint file. \n"
+ indent9 + " " + cmdSwitch + " -fsl2c . lh.pial.asc \\ \n"
+ indent9 + " label.paint -spec file.spec \n"
+ indent9 + " \n"
+ indent9 + " Convert the caret paint file into free surfer label files \n"
+ indent9 + " " + cmdSwitch + " -cp2fsl file.paint \\ \n"
+ indent9 + " fiducial.coord \n"
+ indent9 + " \n"
+ indent9 + " Convert the first column in the caret surface shape file \n"
+ indent9 + " into a Free Surfer curvature file. \n"
+ indent9 + " " + cmdSwitch + " -cs2fsc Human.surface_shape 1 \\ \n"
+ indent9 + " Human.FIDUCIAL.coord freesurfer.curv.asc \n"
+ indent9 + " \n"
+ indent9 + " Convert the data files listed in the spec file to binary format. \n"
+ indent9 + " If binary is not supported for a file, try ASCII.\n"
+ indent9 + " " + cmdSwitch + " -spec-convert BINARY:ASCII human.spec \n"
+ indent9 + " \n"
+ indent9 + " Convert the volume file from AFNI to compressed NIFTI format. \n"
+ indent9 + " " + cmdSwitch + " -vc anat+orig.HEAD anat+orig.nii.gz \n"
+ indent9 + "\n");
return helpInfo;
}
/**
* execute the command.
*/
void
CommandFileConvert::executeCommand() throw (BrainModelAlgorithmException,
CommandException,
FileException,
ProgramParametersException,
StatisticException)
{
brainSet = new BrainSet(true);
QString inputVolumeName;
QString outputVolumeName;
QString contourType;
QString contourFileName;
QString caretContourFileName;
QString caretContourCellFileName;
//
// This gets the preferred write type from the preferences file
//
fileWriteType = AbstractFile::FILE_FORMAT_OTHER;
std::vector<QString> areaColorFileNames;
//
// Process the command line options
//
std::vector<QString> dataFileNames;
QString dataFileFormatList;
while (parameters->getParametersAvailable()) {
const QString arg(parameters->getNextParameterAsString("Parameter"));
if (arg == "-area-color-file") {
areaColorFileNames.push_back(parameters->getNextParameterAsString("Area Color File Name"));
}
else if (arg == "-format-convert") {
if (mode == MODE_NONE) {
mode = MODE_FORMAT_CONVERT;
}
else {
throw CommandException("More than one mode parameter specified.");
std::cout << std::endl;
}
dataFileFormatList = parameters->getNextParameterAsString("File Format");
while (parameters->getParametersAvailable()) {
dataFileNames.push_back(parameters->getNextParameterAsString("Data File Name"));
}
}
else if (arg == "-fsc2c") {
mode = MODE_FREE_SURFER_CURVATURE_TO_CARET;
inputSurfaceName = parameters->getNextParameterAsString("Input Surface Name");
inputSurfaceName2 = parameters->getNextParameterAsString("Input Surface Name 2");
outputSurfaceName = parameters->getNextParameterAsString("Output Surface Name");
}
else if (arg == "-fsf2c") {
mode = MODE_FREE_SURFER_FUNCTIONAL_TO_CARET;
inputSurfaceName = parameters->getNextParameterAsString("Input Surface Name");
inputSurfaceName2 = parameters->getNextParameterAsString("Input Surface Name 2");
outputSurfaceName = parameters->getNextParameterAsString("Output Surface Name");
}
else if (arg == "-fsl2c") {
mode = MODE_FREE_SURFER_LABEL_TO_CARET;
inputSurfaceName = parameters->getNextParameterAsString("Input Surface Name");
inputSurfaceName2 = parameters->getNextParameterAsString("Input Surface Name 2");
outputSurfaceName = parameters->getNextParameterAsString("Output Surface Name");
}
else if (arg == "-cp2fsl") {
mode = MODE_CARET_PAINT_TO_FREE_SURFER_LABEL;
inputSurfaceName = parameters->getNextParameterAsString("Input Surface Name");
inputSurfaceName2 = parameters->getNextParameterAsString("Input Surface Name 2");
}
else if (arg == "-cs2fsc") {
mode = MODE_CARET_SHAPE_TO_FREE_SURFER_CURVATURE;
inputShapeName = parameters->getNextParameterAsString("Input Caret Shape File");
inputShapeColumn = parameters->getNextParameterAsString("Input Caret Shape File Column");
inputSurfaceName = parameters->getNextParameterAsString("Input Fiducial Coordinate Name");
outputCurvatureName = parameters->getNextParameterAsString("Output Free Surfer Curvature Name");
}
else if (arg == "-sc") {
mode = MODE_SURFACE_CONVERT;
}
else if (arg == "-format-info") {
if (mode == MODE_NONE) {
mode = MODE_FORMAT_INFO;
}
else {
throw CommandException("More than one mode parameter specified.");
}
while (parameters->getParametersAvailable()) {
dataFileNames.push_back(parameters->getNextParameterAsString("Data File Name"));
}
}
else if (arg == "-ic") {
if (mode == MODE_NONE) {
mode = MODE_CONTOUR_CONVERT;
}
else {
throw CommandException("More than one mode parameter specified.");
}
contourType = parameters->getNextParameterAsString("Contour Type");
contourFileName = parameters->getNextParameterAsString("Contour File Name");
caretContourFileName = parameters->getNextParameterAsString("Caret Contour File Name");
caretContourCellFileName = parameters->getNextParameterAsString("Caret Contour Cell File Name");
}
else if (arg == "-is") {
QString inputTypeName;
inputTypeName = parameters->getNextParameterAsString("Input Type Name");
inputSurfaceType = getSurfaceFileType(inputTypeName, "input");
inputSurfaceName = parameters->getNextParameterAsString("Input Surface Name");
switch(inputSurfaceType) {
case SURFACE_TYPE_BYU:
break;
case SURFACE_TYPE_CARET:
inputSurfaceName2 = parameters->getNextParameterAsString("Input Surface Name 2");
break;
case SURFACE_TYPE_FREE_SURFER:
break;
case SURFACE_TYPE_FREE_SURFER_PATCH:
inputSurfaceName2 = parameters->getNextParameterAsString("Input Surface Name 2");
break;
case SURFACE_TYPE_GIFTI:
break;
case SURFACE_TYPE_MNI_OBJ:
break;
case SURFACE_TYPE_OPEN_INVENTOR:
throw CommandException("Open Inventor not supported for input.");
break;
case SURFACE_TYPE_STL:
break;
case SURFACE_TYPE_VTK:
break;
case SURFACE_TYPE_XML_VTK:
break;
case SURFACE_TYPE_UNKNOWN:
break;
}
}
else if (arg == "-os") {
QString outputTypeName;
outputTypeName = parameters->getNextParameterAsString("Output Type Name");
outputSurfaceType = getSurfaceFileType(outputTypeName, "output");
outputSurfaceName = parameters->getNextParameterAsString("Output Surface Name");
switch(outputSurfaceType) {
case SURFACE_TYPE_BYU:
break;
case SURFACE_TYPE_CARET:
outputSurfaceName2 = parameters->getNextParameterAsString("Output Surface Name 2");
outputCoordTypeName = parameters->getNextParameterAsString("Output Coord Type Name");
outputTopoTypeName = parameters->getNextParameterAsString("Output Topo Type Name");
break;
case SURFACE_TYPE_FREE_SURFER:
break;
case SURFACE_TYPE_FREE_SURFER_PATCH:
outputSurfaceName2 = parameters->getNextParameterAsString("Output Surface Name 2");
break;
case SURFACE_TYPE_GIFTI:
break;
case SURFACE_TYPE_MNI_OBJ:
throw CommandException("MNI OBJ not supported for writing.");
break;
case SURFACE_TYPE_OPEN_INVENTOR:
break;
case SURFACE_TYPE_STL:
break;
case SURFACE_TYPE_VTK:
break;
case SURFACE_TYPE_XML_VTK:
break;
case SURFACE_TYPE_UNKNOWN:
break;
}
}
else if (arg == "-spec") {
specFileName = parameters->getNextParameterAsString("Spec File Name");
}
else if (arg == "-spec-convert") {
if (mode == MODE_NONE) {
mode = MODE_SPEC_CONVERT;
}
else {
throw CommandException("More than one mode parameter specified.");
}
dataFileFormatList = parameters->getNextParameterAsString("File Format");
specFileName = parameters->getNextParameterAsString("Spec File Name");
}
else if (arg == "-struct") {
structureName = parameters->getNextParameterAsString("Structure").toLower();
}
else if (arg == "-outbin") {
fileWriteType = AbstractFile::FILE_FORMAT_BINARY;
}
else if (arg == "-outtext") {
fileWriteType = AbstractFile::FILE_FORMAT_ASCII;
}
else if (arg == "-outxml") {
fileWriteType = AbstractFile::FILE_FORMAT_XML;
}
else if (arg == "-vc") {
if (mode == MODE_NONE) {
mode = MODE_VOLUME;
inputVolumeName = parameters->getNextParameterAsString("Input Volume Name");
outputVolumeName = parameters->getNextParameterAsString("Input Volume Name");
}
else {
throw CommandException("More than one mode parameter specified.");
}
}
else {
throw CommandException("Unrecognized parameter: " + arg);
}
}
if (mode == MODE_NONE) {
throw CommandException("You must specify a mode parameter.");
}
AreaColorFile areaColorFile;
int numAreaColorFiles = static_cast<int>(areaColorFileNames.size());
for (int i = 0; i < numAreaColorFiles; i++) {
AreaColorFile acf;
acf.readFile(areaColorFileNames[i]);
areaColorFile.append(acf);
}
const int numberOfDataFiles = static_cast<int>(dataFileNames.size());
switch (mode) {
case MODE_NONE:
break;
case MODE_CONTOUR_CONVERT:
contourConversion(contourType,
contourFileName,
caretContourFileName,
caretContourCellFileName);
break;
case MODE_FORMAT_CONVERT:
if (numberOfDataFiles <= 0) {
throw CommandException("No files specified.");
}
fileFormatConvert(dataFileNames, dataFileFormatList, areaColorFile);
break;
case MODE_FORMAT_INFO:
if (numberOfDataFiles <= 0) {
throw CommandException("No files specified.");
}
fileFormatConvert(dataFileNames, "INFO", areaColorFile);
break;
case MODE_SPEC_CONVERT:
specFileConvert(dataFileFormatList, specFileName);
break;
case MODE_SURFACE_CONVERT:
surfaceFileConversion();
break;
case MODE_FREE_SURFER_CURVATURE_TO_CARET:
freeSurferCurvatureToCaretConvert();
break;
case MODE_FREE_SURFER_FUNCTIONAL_TO_CARET:
freeSurferFunctionalToCaretConvert();
break;
case MODE_FREE_SURFER_LABEL_TO_CARET:
freeSurferLabelToCaretConvert();
break;
case MODE_CARET_PAINT_TO_FREE_SURFER_LABEL:
caretPaintToFreeSurferLabel();
break;
case MODE_CARET_SHAPE_TO_FREE_SURFER_CURVATURE:
caretShapeToFreeSurferCurvature();
break;
case MODE_VOLUME:
volumeConversion(inputVolumeName, outputVolumeName);
break;
}
}
/**
* Convert a contour file.
*/
void
CommandFileConvert::contourConversion(const QString& contourType,
const QString& contourFileName,
const QString& caretContourFileName,
const QString& caretContourCellFileName) throw (CommandException)
{
if (caretContourFileName.isEmpty()) {
throw CommandException("Caret contour file name is empty.");
}
try {
//
// Import contours
//
BrainSet bs;
if (contourType == "MDPLOT") {
bs.importMDPlotFile(contourFileName,
true,
true,
false,
false);
}
else if (contourType == "NEURO") {
bs.importNeurolucidaFile(contourFileName,
true,
true,
false,
false);
}
//
// Write contours
//
BrainModelContours* bmc = bs.getBrainModelContours();
if (bmc == NULL) {
throw CommandException("Contours import failed.");
}
ContourFile* cf = bmc->getContourFile();
if (cf->getNumberOfContours() <= 0) {
throw CommandException("File read but no contours found.");
}
bs.writeContourFile(caretContourFileName, cf);
//
// Write contour cells
//
if (caretContourCellFileName.isEmpty() == false) {
ContourCellFile* cells = bs.getContourCellFile();
if (cells->getNumberOfCells() > 0) {
bs.writeContourCellFile(caretContourCellFileName);
}
}
}
catch (FileException& e) {
throw (CommandException(e));
}
}
/**
* Convert caret files between binary and text format or display
* info about the file.
*/
void
CommandFileConvert::fileFormatConvert(const std::vector<QString>& dataFileNames,
const QString& dataFileFormatList,
const AreaColorFile& areaColorFile) throw (CommandException)
{
//
// Convert the data format list to file types
//
const QStringList sl = dataFileFormatList.split(':');
const int numFormats = sl.count();
if (numFormats < 1) {
throw CommandException("No file formats provided for file format conversion.");
}
//
// Just Info ?
//
std::vector<AbstractFile::FILE_FORMAT> conversionFormats;
bool infoFlag = false;
if ((numFormats == 1) &&
(sl.at(0) == "INFO")) {
infoFlag = true;
}
else {
for (int i = 0; i < numFormats; i++) {
const QString formatName(sl.at(i));
bool valid = false;
const AbstractFile::FILE_FORMAT format =
AbstractFile::convertFormatNameToType(formatName, &valid);
if (valid) {
conversionFormats.push_back(format);
}
else {
throw CommandException("Invalid file format name \""
+ formatName
+ "\"");
}
}
}
//
// Process the files
//
const int numberOfDataFiles = static_cast<int>(dataFileNames.size());
if (numberOfDataFiles < 1) {
throw CommandException("No files provided for conversion.");
}
for (int i = 0; i < numberOfDataFiles; i++) {
const QString filename(dataFileNames[i]);
QString errorMessage;
//
// Skip directories and symbolic links
//
QFileInfo fileInfo(filename);
if (fileInfo.isDir() ||
fileInfo.isSymLink()) {
continue;
}
//
// Read the header of the file
//
AbstractFile* af = AbstractFile::readAnySubClassDataFile(filename, true, errorMessage);
std::cout << FileUtilities::basename(filename).toAscii().constData() << ": ";
if (af == NULL) {
std::cout << "unable to read file or not a caret data file.\n"
<< "error: "
<< errorMessage.toAscii().constData();
}
else if (af->getFileHasHeader() == false) {
std::cout << "file does not have header.";
}
else {
//
// Get files current encoding
//
const QString formatString(af->getHeaderTag(AbstractFile::headerTagEncoding));
bool validFormatFlag = false;
const AbstractFile::FILE_FORMAT dataFileFormat =
AbstractFile::convertFormatNameToType(formatString, &validFormatFlag);
if (infoFlag) {
if (validFormatFlag == false) {
std::cout << "unrecognized format: "
<< formatString.toAscii().constData();
}
else {
std::cout << formatString.toAscii().constData() << ".";
}
}
else {
bool fileProcessedFlag = false;
for (unsigned int i = 0; i < conversionFormats.size(); i++) {
if (validFormatFlag &&
(dataFileFormat == conversionFormats[i])) {
std::cout << " already in "
<< formatString.toAscii().constData()
<< " format";
fileProcessedFlag = true;
}
else if (af->getCanWrite(conversionFormats[i])) {
try {
af->readFile(filename);
af->setFileWriteType(conversionFormats[i]);
//
// Assign colors to paint files since may be GIFTI output
//
PaintFile* pf = dynamic_cast<PaintFile*>(af);
if (pf != NULL) {
pf->assignColors(areaColorFile);
}
af->writeFile(filename);
std::cout << "converted to "
<< AbstractFile::convertFormatTypeToName(conversionFormats[i]).toAscii().constData()
<< ".";
}
catch (FileException& e) {
std::cout << "error converting or writing.";
}
fileProcessedFlag = true;
}
if (fileProcessedFlag) {
break;
}
}
if (fileProcessedFlag == false) {
std::cout << " does not support specified formats.";
}
}
}
if (af != NULL) {
delete af; // can't delete ?? compiler bug ??
}
std::cout << std::endl;
}
}
/**
* Write/Update a spec file.
*/
void
CommandFileConvert::updateSpecFile(const std::vector<QString>& tags,
const std::vector<QString>& values) throw (CommandException)
{
try {
//
// If the user specified a spec file
//
if (specFileName.isEmpty() == false) {
//
// Should spec file be created
//
if (QFile::exists(specFileName) == false) {
SpecFile sf;
sf.writeFile(specFileName);
}
//
// Try reading the spec file but ignore errors since it may not exist
//
SpecFile specFile;
specFile.readFile(specFileName);
//
// Add the spec file tags
//
for (int i = 0; i < static_cast<int>(tags.size()); i++) {
specFile.addToSpecFile(tags[i], values[i], "", false);
}
//
// Set the structure
//
if (structureName.isEmpty() == false) {
specFile.setStructure(structureName);
}
//
// Write the spec file
//
specFile.writeFile(specFileName);
}
}
catch (FileException& e) {
throw CommandException(e);
}
}
/**
* Convert a free surfer curvature file to caret surface shape.
*/
void
CommandFileConvert::freeSurferCurvatureToCaretConvert() throw (CommandException)
{
try {
QString freeSurfaceCurvatureName(inputSurfaceName);
QString freeSurfaceSurfaceName(inputSurfaceName2);
QString shapeName(outputSurfaceName);
//
// Read in the free surfer surface file
//
AbstractFile::FILE_FORMAT format = AbstractFile::FILE_FORMAT_BINARY;
if (freeSurfaceSurfaceName.right(3) == "asc") {
format = AbstractFile::FILE_FORMAT_ASCII;
}
FreeSurferSurfaceFile freeSurferSurfaceFile;
freeSurferSurfaceFile.setFileReadType(format);
freeSurferSurfaceFile.readFile(freeSurfaceSurfaceName);
//
// convert the free surface curvature file to the surface shape file.
//
SurfaceShapeFile shapeFile;
format = AbstractFile::FILE_FORMAT_BINARY;
if (freeSurfaceCurvatureName.right(3) == "asc") {
format = AbstractFile::FILE_FORMAT_ASCII;
}
shapeFile.importFreeSurferCurvatureFile(freeSurferSurfaceFile.getNumberOfVertices(),
freeSurfaceCurvatureName,
format);
//
// Write the surface shape file
//
if (fileWriteType != AbstractFile::FILE_FORMAT_OTHER) {
shapeFile.setFileWriteType(fileWriteType);
}
shapeFile.writeFile(shapeName);
//
// Add the surface shape files to the spec file
//
std::vector<QString> tags;
std::vector<QString> values;
tags.push_back(SpecFile::getSurfaceShapeFileTag());
values.push_back(shapeName);
updateSpecFile(tags, values);
}
catch (FileException& e) {
throw CommandException(e);
}
}
/**
* Convert a caret shape column to free surfer curvature file.
*/
void
CommandFileConvert::caretShapeToFreeSurferCurvature() throw (CommandException)
{
try {
//
// Load the shape file
//
SurfaceShapeFile shapeFile;
shapeFile.readFile(inputShapeName);
const int columnNumber = shapeFile.getColumnFromNameOrNumber(inputShapeColumn, false);
//
// Load the coordinate file
//
CoordinateFile coordFile;
coordFile.readFile(inputSurfaceName);
//
// Export to free surfer
//
shapeFile.exportFreeSurferAsciiCurvatureFile(columnNumber,
&coordFile,
outputCurvatureName);
}
catch (FileException& e) {
throw CommandException(e.whatQString());
}
}
/**
* Convert a caret paint file to free surfer label file.
*/
void
CommandFileConvert::caretPaintToFreeSurferLabel() throw (CommandException)
{
try {
//
// Load the paint file
//
PaintFile paintFile;
paintFile.readFile(inputSurfaceName);
//
// Load the coordinate file
//
CoordinateFile coordFile;
coordFile.readFile(inputSurfaceName2);
//
// Export to label files
//
for (int i = 0; i < paintFile.getNumberOfColumns(); i++) {
paintFile.exportFreeSurferAsciiLabelFile(i,
"",
&coordFile);
}
}
catch (FileException& e) {
throw CommandException(e);
}
}
/**
* Convert a free surfer functional file to caret metric.
*/
void
CommandFileConvert::freeSurferLabelToCaretConvert() throw (CommandException)
{
try {
QString freeSurfaceLabelDirName(inputSurfaceName);
freeSurfaceLabelDirName.append("/junk");
QString freeSurfaceSurfaceName(inputSurfaceName2);
QString paintName(outputSurfaceName);
//
// Read in the free surfer surface file
//
AbstractFile::FILE_FORMAT format = AbstractFile::FILE_FORMAT_BINARY;
if (freeSurfaceSurfaceName.right(3) == "asc") {
format = AbstractFile::FILE_FORMAT_ASCII;
}
FreeSurferSurfaceFile freeSurferSurfaceFile;
freeSurferSurfaceFile.setFileReadType(format);
freeSurferSurfaceFile.readFile(freeSurfaceSurfaceName);
//
// convert the free surface label files to the paint file.
//
PaintFile paintFile;
paintFile.importFreeSurferAsciiLabelFile(freeSurferSurfaceFile.getNumberOfVertices(),
freeSurfaceLabelDirName,
NULL,
true);
//
// Write the paint file
//
if (fileWriteType != AbstractFile::FILE_FORMAT_OTHER) {
paintFile.setFileWriteType(fileWriteType);
}
paintFile.writeFile(paintName);
//
// Add the surface shape files to the spec file
//
std::vector<QString> tags;
std::vector<QString> values;
tags.push_back(SpecFile::getPaintFileTag());
values.push_back(paintName);
updateSpecFile(tags, values);
}
catch (FileException& e) {
throw CommandException(e);
}
}
/**
* Convert a free surfer functional file to caret metric.
*/
void
CommandFileConvert::freeSurferFunctionalToCaretConvert() throw (CommandException)
{
try {
QString freeSurfaceFunctionalName(inputSurfaceName);
QString freeSurfaceSurfaceName(inputSurfaceName2);
QString metricName(outputSurfaceName);
//
// Read in the free surfer surface file
//
AbstractFile::FILE_FORMAT format = AbstractFile::FILE_FORMAT_BINARY;
if (freeSurfaceSurfaceName.right(3) == "asc") {
format = AbstractFile::FILE_FORMAT_ASCII;
}
FreeSurferSurfaceFile freeSurferSurfaceFile;
freeSurferSurfaceFile.setFileReadType(format);
freeSurferSurfaceFile.readFile(freeSurfaceSurfaceName);
//
// convert the free surface functional file to the metric file.
//
MetricFile metricFile;
format = AbstractFile::FILE_FORMAT_BINARY;
if (freeSurfaceFunctionalName.right(3) == "asc") {
format = AbstractFile::FILE_FORMAT_ASCII;
}
metricFile.importFreeSurferFunctionalFile(freeSurferSurfaceFile.getNumberOfVertices(),
freeSurfaceFunctionalName,
format);
//
// Write the surface shape file
//
if (fileWriteType != AbstractFile::FILE_FORMAT_OTHER) {
metricFile.setFileWriteType(fileWriteType);
}
metricFile.writeFile(metricName);
//
// Add the surface shape files to the spec file
//
std::vector<QString> tags;
std::vector<QString> values;
tags.push_back(SpecFile::getMetricFileTag());
values.push_back(metricName);
updateSpecFile(tags, values);
}
catch (FileException& e) {
throw CommandException(e);
}
}
/**
* Convert a surface file to another type.
*/
void
CommandFileConvert::surfaceFileConversion() throw (CommandException)
{
try {
//
// Convert the coordinate type name to a surface type
//
const BrainModelSurface::SURFACE_TYPES surfaceType =
BrainModelSurface::getSurfaceTypeFromConfigurationID(outputCoordTypeName);
//
// Convert the topology type name to a topology type
//
const TopologyFile::TOPOLOGY_TYPES topoType =
TopologyFile::getTopologyTypeFromPerimeterID(outputTopoTypeName);
int brainModelOfInterest = 0;
//
// Read in the appropriate surface
//
switch(inputSurfaceType) {
case SURFACE_TYPE_BYU:
brainSet->importByuSurfaceFile(inputSurfaceName, true, true,
surfaceType, topoType);
break;
case SURFACE_TYPE_CARET:
{
SpecFile sf;
sf.addToSpecFile(SpecFile::getClosedTopoFileTag(), inputSurfaceName2, "", false);
sf.addToSpecFile(SpecFile::getFiducialCoordFileTag(), inputSurfaceName, "", true);
sf.setAllFileSelections(SpecFile::SPEC_TRUE);
QString errorMessages;
brainSet->readSpecFile(sf, "spec-name", errorMessages);
if (errorMessages.isEmpty() == false) {
throw CommandException("Reading coordinate and topology files:"
+ errorMessages);
}
}
break;
case SURFACE_TYPE_FREE_SURFER:
{
AbstractFile::FILE_FORMAT format = AbstractFile::FILE_FORMAT_BINARY;
if (inputSurfaceName.right(3) == "asc") {
format = AbstractFile::FILE_FORMAT_ASCII;
}
brainSet->importFreeSurferSurfaceFile(inputSurfaceName, true, true, format,
surfaceType, topoType);
}
break;
case SURFACE_TYPE_FREE_SURFER_PATCH:
{
AbstractFile::FILE_FORMAT format2 = AbstractFile::FILE_FORMAT_BINARY;
if (inputSurfaceName2.right(3) == "asc") {
format2 = AbstractFile::FILE_FORMAT_ASCII;
}
brainSet->importFreeSurferSurfaceFile(inputSurfaceName2, true, true, format2,
surfaceType, topoType);
AbstractFile::FILE_FORMAT format = AbstractFile::FILE_FORMAT_BINARY;
if (inputSurfaceName.right(3) == "asc") {
format = AbstractFile::FILE_FORMAT_ASCII;
}
brainSet->importFreeSurferSurfaceFile(inputSurfaceName, true, true, format,
surfaceType, topoType);
brainModelOfInterest = 1;
}
break;
case SURFACE_TYPE_GIFTI:
brainSet->readSurfaceFile(inputSurfaceName,
surfaceType,
false,
true,
false);
break;
case SURFACE_TYPE_MNI_OBJ:
brainSet->importMniObjSurfaceFile(inputSurfaceName, true, true, true,
surfaceType, topoType);
break;
case SURFACE_TYPE_OPEN_INVENTOR:
throw CommandException("Open Inventor not supported for input.");
break;
case SURFACE_TYPE_STL:
brainSet->importStlSurfaceFile(inputSurfaceName, true, true,
surfaceType, topoType);
break;
case SURFACE_TYPE_VTK:
brainSet->importVtkSurfaceFile(inputSurfaceName, true, true, false,
surfaceType, topoType);
break;
case SURFACE_TYPE_XML_VTK:
brainSet->importVtkXmlSurfaceFile(inputSurfaceName, true, true, false,
surfaceType, topoType);
break;
case SURFACE_TYPE_UNKNOWN:
break;
}
//
// Make sure the surface is available
//
BrainModelSurface* bms = brainSet->getBrainModelSurface(brainModelOfInterest);
if (bms == NULL) {
throw CommandException("problems reading surface, brain model not found.");
}
//
// Write out the appropriate surface
//
switch(outputSurfaceType) {
case SURFACE_TYPE_BYU:
brainSet->exportByuSurfaceFile(bms, outputSurfaceName);
break;
case SURFACE_TYPE_CARET:
{
//
// Get the coordinate and topology files
//
CoordinateFile* coordFile = bms->getCoordinateFile();
TopologyFile* topoFile = bms->getTopologyFile();
//
// Get the coordinate files spec file type tag
//
const QString coordSpecFileTag(
BrainModelSurface::getCoordSpecFileTagFromSurfaceType(surfaceType));
//
// Set the coordinate file's type
//
coordFile->setHeaderTag(AbstractFile::headerTagConfigurationID,
BrainModelSurface::getSurfaceConfigurationIDFromType(surfaceType));
//
// Get the topo file's spec file tag
//
const QString topoSpecFileTag(
TopologyFile::getSpecFileTagFromTopologyType(topoType));
//
// Set the topo file's type
//
topoFile->setTopologyType(topoType);
//
// Write the coordinate file
//
if (fileWriteType != AbstractFile::FILE_FORMAT_OTHER) {
coordFile->setFileWriteType(fileWriteType);
}
if (structureName.isEmpty() == false) {
coordFile->setHeaderTag(AbstractFile::headerTagStructure,
structureName);
}
coordFile->writeFile(outputSurfaceName);
//
// Write the topology file
//
if (fileWriteType != AbstractFile::FILE_FORMAT_OTHER) {
topoFile->setFileWriteType(fileWriteType);
}
topoFile->writeFile(outputSurfaceName2);
//
// Update the spec file
//
std::vector<QString> tags;
std::vector<QString> values;
tags.push_back(topoSpecFileTag);
values.push_back(outputSurfaceName2);
tags.push_back(coordSpecFileTag);
values.push_back(outputSurfaceName);
updateSpecFile(tags, values);
}
break;
case SURFACE_TYPE_FREE_SURFER:
brainSet->exportFreeSurferAsciiSurfaceFile(bms, outputSurfaceName);
break;
case SURFACE_TYPE_FREE_SURFER_PATCH:
brainSet->exportFreeSurferAsciiSurfaceFile(bms, outputSurfaceName);
brainModelOfInterest = 1;
break;
case SURFACE_TYPE_GIFTI:
brainSet->writeSurfaceFile(outputSurfaceName,
surfaceType,
bms,
false);
break;
case SURFACE_TYPE_MNI_OBJ:
throw CommandException("MNI OBJ not supported for writing.");
break;
case SURFACE_TYPE_OPEN_INVENTOR:
brainSet->exportInventorSurfaceFile(bms, outputSurfaceName);
break;
case SURFACE_TYPE_STL:
brainSet->exportStlSurfaceFile(bms, outputSurfaceName);
break;
case SURFACE_TYPE_VTK:
brainSet->exportVtkSurfaceFile(bms, outputSurfaceName, false);
break;
case SURFACE_TYPE_XML_VTK:
brainSet->exportVtkXmlSurfaceFile(bms, outputSurfaceName, false);
break;
case SURFACE_TYPE_UNKNOWN:
break;
}
}
catch (FileException& e) {
throw CommandException(e);
}
}
/**
* Convert a surface type name to an enum.
*/
CommandFileConvert::SURFACE_FILE_TYPE
CommandFileConvert::getSurfaceFileType(const QString& surfaceTypeName,
const QString& inputOutputName)
throw (CommandException)
{
if (surfaceTypeName == "BYU") {
return SURFACE_TYPE_BYU;
}
if (surfaceTypeName == "CARET") {
return SURFACE_TYPE_CARET;
}
else if (surfaceTypeName == "FSS") {
return SURFACE_TYPE_FREE_SURFER;
}
else if (surfaceTypeName == "FSP") {
return SURFACE_TYPE_FREE_SURFER_PATCH;
}
else if (surfaceTypeName == "GS") {
return SURFACE_TYPE_GIFTI;
}
else if (surfaceTypeName == "MNIOBJ") {
return SURFACE_TYPE_MNI_OBJ;
}
else if (surfaceTypeName == "OI") {
return SURFACE_TYPE_OPEN_INVENTOR;
}
else if (surfaceTypeName == "STL") {
return SURFACE_TYPE_STL;
}
else if (surfaceTypeName == "VTKP") {
return SURFACE_TYPE_VTK;
}
else if (surfaceTypeName == "VTKXP") {
return SURFACE_TYPE_XML_VTK;
}
else {
throw CommandException("Invalid "
+ inputOutputName
+ " surface type: "
+ surfaceTypeName);
}
return SURFACE_TYPE_UNKNOWN;
}
/**
* convert a volume.
*/
void
CommandFileConvert::volumeConversion(const QString& inputVolumeName,
const QString& outputVolumeName) throw (CommandException)
{
try {
//
// Read the input file
//
std::vector<VolumeFile*> volumes;
VolumeFile::readFile(inputVolumeName,
VolumeFile::VOLUME_READ_SELECTION_ALL,
volumes);
if (volumes.empty() == false) {
//
// Write the output file
//
VolumeFile::writeFile(outputVolumeName,
volumes[0]->getVolumeType(),
volumes[0]->getVoxelDataType(),
volumes);
//
// Free memory
//
for (unsigned int i = 0; i < volumes.size(); i++) {
delete volumes[i];
}
}
else {
throw FileException("No volumes were read successfully.");
}
}
catch (FileException& e) {
throw CommandException(e);
}
}
/**
* Convert a spec file's data files.
*/
void
CommandFileConvert::specFileConvert(const QString& dataFileFormatList,
const QString& specFileName) throw (CommandException)
{
std::vector<AbstractFile::FILE_FORMAT> conversionFormats;
const QStringList sl = dataFileFormatList.split(':');
for (int i = 0; i < sl.count(); i++) {
const QString formatName(sl.at(i));
bool valid = false;
const AbstractFile::FILE_FORMAT format =
AbstractFile::convertFormatNameToType(formatName, &valid);
if (valid) {
conversionFormats.push_back(format);
}
else {
throw CommandException("Invalid file format name \""
+ formatName
+ "\"");
}
}
try {
SpecFile sf;
sf.readFile(specFileName);
sf.convertAllDataFilesToType(conversionFormats, true);
}
catch (FileException& e) {
throw CommandException(e);
}
}
|