|
0 |
#include "CiftiException.h"
|
|
1 |
#include "CiftiFile.h"
|
|
2 |
|
|
3 |
#include <iostream>
|
|
4 |
#include <vector>
|
|
5 |
|
|
6 |
using namespace std;
|
|
7 |
using namespace cifti;
|
|
8 |
|
|
9 |
/**\file xmlinfo.cxx
|
|
10 |
This program reads a Cifti file from argv[1], and prints out a summary of the XML.
|
|
11 |
|
|
12 |
\include xmlinfo.cxx
|
|
13 |
*/
|
|
14 |
|
|
15 |
int main(int argc, char** argv)
|
|
16 |
{
|
|
17 |
if (argc < 1)
|
|
18 |
{
|
|
19 |
cout << "this program requires one argument: an input cifti file" << endl;
|
|
20 |
return 1;
|
|
21 |
}
|
|
22 |
try
|
|
23 |
{
|
|
24 |
CiftiFile inputFile(argv[1]);//on-disk reading by default, and we only need the XML header anyway
|
|
25 |
const CiftiXML& myXML = inputFile.getCiftiXML();
|
|
26 |
for (int whichDim = 0; whichDim < myXML.getNumberOfDimensions(); ++whichDim)
|
|
27 |
{
|
|
28 |
cout << "Dimension " << whichDim << ": ";
|
|
29 |
switch (myXML.getMappingType(whichDim))
|
|
30 |
{
|
|
31 |
case CiftiMappingType::BRAIN_MODELS:
|
|
32 |
{
|
|
33 |
const CiftiBrainModelsMap& myMap = myXML.getBrainModelsMap(whichDim);
|
|
34 |
cout << "Brain Models, length " << myMap.getLength() << endl;
|
|
35 |
vector<CiftiBrainModelsMap::ModelInfo> myInfo = myMap.getModelInfo();//this is only summary info, same order as the models are in the cifti indices
|
|
36 |
for (int i = 0; i < (int)myInfo.size(); ++i)//to get the lists of vertices/voxels for a model, see getSurfaceMap, getVolumeStructureMap, and getFullVolumeMap
|
|
37 |
{
|
|
38 |
switch (myInfo[i].m_type)
|
|
39 |
{
|
|
40 |
case CiftiBrainModelsMap::SURFACE:
|
|
41 |
cout << " Surface " << StructureEnum::toName(myInfo[i].m_structure) << ": ";
|
|
42 |
cout << myInfo[i].m_indexCount << " out of " << myMap.getSurfaceNumberOfNodes(myInfo[i].m_structure) << " vertices" << endl;
|
|
43 |
break;
|
|
44 |
case CiftiBrainModelsMap::VOXELS:
|
|
45 |
cout << " Voxels " << StructureEnum::toName(myInfo[i].m_structure) << ": ";
|
|
46 |
cout << myInfo[i].m_indexCount << " voxels" << endl;
|
|
47 |
break;
|
|
48 |
}
|
|
49 |
}
|
|
50 |
break;
|
|
51 |
}
|
|
52 |
case CiftiMappingType::LABELS:
|
|
53 |
{
|
|
54 |
const CiftiLabelsMap& myMap = myXML.getLabelsMap(whichDim);
|
|
55 |
cout << "Labels, length " << myMap.getLength() << endl;
|
|
56 |
for (int i = 0; i < myMap.getLength(); ++i)
|
|
57 |
{
|
|
58 |
cout << " Index " << i << ": " << myMap.getMapName(i) << endl;
|
|
59 |
}
|
|
60 |
break;
|
|
61 |
}
|
|
62 |
case CiftiMappingType::PARCELS:
|
|
63 |
{
|
|
64 |
const CiftiParcelsMap& myMap = myXML.getParcelsMap(whichDim);
|
|
65 |
cout << "Parcels, length " << myMap.getLength() << endl;
|
|
66 |
const vector<CiftiParcelsMap::Parcel>& myParcels = myMap.getParcels();
|
|
67 |
for (int i = 0; i < (int)myParcels.size(); ++i)
|
|
68 |
{
|
|
69 |
cout << " Index " << i << ", name '" << myParcels[i].m_name << "': ";
|
|
70 |
int numVerts = 0;
|
|
71 |
for (map<StructureEnum::Enum, set<int64_t> >::const_iterator iter = myParcels[i].m_surfaceNodes.begin(); iter != myParcels[i].m_surfaceNodes.end(); ++iter)
|
|
72 |
{
|
|
73 |
numVerts += iter->second.size();
|
|
74 |
}
|
|
75 |
cout << numVerts << " vertices, " << myParcels[i].m_voxelIndices.size() << " voxels" << endl;
|
|
76 |
}
|
|
77 |
break;
|
|
78 |
}
|
|
79 |
case CiftiMappingType::SCALARS:
|
|
80 |
{
|
|
81 |
const CiftiScalarsMap& myMap = myXML.getScalarsMap(whichDim);
|
|
82 |
cout << "Scalars, length " << myMap.getLength() << endl;
|
|
83 |
for (int i = 0; i < myMap.getLength(); ++i)
|
|
84 |
{
|
|
85 |
cout << " Index " << i << ": " << myMap.getMapName(i) << endl;
|
|
86 |
}
|
|
87 |
break;
|
|
88 |
}
|
|
89 |
case CiftiMappingType::SERIES:
|
|
90 |
{
|
|
91 |
const CiftiSeriesMap& myMap = myXML.getSeriesMap(whichDim);
|
|
92 |
cout << "Series, length " << myMap.getLength() << endl;
|
|
93 |
cout << " Start: " << myMap.getStart() << endl;
|
|
94 |
cout << " Step: " << myMap.getStep() << endl;
|
|
95 |
cout << " Unit: ";
|
|
96 |
switch (myMap.getUnit())
|
|
97 |
{
|
|
98 |
case CiftiSeriesMap::SECOND:
|
|
99 |
cout << "Seconds" << endl;
|
|
100 |
break;
|
|
101 |
case CiftiSeriesMap::HERTZ:
|
|
102 |
cout << "Hertz" << endl;
|
|
103 |
break;
|
|
104 |
case CiftiSeriesMap::METER:
|
|
105 |
cout << "Meters" << endl;
|
|
106 |
break;
|
|
107 |
case CiftiSeriesMap::RADIAN:
|
|
108 |
cout << "Radians" << endl;
|
|
109 |
break;
|
|
110 |
}
|
|
111 |
break;
|
|
112 |
}
|
|
113 |
}
|
|
114 |
cout << endl;//extra line break between dimensions
|
|
115 |
}
|
|
116 |
} catch (CiftiException& e) {
|
|
117 |
cout << "Caught CiftiException: " + AString_to_std_string(e.whatString()) << endl;
|
|
118 |
return 1;
|
|
119 |
}
|
|
120 |
return 0;
|
|
121 |
}
|