Medical Imaging Interaction Toolkit  2018.4.99-c4b6bb11
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 
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, bool useActiveLayer = true, unsigned int layer = 0);
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  ~LabelSetImage() override;
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 LabelSetImageType, typename ImageType>
304  void InitializeByLabeledImageProcessing(LabelSetImageType *input, ImageType *other);
305 
306  std::vector<LabelSet::Pointer> m_LabelSetContainer;
307  std::vector<Image::Pointer> m_LayerContainer;
308 
310 
312 
314  };
315 
333  MITKMULTILABEL_EXPORT bool Equal(const mitk::LabelSetImage &leftHandSide,
334  const mitk::LabelSetImage &rightHandSide,
335  ScalarType eps,
336  bool verbose);
337 
338 } // namespace mitk
339 
340 #endif // __mitkLabelSetImage_H_
Base of all data objects.
Definition: mitkBaseData.h:42
itk::Image< unsigned char, 3 > ImageType
void Initialize() override
Definition: mitkImage.cpp:803
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:31
#define MITKMULTILABEL_EXPORT
mitk::Label::Pointer m_ExteriorLabel
std::vector< Image::Pointer > m_LayerContainer
#define mitkClassMacro(className, SuperClassName)
Definition: mitkCommon.h:40
bool verbose(false)
Image class for storing images.
Definition: mitkImage.h:72
Event/message/notification class.
Definition: mitkMessage.h:568
mitk::Label::PixelType PixelType
mitk::Image::Pointer image
#define mitkCloneMacro(classname)
Definition: mitkCommon.h:158
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.
itk::SmartPointer< Self > Pointer
MITKCORE_EXPORT const ScalarType eps
unsigned short PixelType
Definition: mitkLabel.h:36
mitk::Image::Pointer mask
std::vector< LabelSet::Pointer > m_LabelSetContainer
Message AfterChangeLayerEvent
AfterchangeLayerEvent (e.g. used for GUI integration) As soon as active labelset was changed...