Medical Imaging Interaction Toolkit  2016.11.0
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,
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 
18 #include <mitkImageAccessByItk.h>
19 #include <sstream>
20 
21 namespace mitk
22 {
23  // The output operator for RGBA in ITK does not properly cast to printable type,
24  // like the RGB pixel output operator. This here is an indirection to fix this until
25  // ITK-3501 is fixed.
26  template <typename TComponent>
27  std::ostream &operator<<(std::ostream &os, const itk::RGBPixel<TComponent> &c)
28  {
29  return itk::operator<<(os, c);
30  }
31 
32  template <typename TComponent>
33  std::ostream &operator<<(std::ostream &os, const itk::RGBAPixel<TComponent> &c)
34  {
35  os << static_cast<typename itk::NumericTraits<TComponent>::PrintType>(c[0]) << " ";
36  os << static_cast<typename itk::NumericTraits<TComponent>::PrintType>(c[1]) << " ";
37  os << static_cast<typename itk::NumericTraits<TComponent>::PrintType>(c[2]) << " ";
38  os << static_cast<typename itk::NumericTraits<TComponent>::PrintType>(c[3]);
39  return os;
40  }
41 
42  template <typename TPixel, unsigned int VImageDimension>
43  static void ConvertCompositePixelValueToString(itk::Image<TPixel, VImageDimension> *image,
44  itk::Index<3> index3,
45  std::string &string)
46  {
48  for (unsigned int i = 0; i < VImageDimension; ++i)
49  index[i] = index3[i];
50 
51  if (image->GetLargestPossibleRegion().IsInside(index))
52  {
53  std::ostringstream stream;
54  mitk::operator<<(stream, image->GetPixel(index));
55 
56  string = stream.str();
57  }
58  else
59  {
60  string = "Out of bounds";
61  }
62  }
63 }
64 
66 {
67  std::string string;
68 
69  if (image.IsNull())
70  {
71  mitkThrow() << "Image is null.";
72  }
73 
76 
77  return string;
78 }
MITKCORE_EXPORT std::ostream & operator<<(std::ostream &o, DataNode::Pointer &dtn)
#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.
static void ConvertCompositePixelValueToString(itk::Image< TPixel, VImageDimension > *image, itk::Index< 3 > index3, std::string &string)
std::string MITKCORE_EXPORT ConvertCompositePixelValueToString(Image::Pointer image, itk::Index< 3 > index)
Converts composite pixel values to a displayable string.
#define mitkThrow()
MITKDIFFUSIONCORE_EXPORT OutputStreamType & operator<<(OutputStreamType &os, const OrientationDistributionFunction< TComponent, NOdfDirections > &c)
#define MITK_ACCESSBYITK_COMPOSITE_PIXEL_TYPES_SEQ
Definition: mitkConfig.h:23