Skip to content

Commit ead2406

Browse files
committed
ENH: Add FourDConjugateGradient example and corresponding doc page
1 parent eeb2c91 commit ead2406

5 files changed

Lines changed: 111 additions & 1 deletion

File tree

applications/rtkfourdconjugategradient/rtkfourdconjugategradient.cxx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626

2727
#ifdef RTK_USE_CUDA
2828
# include "itkCudaImage.h"
29-
# include "rtkCudaConstantVolumeSeriesSource.h"
3029
#endif
3130

3231
#include <itkImageFileWriter.h>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
cmake_minimum_required(VERSION 3.9.5 FATAL_ERROR)
2+
3+
# This project is designed to be built outside the RTK source tree.
4+
project(FourDConjugateGradient)
5+
6+
# Find ITK with RTK
7+
find_package(ITK REQUIRED COMPONENTS RTK)
8+
include(${ITK_USE_FILE})
9+
10+
# Executable(s)
11+
add_executable(FourDConjugateGradient FourDConjugateGradient.cxx)
12+
target_link_libraries(FourDConjugateGradient ${ITK_LIBRARIES})
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
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+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# 4D Conjugate Gradient
2+
3+
FourDConjugateGradient shows how to perform iterative cone-beam CT reconstruction using either CPU or GPU resources.
4+
You can refer to the [projectors documentation](../../documentation/docs/Projectors.md) to see all options available for the back and forwardprojections.
5+
6+
This example generates its own input data: a phantom made of two ellipsoids, one of which is moving. Projections are computed through this moving phantom.
7+
8+
`````{tab-set}
9+
10+
````{tab-item} C++
11+
12+
```{literalinclude} ./FourDConjugateGradient.cxx
13+
:language: c++
14+
```
15+
````
16+
17+
`````

test/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,9 @@ rtk_add_test(rtkConjugateGradientExampleTest
376376
../examples/ConjugateGradient/ConjugateGradient.cxx
377377
DATA{Input/Forbild/Thorax}
378378
)
379+
rtk_add_test(rtkFourDConjugateGradientExampleTest
380+
../examples/FourDConjugateGradient/FourDConjugateGradient.cxx
381+
)
379382

380383
if(ITK_WRAP_PYTHON)
381384
itk_python_add_test(NAME rtkMaximumIntensityPythonTest COMMAND rtkMaximumIntensity.py)

0 commit comments

Comments
 (0)