Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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,
6 Division of Medical and Biological Informatics.
7 All rights reserved.
8 
9 This software is distributed WITHOUT ANY WARRANTY; without
10 even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 A PARTICULAR PURPOSE.
12 
13 See LICENSE.txt or http://www.mitk.org for details.
14 
15 ===================================================================*/
16 
17 #ifndef __mitkLabelSetImage_H_
18 #define __mitkLabelSetImage_H_
19 
20 #include <mitkImage.h>
21 #include <mitkLabelSet.h>
22 
23 #include <MitkMultilabelExports.h>
24 
25 namespace mitk
26 {
27  //##Documentation
28  //## @brief LabelSetImage class for handling labels and layers in a segmentation session.
29  //##
30  //## Handles operations for adding, removing, erasing and editing labels and layers.
31  //## @ingroup Data
32 
34  {
35  public:
36  mitkClassMacro(LabelSetImage, Image) itkNewMacro(Self)
37 
39 
45  Message<> BeforeChangeLayerEvent;
46 
52  Message<> AfterChangeLayerEvent;
53 
59  using mitk::Image::Initialize;
60  virtual void Initialize(const mitk::Image *image) override;
61 
64  void Concatenate(mitk::LabelSetImage *image);
65 
68  void ClearBuffer();
69 
75  void MergeLabel(PixelType targetPixelValue, unsigned int layer = 0);
76 
83  void MergeLabels(std::vector<PixelType> &VectorOfLablePixelValues, PixelType index, 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 
142  mitk::Label *GetLabel(PixelType pixelValue, unsigned int layer = 0) const;
143 
148  mitk::LabelSet *GetActiveLabelSet();
149 
155  mitk::LabelSet *GetLabelSet(unsigned int layer = 0);
156  const mitk::LabelSet *GetLabelSet(unsigned int layer = 0) const;
157 
162  unsigned int GetActiveLayer() const;
163 
169  unsigned int GetNumberOfLabels(unsigned int layer = 0) const;
170 
175  unsigned int GetTotalNumberOfLabels() const;
176 
177  // This function will need to be ported to an external class
178  // it requires knowledge of pixeltype and dimension and includes
179  // too much algorithm to be sensibly part of a data class
181  // * \brief */
182  // void SurfaceStamp(mitk::Surface* surface, bool forceOverwrite);
183 
186  mitk::Image::Pointer CreateLabelMask(PixelType index);
187 
195  void InitializeByLabeledImage(mitk::Image::Pointer image);
196 
199  void MaskStamp(mitk::Image *mask, bool forceOverwrite);
200 
203  void SetActiveLayer(unsigned int layer);
204 
207  unsigned int GetNumberOfLayers() const;
208 
214  unsigned int AddLayer(mitk::LabelSet::Pointer layer = nullptr);
215 
222  unsigned int AddLayer(mitk::Image::Pointer layerImage, mitk::LabelSet::Pointer lset = nullptr);
223 
236  void AddLabelSetToLayer(const unsigned int layerIdx, const mitk::LabelSet::Pointer labelSet);
237 
242  void RemoveLayer();
243 
246  mitk::Image *GetLayerImage(unsigned int layer);
247 
248  const mitk::Image *GetLayerImage(unsigned int layer) const;
249 
250  void OnLabelSetModified();
251 
256  void SetExteriorLabel(mitk::Label *label);
257 
262  mitk::Label *GetExteriorLabel();
263 
264  const mitk::Label *GetExteriorLabel() const;
265 
266  protected:
268 
269  LabelSetImage();
270  LabelSetImage(const LabelSetImage &other);
271  virtual ~LabelSetImage();
272 
273  template <typename ImageType1, typename ImageType2>
274  void ChangeLayerProcessing(ImageType1 *source, ImageType2 *target);
275 
276  template <typename TPixel, unsigned int VImageDimension>
277  void LayerContainerToImageProcessing(itk::Image<TPixel, VImageDimension> *source, unsigned int layer);
278 
279  template <typename TPixel, unsigned int VImageDimension>
280  void ImageToLayerContainerProcessing(itk::Image<TPixel, VImageDimension> *source, unsigned int layer) const;
281 
282  template <typename ImageType>
283  void CalculateCenterOfMassProcessing(ImageType *input, PixelType index, unsigned int layer);
284 
285  template <typename ImageType>
286  void ClearBufferProcessing(ImageType *input);
287 
288  template <typename ImageType>
289  void EraseLabelProcessing(ImageType *input, PixelType index, unsigned int layer);
290 
291  // template < typename ImageType >
292  // void ReorderLabelProcessing( ImageType* input, int index, int layer);
293 
294  template <typename ImageType>
295  void MergeLabelProcessing(ImageType *input, PixelType pixelValue, PixelType index);
296 
297  template <typename ImageType>
298  void ConcatenateProcessing(ImageType *input, mitk::LabelSetImage *other);
299 
300  template <typename ImageType>
301  void MaskStampProcessing(ImageType *input, mitk::Image *mask, bool forceOverwrite);
302 
303  template <typename ImageType>
304  void CreateLabelMaskProcessing(ImageType *input, mitk::Image *mask, PixelType index);
305 
306  template <typename LabelSetImageType, typename ImageType>
307  void InitializeByLabeledImageProcessing(LabelSetImageType *input, ImageType *other);
308 
309  std::vector<LabelSet::Pointer> m_LabelSetContainer;
310  std::vector<Image::Pointer> m_LayerContainer;
311 
312  int m_ActiveLayer;
313 
314  bool m_activeLayerInvalid;
315 
316  mitk::Label::Pointer m_ExteriorLabel;
317  };
318 
336  MITKMULTILABEL_EXPORT bool Equal(const mitk::LabelSetImage &leftHandSide,
337  const mitk::LabelSetImage &rightHandSide,
338  ScalarType eps,
339  bool verbose);
340 
341 } // namespace mitk
342 
343 #endif // __mitkLabelSetImage_H_
Base of all data objects.
Definition: mitkBaseData.h:39
double ScalarType
STL namespace.
DataCollection - Class to facilitate loading/accessing structured data.
A data structure describing a label.
Definition: mitkLabel.h:35
#define MITKMULTILABEL_EXPORT
map::core::discrete::Elements< 3 >::InternalImageType ImageType
#define mitkClassMacro(className, SuperClassName)
Definition: mitkCommon.h:44
Image class for storing images.
Definition: mitkImage.h:76
Event/message/notification class.
Definition: mitkMessage.h:572
mitk::Label::PixelType PixelType
#define mitkCloneMacro(classname)
Definition: mitkCommon.h:162
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.
LabelSetImage class for handling labels and layers in a segmentation session.
MITKCORE_EXPORT const ScalarType eps