Medical Imaging Interaction Toolkit  2021.02.99-c7792db0
Medical Imaging Interaction Toolkit
mitkLabelSetImage.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 __mitkLabelSetImage_H_
14 #define __mitkLabelSetImage_H_
15 
16 #include <mitkImage.h>
17 #include <mitkLabelSet.h>
18 
19 #include <MitkMultilabelExports.h>
20 
21 namespace mitk
22 {
23  //##Documentation
24  //## @brief LabelSetImage class for handling labels and layers in a segmentation session.
25  //##
26  //## Handles operations for adding, removing, erasing and editing labels and layers.
27  //## @ingroup Data
28 
30  {
31  public:
33  itkNewMacro(Self);
34 
36 
43 
50 
57  void Initialize(const mitk::Image *image) override;
58 
61  void Concatenate(mitk::LabelSetImage *image);
62 
65  void ClearBuffer();
66 
74  void MergeLabel(PixelType pixelValue, PixelType sourcePixelValue, unsigned int layer = 0);
75 
83  void MergeLabels(PixelType pixelValue, std::vector<PixelType>& vectorOfSourcePixelValues, unsigned int layer = 0);
84 
87  void UpdateCenterOfMass(PixelType pixelValue, unsigned int layer = 0);
88 
95  void RemoveLabels(std::vector<PixelType> &VectorOfLabelPixelValues, unsigned int layer = 0);
96 
104  void EraseLabel(PixelType pixelValue, unsigned int layer = 0);
105 
111  void EraseLabels(std::vector<PixelType> &VectorOfLabelPixelValues, unsigned int layer = 0);
112 
115  bool ExistLabel(PixelType pixelValue) const;
116 
123  bool ExistLabel(PixelType pixelValue, unsigned int layer) const;
124 
127  bool ExistLabelSet(unsigned int layer) const;
128 
134  mitk::Label *GetActiveLabel(unsigned int layer = 0);
135  const mitk::Label* GetActiveLabel(unsigned int layer = 0) const;
136 
143  mitk::Label *GetLabel(PixelType pixelValue, unsigned int layer = 0) const;
144 
149  mitk::LabelSet *GetActiveLabelSet();
150  const mitk::LabelSet* GetActiveLabelSet() const;
151 
157  mitk::LabelSet *GetLabelSet(unsigned int layer = 0);
158  const mitk::LabelSet *GetLabelSet(unsigned int layer = 0) const;
159 
164  unsigned int GetActiveLayer() const;
165 
171  unsigned int GetNumberOfLabels(unsigned int layer = 0) const;
172 
177  unsigned int GetTotalNumberOfLabels() const;
178 
179  // This function will need to be ported to an external class
180  // it requires knowledge of pixeltype and dimension and includes
181  // too much algorithm to be sensibly part of a data class
183  // * \brief */
184  // void SurfaceStamp(mitk::Surface* surface, bool forceOverwrite);
185 
188  mitk::Image::Pointer CreateLabelMask(PixelType index, bool useActiveLayer = true, unsigned int layer = 0);
189 
197  void InitializeByLabeledImage(mitk::Image::Pointer image);
198 
201  void MaskStamp(mitk::Image *mask, bool forceOverwrite);
202 
205  void SetActiveLayer(unsigned int layer);
206 
209  unsigned int GetNumberOfLayers() const;
210 
216  unsigned int AddLayer(mitk::LabelSet::Pointer layer = nullptr);
217 
224  unsigned int AddLayer(mitk::Image::Pointer layerImage, mitk::LabelSet::Pointer lset = nullptr);
225 
238  void AddLabelSetToLayer(const unsigned int layerIdx, const mitk::LabelSet::Pointer labelSet);
239 
244  void RemoveLayer();
245 
248  mitk::Image *GetLayerImage(unsigned int layer);
249 
250  const mitk::Image *GetLayerImage(unsigned int layer) const;
251 
252  void OnLabelSetModified();
253 
258  void SetExteriorLabel(mitk::Label *label);
259 
264  mitk::Label *GetExteriorLabel();
265 
266  const mitk::Label *GetExteriorLabel() const;
267 
268  protected:
270 
271  LabelSetImage();
272  LabelSetImage(const LabelSetImage &other);
273  ~LabelSetImage() override;
274 
275  template <typename ImageType1, typename ImageType2>
276  void ChangeLayerProcessing(ImageType1 *source, ImageType2 *target);
277 
278  template <typename TPixel, unsigned int VImageDimension>
279  void LayerContainerToImageProcessing(itk::Image<TPixel, VImageDimension> *source, unsigned int layer);
280 
281  template <typename TPixel, unsigned int VImageDimension>
282  void ImageToLayerContainerProcessing(itk::Image<TPixel, VImageDimension> *source, unsigned int layer) const;
283 
284  template <typename ImageType>
285  void CalculateCenterOfMassProcessing(ImageType *input, PixelType index, unsigned int layer);
286 
287  template <typename ImageType>
288  void ClearBufferProcessing(ImageType *input);
289 
290  template <typename ImageType>
291  void EraseLabelProcessing(ImageType *input, PixelType index, unsigned int layer);
292 
293  // template < typename ImageType >
294  // void ReorderLabelProcessing( ImageType* input, int index, int layer);
295 
296  template <typename ImageType>
297  void MergeLabelProcessing(ImageType *input, PixelType pixelValue, PixelType index);
298 
299  template <typename ImageType>
300  void ConcatenateProcessing(ImageType *input, mitk::LabelSetImage *other);
301 
302  template <typename ImageType>
303  void MaskStampProcessing(ImageType *input, mitk::Image *mask, bool forceOverwrite);
304 
305  template <typename LabelSetImageType, typename ImageType>
306  void InitializeByLabeledImageProcessing(LabelSetImageType *input, ImageType *other);
307 
308  std::vector<LabelSet::Pointer> m_LabelSetContainer;
309  std::vector<Image::Pointer> m_LayerContainer;
310 
312 
314 
316  };
317 
335  MITKMULTILABEL_EXPORT bool Equal(const mitk::LabelSetImage &leftHandSide,
336  const mitk::LabelSetImage &rightHandSide,
337  ScalarType eps,
338  bool verbose);
339 
340 } // namespace mitk
341 
342 #endif // __mitkLabelSetImage_H_
MITKCORE_EXPORT const ScalarType eps
Base of all data objects.
Definition: mitkBaseData.h:42
void Initialize() override
double ScalarType
Message BeforeChangeLayerEvent
BeforeChangeLayerEvent (e.g. used for GUI integration) As soon as active labelset should be changed...
DataCollection - Class to facilitate loading/accessing structured data.
A data structure describing a label.
Definition: mitkLabel.h:28
#define MITKMULTILABEL_EXPORT
MITKNEWMODULE_EXPORT bool Equal(mitk::ExampleDataStructure *leftHandSide, mitk::ExampleDataStructure *rightHandSide, mitk::ScalarType eps, bool verbose)
Returns true if the example data structures are considered equal.
mitk::Label::Pointer m_ExteriorLabel
std::vector< Image::Pointer > m_LayerContainer
#define mitkClassMacro(className, SuperClassName)
Definition: mitkCommon.h:40
Image class for storing images.
Definition: mitkImage.h:73
Event/message/notification class.
Definition: mitkMessage.h:452
mitk::Label::PixelType PixelType
#define mitkCloneMacro(classname)
Definition: mitkCommon.h:158
LabelSetImage class for handling labels and layers in a segmentation session.
unsigned short PixelType
Definition: mitkLabel.h:33
std::vector< LabelSet::Pointer > m_LabelSetContainer
Message AfterChangeLayerEvent
AfterchangeLayerEvent (e.g. used for GUI integration) As soon as active labelset was changed...