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