View Issue Details Jump to Notes ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0007213VTK(No Category)public2008-06-19 15:322014-10-02 11:52
ReporterDavid Feng 
Assigned ToCory Quammen 
PrioritynormalSeverityminorReproducibilityalways
StatusclosedResolutionfixed 
PlatformOSOS Version
Product Version 
Target VersionFixed in Version5.10.0 
Summary0007213: vtkImageData interpolation on XZ and YZ images
DescriptionAfter creating an image of dimensions (x,1,z), where x and y are integers larger than 1, interpolation via vtkProbeFilter began behaving incorrectly. Specifically, interpolating the points (0,0,0) and (0,0,10) would return the same value.

I found two bugs responsible for this behavior, both in the FindCell(...) function in vtkImageData.cxx:

1 - The cell indexing code assumes that the dimensions will be used in order (use XY instead of XZ). When a dimension is of size 1, the code assumes that there are zero cells/voxels in that direction. This is incorrect -- there is always at least one cell/voxel in each dimension. The computed indices for out-of-order dimensions are therefore incorrect, ignoring upper dimensions. To fix this, I simply check if any dimension is of size 1 and increment it before the cell index is computed. This should not affect in-order images, as the upper dimensions of their pixel indices are all zero.

2 - The interpolation weights assume that the dimensions will be used in order. They need to be shifted down to accommodate missing dimensions. This shifting is a bit tricky. It can be done in two passes. First, check the y dimension -- if it of size 1, shift all even-indexed blocks of weights to the front of the weights array. Second, check the x dimension -- if it is of size 1, shift all even-indexed weights to the front of the array. The z dimension can be ignored, as it clearly already works properly.

I have included the patch in the additional information section of this report.
Additional InformationIndex: vtkImageData.cxx
===================================================================
RCS file: /cvsroot/VTK/VTK/Filtering/vtkImageData.cxx,v
retrieving revision 1.31
diff -u -r1.31 vtkImageData.cxx
--- vtkImageData.cxx 24 Mar 2008 20:52:47 -0000 1.31
+++ vtkImageData.cxx 19 Jun 2008 19:09:54 -0000
@@ -767,6 +767,34 @@
   this->Voxel->InterpolateFunctions(pcoords,weights);
 
   //
+ // Dimensions are used for cell indexing later. if a dimension has only one
+ // voxel, we need to make sure it still has one cell. Also,
+ // the coordinate weights need to be shifted to ignore that dimension.
+ // This is ugly. The order of these ifs makes a difference.
+ //
+
+ //
+ // is y trivial? if so, keep all even blocks of two weights
+ //
+ if (dims[1] == 1)
+ {
+ dims[1] = 2;
+ weights[2] = weights[4];
+ weights[3] = weights[5];
+ }
+
+ //
+ // is x trivial? if so, keep all even indexed weights
+ //
+ if (dims[0] == 1)
+ {
+ dims[0] = 2;
+ weights[1] = weights[2];
+ weights[2] = weights[4];
+ weights[3] = weights[6];
+ }
+
+ //
   // From this location get the cell id
   //
   subId = 0;
TagsNo tags attached.
Project
Type
Attached Files

 Relationships

  Notes
(0012440)
David Feng (reporter)
2008-06-20 10:30

David Gobbe pointed out that the problem most likely stems from vtkVoxel doing all of the interpolation, regardless of the DataDescription variable. A first attempt at using the different data nterpolation methods improved the situation (more of the values interpolated correctly), but still introduced errors on interpolated values on the upper boundaries of the image:

switch (this->DataDescription)
  {
  case VTK_EMPTY:
  default:
    return -1;
    break;

  case VTK_SINGLE_POINT: // cellId can only be = 0
    vtkVertex::InterpolationFunctions(pcoords,weights);
    break;
  
  case VTK_X_LINE:
  case VTK_Y_LINE:
  case VTK_Z_LINE:
    vtkLine::InterpolationFunctions(pcoords,weights);
    break;
 
  case VTK_XY_PLANE:
  case VTK_YZ_PLANE:
  case VTK_XZ_PLANE:
    vtkPixel::InterpolationFunctions(pcoords,weights);
    break;

  case VTK_XYZ_GRID:
    vtkVoxel::InterpolationFunctions(pcoords,weights);
    break;
}
(0012441)
David Feng (reporter)
2008-06-20 10:35

Appologies. Gobbi, not Gobbe.
(0012442)
David Feng (reporter)
2008-06-20 10:40

