26#ifndef __itkGPUKernelManagerHelperFunctions_h
27#define __itkGPUKernelManagerHelperFunctions_h
72template<
typename ImageType >
75 cl_float & direction1d,
76 cl_float4 & direction2d,
77 cl_float16 & direction3d )
79 const unsigned int ImageDim = (
unsigned int)( ImageType::ImageDimension );
83 float direction = 0.0f;
84 direction =
static_cast< float >( dir[ 0 ][ 0 ] );
85 direction1d = direction;
87 else if( ImageDim == 2 )
90 unsigned int index = 0;
91 for(
unsigned int i = 0; i < ImageDim; i++ )
93 for(
unsigned int j = 0; j < ImageDim; j++ )
95 direction[ index ] =
static_cast< float >( dir[ i ][ j ] );
99 for(
unsigned int i = 0; i < 4; i++ )
101 direction2d.s[ i ] = direction[ i ];
107 float direction[ 16 ];
108 unsigned int index = 0;
109 for(
unsigned int i = 0; i < ImageDim; i++ )
111 for(
unsigned int j = 0; j < ImageDim; j++ )
113 direction[ index ] =
static_cast< float >( dir[ i ][ j ] );
117 for(
unsigned int i = 9; i < 16; i++ )
119 direction[ i ] = 0.0f;
121 for(
unsigned int i = 0; i < 16; i++ )
123 direction3d.s[ i ] = direction[ i ];
129template<
typename ImageType >
132 const int kernelIdx, cl_uint & argIdx,
133 const typename ImageType::Pointer & image,
135 const bool copyImage,
136 const bool copyImageBase )
138 if( ImageType::ImageDimension > 3 || ImageType::ImageDimension < 1 )
140 itkGenericExceptionMacro(
"SetKernelWithITKImage only supports 1D/2D/3D images." );
143 if( kernelManager.IsNull() )
145 itkGenericExceptionMacro( <<
"The kernel manager is NULL." );
151 itkGenericExceptionMacro( <<
"The ITK image is NULL. "
152 "Unable to set ITK image information to the kernel manager." );
159 kernelManager->SetKernelArgWithImage( kernelIdx, argIdx++, image->GetGPUDataManager() );
165 const unsigned int ImageDim = (
unsigned int)( ImageType::ImageDimension );
171 typename ImageType::RegionType largestPossibleRegion;
172 if( image.IsNotNull() )
174 largestPossibleRegion = image->GetLargestPossibleRegion();
177 typedef unsigned int size_type;
178 size_type size[ ImageType::ImageDimension ];
179 for(
unsigned int i = 0; i < ImageDim; i++ )
181 if( image.IsNotNull() )
183 size[ i ] =
static_cast< size_type
>( largestPossibleRegion.GetSize()[ i ] );
192 imageBase1D.
Size = size[ 0 ];
194 else if( ImageDim == 2 )
196 for(
unsigned int i = 0; i < ImageDim; i++ )
198 imageBase2D.
Size.s[ i ] = size[ i ];
201 else if( ImageDim == 3 )
203 for(
unsigned int i = 0; i < ImageDim; i++ )
205 imageBase3D.
Size.s[ i ] = size[ i ];
210 float spacing[ ImageType::ImageDimension ];
211 for(
unsigned int i = 0; i < ImageDim; i++ )
213 if( image.IsNotNull() )
215 spacing[ i ] =
static_cast< float >( image->GetSpacing()[ i ] );
224 imageBase1D.
Spacing = spacing[ 0 ];
226 else if( ImageDim == 2 )
228 for(
unsigned int i = 0; i < ImageDim; i++ )
230 imageBase2D.
Spacing.s[ i ] = spacing[ i ];
233 else if( ImageDim == 3 )
235 for(
unsigned int i = 0; i < ImageDim; i++ )
237 imageBase3D.
Spacing.s[ i ] = spacing[ i ];
242 float origin[ ImageType::ImageDimension ];
243 for(
unsigned int i = 0; i < ImageDim; i++ )
245 if( image.IsNotNull() )
247 origin[ i ] =
static_cast< float >( image->GetOrigin()[ i ] );
256 imageBase1D.
Origin = origin[ 0 ];
258 else if( ImageDim == 2 )
260 for(
unsigned int i = 0; i < ImageDim; i++ )
262 imageBase2D.
Origin.s[ i ] = origin[ i ];
265 else if( ImageDim == 3 )
267 for(
unsigned int i = 0; i < ImageDim; i++ )
269 imageBase3D.
Origin.s[ i ] = origin[ i ];
273 if( image.IsNotNull() )
275 SetKernelWithDirection< ImageType >( image->GetDirection(),
280 SetKernelWithDirection< ImageType >( image->GetIndexToPhysicalPoint(),
285 SetKernelWithDirection< ImageType >( image->GetPhysicalPointToIndex(),
292 typename ImageType::DirectionType dir_null;
294 SetKernelWithDirection< ImageType >( dir_null,
299 SetKernelWithDirection< ImageType >( dir_null,
304 SetKernelWithDirection< ImageType >( dir_null,
311 imageBase->Initialize();
312 imageBase->SetBufferFlag( CL_MEM_READ_ONLY );
317 else if( ImageDim == 2 )
321 else if( ImageDim == 3 )
326 imageBase->Allocate();
330 imageBase->SetCPUBufferPointer( &imageBase1D );
332 else if( ImageDim == 2 )
334 imageBase->SetCPUBufferPointer( &imageBase2D );
336 else if( ImageDim == 3 )
338 imageBase->SetCPUBufferPointer( &imageBase3D );
341 imageBase->SetGPUDirtyFlag(
true );
342 imageBase->UpdateGPUBuffer();
344 kernelManager->SetKernelArgWithImage( kernelIdx, argIdx++, imageBase );
void SetKernelWithITKImage(OpenCLKernelManager::Pointer &kernelManager, const int kernelIdx, cl_uint &argIdx, const typename ImageType::Pointer &image, typename GPUDataManager::Pointer &imageBase, const bool copyImage, const bool copyImageBase)
void SetKernelWithDirection(const typename ImageType::DirectionType &dir, cl_float &direction1d, cl_float4 &direction2d, cl_float16 &direction3d)
cl_float IndexToPhysicalPoint
cl_float PhysicalPointToIndex
cl_float4 IndexToPhysicalPoint
cl_float4 PhysicalPointToIndex
cl_float16 IndexToPhysicalPoint
cl_float16 PhysicalPointToIndex