[Rtk-users] cast itk:::Image to itk::CudaImage
tao sun
colddiesun at gmail.com
Wed Jan 30 11:45:58 EST 2019
Here it is the piece of codes:
typedef float PixelType;
const unsigned int Dimension = 3;
typedef itk::CudaImage< PixelType, Dimension > CudaImageType;
typedef itk::Image< PixelType, Dimension > ImageType;
typedef itk::ImportImageFilter <PixelType, Dimension> ImportFilterType;
extern "C" int idlrtkbackprojection_gpu(int argc, float * argv[])
{
volume = (float *) argv[0];
projection = (float *) argv[1];
debug = *(unsigned int*) argv[2];
gpu = *(unsigned int*) argv[3];
bp_arg = *(unsigned int*) argv[4];
//string((*(idls *) argv[4]).s);
geometry = std::string((*(idls *) argv[5]).s);
sizexv = *(unsigned int*) argv[6];
sizeyv = *(unsigned int*) argv[7];
sizezv = *(unsigned int*) argv[8];
spacingxv = *(float *) argv[9];
spacingyv = *(float *) argv[10];
spacingzv = *(float *) argv[11];
offsetxv = *(float *) argv[12];
offsetyv = *(float *) argv[13];
offsetzv = *(float *) argv[14];
sizexp = *(unsigned int*) argv[15];
sizeyp = *(unsigned int*) argv[16];
sizezp = *(unsigned int*) argv[17];
spacingxp = *(float *) argv[18];
spacingyp = *(float *) argv[19];
spacingzp = *(float *) argv[20];
offsetxp = *(float *) argv[21];
offsetyp = *(float *) argv[22];
offsetzp = *(float *) argv[23];
// Geometry
rtk::ThreeDCircularProjectionGeometryXMLFileReader::Pointer
geometryReader;
geometryReader =
rtk::ThreeDCircularProjectionGeometryXMLFileReader::New();
geometryReader->SetFilename(geometry);
TRY_AND_EXIT_ON_ITK_EXCEPTION(
geometryReader->GenerateOutputInformation() )
// Volume reader
ImportFilterType::Pointer volumeReader = ImportFilterType::New();
ImageType::SizeType sizev;// = {{sizexv,sizeyv,sizezv}};
sizev[0] = sizexv; //406; //int(dim[0]);
sizev[1] = sizeyv; //408; //int(dim[1]);
sizev[2] = sizezv;
ImageType::IndexType start;// = {{0,0,0}};
start[0] = 0;
start[1] = 0;
start[2] = 0;
ImageType::RegionType regionv;
regionv.SetSize(sizev);
regionv.SetIndex(start);
volumeReader->SetRegion(regionv);
double spacingv[3];
spacingv[0] = spacingxv;
spacingv[1] = spacingyv;
spacingv[2] = spacingzv;
volumeReader->SetSpacing(spacingv);
double originv[3];
originv[0] = offsetxv;
originv[1] = offsetyv;
originv[2] = offsetzv;
volumeReader->SetOrigin(originv);
// Projections reader
ImportFilterType::Pointer projectionReader = ImportFilterType::New();
ImageType::SizeType sizep;
sizep[0] = sizexp; //406; //int(dim[0]);
sizep[1] = sizeyp; //408; //int(dim[1]);
sizep[2] = sizezp;
ImageType::RegionType regionp;
regionp.SetSize(sizep);
regionp.SetIndex(start);
projectionReader->SetRegion(regionp);
double spacingp[3];
spacingp[0] = spacingxp;
spacingp[1] = spacingyp;
spacingp[2] = spacingzp;
projectionReader->SetSpacing(spacingp);
double originp[3];
originp[0] = offsetxp;
originp[1] = offsetyp;
originp[2] = offsetzp;
projectionReader->SetOrigin(originp);
// Create backprojection image filter
rtk::CudaFDKBackProjectionImageFilter::Pointer bp;
bp = rtk::CudaFDKBackProjectionImageFilter::New();
// where error was thrown out
CudaImageType::Pointer cuImg1 = CudaImageType::New();
cuImg1->Graft(projectionReader->GetOutput());
CudaImageType::Pointer cuImg2 = CudaImageType::New();
cuImg2->Graft(volumeReader->GetOutput());
bp->SetInput( cuImg2 );
bp->SetInput( 1, cuImg1 );
bp->SetGeometry( geometryReader->GetOutputObject() );
TRY_AND_EXIT_ON_ITK_EXCEPTION( bp->Update() )
Thanks,
Tao
Simon Rit <simon.rit at creatis.insa-lyon.fr> 於 2019年1月30日 週三 上午11:29寫道:
> Can you send the code if you want us to help?
>
> On Wed, Jan 30, 2019 at 5:21 PM tao sun <colddiesun at gmail.com> wrote:
>
>> No I am not using that. But the error was thrown before GRAFT() function
>> was called. It happens when I initialized the backprojector:
>> bp = rtk::CudaRayCastBackProjectionImageFilter::New().
>>
>> Tao
>>
>> Simon Rit <simon.rit at creatis.insa-lyon.fr> 於 2019年1月30日 週三 上午11:13寫道:
>>
>>> Are you using the HEAD version of the git ? Because I recently corrected
>>> a bug in the Graft function (commit
>>> b2d73642ce171ba9890af2c107a1a31f923454b5).
>>> Simon
>>>
>>> On Wed, Jan 30, 2019 at 5:05 PM tao sun <colddiesun at gmail.com> wrote:
>>>
>>>> Hi Simon,
>>>>
>>>> CUDA_HAVE_GPU is on. So is CUDA_FOUND. I can run examples like
>>>> rtkfdk with gpu on without any problem though,
>>>> By the way I am using CUDA 9.2.88.
>>>>
>>>> Tao
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> Simon Rit <simon.rit at creatis.insa-lyon.fr> 於 2019年1月30日 週三 上午1:25寫道:
>>>>
>>>>> Hi,
>>>>> No, not really. In my experience, this occurs mainly when you don't
>>>>> have a GPU properly configured for CUDA. Can you check the value of
>>>>> CUDA_HAVE_GPU in cmake ? If it's OFF, then this is indeed the problem.
>>>>> Simon
>>>>>
>>>>> On Wed, Jan 30, 2019 at 1:23 AM tao sun <colddiesun at gmail.com> wrote:
>>>>>
>>>>>> Hi again,
>>>>>>
>>>>>> Finally I got time to work on this. I was able to compile the program
>>>>>> this time using the Graft() function. However, there's a runtime error when
>>>>>> I run the program:
>>>>>>
>>>>>>
>>>>>> /home/tsun/bin/RTK-1.4.0/utilities/ITKCudaCommon/src/itkCudaDataManager.cxx:38
>>>>>> @ unknown : Cuda Error #3
>>>>>> terminate called after throwing an instance of
>>>>>> 'itk::ExceptionObject'
>>>>>> what():
>>>>>> /home/tsun/bin/RTK-1.4.0/utilities/ITKCudaCommon/src/itkCudaDataManager.cxx:38:
>>>>>> Cuda Error # 3
>>>>>> Aborted
>>>>>>
>>>>>> It happens when a new gpu backprojector is created:
>>>>>> bp = rtk::CudaRayCastBackProjectionImageFilter::New();
>>>>>>
>>>>>> Any insights for this?
>>>>>>
>>>>>> Thanks,
>>>>>> Tao
>>>>>>
>>>>>> tao sun <colddiesun at gmail.com> 於 2019年1月19日 週六 下午8:51寫道:
>>>>>>
>>>>>>> Thank you all! I will give a try using your solutions.
>>>>>>> Tao
>>>>>>>
>>>>>>> Simon Rit <simon.rit at creatis.insa-lyon.fr> 於 2019年1月17日 週四
>>>>>>> 上午12:26寫道:
>>>>>>>
>>>>>>>> Hi,
>>>>>>>> That's one solution. Two other:
>>>>>>>> - graft the output to a Cuda image
>>>>>>>> itk::CudaImage<float, 3>::Pointer cuImg = itk::CudaImage<float,
>>>>>>>> 3>::New();
>>>>>>>> cuImg->Graft(projectionReader->GetOutput())
>>>>>>>> - use the rtk::ImportImageFilter which is templated over image type
>>>>>>>> to allow precisely this (I used it in Gate here
>>>>>>>> <https://github.com/OpenGATE/Gate/blob/develop/source/digits_hits/src/GateFixedForcedDetectionActor.cc#L1583>
>>>>>>>> ).
>>>>>>>> Best regards,
>>>>>>>> Simon
>>>>>>>>
>>>>>>>> On Wed, Jan 16, 2019 at 11:06 PM Andreas Andersen <
>>>>>>>> andreasga22 at gmail.com> wrote:
>>>>>>>>
>>>>>>>>> Hi Tao,
>>>>>>>>>
>>>>>>>>> I think you want the CastImageFilter
>>>>>>>>> <https://itk.org/Doxygen/html/classitk_1_1CastImageFilter.html>
>>>>>>>>> from ITK.
>>>>>>>>>
>>>>>>>>> Something like this:
>>>>>>>>> using castToImageType = itk::CastImageFilter<itk:::Image<float,3>
>>>>>>>>> , itk::CudaImage<float,3>>;
>>>>>>>>> typename castToImageType::Pointer castfilter =
>>>>>>>>> castToImageType::New();
>>>>>>>>> castfilter->SetInput(projectionReader->GetOutput());
>>>>>>>>> castfilter->Update();
>>>>>>>>> auto cuda_image = castfilter->GetOutput();
>>>>>>>>>
>>>>>>>>> Best regards Andreas
>>>>>>>>>
>>>>>>>>> __________________________________
>>>>>>>>>
>>>>>>>>> Andreas Gravgaard Andersen
>>>>>>>>>
>>>>>>>>> Department of Oncology,
>>>>>>>>>
>>>>>>>>> Aarhus University Hospital
>>>>>>>>>
>>>>>>>>> Nørrebrogade 44,
>>>>>>>>>
>>>>>>>>> 8000, Aarhus C
>>>>>>>>>
>>>>>>>>> Mail: agravgaard at protonmail.com
>>>>>>>>>
>>>>>>>>> Cell: +45 3165 8140
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> On Wed, 16 Jan 2019 at 22:59, tao sun <colddiesun at gmail.com>
>>>>>>>>> wrote:
>>>>>>>>>
>>>>>>>>>> Hi,
>>>>>>>>>>
>>>>>>>>>> I have read in some image using itk::ImportImageFilter.
>>>>>>>>>> ImportFilterType::Pointer projectionReader =
>>>>>>>>>> ImportFilterType::New();
>>>>>>>>>> ...
>>>>>>>>>> projectionReader->Update();
>>>>>>>>>>
>>>>>>>>>> The type of the image is itk:::Image<float,3>. I wonder if there
>>>>>>>>>> is any way I can cast it to itk::CudaImage<float,3>?
>>>>>>>>>> In rtkforwardprojections.cxx the imageReaderType is defined as
>>>>>>>>>> CudaImageType so there is no such problem.
>>>>>>>>>>
>>>>>>>>>> Thanks,
>>>>>>>>>> Tao
>>>>>>>>>> _______________________________________________
>>>>>>>>>> Rtk-users mailing list
>>>>>>>>>> Rtk-users at public.kitware.com
>>>>>>>>>> https://public.kitware.com/mailman/listinfo/rtk-users
>>>>>>>>>>
>>>>>>>>> _______________________________________________
>>>>>>>>> Rtk-users mailing list
>>>>>>>>> Rtk-users at public.kitware.com
>>>>>>>>> https://public.kitware.com/mailman/listinfo/rtk-users
>>>>>>>>>
>>>>>>>> _______________________________________________
>>>>>> Rtk-users mailing list
>>>>>> Rtk-users at public.kitware.com
>>>>>> https://public.kitware.com/mailman/listinfo/rtk-users
>>>>>>
>>>>>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://public.kitware.com/pipermail/rtk-users/attachments/20190130/19d8d253/attachment-0001.html>
More information about the Rtk-users
mailing list