21 #pragma warning(disable : 4715) 24 #include <boost/property_tree/json_parser.hpp> 25 #include <boost/property_tree/ptree.hpp> 26 #include <boost/type_traits/make_unsigned.hpp> 34 m_Values.insert(std::make_pair(0, slices));
42 m_Values.insert(std::make_pair(0, slices));
50 bool mitk::TemporoSpatialStringProperty::IsEqual(
const BaseProperty &property)
const 55 bool mitk::TemporoSpatialStringProperty::Assign(
const BaseProperty &property)
66 itk::LightObject::Pointer mitk::TemporoSpatialStringProperty::InternalClone()
const 68 itk::LightObject::Pointer result(
new Self(*
this));
75 std::string result =
"";
79 if (!
m_Values.begin()->second.empty())
81 result =
m_Values.begin()->second.begin()->second;
90 std::string value =
"";
93 auto timeIter =
m_Values.find(timeStep);
95 if (timeIter == timeEnd && allowCloseTime)
97 timeIter =
m_Values.upper_bound(timeStep);
100 timeIter = std::prev(timeIter);
104 if (timeIter != timeEnd)
108 auto sliceIter = slices.find(zSlice);
109 auto sliceEnd = slices.end();
110 if (sliceIter == sliceEnd && allowCloseSlice)
112 sliceIter = slices.upper_bound(zSlice);
113 if (sliceIter != slices.begin())
115 sliceIter = std::prev(sliceIter);
119 if (sliceIter != sliceEnd)
121 value = sliceIter->second;
126 return std::make_pair(found, value);
132 bool allowCloseSlice)
const 134 return CheckValue(timeStep, zSlice, allowCloseTime, allowCloseSlice).second;
140 return GetValue(0, zSlice,
true, allowClose);
146 return GetValue(timeStep, 0, allowClose,
true);
157 bool allowCloseSlice)
const 159 return CheckValue(timeStep, zSlice, allowCloseTime, allowCloseSlice).first;
164 return HasValue(0, zSlice,
true, allowClose);
169 return HasValue(timeStep, 0, allowClose,
true);
175 std::vector<IndexValueType> result;
177 auto timeIter =
m_Values.find(timeStep);
180 if (timeIter != timeEnd)
182 for (
auto const &element : timeIter->second)
184 result.push_back(element.first);
193 std::vector<mitk::TimeStepType> result;
195 for (
auto const &element :
m_Values)
197 result.push_back(element.first);
207 auto timeIter =
m_Values.find(timeStep);
210 if (timeIter == timeEnd)
213 m_Values.insert(std::make_pair(timeStep, slices));
217 timeIter->second[zSlice] = value;
239 std::basic_string<Ch> result;
240 typename std::basic_string<Ch>::const_iterator b = s.begin();
241 typename std::basic_string<Ch>::const_iterator e = s.end();
244 typedef typename boost::make_unsigned<Ch>::type UCh;
249 if (c == 0x20 || c == 0x21 || (c >= 0x23 && c <= 0x2E) || (c >= 0x30 && c <= 0x5B) || (c >= 0x5D && c <= 0x7F))
251 else if (*b == Ch(
'\b'))
252 result += Ch(
'\\'), result += Ch(
'b');
253 else if (*b == Ch(
'\f'))
254 result += Ch(
'\\'), result += Ch(
'f');
255 else if (*b == Ch(
'\n'))
256 result += Ch(
'\\'), result += Ch(
'n');
257 else if (*b == Ch(
'\r'))
258 result += Ch(
'\\'), result += Ch(
'r');
259 else if (*b == Ch(
'\t'))
260 result += Ch(
'\\'), result += Ch(
't');
261 else if (*b == Ch(
'/'))
262 result += Ch(
'\\'), result += Ch(
'/');
263 else if (*b == Ch(
'"'))
264 result += Ch(
'\\'), result += Ch(
'"');
265 else if (*b == Ch(
'\\'))
266 result += Ch(
'\\'), result += Ch(
'\\');
269 const char *hexdigits =
"0123456789ABCDEF";
270 unsigned long u = (
std::min)(static_cast<unsigned long>(static_cast<UCh>(*b)), 0xFFFFul);
280 result += Ch(hexdigits[d1]);
281 result += Ch(hexdigits[d2]);
282 result += Ch(hexdigits[d3]);
283 result += Ch(hexdigits[d4]);
302 mitkThrow() <<
"Cannot serialize properties of types other than TemporoSpatialStringProperty.";
305 std::ostringstream stream;
306 stream <<
"{\"values\":[";
308 std::vector<mitk::TimeStepType> ts = tsProp->GetAvailableTimeSteps();
312 std::vector<mitk::TemporoSpatialStringProperty::IndexValueType> zs = tsProp->GetAvailableSlices(t);
326 stream <<
"{\"t\":" << t <<
", \"z\":" << z <<
", \"value\":\"" << value <<
"\"}";
336 const std::string &value)
343 boost::property_tree::ptree root;
345 std::istringstream stream(value);
347 boost::property_tree::read_json(stream, root);
349 for (boost::property_tree::ptree::value_type &element : root.get_child(
"values"))
351 std::string value = element.second.get(
"value",
"");
356 prop->SetValue(t, z, value);
359 return prop.GetPointer();
std::basic_string< Ch > CreateJSONEscapes(const std::basic_string< Ch > &s)
MITKCORE_EXPORT::std::string serializeTemporoSpatialStringPropertyToJSON(const mitk::BaseProperty *prop)
ValueType GetValueBySlice(const IndexValueType &zSlice, bool allowClose=false) const
std::pair< bool, ValueType > CheckValue(const TimeStepType &timeStep, const IndexValueType &zSlice, bool allowCloseTime=false, bool allowCloseSlice=false) const
void SetValue(const TimeStepType &timeStep, const IndexValueType &zSlice, const ValueType &value)
Abstract base class for properties.
std::vector< IndexValueType > GetAvailableSlices(const TimeStepType &timeStep) const
bool HasValueByTimeStep(const TimeStepType &timeStep, bool allowClose=false) const
std::vector< TimeStepType > GetAvailableTimeSteps() const
ValueType GetValueByTimeStep(const TimeStepType &timeStep, bool allowClose=false) const
TemporoSpatialStringProperty Self
TemporoSpatialStringProperty(const char *string=nullptr)
std::vcl_size_t TimeStepType
std::string GetValueAsString() const override
ValueType GetValue() const
bool HasValueBySlice(const IndexValueType &zSlice, bool allowClose=false) const
std::map< IndexValueType, std::string > SliceMapType
MITKCORE_EXPORT mitk::BaseProperty::Pointer deserializeJSONToTemporoSpatialStringProperty(const std::string &value)
::itk::IndexValueType IndexValueType
Property for time and space resolved string values.