trilinear interpolation
Ray geometry and interpolation fixed.
This commit is contained in:
@ -48,6 +48,7 @@ CIT 6, 89-94 (1998).
|
||||
#define itkgSiddonJacobsRayCastInterpolateImageFunction_hxx
|
||||
|
||||
#include "itkgSiddonJacobsRayCastInterpolateImageFunction.h"
|
||||
#include "itkContinuousIndex.h"
|
||||
|
||||
#include "itkMath.h"
|
||||
#include <cstdlib>
|
||||
@ -473,37 +474,52 @@ gSiddonJacobsRayCastInterpolateImageFunction<TInputImage, TCoordRep>::Evaluate(c
|
||||
if (value > m_Threshold) /* Ignore voxels whose intensities are below the threshold. */
|
||||
{
|
||||
|
||||
// Move along the ray by alphaCminPrev to find the entry point of this voxel
|
||||
PointType entryPoint;
|
||||
entryPoint[0] = SourceWorld[0] + alphaCminPrev * rayVector[0] ;
|
||||
entryPoint[1] = SourceWorld[1] + alphaCminPrev * rayVector[1] ;
|
||||
entryPoint[2] = SourceWorld[2] + alphaCminPrev * rayVector[2] ;
|
||||
|
||||
// Move along the ray by alphaCmin to find the exit point of this voxel
|
||||
PointType exitPoint;
|
||||
exitPoint[0] = SourceWorld[0] + alphaCmin * rayVector[0] ;
|
||||
exitPoint[1] = SourceWorld[1] + alphaCmin * rayVector[1] ;
|
||||
exitPoint[2] = SourceWorld[2] + alphaCmin * rayVector[2] ;
|
||||
|
||||
// PointType entryPoint = SourceWorld + alphaCminPrev * rayVector;
|
||||
// PointType exitPoint = SourceWorld + alphaCmin * rayVector;
|
||||
// Get the mid-point of the voxel / ray interception
|
||||
PointType midpoint;
|
||||
midpoint[0]= (entryPoint[0] + exitPoint[0]) * 0.5;
|
||||
midpoint[1]= (entryPoint[1] + exitPoint[1]) * 0.5;
|
||||
midpoint[2]= (entryPoint[2] + exitPoint[2]) * 0.5;
|
||||
|
||||
// = (entryPoint + exitPoint) * 0.5;
|
||||
// Ray is computed in 'Siddon' geometry with zero origin,
|
||||
// whereas the continuous index will be computed from the input
|
||||
// image. The origin and shifts to the voxel edge are to be account for
|
||||
midpoint[0] += ctOrigin[0] ;//+ O[0];
|
||||
midpoint[1] += ctOrigin[1] ;//+ O[1];
|
||||
midpoint[2] += ctOrigin[2] ;//+ O[2];
|
||||
|
||||
// Convert mid-point phyisical point into continuous index
|
||||
// We need to use this position to find the neighbouring voxels
|
||||
// for trilinear interpolation - not the cIndex!
|
||||
itk::ContinuousIndex <double,3> continuousIndex;
|
||||
inputPtr->TransformPhysicalPointToContinuousIndex(midpoint,continuousIndex);
|
||||
|
||||
// Get the baseIndex by flooring the continuous index
|
||||
IndexType baseIndex;
|
||||
baseIndex[0]=static_cast<IndexValueType>(std::floor(continuousIndex[0]));
|
||||
baseIndex[1]=static_cast<IndexValueType>(std::floor(continuousIndex[1]));
|
||||
baseIndex[2]=static_cast<IndexValueType>(std::floor(continuousIndex[2]));
|
||||
|
||||
// Calculate fractional parts for interpolation at the midpoint
|
||||
double x_frac = midpoint[0] - std::floor(midpoint[0]);
|
||||
double y_frac = midpoint[1] - std::floor(midpoint[1]);
|
||||
double z_frac = midpoint[2] - std::floor(midpoint[2]);
|
||||
double x_frac = continuousIndex[0] - baseIndex[0];
|
||||
double y_frac = continuousIndex[1] - baseIndex[1];
|
||||
double z_frac = continuousIndex[2] - baseIndex[2];
|
||||
|
||||
// Perform boundary checks for trilinear interpolation
|
||||
IndexType baseIndex = cIndex;
|
||||
bool within_bounds = (baseIndex[0] >= 0 && baseIndex[0] < sizeCT[0] - 1) &&
|
||||
(baseIndex[1] >= 0 && baseIndex[1] < sizeCT[1] - 1) &&
|
||||
(baseIndex[2] >= 0 && baseIndex[2] < sizeCT[2] - 1);
|
||||
|
||||
if (within_bounds)
|
||||
{
|
||||
// Fetch intensities from neighboring voxels for trilinear interpolation
|
||||
@ -523,6 +539,8 @@ gSiddonJacobsRayCastInterpolateImageFunction<TInputImage, TCoordRep>::Evaluate(c
|
||||
baseIndex[0] -= 1;
|
||||
float c001 = static_cast<float>(inputPtr->GetPixel(baseIndex));
|
||||
|
||||
// NOTE: do not use baseIndex anymore after this. It's messed up.
|
||||
|
||||
// Perform trilinear interpolation at the midpoint
|
||||
float c00 = c000 * (1 - x_frac) + c100 * x_frac;
|
||||
float c01 = c001 * (1 - x_frac) + c101 * x_frac;
|
||||
|
Reference in New Issue
Block a user