Skip to content

Commit

Permalink
ENH: WIP: Issue Slicer#7179 Curved Planar Reformation
Browse files Browse the repository at this point in the history
Make qSlicerCLIScalarVectorDWIVolumeResampler::Resample compile.

Co-authored-by: Jean-Christophe Fillion-Robin <jchris.fillionr@kitware.com>
  • Loading branch information
Leengit and jcfr committed Jan 11, 2025
1 parent c448be0 commit 27789a3
Show file tree
Hide file tree
Showing 2 changed files with 116 additions and 44 deletions.
144 changes: 108 additions & 36 deletions Base/QTCLI/qSlicerCLIScalarVectorDWIVolumeResampler.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -15,57 +15,120 @@
==============================================================================*/

#include "qSlicerCLIModule.h"
#include "qSlicerCLIScalarVectorDWIVolumeResampler.h"
#include "qSlicerCoreApplication.h"
#include "qSlicerModuleManager.h"
#include "vtkMRMLAbstractVolumeResampler.h"
#include "vtkMRMLCommandLineModuleNode.h"
#include "vtkMRMLTransformNode.h"
#include "vtkMRMLVolumeNode.h"
#include "vtkSlicerCLIModuleLogic.h"
#include "vtkSlicerModuleLogic.h"

// ITK includes
// TODO: Which of these do we really need?
#include <itkBSplineDeformableTransform.h>
#include <itkCompositeTransform.h>
#include <itkImageFileReader.h>
#include <itkImageFileWriter.h>
#include <itkMetaDataObject.h>
#include <itkNearestNeighborInterpolateImageFunction.h>
#include <itkResampleImageFilter.h>
#include <itkBSplineInterpolateImageFunction.h>
#include <itkRigid3DTransform.h>
#include <itkThinPlateSplineKernelTransform.h>
#include <itkTransformFileReader.h>
#include <itkVectorResampleImageFilter.h>
#include <itkWindowedSincInterpolateImageFunction.h>
#include <itkConstantBoundaryCondition.h>
#include <itkTransformFactory.h>

//----------------------------------------------------------------------------
void qSlicerCLIScalarVectorDWIVolumeResampler::PrintSelf(ostream & os, vtkIndent indent)
void qSlicerCLIScalarVectorDWIVolumeResampler::PrintSelf(ostream& os, vtkIndent indent)
{
this->Superclass::PrintSelf(os, indent);
}

