Medical Imaging Interaction Toolkit  2026.06.00
Medical Imaging Interaction Toolkit
TemporoSpatialStringSerialization.h
Go to the documentation of this file.
1 /*============================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center (DKFZ)
6 All rights reserved.
7 
8 Use of this source code is governed by a 3-clause BSD license that can be
9 found in the LICENSE file.
10 
11 ============================================================================*/
12 
22 #pragma once
23 
25 #include <mitkBaseProperty.h>
26 #include <pybind11/pybind11.h>
27 
28 namespace py = pybind11;
29 
30 namespace mitk::python
31 {
32  // Returns true if prop was TemporoSpatialStringProperty and was serialized into result.
33  inline bool tryTemporoSpatialStringToDict(const mitk::BaseProperty& prop, py::dict& result)
34  {
35  const auto* tsProp = dynamic_cast<const mitk::TemporoSpatialStringProperty*>(&prop);
36  if (!tsProp) return false;
37 
38  result["type"] = "TemporoSpatialStringProperty";
39  py::list entries;
40 
41  for (auto ts : tsProp->GetAvailableTimeSteps())
42  for (auto slice : tsProp->GetAvailableSlices(ts))
43  entries.append(py::make_tuple(ts, slice, tsProp->GetValue(ts, slice)));
44 
45  result["entries"] = entries;
46  return true;
47  }
48 
49  // Returns non-null if type == "TemporoSpatialStringProperty".
50  inline mitk::BaseProperty::Pointer tryDictToTemporoSpatialString(const py::dict& d)
51  {
52  if (d["type"].cast<std::string>() != "TemporoSpatialStringProperty")
53  return nullptr;
54 
56 
57  for (auto entry : d["entries"].cast<py::list>())
58  {
59  auto t = entry.cast<py::tuple>();
60  prop->SetValue(t[0].cast<mitk::TimeStepType>(),
62  t[2].cast<std::string>());
63  }
64 
65  return prop.GetPointer();
66  }
67 
68 } // namespace mitk::python
Abstract base class for properties.
Property for storing string values resolved by time step and slice index.
::itk::IndexValueType IndexValueType
Index type for slice indices.
mitk::BaseProperty::Pointer tryDictToTemporoSpatialString(const py::dict &d)
bool tryTemporoSpatialStringToDict(const mitk::BaseProperty &prop, py::dict &result)