CiftiLib
A C++ library for CIFTI-2 and CIFTI-1 files
CiftiSeriesMap.h
1 #ifndef __CIFTI_SERIES_MAP_H__
2 #define __CIFTI_SERIES_MAP_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 
33 namespace cifti
34 {
36  {
37  public:
38  enum Unit
39  {
40  HERTZ,
41  METER,
42  RADIAN,
43  SECOND
44  };//should this go somewhere else?
45  float getStart() const { return m_start; }//using getter/setter as style choice to match other mapping types
46  float getStep() const { return m_step; }//getter for number of series points is getLength(), specified by CiftiIndexMap
47  Unit getUnit() const { return m_unit; }
48 
50  {
51  m_start = 0.0f;
52  m_step = 1.0f;
53  m_unit = SECOND;
54  m_length = -1;//to make it clear an improperly initialized series map object was used
55  }
56  CiftiSeriesMap(const int64_t& length, const float& start = 0.0f, const float& step = 1.0f, const Unit& unit = SECOND)
57  {
58  m_start = start;
59  m_step = step;
60  m_unit = unit;
61  m_length = length;
62  }
63  void setStart(const float& start) { m_start = start; }
64  void setStep(const float& step) { m_step = step; }
65  void setUnit(const Unit& unit) { m_unit = unit; }
66  void setLength(const int64_t& length);
67 
68  static Unit stringToUnit(const AString& string, bool& ok);
69  static AString unitToString(const Unit& theUnit);
70  static std::vector<Unit> getAllUnits();
71 
72  CiftiMappingType* clone() const { return new CiftiSeriesMap(*this); }
73  MappingType getType() const { return SERIES; }
74  int64_t getLength() const { return m_length; }
75  bool operator==(const CiftiMappingType& rhs) const
76  {
77  if (rhs.getType() != getType()) return false;
78  const CiftiSeriesMap& temp = dynamic_cast<const CiftiSeriesMap&>(rhs);
79  return (temp.m_length == m_length &&
80  temp.m_unit == m_unit &&
81  temp.m_start == m_start &&
82  temp.m_step == m_step);
83  }
84  bool approximateMatch(const CiftiMappingType& rhs, AString* explanation = NULL) const
85  {
86  switch (rhs.getType())
87  {
88  case SCALARS://maybe?
89  case SERIES:
90  case LABELS://maybe?
91  if (getLength() != rhs.getLength())
92  {
93  if (explanation != NULL) *explanation = "mappings have different length";
94  return false;
95  } else return true;
96  default:
97  if (explanation != NULL) *explanation = CiftiMappingType::mappingTypeToName(rhs.getType()) + " mapping never matches " + CiftiMappingType::mappingTypeToName(getType());
98  return false;
99  }
100  }
101  void readXML1(XmlReader& xml);
102  void readXML2(XmlReader& xml);
103  void writeXML1(XmlWriter& xml) const;
104  void writeXML2(XmlWriter& xml) const;
105  private:
106  int64_t m_length;
107  float m_start, m_step;//exponent gets applied to these on reading
108  Unit m_unit;
109  };
110 }
111 
112 #endif //__CIFTI_SERIES_MAP_H__
cifti::CiftiSeriesMap
Definition: CiftiSeriesMap.h:36
cifti
namespace for all CiftiLib functionality
Definition: CiftiBrainModelsMap.h:42
cifti::CiftiMappingType
Definition: CiftiMappingType.h:39