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
mitkImageDescriptor.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 #include "mitkImageDescriptor.h"
17 
19 {
20  // initialize the dimensions array
21  for (auto &elem : m_Dimensions)
22  {
23  elem = 1;
24  }
25 
26  this->m_NumberOfChannels = 0;
27 }
28 
29 // FIXME manage memory flag
31 {
32  size_t elems = 1;
33 
34  for (unsigned int i = 0; i < this->m_NumberOfDimensions; i++)
35  elems *= this->m_Dimensions[i];
36 
37  mitk::ChannelDescriptor desc(ptype, elems);
38 
39  this->m_ChannelDesc.push_back(desc);
40 
41  if (name == nullptr)
42  m_ChannelNames.push_back("Unnamed [" + ptype.GetPixelTypeAsString() + "]");
43  else
44  m_ChannelNames.push_back(name);
45 
46  this->m_NumberOfChannels++;
47 
48  return;
49 }
50 
51 void mitk::ImageDescriptor::Initialize(const ImageDescriptor::Pointer refDescriptor, unsigned int channel)
52 {
53  // initialize the members holding dimension information
54  this->m_NumberOfChannels = refDescriptor->GetNumberOfChannels();
55  this->m_NumberOfDimensions = refDescriptor->GetNumberOfDimensions();
56  const unsigned int *refDims = refDescriptor->GetDimensions();
57 
58  // copy the dimension information
59  for (unsigned int i = 0; i < this->m_NumberOfDimensions; i++)
60  {
61  this->m_Dimensions[i] = refDims[i];
62  }
63 
64  // get the channel descriptor and store them and so the name of the channel
65  mitk::ChannelDescriptor desc = refDescriptor->GetChannelDescriptor(channel);
66  this->m_ChannelDesc.push_back(desc);
67  this->m_ChannelNames.push_back(refDescriptor->GetChannelName(channel));
68 }
69 
70 void mitk::ImageDescriptor::Initialize(const unsigned int *dims, const unsigned int dim)
71 {
72  this->m_NumberOfDimensions = dim;
73 
74  // copy the dimension information
75  for (unsigned int i = 0; i < this->m_NumberOfDimensions; i++)
76  {
77  this->m_Dimensions[i] = dims[i];
78  }
79 }
80 
82 {
83  return this->m_ChannelDesc[id];
84 }
85 
87 {
88  unsigned int idFound = 0;
89  const std::string search_str(name);
90 
91  for (auto iter = this->m_ChannelNames.begin(); iter < this->m_ChannelNames.end(); iter++)
92  {
93  if (search_str.compare(*iter))
94  idFound = iter - this->m_ChannelNames.begin();
95  }
96 
97  return (m_ChannelDesc[idFound]).GetPixelType();
98 }
99 
101 {
102  if (id > this->m_NumberOfChannels)
103  {
104  throw std::invalid_argument("The given id exceeds the number of active channel.");
105  }
106  else
107  {
108  mitk::ChannelDescriptor refDesc = this->m_ChannelDesc[id];
109  return refDesc.GetPixelType(); //
110  }
111 }
112 
113 const std::string mitk::ImageDescriptor::GetChannelName(unsigned int id) const
114 {
115  if (id > this->m_ChannelNames.size())
116  return "Out-of-range-access";
117  else
118  return this->m_ChannelNames.at(id);
119 }
std::string GetPixelTypeAsString() const
Returns a string containing the ITK pixel type name.
An object which holds all essential information about a single channel of an Image.
void Initialize(const unsigned int *dims, const unsigned int dim)
Initialize the image descriptor by the dimensions.
PixelType GetPixelType() const
Get the type of channel's elements.
const std::string GetChannelName(unsigned int id) const
Get the name of selected channel.
PixelType GetChannelTypeByName(const char *name) const
Get the pixel type of a channel specified by its name.
PixelType GetChannelTypeById(unsigned int id) const
Get the pixel type of a channel specified by its id.
ChannelDescriptor GetChannelDescriptor(unsigned int id=0) const
Get the ChannelDescriptor for a channel specified by its id.
void AddNewChannel(mitk::PixelType ptype, const char *name=nullptr)
Class for defining the data type of pixels.
Definition: mitkPixelType.h:55