Sigh. Apologies, not appologies. :)
(0012446)
David Feng (reporter)
2008-06-20 11:44

David Gobbi's suggestion, along with a tweak to the ComputeStructuredCoordinates function, did the trick. The parametric coordinates needed to be shifted to compensate for missing dimensions. The FilterCxxTests still appear to pass. Below is the diff with my file:

Index: vtkImageData.cxx
===================================================================
RCS file: /cvsroot/VTK/VTK/Filtering/vtkImageData.cxx,v
retrieving revision 1.31
diff -u -r1.31 vtkImageData.cxx
--- vtkImageData.cxx 24 Mar 2008 20:52:47 -0000 1.31
+++ vtkImageData.cxx 20 Jun 2008 15:36:41 -0000
@@ -764,8 +764,49 @@
     return -1;
     }
 
- this->Voxel->InterpolateFunctions(pcoords,weights);
+ switch (this->DataDescription)
+ {
+ case VTK_EMPTY:
+ default:
+ return -1;
+ break;
+
+ case VTK_SINGLE_POINT: // cellId can only be = 0
+ vtkVertex::InterpolationFunctions(pcoords,weights);
+ break;
+
+ case VTK_X_LINE:
+ case VTK_Y_LINE:
+ case VTK_Z_LINE:
+ vtkLine::InterpolationFunctions(pcoords,weights);
+ break;
+
+
+ case VTK_XY_PLANE:
+ case VTK_YZ_PLANE:
+ case VTK_XZ_PLANE:
+ vtkPixel::InterpolationFunctions(pcoords,weights);
+ break;
+
+ case VTK_XYZ_GRID:
+ vtkVoxel::InterpolationFunctions(pcoords,weights);
+ break;
+ }
+
+ //
+ // Dimensions are used for cell indexing later. if a dimension has only one
+ // voxel, we need to make sure it still has one cell.
+ //
+ if (dims[1] == 1)
+ {
+ dims[1] = 2;
+ }
 
+ if (dims[0] == 1)
+ {
+ dims[0] = 2;
+ }
+
   //
   // From this location get the cell id
   //
@@ -1138,6 +1179,25 @@
     // extent[2], extent[4]) to (0, 0, 0)
     ijk[i] -= extent[i*2];
     }
+
+ // finally, correct the parametric coordinates by removing/ignoring
+ // the coordinates that don't matter
+ switch (this->DataDescription)
+ {
+ case VTK_Y_LINE:
+ pcoords[0] = pcoords[1];
+ break;
+ case VTK_Z_LINE:
+ pcoords[0] = pcoords[2];
+ break;
+ case VTK_YZ_PLANE:
+ pcoords[0] = pcoords[1];
+ pcoords[1] = pcoords[2];
+ break;
+ case VTK_XZ_PLANE:
+ pcoords[1] = pcoords[2];
+ break;
+ }
   return 1;
 }
(0033472)
Cory Quammen (developer)
2014-10-02 11:51

Fixed in commit:

commit dea934f4f004fc01b1195401c36a8aa978a5f6be
Author: George Zagaris <george.zagaris@kitware.com>
Date: Mon Aug 29 18:11:21 2011 -0400

    BUGFIX:Fix image data interpolationon XZ/YZ planes
    
    Fixed issue wherein the interpolation weights were
    not calculated correctly for image data defined on
    the XZ and YZ planes.
    
    Change-Id: I78746b0df2b16181486558fd274f3807a2f1c64a

 Issue History
Date Modified Username Field Change
2008-06-19 15:32 David Feng New Issue
2008-06-20 10:30 David Feng Note Added: 0012440
2008-06-20 10:35 David Feng Note Added: 0012441
2008-06-20 10:40 David Feng Note Added: 0012442
2008-06-20 11:44 David Feng Note Added: 0012446
2011-02-26 10:33 David Gobbi Assigned To => David Gobbi
2011-02-26 10:33 David Gobbi Status backlog => tabled
2011-06-16 13:11 Zack Galbreath Category => (No Category)
2014-10-02 11:27 Cory Quammen Assigned To David Gobbi => Cory Quammen
2014-10-02 11:51 Cory Quammen Note Added: 0033472
2014-10-02 11:52 Cory Quammen Status backlog => closed
2014-10-02 11:52 Cory Quammen Resolution open => fixed
2014-10-02 11:52 Cory Quammen Fixed in Version => 5.10.0


Copyright © 2000 - 2018 MantisBT Team