Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 31 additions & 7 deletions applications/rtkbackprojections/rtkbackprojections.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ main(int argc, char * argv[])
bp = rtk::FDKBackProjectionImageFilter<OutputImageType, OutputImageType>::New();
break;
case (bp_arg_FDKWarpBackProjection):
{
if (!args_info.signal_given || !args_info.dvf_given)
{
std::cerr << "FDKWarpBackProjection requires input 4D deformation "
Expand All @@ -104,10 +105,17 @@ main(int argc, char * argv[])
def->SetInput(itk::ReadImage<DeformationType::InputImageType>(args_info.dvf_arg));
bp = rtk::FDKWarpBackProjectionImageFilter<OutputImageType, OutputImageType, DeformationType>::New();
def->SetSignalFilename(args_info.signal_arg);
dynamic_cast<rtk::FDKWarpBackProjectionImageFilter<OutputImageType, OutputImageType, DeformationType> *>(
bp.GetPointer())
->SetDeformation(def);
auto * fdkWarp =
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find the proposed changes too systematic. Here, it is obvious that it won't fail, it's been instantiated with this type 2 lines above. Can you go over the changes and only check the ones for which it might not work?

dynamic_cast<rtk::FDKWarpBackProjectionImageFilter<OutputImageType, OutputImageType, DeformationType> *>(
bp.GetPointer());
if (fdkWarp == nullptr)
{
std::cerr << "Failed to cast back projection filter to FDKWarpBackProjectionImageFilter." << std::endl;
return EXIT_FAILURE;
}
fdkWarp->SetDeformation(def);
break;
}
case (bp_arg_Joseph):
bp = rtk::JosephBackProjectionImageFilter<OutputImageType, OutputImageType>::New();
break;
Expand Down Expand Up @@ -151,11 +159,27 @@ main(int argc, char * argv[])
if (args_info.attenuationmap_given)
bp->SetInput(2, attenuationMap);
if (args_info.sigmazero_given && args_info.bp_arg == bp_arg_Zeng)
dynamic_cast<rtk::ZengBackProjectionImageFilter<OutputImageType, OutputImageType> *>(bp.GetPointer())
->SetSigmaZero(args_info.sigmazero_arg);
{
auto * zengBack =
dynamic_cast<rtk::ZengBackProjectionImageFilter<OutputImageType, OutputImageType> *>(bp.GetPointer());
if (zengBack == nullptr)
{
std::cerr << "Failed to cast back projection filter to ZengBackProjectionImageFilter." << std::endl;
return EXIT_FAILURE;
}
zengBack->SetSigmaZero(args_info.sigmazero_arg);
}
if (args_info.alphapsf_given && args_info.bp_arg == bp_arg_Zeng)
dynamic_cast<rtk::ZengBackProjectionImageFilter<OutputImageType, OutputImageType> *>(bp.GetPointer())
->SetAlpha(args_info.alphapsf_arg);
{
auto * zengBack =
dynamic_cast<rtk::ZengBackProjectionImageFilter<OutputImageType, OutputImageType> *>(bp.GetPointer());
if (zengBack == nullptr)
{
std::cerr << "Failed to cast back projection filter to ZengBackProjectionImageFilter." << std::endl;
return EXIT_FAILURE;
}
zengBack->SetAlpha(args_info.alphapsf_arg);
}
bp->SetGeometry(geometry);
TRY_AND_EXIT_ON_ITK_EXCEPTION(bp->Update())

Expand Down
109 changes: 82 additions & 27 deletions applications/rtkforwardprojections/rtkforwardprojections.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -117,16 +117,23 @@ main(int argc, char * argv[])
forwardProjection = rtk::MaximumIntensityProjectionImageFilter<OutputImageType, OutputImageType>::New();
break;
case (fp_arg_CudaRayCast):
{
#ifdef RTK_USE_CUDA
forwardProjection = rtk::CudaForwardProjectionImageFilter<OutputImageType, OutputImageType>::New();
dynamic_cast<rtk::CudaForwardProjectionImageFilter<OutputImageType, OutputImageType> *>(
forwardProjection.GetPointer())
->SetStepSize(args_info.step_arg);
auto * cudaForward = dynamic_cast<rtk::CudaForwardProjectionImageFilter<OutputImageType, OutputImageType> *>(
forwardProjection.GetPointer());
if (cudaForward == nullptr)
{
std::cerr << "Failed to cast forward projection filter to CudaForwardProjectionImageFilter." << std::endl;
return EXIT_FAILURE;
}
cudaForward->SetStepSize(args_info.step_arg);
#else
std::cerr << "The program has not been compiled with cuda option" << std::endl;
return EXIT_FAILURE;
#endif
break;
}
default:
std::cerr << "Unhandled --method value." << std::endl;
return EXIT_FAILURE;
Expand All @@ -139,52 +146,100 @@ main(int argc, char * argv[])
{
if (args_info.fp_arg == fp_arg_Joseph)
{
dynamic_cast<rtk::JosephForwardProjectionImageFilter<OutputImageType, OutputImageType> *>(
forwardProjection.GetPointer())
->SetInferiorClipImage(inferiorClipImage);
auto * josephForward = dynamic_cast<rtk::JosephForwardProjectionImageFilter<OutputImageType, OutputImageType> *>(
forwardProjection.GetPointer());
if (josephForward == nullptr)
{
std::cerr << "Failed to cast forward projection filter to JosephForwardProjectionImageFilter." << std::endl;
return EXIT_FAILURE;
}
josephForward->SetInferiorClipImage(inferiorClipImage);
}
else if (args_info.fp_arg == fp_arg_JosephAttenuated)
{
dynamic_cast<rtk::JosephForwardAttenuatedProjectionImageFilter<OutputImageType, OutputImageType> *>(
forwardProjection.GetPointer())
->SetInferiorClipImage(inferiorClipImage);
auto * josephAttenuatedForward =
dynamic_cast<rtk::JosephForwardAttenuatedProjectionImageFilter<OutputImageType, OutputImageType> *>(
forwardProjection.GetPointer());
if (josephAttenuatedForward == nullptr)
{
std::cerr << "Failed to cast forward projection filter to JosephForwardAttenuatedProjectionImageFilter."
<< std::endl;
return EXIT_FAILURE;
}
josephAttenuatedForward->SetInferiorClipImage(inferiorClipImage);
}
else if (args_info.fp_arg == fp_arg_MIP)
{
dynamic_cast<rtk::MaximumIntensityProjectionImageFilter<OutputImageType, OutputImageType> *>(
forwardProjection.GetPointer())
->SetInferiorClipImage(inferiorClipImage);
auto * mipForward = dynamic_cast<rtk::MaximumIntensityProjectionImageFilter<OutputImageType, OutputImageType> *>(
forwardProjection.GetPointer());
if (mipForward == nullptr)
{
std::cerr << "Failed to cast forward projection filter to MaximumIntensityProjectionImageFilter." << std::endl;
return EXIT_FAILURE;
}
mipForward->SetInferiorClipImage(inferiorClipImage);
}
}
if (args_info.superiorclipimage_given)
{
if (args_info.fp_arg == fp_arg_Joseph)
{
dynamic_cast<rtk::JosephForwardProjectionImageFilter<OutputImageType, OutputImageType> *>(
forwardProjection.GetPointer())
->SetSuperiorClipImage(superiorClipImage);
auto * josephForward = dynamic_cast<rtk::JosephForwardProjectionImageFilter<OutputImageType, OutputImageType> *>(
forwardProjection.GetPointer());
if (josephForward == nullptr)
{
std::cerr << "Failed to cast forward projection filter to JosephForwardProjectionImageFilter." << std::endl;
return EXIT_FAILURE;
}
josephForward->SetSuperiorClipImage(superiorClipImage);
}
else if (args_info.fp_arg == fp_arg_JosephAttenuated)
{
dynamic_cast<rtk::JosephForwardAttenuatedProjectionImageFilter<OutputImageType, OutputImageType> *>(
forwardProjection.GetPointer())
->SetSuperiorClipImage(superiorClipImage);
auto * josephAttenuatedForward =
dynamic_cast<rtk::JosephForwardAttenuatedProjectionImageFilter<OutputImageType, OutputImageType> *>(
forwardProjection.GetPointer());
if (josephAttenuatedForward == nullptr)
{
std::cerr << "Failed to cast forward projection filter to JosephForwardAttenuatedProjectionImageFilter."
<< std::endl;
return EXIT_FAILURE;
}
josephAttenuatedForward->SetSuperiorClipImage(superiorClipImage);
}
else if (args_info.fp_arg == fp_arg_MIP)
{
dynamic_cast<rtk::MaximumIntensityProjectionImageFilter<OutputImageType, OutputImageType> *>(
forwardProjection.GetPointer())
->SetSuperiorClipImage(superiorClipImage);
auto * mipForward = dynamic_cast<rtk::MaximumIntensityProjectionImageFilter<OutputImageType, OutputImageType> *>(
forwardProjection.GetPointer());
if (mipForward == nullptr)
{
std::cerr << "Failed to cast forward projection filter to MaximumIntensityProjectionImageFilter." << std::endl;
return EXIT_FAILURE;
}
mipForward->SetSuperiorClipImage(superiorClipImage);
}
}
if (args_info.sigmazero_given && args_info.fp_arg == fp_arg_Zeng)
dynamic_cast<rtk::ZengForwardProjectionImageFilter<OutputImageType, OutputImageType> *>(
forwardProjection.GetPointer())
->SetSigmaZero(args_info.sigmazero_arg);
{
auto * zengForward = dynamic_cast<rtk::ZengForwardProjectionImageFilter<OutputImageType, OutputImageType> *>(
forwardProjection.GetPointer());
if (zengForward == nullptr)
{
std::cerr << "Failed to cast forward projection filter to ZengForwardProjectionImageFilter." << std::endl;
return EXIT_FAILURE;
}
zengForward->SetSigmaZero(args_info.sigmazero_arg);
}
if (args_info.alphapsf_given && args_info.fp_arg == fp_arg_Zeng)
dynamic_cast<rtk::ZengForwardProjectionImageFilter<OutputImageType, OutputImageType> *>(
forwardProjection.GetPointer())
->SetAlpha(args_info.alphapsf_arg);
{
auto * zengForward = dynamic_cast<rtk::ZengForwardProjectionImageFilter<OutputImageType, OutputImageType> *>(
forwardProjection.GetPointer());
if (zengForward == nullptr)
{
std::cerr << "Failed to cast forward projection filter to ZengForwardProjectionImageFilter." << std::endl;
return EXIT_FAILURE;
}
zengForward->SetAlpha(args_info.alphapsf_arg);
}
forwardProjection->SetGeometry(geometry);
if (!args_info.lowmem_flag)
{
Expand Down
7 changes: 6 additions & 1 deletion include/rtkDrawConeImageFilter.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,12 @@ void
DrawConeImageFilter<TInputImage, TOutputImage>::BeforeThreadedGenerateData()
{
Superclass::BeforeThreadedGenerateData();
dynamic_cast<QuadricShape *>(this->GetModifiableConvexShape())->SetJ(0.);
auto * quadricShape = dynamic_cast<QuadricShape *>(this->GetModifiableConvexShape());
if (quadricShape == nullptr)
{
itkExceptionMacro(<< "Failed to cast convex shape to QuadricShape.");
}
quadricShape->SetJ(0.);
}

} // end namespace rtk
Expand Down
34 changes: 27 additions & 7 deletions include/rtkImagXGeometryReader.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,12 @@ ImagXGeometryReader<TInputImage>::GetGeometryForAI2p1()

for (const auto & flexmap : list_flexmap)
{
std::string str = dynamic_cast<const itk::DOMTextNode *>(flexmap)->GetText();
const auto * textNode = dynamic_cast<const itk::DOMTextNode *>(flexmap);
if (textNode == nullptr)
{
itkExceptionMacro(<< "Unexpected non-text node in flexmap.");
}
std::string str = textNode->GetText();
std::stringstream iss(str);
std::vector<float> v;
while (iss.good())
Expand Down Expand Up @@ -264,7 +269,12 @@ ImagXGeometryReader<TInputImage>::GetGeometryForAI1p5()
itk::ImageIOBase::Pointer imageIO = itk::ImageIOFactory::CreateImageIO(m_ProjectionsFileNames[0].c_str(),
itk::ImageIOFactory::IOFileModeEnum::ReadMode);
imageIO = itk::GDCMImageIO::New();
dynamic_cast<itk::GDCMImageIO *>(imageIO.GetPointer())->LoadPrivateTagsOn();
auto * gdcmImageIO = dynamic_cast<itk::GDCMImageIO *>(imageIO.GetPointer());
if (gdcmImageIO == nullptr)
{
itkExceptionMacro(<< "Failed to cast ImageIO to GDCMImageIO.");
}
gdcmImageIO->LoadPrivateTagsOn();

// Define, create and set projection reader
using ReaderType = itk::ImageFileReader<TInputImage>;
Expand All @@ -276,7 +286,7 @@ ImagXGeometryReader<TInputImage>::GetGeometryForAI1p5()
// Read room setup parameters in the DICOM info of the first projection
std::string roomSetupTagKey = "3001|0012";
std::string roomSetupInfo;
dynamic_cast<itk::GDCMImageIO *>(imageIO.GetPointer())->GetValueFromTag(roomSetupTagKey, roomSetupInfo);
gdcmImageIO->GetValueFromTag(roomSetupTagKey, roomSetupInfo);

// Extract SID, SDD and angle offset from the roomSetupInfo
auto parser = itk::DOMNodeXMLReader::New();
Expand All @@ -291,7 +301,7 @@ ImagXGeometryReader<TInputImage>::GetGeometryForAI1p5()
// Read calibration model's parameters in the DICOM info of the first projection
std::string calibrationTagKey = "3001|0013";
std::string calibrationInfo;
dynamic_cast<itk::GDCMImageIO *>(imageIO.GetPointer())->GetValueFromTag(calibrationTagKey, calibrationInfo);
gdcmImageIO->GetValueFromTag(calibrationTagKey, calibrationInfo);

// Extract calibration model's parameters from calibrationInfo
is.clear();
Expand Down Expand Up @@ -473,7 +483,12 @@ ImagXGeometryReader<TInputImage>::getAIversion()
itk::ImageIOFactory::IOFileModeEnum::ReadMode);

imageIO = itk::GDCMImageIO::New();
dynamic_cast<itk::GDCMImageIO *>(imageIO.GetPointer())->LoadPrivateTagsOn();
auto * gdcmImageIO = dynamic_cast<itk::GDCMImageIO *>(imageIO.GetPointer());
if (gdcmImageIO == nullptr)
{
itkExceptionMacro(<< "Failed to cast ImageIO to GDCMImageIO.");
}
gdcmImageIO->LoadPrivateTagsOn();

// Define, create and set projection reader
using ReaderType = itk::ImageFileReader<TInputImage>;
Expand All @@ -485,7 +500,7 @@ ImagXGeometryReader<TInputImage>::getAIversion()
// Read room setup parameters in the DICOM info of the first projection
std::string AIVersionTagKey = "0018|1020";
std::string AIVersion = "";
dynamic_cast<itk::GDCMImageIO *>(imageIO.GetPointer())->GetValueFromTag(AIVersionTagKey, AIVersion);
gdcmImageIO->GetValueFromTag(AIVersionTagKey, AIVersion);

return AIVersion;
}
Expand Down Expand Up @@ -551,7 +566,12 @@ ImagXGeometryReader<TInputImage>::GenerateData()
// Reading Gantry Angle
std::string labelId, value;
itk::GDCMImageIO::GetLabelFromTag(gantryAngleTag, labelId);
dynamic_cast<itk::GDCMImageIO *>(imageIO.GetPointer())->GetValueFromTag(gantryAngleTag, value);
auto * gdcmProjectionImageIO = dynamic_cast<itk::GDCMImageIO *>(imageIO.GetPointer());
if (gdcmProjectionImageIO == nullptr)
{
itkExceptionMacro(<< "Failed to cast ImageIO to GDCMImageIO for projection " << m_ProjectionsFileName << ".");
}
gdcmProjectionImageIO->GetValueFromTag(gantryAngleTag, value);

if (isImagX1p5 || isImagX1p2) // Using CalibModel
{
Expand Down
Loading
Loading