interpolation and padding

29 views
Skip to first unread message

Phil Suess

unread,
Mar 3, 2015, 6:23:04 PM3/3/15
to field...@googlegroups.com
Hi,

first off: great library. It has a very clean and good "feel" to it. However, I did run into a confusing fact and I hope there is a simple explanation for what I'm doing wrong.

I'm trying to interpolate a dense field into another which is of same resolution, but shifted by half a voxel. In my application there could be arbitrary shifts and different resolutions (# voxels and voxel sizes). I attached a program that illustrates what is happening and its output to this. I expected it to be different.

As the grids might not overlap and I want to interpolate correctly at the boundary (i.e. assume 0 everywhere outside my data window), I thought I would use padding when setting the size of the field:
setSize(Field3D::V3i(nNumVoxels), nNumVoxelsPadding);

 What happens is that the values don't initialize at the one side of the padding. Here's a print of one slice of the source field - it's the third slice of the source field in out.txt, padding is 2 voxels:

0    0    0    0    0    #    #   
0    0    0    0    0    #    #   
0    0    0    1    2    #    #   
0    0    3    4    5    #    #   
0    0    6    7    8    #    #   
#    #    #    #    #    #    #   
#    #    #    #    #    #    #


The # denote voxels that are not inBound of the field and hence don't have a value. When I interpolate (linear) these values in world coordinates shifted by half a voxel to the right (in x direction), I get the following for the same slice:

0    0    0    0    0    #    #   
0    0    0    0    0    #    #   
0    0    0.5  1.5  2    #    #   
0    0    3.5  4.5  5    #    #   
0    0    6.5  7.5  8    #    #   
#    #    #    #    #    #    #   
#    #    #    #    #    #    #   


That is, the first two values in the data window are exactly as I expect them to be: the average between the neighboring entries. However, I would have expected the padding voxels to hold "0" as well, so that the interpolated slice would have looked like this:

0    0    0    0    0    #    #   
0    0    0    0    0    #    #   
0    0    0.5  1.5  1    #    #   
0    0    3.5  4.5  2.5  #    #   
0    0    6.5  7.5  4    #    #   
#    #    #    #    #    #    #   
#    #    #    #    #    #    #  


Am I operating based on wrong assumptions?

Thanks in advance,

Phil
out.txt
Field3DSimple.cpp

Sosh Mirsepassi

unread,
Mar 3, 2015, 7:59:50 PM3/3/15
to field...@googlegroups.com
I think the problem is that you i,j,k for the sampling values starts at nNumVoxelsPadding rather than -nNumVoxelsPadding

Also there is iterator you can use for this as follow:

  Field3D::DenseFieldf::iterator i = vxlField_Shifted.begin();
  Field3D::DenseFieldf::iterator end = vxlField_Shifted.end();
  for (; i != end; ++i) {
    vxlField_Shifted.mapping()->voxelToWorld(Field3D::discToCont(Field3D::V3i(i.x,i.y,i.z)), vwsTargetVoxel);
    vxlField.mapping()->worldToVoxel(vwsTargetVoxel, vvsSourceVoxel);
    *i = vxlInterpolator.sample(vxlField, vvsSourceVoxel);
  }




--
You received this message because you are subscribed to the Google Groups "Field3D dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to field3d-dev...@googlegroups.com.
To post to this group, send email to field...@googlegroups.com.
Visit this group at http://groups.google.com/group/field3d-dev.
For more options, visit https://groups.google.com/d/optout.

Phil Suess

unread,
Mar 4, 2015, 2:53:20 AM3/4/15
to field...@googlegroups.com
Thanks for the quick reply, Sosh. The snipplet about the iterator is great, I hadn't looked at that yet and it is helpful to get good advice like that.

However, as for the interpolation, it didn't change the result. The right part of the slice still comes up as I would not expect it to. BTW, if I change the shift to the left (i.e. a -1 in x direction), the interpolation does exactly what I expect it to, as the padded voxels "to the left" are initialized to 0 internally.

Still confused,

Phil
Reply all
Reply to author
Forward
0 new messages