enthought / mayavi

3D visualization of scientific data in Python
http://docs.enthought.com/mayavi/mayavi/
Other
1.32k stars 285 forks source link

CPU freeze with filled contours for array with nans #67

Open klonuo opened 11 years ago

klonuo commented 11 years ago

If I draw with mlab.surf(z), and change surface preferences to contours, I get line contours as expected. If I set filled contours CPU is maxed and process never finishes. z is array with nans, and I guess that's the reason for this behavior as otherwise filled contours works fine.

For example:

array([[ -2. ,   2. ,  -3.4,  -3.5,  -3.1,  -2.9,  -5.2,   0. ,  -0.7,
         -3. ,  -3. ,  -4.7,  -2.7,   1.8,   4.2,   6.6,   5.3,   1.9,
          7.1,  10.1,   8.2,  16.5,  10.3,  10.3,  10.2,  11.3,   6.6,
          8.2,   7.9,   4.7,   4.1],
       [  5.2,   8.1,  10.1,  17.4,  17. ,  12.1,  15.7,  13.1,   7.8,
          8.4,  12.1,   4.9,   2.8,   2.7,   2.3,   2.7,   3.3,   5.2,
          0.3,   0.9,   2.8,   2.3,   2.7,   5.4,   6.5,   6.8,   9.2,
          9.2,   nan,   nan,   nan],
       [ 14.7,  14.2,  10.7,  12.4,  12.4,  14. ,  11. ,   9.4,  13. ,
          9.2,  11.4,   7.3,  10.3,   8.4,  12.5,  11. ,   8.5,   8.7,
          8.9,   0. ,   1.2,   3.8,   6.8,   8. ,   1.7,   6.1,  12.5,
         15.1,  15.4,  18.4,  20.5],
       [ 19.7,  22.1,  17.7,  19.8,  21.6,  21.3,  20.9,  21.3,  22.4,
         22.6,  21.4,  20.8,  11.5,  10.7,  15.7,  21.2,  23.5,  18.3,
         17.7,  18.9,  18.4,  11.6,  16.8,  18.5,  19.9,  18. ,  18.2,
         15.2,  16.5,  15.1,   nan],
       [ 12. ,  19. ,  18.7,  21.2,  16.7,  20.3,  18.8,  22.7,  26. ,
         26.9,  27.2,  27.2,  27.9,  26. ,  28.1,  26.9,  27.6,  26. ,
         27.1,  28.5,  27.4,  28.7,  29.5,  30. ,  27.3,  25.4,  26.7,
         25. ,  13.3,  12.4,  22. ],
       [ 23.9,  25.7,  20.9,  24.6,  26.2,  27.8,  30. ,  28.8,  31.4,
         32.6,  31.4,  25.1,  24.6,  25.9,  29.1,  31.9,  29.1,  25. ,
         28.8,  31.5,  26. ,  21.3,  24. ,  18. ,  20.1,  24.9,  20. ,
         27.6,  27.9,  27.4,   nan],
       [ 27. ,  28.7,  28.5,  28.8,  28.8,  28.3,  27.9,  31.2,  27.9,
         24.7,  20.8,  23.2,  26.3,  29.5,  33. ,  33.7,  33. ,  34. ,
         26.6,  27.1,  28.7,  31.2,  32.9,  36.1,  37.4,  27.5,  29. ,
         30.7,  32.1,  32.1,  32.5],
       [ 32.8,  34.5,  34.6,  34.3,  28.6,  25.6,  21.1,  29.3,  28.1,
         29.5,  29. ,  23.7,  28.8,  30.5,  28.6,  29.5,  31.3,  31.6,
         31.9,  31.5,  31.5,  31.3,  30.8,  26.7,  26.5,  30.2,  31.2,
         32. ,  32.3,  27.2,  26.8],
       [ 28.2,  30.2,  31.6,  32.9,  33.3,  19.3,  18.4,  20.8,  24.3,
         26.6,  26.2,  20.4,  22.9,  23.8,  26.4,  28.5,  25.8,  26.9,
         23.4,  25.2,  24.6,  24.6,  25.1,  26.7,  21.5,  24.8,  25.1,
         24.7,  25.6,  26.6,   nan],
       [ 27.8,  23.4,  12.2,  18.8,  24.5,  24.3,  25.3,  25.4,  26. ,
         27.1,  25.6,  22.4,  11.7,  12.2,  12.8,   6.5,  11.4,   8.1,
          9.7,  12.4,  13.3,  15.7,  19. ,  16.1,  19.1,  20.9,  16.8,
         16.1,  16.7,  11.8,   9.5],
       [  9.8,   8. ,   4.7,  10.8,   7.7,  19.3,  17.9,  15.8,  12.7,
         13.2,  10.4,  13.4,  14. ,  13.3,  10.9,  13.9,  16.7,  13.4,
         13. ,  15.2,  13.6,  13. ,  12.3,  11.8,  15.1,  12.8,   9.1,
          8.9,   9. ,   4.9,   nan],
       [ 13.5,  14.3,  11.6,  10.7,  11. ,  10.2,  10.6,  11. ,   8.5,
          8.1,   7.4,   1.6,   4.5,   3.4,   5. ,   3.1,   5.2,  -0.6,
         -2.6,  -2.2,  -4.8,  -2.5,   5.3,   2.6,  14.4,  14.1,   9.9,
          6.8,   9.1,   5.7,  11.2]])
stefanoborini commented 8 years ago

Cannot reproduce on OSX. Can reproduce on Linux Ubuntu. Investigating.

stefanoborini commented 8 years ago

Currently building VTK to debug the problem. Will leave pending until done and move to something else.

stefanoborini commented 8 years ago

The freeze seems to happen in int vtkBandedPolyDataContourFilter::RequestData. Very substantial routine, so it will take some time.

stefanoborini commented 8 years ago

Apparently, it is stuck in this part of the RequestData

      for ( mR=idx, intersectionPoint=0; !intersectionPoint; )
        {
        numPointsToAdd++;
        mR = (mR + 1) % numFullPts;
        if ( isContourValue[mR] && s[mR] != s[idx] ) intersectionPoint = 1;
        }

never finding an intersection point, so the loop becomes infinite.

stefanoborini commented 8 years ago

I start to think that nans are not the reason. do you get reasonable contour curves if you remove the nans, or do they look tangled and broken?

stefanoborini commented 8 years ago

managed to reduce the dataset to the minimalistic

from numpy import array, nan
from mayavi import mlab

z=array([
       [ -2.0, 4.7,  4.1],
       [ 23.9, 27.4, nan],
       [ 28.2, 26.6, nan],
])

mlab.surf(z)
mlab.show()

both the negative and the two nans seem to be important to obtain the problem. In any case, I am confident it's a vtk problem. I will write a pure vtk example and then submit it to the vtk bug tracker. I am unsure I can do much more than this.

stefanoborini commented 8 years ago

I give up on this. I wanted to create the exact vtk pipeline that generates the bug to post a bug report to vtk, but I can't find a way to extract the runtime generated vtk pipeline from mayavi, short of going low-level.

I will do a bug report anyway, and I hope they can come up with a better understanding of what happens at low level. Will update this comment with a link to the vtk bug report.

stefanoborini commented 8 years ago

Reported here

http://www.vtk.org/Bug/view.php?id=16065

@prabhuramachandran maybe you have some useful hints about the mayavi pipeline that might help me in providing a "working" vtk case.