25 #pragma warning(disable : 4715)
28 #include <boost/property_tree/json_parser.hpp>
29 #include <boost/property_tree/ptree.hpp>
30 #include <boost/type_traits/make_unsigned.hpp>
38 m_Values.insert(std::make_pair(0, slices));
46 m_Values.insert(std::make_pair(0, slices));
54 bool mitk::TemporoSpatialStringProperty::IsEqual(
const BaseProperty &property)
const
56 return this->m_Values ==
static_cast<const Self &
>(property).m_Values;
59 bool mitk::TemporoSpatialStringProperty::Assign(
const BaseProperty &property)
61 this->m_Values =
static_cast<const Self &
>(property).m_Values;
79 std::string result =
"";
81 if (!m_Values.empty())
83 if (!m_Values.begin()->second.empty())
85 result = m_Values.begin()->second.begin()->second;
94 std::string value =
"";
97 TimeMapType::const_iterator timeIter = m_Values.find(timeStep);
98 TimeMapType::const_iterator timeEnd = m_Values.end();
99 if (timeIter == timeEnd && allowCloseTime)
101 timeIter = m_Values.upper_bound(timeStep);
102 if (timeIter != m_Values.begin())
104 timeIter = std::prev(timeIter);
108 if (timeIter != timeEnd)
112 SliceMapType::const_iterator sliceIter = slices.find(zSlice);
113 SliceMapType::const_iterator sliceEnd = slices.end();
114 if (sliceIter == sliceEnd && allowCloseSlice)
116 sliceIter = slices.upper_bound(zSlice);
117 if (sliceIter != slices.begin())
119 sliceIter = std::prev(sliceIter);
123 if (sliceIter != sliceEnd)
125 value = sliceIter->second;
130 return std::make_pair(found, value);
136 bool allowCloseSlice)
const
138 return CheckValue(timeStep, zSlice, allowCloseTime, allowCloseSlice).second;
144 return GetValue(0, zSlice,
true, allowClose);
150 return GetValue(timeStep, 0, allowClose,
true);
155 return !m_Values.empty();
161 bool allowCloseSlice)
const
163 return CheckValue(timeStep, zSlice, allowCloseTime, allowCloseSlice).first;
168 return HasValue(0, zSlice,
true, allowClose);
173 return HasValue(timeStep, 0, allowClose,
true);
179 std::vector<IndexValueType> result;
181 TimeMapType::const_iterator timeIter = m_Values.find(timeStep);
182 TimeMapType::const_iterator timeEnd = m_Values.end();
184 if (timeIter != timeEnd)
186 for (
auto const &element : timeIter->second)
188 result.push_back(element.first);
197 std::vector<mitk::TimeStepType> result;
199 for (
auto const &element : m_Values)
201 result.push_back(element.first);
211 TimeMapType::iterator timeIter = m_Values.find(timeStep);
212 TimeMapType::iterator timeEnd = m_Values.end();
214 if (timeIter == timeEnd)
217 m_Values.insert(std::make_pair(timeStep, slices));
221 timeIter->second[zSlice] = value;
230 this->SetValue(0, 0, value);
243 std::basic_string<Ch> result;
244 typename std::basic_string<Ch>::const_iterator b = s.begin();
245 typename std::basic_string<Ch>::const_iterator e = s.end();
248 typedef typename boost::make_unsigned<Ch>::type UCh;
253 if (c == 0x20 || c == 0x21 || (c >= 0x23 && c <= 0x2E) || (c >= 0x30 && c <= 0x5B) || (c >= 0x5D && c <= 0x7F))
255 else if (*b == Ch(
'\b'))
256 result += Ch(
'\\'), result += Ch(
'b');
257 else if (*b == Ch(
'\f'))
258 result += Ch(
'\\'), result += Ch(
'f');
259 else if (*b == Ch(
'\n'))
260 result += Ch(
'\\'), result += Ch(
'n');
261 else if (*b == Ch(
'\r'))
262 result += Ch(
'\\'), result += Ch(
'r');
263 else if (*b == Ch(
'\t'))
264 result += Ch(
'\\'), result += Ch(
't');
265 else if (*b == Ch(
'/'))
266 result += Ch(
'\\'), result += Ch(
'/');
267 else if (*b == Ch(
'"'))
268 result += Ch(
'\\'), result += Ch(
'"');
269 else if (*b == Ch(
'\\'))
270 result += Ch(
'\\'), result += Ch(
'\\');
273 const char *hexdigits =
"0123456789ABCDEF";
274 unsigned long u = (
std::min)(static_cast<unsigned long>(static_cast<UCh>(*b)), 0xFFFFul);
284 result += Ch(hexdigits[d1]);
285 result += Ch(hexdigits[d2]);
286 result += Ch(hexdigits[d3]);
287 result += Ch(hexdigits[d4]);
309 std::ostringstream stream;
310 stream <<
"{\"values\":[";
316 std::vector<mitk::TemporoSpatialStringProperty::IndexValueType> zs = tsProp->
GetAvailableSlices(t);
330 stream <<
"{\"t\":" << t <<
", \"z\":" << z <<
", \"value\":\"" << value <<
"\"}";
340 const std::string &value)
344 boost::property_tree::ptree root;
346 std::istringstream stream(value);
348 boost::property_tree::read_json(stream, root);
351 for (boost::property_tree::ptree::value_type &element : root.get_child(
"values"))
353 std::string value = element.second.get(
"value",
"");
358 prop->SetValue(t, z, value);
361 return prop.GetPointer();
std::basic_string< Ch > CreateJSONEscapes(const std::basic_string< Ch > &s)
std::pair< bool, ValueType > CheckValue(const TimeStepType &timeStep, const IndexValueType &zSlice, bool allowCloseTime=false, bool allowCloseSlice=false) const
itk::SmartPointer< Self > Pointer
MITKCORE_EXPORT::std::string serializeTemporoSpatialStringPropertyToJSON(const mitk::BaseProperty *prop)
std::vector< TimeStepType > GetAvailableTimeSteps() const
ValueType GetValueByTimeStep(const TimeStepType &timeStep, bool allowClose=false) const
void SetValue(const TimeStepType &timeStep, const IndexValueType &zSlice, const ValueType &value)
std::vector< IndexValueType > GetAvailableSlices(const TimeStepType &timeStep) const
Abstract base class for properties.
TemporoSpatialStringProperty(const char *string=nullptr)
ValueType GetValue() const
std::vcl_size_t TimeStepType
virtual std::string GetValueAsString() const override
bool HasValueBySlice(const IndexValueType &zSlice, bool allowClose=false) const
bool HasValueByTimeStep(const TimeStepType &timeStep, bool allowClose=false) const
std::map< IndexValueType, std::string > SliceMapType
MITKCORE_EXPORT mitk::BaseProperty::Pointer deserializeJSONToTemporoSpatialStringProperty(const std::string &value)
ValueType GetValueBySlice(const IndexValueType &zSlice, bool allowClose=false) const
::itk::IndexValueType IndexValueType
Property for time and space resolved string values.