Skip to content

Commit

Permalink
ENH: WIP: Issue Slicer#7179 Curved Planar Reformation
Browse files Browse the repository at this point in the history
This code is WIP and does not compile!

Create vtkMRMLScalarVectorDWIVolumeResampler, a subclass of
vtkMRMLAbstractVolumeResampler, so that
vtkMRMLApplicationLogic->ResampleVolume() can be used.

The compile problems include that vtkMRMLCommandLineModuleNode.h,
vtkSlicerCLIModuleLogic.h, and vtkSlicerModuleLogic.h cannot be found
from Libs/MRML/Logic.

Also, windowed sinc functions do not appear to be accessible from
Libs/MRML/Logic, and have been commented out.
  • Loading branch information
Leengit committed Jan 9, 2025
1 parent a291203 commit e1a501d
Show file tree
Hide file tree
Showing 3 changed files with 173 additions and 0 deletions.
1 change: 1 addition & 0 deletions Libs/MRML/Logic/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ set(MRMLLogic_SRCS
vtkMRMLDisplayableHierarchyLogic.cxx
vtkMRMLRemoteIOLogic.cxx
vtkMRMLLayoutLogic.cxx
vtkMRMLScalarVectorDWIVolumeResampler.cxx
vtkMRMLSliceLayerLogic.cxx
vtkMRMLSliceLogic.cxx
vtkMRMLSliceLinkLogic.cxx
Expand Down
123 changes: 123 additions & 0 deletions Libs/MRML/Logic/vtkMRMLScalarVectorDWIVolumeResampler.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
/*==============================================================================
Program: 3D Slicer
Copyright(c) Kitware Inc.
See COPYRIGHT.txt
or http://www.slicer.org/copyright/copyright.txt for details.
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/

#include "vtkMRMLAbstractVolumeResampler.h"
#include "vtkMRMLScalarVectorDWIVolumeResampler.h"
#include "vtkMRMLTransformNode.h"
#include "vtkMRMLVolumeNode.h"

// TODO: Replace these with include files
class vtkMRMLCommandLineModuleNode;
class vtkSlicerCLIModuleLogic;
class vtkSlicerModuleLogic;

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

//----------------------------------------------------------------------------
bool vtkMRMLScalarVectorDWIVolumeResampler::Resample(vtkMRMLVolumeNode * inputVolume,
vtkMRMLVolumeNode * outputVolume,
vtkMRMLTransformNode * resamplingTransform,
vtkMRMLVolumeNode * referenceVolume,
int interpolationType,
int windowedSincFunction,
const ResamplingParameters & resamplingParameter)
{
vtkSlicerCLIModuleLogic* resampleLogic =
vtkSlicerCLIModuleLogic::SafeDownCast(vtkSlicerModuleLogic::GetModuleLogic("ResampleScalarVectorDWIVolume"));
if (!resampleLogic)
{
vtkErrorMacro("vtkMRMLScalarVectorDWIVolumeResampler: resample logic is not set");
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)
{
vtkErrorMacro("vtkMRMLScalarVectorDWIVolumeResampler: failed to create command line module node");
return false;
}
#endif

// Also look at Modules/Loadable/CropVolume/Logic/vtkSlicerCropVolumeLogic.cxx
cmdNode->SetParameterAsString("inputVolume", inputVolume->GetID());
cmdNode->SetParameterAsString("outputVolume", outputVolume->GetID());
cmdNode->SetParameterAsString("transformationFile", resamplingTransform->GetID());
cmdNode->SetParameterAsString("referenceVolume", referenceVolume->GetID());
switch (interpolationType)
{
case vtkMRMLAbstractVolumeResampler::InterpolationTypeNearestNeighbor:
cmdNode->SetParameterAsString("interpolationType", "nn");
break;
case vtkMRMLAbstractVolumeResampler::InterpolationTypeLinear:
cmdNode->SetParameterAsString("interpolationType", "linear");
break;
case vtkMRMLAbstractVolumeResampler::InterpolationTypeWindowedSinc:
cmdNode->SetParameterAsString("interpolationType", "ws");
break;
case vtkMRMLAbstractVolumeResampler::InterpolationTypeBSpline:
cmdNode->SetParameterAsString("interpolationType", "bs");
break;
default:
break;
}

#if 0
// TODO: How do we fix this so that it compiles?
static 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;
typedef itk::WindowedSincInterpolateImageFunction<InputImageType, RADIUS, itk::Function::LanczosWindowFunction<RADIUS> > LanczosInterpolatorType;
typedef itk::WindowedSincInterpolateImageFunction<InputImageType, RADIUS, itk::Function::BlackmanWindowFunction<RADIUS> > BlackmanInterpolatorType;

switch (windowedSincFunction)
{
case WindowedSincFunctionHamming:
resampleLogic->SetInterpolator(HammingInterpolatorType::New())
break;
case WindowedSincFunctionCosine:
resampleLogic->SetInterpolator(CosineInterpolatorType::New())
break;
case WindowedSincFunctionWelch:
resampleLogic->SetInterpolator(WelchInterpolatorType::New())
break;
case WindowedSincFunctionLanczos:
resampleLogic->SetInterpolator(LanczosInterpolatorType::New())
break;
case WindowedSincFunctionBlackman:
resampleLogic->SetInterpolator(BlackmanInterpolatorType::New())
break;
default:
break;
}
#endif

// TODO: What should we do with resamplingParameter?

resampleLogic->ApplyAndWait(cmdNode, false);
resampleLogic->GetMRMLScene()->RemoveNode(cmdNode);
return true;
}
49 changes: 49 additions & 0 deletions Libs/MRML/Logic/vtkMRMLScalarVectorDWIVolumeResampler.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*==============================================================================
Program: 3D Slicer
Copyright(c) Kitware Inc.
See COPYRIGHT.txt
or http://www.slicer.org/copyright/copyright.txt for details.
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/

#ifndef __vtkMRMLScalarVectorDWIVolumeResampler_h
#define __vtkMRMLScalarVectorDWIVolumeResampler_h

// MRMLLogic includes
// TODO: If this file gets moved then choose the correct export here and below
#include "vtkMRMLLogicExport.h"

// MRML includes
#include "vtkMRMLAbstractVolumeResampler.h"

class VTK_MRML_LOGIC_EXPORT vtkMRMLScalarVectorDWIVolumeResampler : public vtkMRMLAbstractVolumeResampler
{
public:
vtkTypeMacro(vtkMRMLScalarVectorDWIVolumeResampler, vtkMRMLAbstractVolumeResampler);
void PrintSelf(ostream & os, vtkIndent indent) override;

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

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

#endif

0 comments on commit e1a501d

Please sign in to comment.