|
| 1 | +// #include "rtkThreeDCircularProjectionGeometryXMLFile.h" |
| 2 | +#include "rtkFourDConjugateGradientConeBeamReconstructionFilter.h" |
| 3 | +#include "rtkIterationCommands.h" |
| 4 | +#include "rtkSignalToInterpolationWeights.h" |
| 5 | +#include "rtkReorderProjectionsImageFilter.h" |
| 6 | +#include "../../test/rtkFourDTestHelper.h" |
| 7 | + |
| 8 | +#ifdef RTK_USE_CUDA |
| 9 | +# include <itkCudaImage.h> |
| 10 | +#endif |
| 11 | +#include <itkImageFileWriter.h> |
| 12 | + |
| 13 | +int |
| 14 | +main(int argc, char * argv[]) |
| 15 | +{ |
| 16 | + using OutputPixelType = float; |
| 17 | + |
| 18 | +#ifdef RTK_USE_CUDA |
| 19 | + using VolumeSeriesType = itk::CudaImage<OutputPixelType, 4>; |
| 20 | + using ProjectionStackType = itk::CudaImage<OutputPixelType, 3>; |
| 21 | + using VolumeType = itk::CudaImage<OutputPixelType, 3>; |
| 22 | +#else |
| 23 | + using VolumeSeriesType = itk::Image<OutputPixelType, 4>; |
| 24 | + using ProjectionStackType = itk::Image<OutputPixelType, 3>; |
| 25 | + using VolumeType = itk::Image<OutputPixelType, 3>; |
| 26 | +#endif |
| 27 | + |
| 28 | + auto data = rtk::GenerateFourDTestData<OutputPixelType>(FAST_TESTS_NO_CHECKS); |
| 29 | + |
| 30 | + // Re-order geometry and projections |
| 31 | + // In the new order, projections with identical phases are packed together |
| 32 | + auto reorder = rtk::ReorderProjectionsImageFilter<ProjectionStackType>::New(); |
| 33 | + reorder->SetInput(data.Projections); |
| 34 | + reorder->SetInputGeometry(data.Geometry); |
| 35 | + reorder->SetInputSignal(data.Signal); |
| 36 | + TRY_AND_EXIT_ON_ITK_EXCEPTION(reorder->Update()) |
| 37 | + |
| 38 | + // Release the memory holding the stack of original projections |
| 39 | + data.Projections->ReleaseData(); |
| 40 | + |
| 41 | + // Compute the interpolation weights |
| 42 | + auto signalToInterpolationWeights = rtk::SignalToInterpolationWeights::New(); |
| 43 | + signalToInterpolationWeights->SetSignal(reorder->GetOutputSignal()); |
| 44 | + signalToInterpolationWeights->SetNumberOfReconstructedFrames( |
| 45 | + data.InitialVolumeSeries->GetLargestPossibleRegion().GetSize(3)); |
| 46 | + TRY_AND_EXIT_ON_ITK_EXCEPTION(signalToInterpolationWeights->Update()) |
| 47 | + |
| 48 | + // Set the forward and back projection filters to be used |
| 49 | + using ConjugateGradientFilterType = |
| 50 | + rtk::FourDConjugateGradientConeBeamReconstructionFilter<VolumeSeriesType, ProjectionStackType>; |
| 51 | + auto fourdconjugategradient = ConjugateGradientFilterType::New(); |
| 52 | + |
| 53 | + fourdconjugategradient->SetInputVolumeSeries(data.InitialVolumeSeries); |
| 54 | + fourdconjugategradient->SetNumberOfIterations(2); |
| 55 | +#ifdef RTK_USE_CUDA |
| 56 | + fourdconjugategradient->SetCudaConjugateGradient(true); |
| 57 | + fourdconjugategradient->SetForwardProjectionFilter(ConjugateGradientFilterType::FP_CUDARAYCAST); |
| 58 | + fourdconjugategradient->SetBackProjectionFilter(ConjugateGradientFilterType::BP_CUDAVOXELBASED); |
| 59 | +#else |
| 60 | + fourdconjugategradient->SetForwardProjectionFilter(ConjugateGradientFilterType::FP_JOSEPH); |
| 61 | + fourdconjugategradient->SetBackProjectionFilter(ConjugateGradientFilterType::BP_VOXELBASED); |
| 62 | +#endif |
| 63 | + |
| 64 | + // Set the newly ordered arguments |
| 65 | + fourdconjugategradient->SetInputProjectionStack(reorder->GetOutput()); |
| 66 | + fourdconjugategradient->SetGeometry(reorder->GetOutputGeometry()); |
| 67 | + fourdconjugategradient->SetWeights(signalToInterpolationWeights->GetOutput()); |
| 68 | + fourdconjugategradient->SetSignal(reorder->GetOutputSignal()); |
| 69 | + |
| 70 | + auto verboseIterationCommand = rtk::VerboseIterationCommand<ConjugateGradientFilterType>::New(); |
| 71 | + fourdconjugategradient->AddObserver(itk::AnyEvent(), verboseIterationCommand); |
| 72 | + |
| 73 | + TRY_AND_EXIT_ON_ITK_EXCEPTION(fourdconjugategradient->Update()) |
| 74 | + |
| 75 | + // Write |
| 76 | + TRY_AND_EXIT_ON_ITK_EXCEPTION(itk::WriteImage(fourdconjugategradient->GetOutput(), "fourdconjugategradient.mha")); |
| 77 | + |
| 78 | + return EXIT_SUCCESS; |
| 79 | +} |
0 commit comments