Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
mitkLegacyAdaptors.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 "mitkLegacyAdaptors.h"
17 #include <mitkImageWriteAccessor.h>
18 
20  mitk::ImageWriteAccessor *imageAccess,
21  mitkIpPicDescriptor *picDesc)
22 {
23  const mitk::ImageDescriptor::Pointer imDesc = refImg->GetImageDescriptor();
24 
25  // initialize dimension information
26  for (unsigned int i = 0; i < 8; i++)
27  {
28  picDesc->n[i] = 1;
29  }
30 
31  // set dimension information
32  picDesc->dim = refImg->GetDimension();
33  memcpy(picDesc->n, imDesc->GetDimensions(), picDesc->dim * sizeof(unsigned int));
34 
35  picDesc->type = CastToIpPicType(refImg->GetPixelType().GetComponentType());
36  picDesc->bpe = refImg->GetPixelType().GetBpe();
37  if (imageAccess != nullptr)
38  {
39  picDesc->data = imageAccess->GetData();
40  }
41 
42  return picDesc;
43 }
44 
46  mitk::ImageWriteAccessor *imageAccess,
47  mitkIpPicDescriptor *picDesc)
48 {
49  // initialize dimension information
50  for (unsigned int i = 0; i < 8; i++)
51  {
52  picDesc->n[i] = 1;
53  }
54 
55  // get the dimensionality information from image item
56  picDesc->dim = refItem->GetDimension();
57  for (unsigned int i = 0; i < picDesc->dim; i++)
58  {
59  picDesc->n[i] = refItem->GetDimension(i);
60  }
61 
62  picDesc->type = CastToIpPicType(refItem->GetPixelType().GetComponentType());
63  picDesc->bpe = refItem->GetPixelType().GetBpe();
64  if (imageAccess != nullptr)
65  {
66  picDesc->data = imageAccess->GetData();
67  }
68 
69  return picDesc;
70 }
71 
73 {
74  const mitk::ImageDescriptor::Pointer imDesc = refImg->GetImageDescriptor();
75 
76  // initialize dimension information
77  for (unsigned int i = 0; i < 8; i++)
78  {
79  picDesc->n[i] = 1;
80  }
81 
82  // set dimension information
83  picDesc->dim = refImg->GetDimension();
84  memcpy(picDesc->n, imDesc->GetDimensions(), picDesc->dim * sizeof(unsigned int));
85 
86  picDesc->type = CastToIpPicType(refImg->GetPixelType().GetComponentType());
87  picDesc->bpe = refImg->GetPixelType().GetBpe();
88  mitk::ImageWriteAccessor imAccess(refImg);
89  picDesc->data = imAccess.GetData();
90 
91  return picDesc;
92 }
93 
95  mitkIpPicDescriptor *picDesc)
96 {
97  // initialize dimension information
98  for (unsigned int i = 0; i < 8; i++)
99  {
100  picDesc->n[i] = 1;
101  }
102 
103  // get the dimensionality information from image item
104  picDesc->dim = refItem->GetDimension();
105  for (unsigned int i = 0; i < picDesc->dim; i++)
106  {
107  picDesc->n[i] = refItem->GetDimension(i);
108  }
109 
110  picDesc->type = CastToIpPicType(refItem->GetPixelType().GetComponentType());
111  picDesc->bpe = refItem->GetPixelType().GetBpe();
112  picDesc->data = refItem->GetData();
113 
114  return picDesc;
115 }
116 
118 {
120 
121  imDescriptor->Initialize(desc->n, desc->dim);
122 
123  mitk::PixelType ptype = CastToPixelType(desc->type, (desc->bpe / 8));
124  imDescriptor->AddNewChannel(ptype, "imported by pic");
125 
126  return imDescriptor;
127 }
128 
130 {
131  // const std::type_info& intype = ptype.GetTypeId();
132 
133  // MITK_INFO << "Casting to PicType from " << intype.name() << std::endl;
134 
135  const bool isSignedIntegralType = (intype == itk::ImageIOBase::INT || intype == itk::ImageIOBase::SHORT ||
136  intype == itk::ImageIOBase::CHAR || intype == itk::ImageIOBase::LONG);
137 
138  const bool isUnsignedIntegralType = (intype == itk::ImageIOBase::UINT || intype == itk::ImageIOBase::USHORT ||
139  intype == itk::ImageIOBase::UCHAR || intype == itk::ImageIOBase::ULONG);
140 
141  const bool isFloatingPointType = (intype == itk::ImageIOBase::FLOAT || intype == itk::ImageIOBase::DOUBLE);
142 
143  if (isSignedIntegralType)
144  return mitkIpPicInt;
145  if (isUnsignedIntegralType)
146  return mitkIpPicUInt;
147  if (isFloatingPointType)
148  return mitkIpPicFloat;
149  return mitkIpPicUnknown;
150 }
151 
153 {
154  const bool isSignedIntegralType = (pictype == mitkIpPicInt);
155  const bool isUnsignedIntegralType = (pictype == mitkIpPicUInt);
156 
157  if (isSignedIntegralType)
158  {
159  switch (bpe)
160  {
161  case sizeof(char):
162  return MakeScalarPixelType<char>();
163  case sizeof(short):
164  return MakeScalarPixelType<short>();
165  default:
166  return MakeScalarPixelType<int>();
167  }
168  }
169  else if (isUnsignedIntegralType)
170  {
171  switch (bpe)
172  {
173  case sizeof(unsigned char):
174  return MakeScalarPixelType<unsigned char>();
175  case sizeof(unsigned short):
176  return MakeScalarPixelType<unsigned short>();
177  default:
178  return MakeScalarPixelType<unsigned int>();
179  }
180  }
181  else // is floating point type
182  {
183  switch (bpe)
184  {
185  case sizeof(float):
186  return MakeScalarPixelType<float>();
187  default:
188  return MakeScalarPixelType<double>();
189  }
190  }
191 }
MITKLEGACYADAPTORS_EXPORT mitk::ImageDescriptor::Pointer CastToImageDescriptor(mitkIpPicDescriptor *desc)
Constructs an ImageDescriptor from legacy mitkIpPicDescriptor.
void * GetData()
Gives full data access.
MITKLEGACYADAPTORS_EXPORT PixelType CastToPixelType(mitkIpPicType_t pictype, vcl_size_t bpe)
Returns a mitk::PixelType object corresponding to given mitkIpPicType_t.
mitkIpPicType_t
Definition: mitkIpPic.h:733
mitkIpUInt4_t n[8]
Definition: mitkIpPic.h:792
MITKLEGACYADAPTORS_EXPORT mitkIpPicType_t CastToIpPicType(int componentType)
Constructs a legacy type information from mitk::PixelType.
static Pointer New()
mitkIpPicType_t type
Definition: mitkIpPic.h:789
MITKLEGACYADAPTORS_EXPORT mitkIpPicDescriptor * CastToIpPicDescriptor(mitk::Image::Pointer, mitk::ImageWriteAccessor *, mitkIpPicDescriptor *picDesc)
Constructs a legacy mitkIpPicDescriptor from mitk::Image.
mitkIpUInt4_t dim
Definition: mitkIpPic.h:791
ImageWriteAccessor class to get locked write-access for a particular image part.
mitkIpUInt4_t bpe
Definition: mitkIpPic.h:790
Class for defining the data type of pixels.
Definition: mitkPixelType.h:55