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];
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)
121 for (
unsigned int i = 0; i < 16; ++i)
123 direction3d.s[i] = direction[i];
134 const typename ImageType::Pointer & image,
136 const bool copyImage,
137 const bool copyImageBase)
139 if (ImageType::ImageDimension > 3 || ImageType::ImageDimension < 1)
141 itkGenericExceptionMacro(
"SetKernelWithITKImage only supports 1D/2D/3D images.");
144 if (kernelManager.IsNull())
146 itkGenericExceptionMacro(
"The kernel manager is NULL.");
151 itkGenericExceptionMacro(
"The ITK image is NULL. "
152 "Unable to set ITK image information to the kernel manager.");
158 kernelManager->SetKernelArgWithImage(kernelIdx, argIdx++, image->GetGPUDataManager());
164 const unsigned int ImageDim = (
unsigned int)(ImageType::ImageDimension);
170 typename ImageType::RegionType largestPossibleRegion;
171 if (image.IsNotNull())
173 largestPossibleRegion = image->GetLargestPossibleRegion();
176 using size_type =
unsigned int;
177 size_type size[ImageType::ImageDimension];
178 for (
unsigned int i = 0; i < ImageDim; ++i)
180 if (image.IsNotNull())
182 size[i] =
static_cast<size_type
>(largestPossibleRegion.GetSize()[i]);
191 imageBase1D.
Size = size[0];
193 else if (ImageDim == 2)
195 for (
unsigned int i = 0; i < ImageDim; ++i)
197 imageBase2D.
Size.s[i] = size[i];
200 else if (ImageDim == 3)
202 for (
unsigned int i = 0; i < ImageDim; ++i)
204 imageBase3D.
Size.s[i] = size[i];
209 float spacing[ImageType::ImageDimension];
210 for (
unsigned int i = 0; i < ImageDim; ++i)
212 if (image.IsNotNull())
214 spacing[i] =
static_cast<float>(image->GetSpacing()[i]);
223 imageBase1D.
Spacing = spacing[0];
225 else if (ImageDim == 2)
227 for (
unsigned int i = 0; i < ImageDim; ++i)
229 imageBase2D.
Spacing.s[i] = spacing[i];
232 else if (ImageDim == 3)
234 for (
unsigned int i = 0; i < ImageDim; ++i)
236 imageBase3D.
Spacing.s[i] = spacing[i];
241 float origin[ImageType::ImageDimension];
242 for (
unsigned int i = 0; i < ImageDim; ++i)
244 if (image.IsNotNull())
246 origin[i] =
static_cast<float>(image->GetOrigin()[i]);
255 imageBase1D.
Origin = origin[0];
257 else if (ImageDim == 2)
259 for (
unsigned int i = 0; i < ImageDim; ++i)
261 imageBase2D.
Origin.s[i] = origin[i];
264 else if (ImageDim == 3)
266 for (
unsigned int i = 0; i < ImageDim; ++i)
268 imageBase3D.
Origin.s[i] = origin[i];
272 if (image.IsNotNull())
289 typename ImageType::DirectionType dir_null;
301 imageBase->Initialize();
302 imageBase->SetBufferFlag(CL_MEM_READ_ONLY);
307 else if (ImageDim == 2)
311 else if (ImageDim == 3)
316 imageBase->Allocate();
320 imageBase->SetCPUBufferPointer(&imageBase1D);
322 else if (ImageDim == 2)
324 imageBase->SetCPUBufferPointer(&imageBase2D);
326 else if (ImageDim == 3)
328 imageBase->SetCPUBufferPointer(&imageBase3D);
331 imageBase->SetGPUDirtyFlag(
true);
332 imageBase->UpdateGPUBuffer();
334 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)