Medical Imaging Interaction Toolkit  2026.06.00
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:
69  using PointsType = std::map<TimeStepType, Point3D>;
70 
72  using PropertyListsType = std::map<TimeStepType, PropertyList::Pointer>;
73 
76 
82  explicit Element(unsigned int id);
83 
89  Element(const Element& other);
90 
98 
99  ~Element() = default;
100 
112  BaseProperty::ConstPointer GetConstProperty(const std::string& propertyKey, const std::string& contextName = "", bool fallBackOnDefaultContext = true) const override;
113 
123  BaseProperty::ConstPointer GetConstProperty(const std::string& propertyKey, TimeStepType t, bool fallBackOnDefaultContext = true) const;
124 
134  std::vector<std::string> GetPropertyKeys(const std::string& contextName = "", bool includeDefaultContext = false) const override;
135 
144  std::vector<std::string> GetPropertyKeys(TimeStepType t, bool includeDefaultContext = false) const;
145 
148  std::vector<std::string> GetPropertyContextNames() const override;
149 
161  BaseProperty* GetNonConstProperty(const std::string& propertyKey, const std::string& contextName = "", bool fallBackOnDefaultContext = true) override;
162 
172  BaseProperty* GetNonConstProperty(const std::string& propertyKey, TimeStepType t, bool fallBackOnDefaultContext = true);
173 
185  void SetProperty(const std::string& propertyKey, BaseProperty* property, const std::string& contextName = "", bool fallBackOnDefaultContext = false) override;
186 
199  void SetProperty(const std::string& propertyKey, BaseProperty* property, TimeStepType t, bool fallBackOnDefaultContext = false);
200 
211  void RemoveProperty(const std::string& propertyKey, const std::string& contextName = "", bool fallBackOnDefaultContext = false) override;
212 
224  void RemoveProperty(const std::string& propertyKey, TimeStepType t, bool fallBackOnDefaultContext = false);
225 
231  unsigned int GetID() const;
232 
238  void SetID(unsigned int id);
239 
242  bool HasTimeStep(TimeStepType t) const;
243 
246  bool HasTimeSteps() const;
247 
250  std::vector<TimeStepType> GetTimeSteps() const;
251 
260 
267  void SetMin(const Point3D& min, TimeStepType t = 0);
268 
277 
284  void SetMax(const Point3D& max, TimeStepType t = 0);
285 
292 
300 
304 
311  void SetProperties(PropertyList* properties, TimeStepType t = 0);
312 
313  private:
314  unsigned int m_ID;
315  PointsType m_Min;
316  PointsType m_Max;
317  PropertyList::Pointer m_DefaultProperties;
318  PropertyListsType m_Properties;
319  };
320 
322  itkFactorylessNewMacro(Self)
323  itkCloneMacro(Self)
324 
326  using ElementsType = std::map<unsigned int, Element>;
327 
329  using Iterator = ElementsType::iterator;
330 
332  using ConstIterator = ElementsType::const_iterator;
333 
339  size_t GetNumberOfElements() const;
340 
347  void AddElement(const Element& element);
348 
356  const Element& GetElement(unsigned int id) const;
357 
365  Element& GetElement(unsigned int id);
366 
368  ConstIterator begin() const;
369 
371  ConstIterator end() const;
372 
374  Iterator begin();
375 
377  Iterator end();
378 
380  void SetRequestedRegionToLargestPossibleRegion() override;
381 
387  bool RequestedRegionIsOutsideOfTheBufferedRegion() override;
388 
394  bool VerifyRequestedRegion() override;
395 
401  void SetRequestedRegion(const itk::DataObject* data) override;
402 
403  protected:
405 
406  ROI();
407  ROI(const Self& other);
408  ~ROI() override;
409 
410  private:
411  ElementsType m_Elements;
412  };
413 
422  MITKROI_EXPORT void to_json(nlohmann::json& j, const ROI::Element& roi);
423 
432  MITKROI_EXPORT void from_json(const nlohmann::json& j, ROI::Element& roi);
433 }
434 
435 #endif
#define MITKROI_EXPORT
Base class of all data objects.
Definition: mitkBaseData.h:60
Abstract base class for properties.
Interface implemented by classes that provide write/read access to property information.
Key-value list holding instances of BaseProperty.
Encapsulates a single (possibly time-resolved) ROI.
Definition: mitkROI.h:66
void SetDefaultProperties(PropertyList *properties)
Set the default property list.
Element & operator=(Element other)
Copy-and-swap assignment operator.
Point3D GetMin(TimeStepType t=0) const
Get the minimum corner point of the axis-aligned bounding box.
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)
Set a property at a specific time step.
void SetID(unsigned int id)
Set the unique ID of this ROI element.
void SetProperty(const std::string &propertyKey, BaseProperty *property, const std::string &contextName="", bool fallBackOnDefaultContext=false) override
Set a property for a given context.
Element(const Element &other)
Copy constructor. Deep-copies all properties.
PropertyList * GetProperties(TimeStepType t=0) const
Get properties for a certain time step or nullptr if absent.
Element()
Default constructor. Initializes the element with ID 0.
void RemoveProperty(const std::string &propertyKey, TimeStepType t, bool fallBackOnDefaultContext=false)
Remove a property at a specific time step.
BaseProperty * GetNonConstProperty(const std::string &propertyKey, TimeStepType t, bool fallBackOnDefaultContext=true)
Get a mutable property by key and time step.
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
Get all property keys for a given time step.
std::map< TimeStepType, Point3D > PointsType
Map from time steps to 3D points (used for min/max corners).
Definition: mitkROI.h:69
void SetProperties(PropertyList *properties, TimeStepType t=0)
Set the property list for a specific time step.
void SetMin(const Point3D &min, TimeStepType t=0)
Set the minimum corner point of the axis-aligned bounding box.
void SetMax(const Point3D &max, TimeStepType t=0)
Set the maximum corner point of the axis-aligned bounding box.
std::vector< std::string > GetPropertyKeys(const std::string &contextName="", bool includeDefaultContext=false) const override
Get all property keys for a given context.
PropertyList * GetDefaultProperties() const
Get the default (time-step-independent) property list.
BaseProperty * GetNonConstProperty(const std::string &propertyKey, const std::string &contextName="", bool fallBackOnDefaultContext=true) override
Get a mutable property by key and optional context.
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 by key and optional context.
Point3D GetMax(TimeStepType t=0) const
Get the maximum corner point of the axis-aligned bounding box.
Element(unsigned int id)
Construct an element with the given unique ID.
void RemoveProperty(const std::string &propertyKey, const std::string &contextName="", bool fallBackOnDefaultContext=false) override
Remove a property from a given context.
BaseProperty::ConstPointer GetConstProperty(const std::string &propertyKey, TimeStepType t, bool fallBackOnDefaultContext=true) const
Get a const property by key and time step.
std::map< TimeStepType, PropertyList::Pointer > PropertyListsType
Map from time steps to property lists.
Definition: mitkROI.h:72
unsigned int GetID() const
Get the unique ID of this ROI element.
A collection of region of interests (ROIs).
Definition: mitkROI.h:59
std::map< unsigned int, Element > ElementsType
Map type associating element IDs to their Element objects.
Definition: mitkROI.h:326
mitkClassMacro(ROI, BaseData) static Pointer New()
ElementsType::const_iterator ConstIterator
Const iterator over ROI elements.
Definition: mitkROI.h:332
ElementsType::iterator Iterator
Mutable iterator over ROI elements.
Definition: mitkROI.h:329
#define mitkCloneMacro(classname)
Definition: mitkCommon.h:148
nlohmann::json json
Find image slices visible on a given plane.
void from_json(const nlohmann::json &, GenericLookupTable< T > &)
Deserialize a GenericLookupTable from JSON.
std::size_t TimeStepType
Type for time step indices (non-negative integers starting from 0).
void to_json(nlohmann::json &j, const GenericLookupTable< T > &t)
Serialize a GenericLookupTable to JSON.