1
/*=========================================================================
3
* Copyright Insight Software Consortium
5
* Licensed under the Apache License, Version 2.0 (the "License");
6
* you may not use this file except in compliance with the License.
7
* You may obtain a copy of the License at
9
* http://www.apache.org/licenses/LICENSE-2.0.txt
11
* Unless required by applicable law or agreed to in writing, software
12
* distributed under the License is distributed on an "AS IS" BASIS,
13
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
* See the License for the specific language governing permissions and
15
* limitations under the License.
17
*=========================================================================*/
21
#include "sitkImage.h"
24
#include "itkVectorImage.h"
25
#include "itkLabelMap.h"
26
#include "itkLabelObject.h"
28
#include "sitkExceptionObject.h"
29
#include "sitkPimpleImageBase.hxx"
30
#include "sitkPixelIDTypeLists.h"
38
// this is a little specialization just to get the
39
// InternalInitialization method's PixelIDTpImageType lookup to get
40
// a valid void type, so it'll dispatch to the a specialized
41
// method. All this is just to instantiate something that will never
43
template <unsigned int VImageDimension>
44
struct PixelIDToImageType< typelist::NullType , VImageDimension >
46
typedef void ImageType;
49
// This method is explicitly instantiated, and in-turn implicitly
50
// instantates the PipleImage for all used image types. This method
51
// just dispatces to nother method, to aid in instantiating only the
53
template <int VPixelIDValue, unsigned int VImageDimension>
54
void Image::InternalInitialization( typename PixelIDToImageType<typename typelist::TypeAt<InstantiatedPixelIDTypeList,
55
VPixelIDValue>::Result,
56
VImageDimension>::ImageType *i )
58
this->ConditionalInternalInitialization<VPixelIDValue>( i );
61
template<int VPixelIDValue, typename TImageType>
62
typename DisableIf<nsstd::is_same<TImageType, void>::value>::Type
63
Image::ConditionalInternalInitialization( TImageType *image )
65
// no need to check if null
66
delete this->m_PimpleImage;
67
this->m_PimpleImage = NULL;
69
this->m_PimpleImage = new PimpleImage<TImageType>( image );
73
template<class TImageType>
74
typename EnableIf<IsBasic<TImageType>::Value>::Type
75
Image::AllocateInternal ( unsigned int Width, unsigned int Height, unsigned int Depth, unsigned int dim4, unsigned int numberOfComponents )
77
if ( numberOfComponents != 1 && numberOfComponents != 0 )
79
sitkExceptionMacro( "Specified number of components as " << numberOfComponents
80
<< " but did not specify pixelID as a vector type!" );
83
typename TImageType::IndexType index;
84
typename TImageType::SizeType size;
85
typename TImageType::RegionType region;
92
if ( TImageType::ImageDimension > 2 )
98
if ( TImageType::ImageDimension > 3 )
104
region.SetSize ( size );
105
region.SetIndex ( index );
107
typename TImageType::Pointer image = TImageType::New();
108
image->SetRegions ( region );
110
image->FillBuffer ( itk::NumericTraits<typename TImageType::PixelType>::Zero );
112
delete this->m_PimpleImage;
113
this->m_PimpleImage = NULL;
114
m_PimpleImage = new PimpleImage<TImageType>( image );
117
template<class TImageType>
118
typename EnableIf<IsVector<TImageType>::Value>::Type
119
Image::AllocateInternal ( unsigned int Width, unsigned int Height, unsigned int Depth, unsigned int dim4, unsigned int numberOfComponents )
121
if ( numberOfComponents == 0 )
123
numberOfComponents = TImageType::ImageDimension;
126
typename TImageType::IndexType index;
127
typename TImageType::SizeType size;
128
typename TImageType::RegionType region;
129
typename TImageType::PixelType zero;
136
if ( TImageType::ImageDimension > 2 )
138
assert( Depth != 0 );
142
if ( TImageType::ImageDimension > 3 )
148
region.SetSize ( size );
149
region.SetIndex ( index );
151
zero.SetSize( numberOfComponents );
152
zero.Fill ( itk::NumericTraits<typename TImageType::PixelType::ValueType>::Zero );
154
typename TImageType::Pointer image = TImageType::New();
155
image->SetRegions ( region );
156
image->SetVectorLength( numberOfComponents );
158
image->FillBuffer ( zero );
160
delete this->m_PimpleImage;
161
this->m_PimpleImage = NULL;
163
m_PimpleImage = new PimpleImage<TImageType>( image );
166
template<class TImageType>
167
typename EnableIf<IsLabel<TImageType>::Value>::Type
168
Image::AllocateInternal ( unsigned int Width, unsigned int Height, unsigned int Depth, unsigned int dim4, unsigned int numberOfComponents )
170
if ( numberOfComponents != 1 && numberOfComponents != 0 )
172
sitkExceptionMacro( "Specified number of components as " << numberOfComponents
173
<< " but did not specify pixelID as a vector type!" );
176
typename TImageType::IndexType index;
177
typename TImageType::SizeType size;
178
typename TImageType::RegionType region;
185
if ( TImageType::ImageDimension > 2 )
187
assert( Depth != 0 );
191
if ( TImageType::ImageDimension > 3 )
197
region.SetSize ( size );
198
region.SetIndex ( index );
200
typename TImageType::Pointer image = TImageType::New();
201
image->SetRegions ( region );
203
image->SetBackgroundValue( 0 );
205
delete this->m_PimpleImage;
206
this->m_PimpleImage = NULL;
208
m_PimpleImage = new PimpleImage<TImageType>( image );
214
#endif // sitkImage_h