CiftiLib
A C++ library for CIFTI-2 and CIFTI-1 files
CiftiXML.h
1 #ifndef __CIFTI_XML_H__
2 #define __CIFTI_XML_H__
3 
4 /*LICENSE_START*/
5 /*
6  * Copyright (c) 2014, Washington University School of Medicine
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without modification,
10  * are permitted provided that the following conditions are met:
11  *
12  * 1. Redistributions of source code must retain the above copyright notice,
13  * this list of conditions and the following disclaimer.
14  *
15  * 2. Redistributions in binary form must reproduce the above copyright notice,
16  * this list of conditions and the following disclaimer in the documentation
17  * and/or other materials provided with the distribution.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
21  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
23  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
26  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
28  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  */
30 
31 #include "CiftiMappingType.h"
32 #include "CiftiVersion.h"
33 #include "MetaData.h"
34 
35 #include "CiftiBrainModelsMap.h"
36 #include "CiftiLabelsMap.h"
37 #include "CiftiParcelsMap.h"
38 #include "CiftiScalarsMap.h"
39 #include "CiftiSeriesMap.h"
40 
41 #include "boost/shared_ptr.hpp"
42 
43 #include <vector>
44 
45 namespace cifti
46 {
48  class CiftiXML
49  {
50  public:
51  enum
52  {
53  ALONG_ROW = 0,
54  ALONG_COLUMN = 1,
55  ALONG_STACK = 2//better name for this?
56  };
57  int getNumberOfDimensions() const { return m_indexMaps.size(); }
58  const CiftiVersion& getParsedVersion() const { return m_parsedVersion; }
59 
61  const CiftiMappingType* getMap(const int& direction) const;
62 
64  CiftiMappingType* getMap(const int& direction);
65  const MetaData& getFileMetaData() const;
66 
67  CiftiMappingType::MappingType getMappingType(const int& direction) const;//convenience functions
68  const CiftiBrainModelsMap& getBrainModelsMap(const int& direction) const;
69  CiftiBrainModelsMap& getBrainModelsMap(const int& direction);
70  const CiftiLabelsMap& getLabelsMap(const int& direction) const;
71  CiftiLabelsMap& getLabelsMap(const int& direction);
72  const CiftiParcelsMap& getParcelsMap(const int& direction) const;
73  CiftiParcelsMap& getParcelsMap(const int& direction);
74  const CiftiScalarsMap& getScalarsMap(const int& direction) const;
75  CiftiScalarsMap& getScalarsMap(const int& direction);
76  const CiftiSeriesMap& getSeriesMap(const int& direction) const;
77  CiftiSeriesMap& getSeriesMap(const int& direction);
78  int64_t getDimensionLength(const int& direction) const;
79  std::vector<int64_t> getDimensions() const;
80 
81  void setNumberOfDimensions(const int& num);
82  void setMap(const int& direction, const CiftiMappingType& mapIn);
83  void setFileMetaData(const MetaData& mdIn) { m_fileMetaData = mdIn; }
84  void clear();
85 
86  void readXML(XmlReader& xml);
87  void readXML(const std::vector<char>& text);
88 
89  std::vector<char> writeXMLToVector(const CiftiVersion& writingVersion = CiftiVersion()) const;
90  void writeXML(XmlWriter& xml, const CiftiVersion& writingVersion = CiftiVersion()) const;
91 
93  int32_t getIntentInfo(const CiftiVersion& writingVersion, char intentNameOut[16]) const;
94 
95  CiftiXML() { }
96  CiftiXML(const CiftiXML& rhs);
97  CiftiXML& operator=(const CiftiXML& rhs);
98  bool operator==(const CiftiXML& rhs) const;
99  bool operator!=(const CiftiXML& rhs) const { return !((*this) == rhs); }
100  bool approximateMatch(const CiftiXML& rhs) const;
101  private:
102  std::vector<boost::shared_ptr<CiftiMappingType> > m_indexMaps;
103  CiftiVersion m_parsedVersion;
104  MetaData m_fileMetaData;
105 
106  void copyHelper(const CiftiXML& rhs);
107  //parsing functions
108  void parseCIFTI1(XmlReader& xml);
109  void parseMatrix1(XmlReader& xml);
110  void parseCIFTI2(XmlReader& xml);
111  void parseMatrix2(XmlReader& xml);
112  void parseMatrixIndicesMap1(XmlReader& xml);
113  void parseMatrixIndicesMap2(XmlReader& xml);
114  //writing functions
115  void writeMatrix1(XmlWriter& xml) const;
116  void writeMatrix2(XmlWriter& xml) const;
117  };
118 }
119 
120 #endif //__CIFTI_XML_H__
const CiftiMappingType * getMap(const int &direction) const
can return null in unfilled XML object
Definition: CiftiXML.cxx:93
namespace for all CiftiLib functionality
Definition: CiftiBrainModelsMap.h:41
Definition: CiftiMappingType.h:38
Definition: CiftiParcelsMap.h:44
int32_t getIntentInfo(const CiftiVersion &writingVersion, char intentNameOut[16]) const
uses the mapping types to figure out what the intent info should be
Definition: CiftiXML.cxx:249
class for retrieving and setting mapping information of cifti files
Definition: CiftiXML.h:48
Definition: CiftiSeriesMap.h:35
Definition: CiftiScalarsMap.h:40
Definition: CiftiLabelsMap.h:42
Definition: CiftiVersion.h:37
Definition: CiftiBrainModelsMap.h:43
Definition: MetaData.h:44