//----------------------------------------------------------------------------
bool qSlicerCLIScalarVectorDWIVolumeResampler::Resample(vtkMRMLVolumeNode * inputVolume,
vtkMRMLVolumeNode * outputVolume,
vtkMRMLTransformNode * resamplingTransform,
vtkMRMLVolumeNode * referenceVolume,
int interpolationType,
int windowedSincFunction,
const ResamplingParameters & resamplingParameter)
bool qSlicerCLIScalarVectorDWIVolumeResampler::Resample(vtkMRMLVolumeNode* inputVolume,
vtkMRMLVolumeNode* outputVolume,
vtkMRMLTransformNode* resamplingTransform,
vtkMRMLVolumeNode* referenceVolume,
int interpolationType,
int windowedSincFunction,
const ResamplingParameters& vtkNotUsed(resamplingParameter))
{
vtkSlicerCLIModuleLogic* resampleLogic =
vtkSlicerCLIModuleLogic::SafeDownCast(vtkSlicerModuleLogic::GetModuleLogic("ResampleScalarVectorDWIVolume"));
if (!resampleLogic)
qSlicerCoreApplication* app = qSlicerCoreApplication::application();
if (!app
|| !app->moduleManager()
|| !dynamic_cast<qSlicerCLIModule*>(app->moduleManager()->module("ResampleScalarVectorDWIVolume")))
{
vtkErrorMacro("qSlicerCLIScalarVectorDWIVolumeResampler: resample logic is not set");
vtkErrorMacro("Resample: ResampleScalarVectorDWIVolume module is not available");
return false;
}

// TODO: Which of these?
# if 0
vtkSmartPointer<vtkMRMLCommandLineModuleNode> cmdNode = vtkSmartPointer<vtkMRMLCommandLineModuleNode>::New();
resampleLogic->GetMRMLScene()->AddNode(cmdNode);
#else
vtkMRMLCommandLineModuleNode* cmdNode = resampleLogic->CreateNodeInScene();
if (cmdNode == nullptr)
qSlicerCLIModule* cliModule =
dynamic_cast<qSlicerCLIModule*>(app->moduleManager()->module("ResampleScalarVectorDWIVolume"));

vtkSlicerCLIModuleLogic* cliLogic = vtkSlicerCLIModuleLogic::SafeDownCast(cliModule->logic());
{
vtkErrorMacro("qSlicerCLIScalarVectorDWIVolumeResampler: failed to create command line module node");
vtkErrorMacro("Resample: ResampleScalarVectorDWIVolume module logic is not available");
return false;
}
#endif

// Also look at Modules/Loadable/CropVolume/Logic/vtkSlicerCropVolumeLogic.cxx
// PERF: Revisit if creating and removing the node impacts performances
vtkMRMLCommandLineModuleNode* cmdNodeTry = cliLogic->CreateNodeInScene();
if (cmdNodeTry == nullptr)
{
vtkErrorMacro("Resample: Failed to create ResampleScalarVectorDWIVolume node");
return false;
}

// We need to cliLogic->GetMRMLScene()->RemoveNode(cmdNode) no matter how we exit this function
struct vtkMRMLCommandLineModuleNodeGC
{
public:
vtkMRMLCommandLineModuleNodeGC(vtkSlicerCLIModuleLogic* cliLogicIn, vtkMRMLCommandLineModuleNode* cmdNodeIn)
{
this->cliLogic = cliLogicIn;
this->cmdNode = cmdNodeIn;
}
~vtkMRMLCommandLineModuleNodeGC() { this->cliLogic->GetMRMLScene()->RemoveNode(this->cmdNode); }
operator vtkMRMLCommandLineModuleNode*() { return this->cmdNode; }
vtkMRMLCommandLineModuleNode* operator->() { return this->cmdNode; }

private:
vtkSlicerCLIModuleLogic* cliLogic;
vtkMRMLCommandLineModuleNode* cmdNode;
};
vtkMRMLCommandLineModuleNodeGC cmdNode(cliLogic, cmdNodeTry);

if (inputVolume == nullptr)
{
vtkErrorMacro("Resample: Input volume node is not set");
return false;
}
cmdNode->SetParameterAsString("inputVolume", inputVolume->GetID());

if (outputVolume == nullptr)
{
vtkErrorMacro("Resample: Output volume node is not set");
return false;
}
cmdNode->SetParameterAsString("outputVolume", outputVolume->GetID());
cmdNode->SetParameterAsString("transformationFile", resamplingTransform->GetID());
cmdNode->SetParameterAsString("referenceVolume", referenceVolume->GetID());

if (resamplingTransform != nullptr)
{
cmdNode->SetParameterAsString("transformationFile", resamplingTransform->GetID());
}
if (referenceVolume != nullptr)
{
cmdNode->SetParameterAsString("referenceVolume", referenceVolume->GetID());
}

switch (interpolationType)
{
{
case vtkMRMLAbstractVolumeResampler::InterpolationTypeNearestNeighbor:
cmdNode->SetParameterAsString("interpolationType", "nn");
break;
Expand All @@ -80,11 +143,11 @@ bool qSlicerCLIScalarVectorDWIVolumeResampler::Resample(vtkMRMLVolumeNode *
break;
default:
break;
}
}

#if 0
// TODO: How do we fix this so that it compiles?
static const int RADIUS = 3;
const int RADIUS = 3;
typedef itk::WindowedSincInterpolateImageFunction<InputImageType, RADIUS, itk::Function::HammingWindowFunction<RADIUS> > HammingInterpolatorType;
typedef itk::WindowedSincInterpolateImageFunction<InputImageType, RADIUS, itk::Function::CosineWindowFunction<RADIUS> > CosineInterpolatorType;
typedef itk::WindowedSincInterpolateImageFunction<InputImageType, RADIUS, itk::Function::WelchWindowFunction<RADIUS> > WelchInterpolatorType;
Expand All @@ -94,28 +157,37 @@ bool qSlicerCLIScalarVectorDWIVolumeResampler::Resample(vtkMRMLVolumeNode *
switch (windowedSincFunction)
{
case WindowedSincFunctionHamming:
resampleLogic->SetInterpolator(HammingInterpolatorType::New())
cliLogic->SetInterpolator(HammingInterpolatorType::New())
break;
case WindowedSincFunctionCosine:
resampleLogic->SetInterpolator(CosineInterpolatorType::New())
cliLogic->SetInterpolator(CosineInterpolatorType::New())
break;
case WindowedSincFunctionWelch:
resampleLogic->SetInterpolator(WelchInterpolatorType::New())
cliLogic->SetInterpolator(WelchInterpolatorType::New())
break;
case WindowedSincFunctionLanczos:
resampleLogic->SetInterpolator(LanczosInterpolatorType::New())
cliLogic->SetInterpolator(LanczosInterpolatorType::New())
break;
case WindowedSincFunctionBlackman:
resampleLogic->SetInterpolator(BlackmanInterpolatorType::New())
cliLogic->SetInterpolator(BlackmanInterpolatorType::New())
break;
default:
break;
}
#endif

// TODO: What should we do with resamplingParameter?
#if 0
cmdNode->SetParameterAsString("windowFunction", ...);
#endif

cliLogic->ApplyAndWait(cmdNode, /* updateDisplay= */ false);

bool success = cmdNode->GetStatus() == vtkMRMLCommandLineModuleNode::Completed;

if (!success)
{
vtkErrorMacro("Resample: " << cmdNode->GetErrorText());
}

resampleLogic->ApplyAndWait(cmdNode, false);
resampleLogic->GetMRMLScene()->RemoveNode(cmdNode);
return true;
return success;
}
16 changes: 8 additions & 8 deletions Base/QTCLI/qSlicerCLIScalarVectorDWIVolumeResampler.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,21 @@ class Q_SLICER_BASE_QTCLI_EXPORT qSlicerCLIScalarVectorDWIVolumeResampler : publ
{
public:
vtkTypeMacro(qSlicerCLIScalarVectorDWIVolumeResampler, vtkMRMLAbstractVolumeResampler);
void PrintSelf(ostream & os, vtkIndent indent) override;
void PrintSelf(ostream& os, vtkIndent indent) override;

virtual bool Resample(vtkMRMLVolumeNode * inputVolume,
vtkMRMLVolumeNode * outputVolume,
vtkMRMLTransformNode * resamplingTransform,
vtkMRMLVolumeNode * referenceVolume,
virtual bool Resample(vtkMRMLVolumeNode* inputVolume,
vtkMRMLVolumeNode* outputVolume,
vtkMRMLTransformNode* resamplingTransform,
vtkMRMLVolumeNode* referenceVolume,
int interpolationType,
int windowedSincFunction,
const vtkMRMLAbstractVolumeResampler::ResamplingParameters & resamplingParameter);
const vtkMRMLAbstractVolumeResampler::ResamplingParameters& resamplingParameter);

protected:
qSlicerCLIScalarVectorDWIVolumeResampler() = default;
~qSlicerCLIScalarVectorDWIVolumeResampler() override = default;
qSlicerCLIScalarVectorDWIVolumeResampler(const qSlicerCLIScalarVectorDWIVolumeResampler &) = delete;
void operator=(const qSlicerCLIScalarVectorDWIVolumeResampler &) = delete;
qSlicerCLIScalarVectorDWIVolumeResampler(const qSlicerCLIScalarVectorDWIVolumeResampler&) = delete;
void operator=(const qSlicerCLIScalarVectorDWIVolumeResampler&) = delete;
};

#endif

0 comments on commit 27789a3

Please sign in to comment.