Medical Imaging Interaction Toolkit  2025.12.02
Medical Imaging Interaction Toolkit
mitkROI.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 
13 #ifndef mitkROI_h
14 #define mitkROI_h
15 
16 #include <mitkBaseData.h>
17 #include <MitkROIExports.h>
18 
19 namespace mitk
20 {
58  class MITKROI_EXPORT ROI : public BaseData
59  {
60  public:
66  {
67  public:
68  using PointsType = std::map<TimeStepType, Point3D>;
69  using PropertyListsType = std::map<TimeStepType, PropertyList::Pointer>;
70 
72  explicit Element(unsigned int id);
73  ~Element() = default;
74 
80  BaseProperty::ConstPointer GetConstProperty(const std::string& propertyKey, const std::string& contextName = "", bool fallBackOnDefaultContext = true) const override;
81  BaseProperty::ConstPointer GetConstProperty(const std::string& propertyKey, TimeStepType t, bool fallBackOnDefaultContext = true) const;
82 
88  std::vector<std::string> GetPropertyKeys(const std::string& contextName = "", bool includeDefaultContext = false) const override;
89  std::vector<std::string> GetPropertyKeys(TimeStepType t, bool includeDefaultContext = false) const;
90 
93  std::vector<std::string> GetPropertyContextNames() const override;
94 
100  BaseProperty* GetNonConstProperty(const std::string& propertyKey, const std::string& contextName = "", bool fallBackOnDefaultContext = true) override;
101  BaseProperty* GetNonConstProperty(const std::string& propertyKey, TimeStepType t, bool fallBackOnDefaultContext = true);
102 
108  void SetProperty(const std::string& propertyKey, BaseProperty* property, const std::string& contextName = "", bool fallBackOnDefaultContext = false) override;
109  void SetProperty(const std::string& propertyKey, BaseProperty* property, TimeStepType t, bool fallBackOnDefaultContext = false);
110 
116  void RemoveProperty(const std::string& propertyKey, const std::string& contextName = "", bool fallBackOnDefaultContext = false) override;
117  void RemoveProperty(const std::string& propertyKey, TimeStepType t, bool fallBackOnDefaultContext = false);
118 
119  unsigned int GetID() const;
120  void SetID(unsigned int id);
121 
124  bool HasTimeStep(TimeStepType t) const;
125 
128  bool HasTimeSteps() const;
129 
132  std::vector<TimeStepType> GetTimeSteps() const;
133 
135  void SetMin(const Point3D& min, TimeStepType t = 0);
136 
138  void SetMax(const Point3D& max, TimeStepType t = 0);
139 
142 
146 
147  void SetProperties(PropertyList* properties, TimeStepType t = 0);
148 
149  private:
150  unsigned int m_ID;
151  PointsType m_Min;
152  PointsType m_Max;
153  PropertyList::Pointer m_DefaultProperties;
154  PropertyListsType m_Properties;
155  };
156 
158  itkFactorylessNewMacro(Self)
159  itkCloneMacro(Self)
160 
161  using ElementsType = std::map<unsigned int, Element>;
162  using Iterator = ElementsType::iterator;
163  using ConstIterator = ElementsType::const_iterator;
164 
165  size_t GetNumberOfElements() const;
166 
171  void AddElement(const Element& element);
172 
173  const Element& GetElement(unsigned int id) const;
174  Element& GetElement(unsigned int id);
175 
176  ConstIterator begin() const;
177  ConstIterator end() const;
178 
179  Iterator begin();
180  Iterator end();
181 
182  void SetRequestedRegionToLargestPossibleRegion() override;
183  bool RequestedRegionIsOutsideOfTheBufferedRegion() override;
184  bool VerifyRequestedRegion() override;
185  void SetRequestedRegion(const itk::DataObject* data) override;
186 
187  protected:
189 
190  ROI();
191  ROI(const Self& other);
192  ~ROI() override;
193 
194  private:
195  ElementsType m_Elements;
196  };
197 
198  MITKROI_EXPORT void to_json(nlohmann::json& j, const ROI::Element& roi);
199  MITKROI_EXPORT void from_json(const nlohmann::json& j, ROI::Element& roi);
200 }
201 
202 #endif
#define MITKROI_EXPORT
Base of all data objects.
Definition: mitkBaseData.h:44
Abstract base class for properties.
Key-value list holding instances of BaseProperty.
Encapsulates a single (possibly time-resolved) ROI.
Definition: mitkROI.h:66
void SetDefaultProperties(PropertyList *properties)
Point3D GetMin(TimeStepType t=0) const
bool HasTimeStep(TimeStepType t) const
Check if the ROI is defined for a certain time step.
std::vector< std::string > GetPropertyContextNames() const override
Get all property context names (stringified time steps).
void SetProperty(const std::string &propertyKey, BaseProperty *property, TimeStepType t, bool fallBackOnDefaultContext=false)
void SetID(unsigned int id)
void SetProperty(const std::string &propertyKey, BaseProperty *property, const std::string &contextName="", bool fallBackOnDefaultContext=false) override
Set a property.
PropertyList * GetProperties(TimeStepType t=0) const
Get properties for a certain time step or nullptr if absent.
void RemoveProperty(const std::string &propertyKey, TimeStepType t, bool fallBackOnDefaultContext=false)
BaseProperty * GetNonConstProperty(const std::string &propertyKey, TimeStepType t, bool fallBackOnDefaultContext=true)
std::vector< TimeStepType > GetTimeSteps() const
Get all valid time steps that have a minimum point and a maximum point.
std::vector< std::string > GetPropertyKeys(TimeStepType t, bool includeDefaultContext=false) const
std::map< TimeStepType, Point3D > PointsType
Definition: mitkROI.h:68
void SetProperties(PropertyList *properties, TimeStepType t=0)
void SetMin(const Point3D &min, TimeStepType t=0)
void SetMax(const Point3D &max, TimeStepType t=0)
std::vector< std::string > GetPropertyKeys(const std::string &contextName="", bool includeDefaultContext=false) const override
Get all property keys.
PropertyList * GetDefaultProperties() const
BaseProperty * GetNonConstProperty(const std::string &propertyKey, const std::string &contextName="", bool fallBackOnDefaultContext=true) override
Get a property.
bool HasTimeSteps() const
Check if the ROI can be considered time-resolved.
BaseProperty::ConstPointer GetConstProperty(const std::string &propertyKey, const std::string &contextName="", bool fallBackOnDefaultContext=true) const override
Get a const property.
Point3D GetMax(TimeStepType t=0) const
Element(unsigned int id)
void RemoveProperty(const std::string &propertyKey, const std::string &contextName="", bool fallBackOnDefaultContext=false) override
Remove a property.
BaseProperty::ConstPointer GetConstProperty(const std::string &propertyKey, TimeStepType t, bool fallBackOnDefaultContext=true) const
std::map< TimeStepType, PropertyList::Pointer > PropertyListsType
Definition: mitkROI.h:69
unsigned int GetID() const
A collection of region of interests (ROIs).
Definition: mitkROI.h:59
std::map< unsigned int, Element > ElementsType
Definition: mitkROI.h:161
mitkClassMacro(ROI, BaseData) static Pointer New()
ElementsType::const_iterator ConstIterator
Definition: mitkROI.h:163
ElementsType::iterator Iterator
Definition: mitkROI.h:162
#define mitkCloneMacro(classname)
Definition: mitkCommon.h:154
nlohmann::json json
Find image slices visible on a given plane.
std::size_t TimeStepType
void to_json(nlohmann::json &j, const GenericLookupTable< T > &t)
void from_json(const nlohmann::json &, GenericLookupTable< T > &)