36 template<
typename SrcVolumeType,
typename DstVolumeType>
45 template<
typename SrcVolumeType,
typename DstVolumeType>
48 int32_t uSrcWidth = m_regSrc.getUpperX() - m_regSrc.getLowerX() + 1;
49 int32_t uSrcHeight = m_regSrc.getUpperY() - m_regSrc.getLowerY() + 1;
50 int32_t uSrcDepth = m_regSrc.getUpperZ() - m_regSrc.getLowerZ() + 1;
52 int32_t uDstWidth = m_regDst.getUpperX() - m_regDst.getLowerX() + 1;
53 int32_t uDstHeight = m_regDst.getUpperY() - m_regDst.getLowerY() + 1;
54 int32_t uDstDepth = m_regDst.getUpperZ() - m_regDst.getLowerZ() + 1;
56 if((uSrcWidth == uDstWidth) && (uSrcHeight == uDstHeight) && (uSrcDepth == uDstDepth))
66 template<
typename SrcVolumeType,
typename DstVolumeType>
69 for(
int32_t sz = m_regSrc.getLowerZ(), dz = m_regDst.getLowerZ(); dz <= m_regDst.getUpperZ(); sz++, dz++)
71 for(
int32_t sy = m_regSrc.getLowerY(), dy = m_regDst.getLowerY(); dy <= m_regDst.getUpperY(); sy++, dy++)
73 for(
int32_t sx = m_regSrc.getLowerX(), dx = m_regDst.getLowerX(); dx <= m_regDst.getUpperX(); sx++,dx++)
75 const typename SrcVolumeType::VoxelType& tSrcVoxel = m_pVolSrc->getVoxelAt(sx,sy,sz);
76 const typename DstVolumeType::VoxelType& tDstVoxel =
static_cast<typename DstVolumeType::VoxelType
>(tSrcVoxel);
77 m_pVolDst->setVoxelAt(dx,dy,dz,tDstVoxel);
83 template<
typename SrcVolumeType,
typename DstVolumeType>
84 void VolumeResampler<SrcVolumeType, DstVolumeType>::resampleArbitrary()
86 float srcWidth = m_regSrc.getWidthInCells();
87 float srcHeight = m_regSrc.getHeightInCells();
88 float srcDepth = m_regSrc.getDepthInCells();
90 float dstWidth = m_regDst.getWidthInCells();
91 float dstHeight = m_regDst.getHeightInCells();
92 float dstDepth = m_regDst.getDepthInCells();
94 float fScaleX = srcWidth / dstWidth;
95 float fScaleY = srcHeight / dstHeight;
96 float fScaleZ = srcDepth / dstDepth;
98 typename SrcVolumeType::Sampler sampler(m_pVolSrc);
100 for(
int32_t dz = m_regDst.getLowerZ(); dz <= m_regDst.getUpperZ(); dz++)
102 for(
int32_t dy = m_regDst.getLowerY(); dy <= m_regDst.getUpperY(); dy++)
104 for(
int32_t dx = m_regDst.getLowerX(); dx <= m_regDst.getUpperX(); dx++)
106 float sx = (dx - m_regDst.getLowerX()) * fScaleX;
107 float sy = (dy - m_regDst.getLowerY()) * fScaleY;
108 float sz = (dz - m_regDst.getLowerZ()) * fScaleZ;
110 sx += m_regSrc.getLowerX();
111 sy += m_regSrc.getLowerY();
112 sz += m_regSrc.getLowerZ();
114 sampler.setPosition(sx,sy,sz);
115 const typename SrcVolumeType::VoxelType& voxel000 = sampler.peekVoxel0px0py0pz();
116 const typename SrcVolumeType::VoxelType& voxel001 = sampler.peekVoxel0px0py1pz();
117 const typename SrcVolumeType::VoxelType& voxel010 = sampler.peekVoxel0px1py0pz();
118 const typename SrcVolumeType::VoxelType& voxel011 = sampler.peekVoxel0px1py1pz();
119 const typename SrcVolumeType::VoxelType& voxel100 = sampler.peekVoxel1px0py0pz();
120 const typename SrcVolumeType::VoxelType& voxel101 = sampler.peekVoxel1px0py1pz();
121 const typename SrcVolumeType::VoxelType& voxel110 = sampler.peekVoxel1px1py0pz();
122 const typename SrcVolumeType::VoxelType& voxel111 = sampler.peekVoxel1px1py1pz();
126 sx = modf(sx, &dummy);
127 sy = modf(sy, &dummy);
128 sz = modf(sz, &dummy);
130 typename SrcVolumeType::VoxelType tInterpolatedValue = trilerp<float>(voxel000,voxel100,voxel010,voxel110,voxel001,voxel101,voxel011,voxel111,sx,sy,sz);
132 typename DstVolumeType::VoxelType result =
static_cast<typename DstVolumeType::VoxelType
>(tInterpolatedValue);
133 m_pVolDst->setVoxelAt(dx,dy,dz,result);