Medical Imaging Interaction Toolkit  2018.4.99-389bf124
Medical Imaging Interaction Toolkit
mitkCompositePixelValueToString.cpp
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 
14 #include <mitkImageAccessByItk.h>
15 #include <sstream>
16 
17 namespace mitk
18 {
19  // The output operator for RGBA in ITK does not properly cast to printable type,
20  // like the RGB pixel output operator. This here is an indirection to fix this until
21  // ITK-3501 is fixed.
22  template <typename TComponent>
23  std::ostream &operator<<(std::ostream &os, const itk::RGBPixel<TComponent> &c)
24  {
25  return itk::operator<<(os, c);
26  }
27 
28  template <typename TComponent>
29  std::ostream &operator<<(std::ostream &os, const itk::RGBAPixel<TComponent> &c)
30  {
31  os << static_cast<typename itk::NumericTraits<TComponent>::PrintType>(c[0]) << " ";
32  os << static_cast<typename itk::NumericTraits<TComponent>::PrintType>(c[1]) << " ";
33  os << static_cast<typename itk::NumericTraits<TComponent>::PrintType>(c[2]) << " ";
34  os << static_cast<typename itk::NumericTraits<TComponent>::PrintType>(c[3]);
35  return os;
36  }
37 
38  template <typename TPixel, unsigned int VImageDimension>
39  static void ConvertCompositePixelValueToString(itk::Image<TPixel, VImageDimension> *image,
40  itk::Index<3> index3,
41  std::string &string)
42  {
44  for (unsigned int i = 0; i < VImageDimension; ++i)
45  index[i] = index3[i];
46 
47  if (image->GetLargestPossibleRegion().IsInside(index))
48  {
49  std::ostringstream stream;
50  mitk::operator<<(stream, image->GetPixel(index));
51 
52  string = stream.str();
53  }
54  else
55  {
56  string = "Out of bounds";
57  }
58  }
59 }
60 
62 {
63  std::string string;
64 
65  if (image.IsNull())
66  {
67  mitkThrow() << "Image is null.";
68  }
69 
72 
73  return string;
74 }
#define AccessFixedPixelTypeByItk_n(mitkImage, itkImageTypeFunction, pixelTypeSeq, va_tuple)
Access a mitk-image with known pixeltype (but unknown dimension) by an itk-image with one or more par...
DataCollection - Class to facilitate loading/accessing structured data.
std::string MITKCORE_EXPORT ConvertCompositePixelValueToString(Image::Pointer image, itk::Index< 3 > index)
Converts composite pixel values to a displayable string.
std::ostream & operator<<(std::ostream &os, const itk::RGBAPixel< TComponent > &c)
#define mitkThrow()
mitk::Image::Pointer image
MITKCORE_EXPORT std::ostream & operator<<(std::ostream &o, DataNode::Pointer &dtn)
#define MITK_ACCESSBYITK_COMPOSITE_PIXEL_TYPES_SEQ
Definition: mitkConfig.h:24