Question

I'm trying to visualize some data I have stored on a regular grid using VTK (drawing a colored isosurface). I wrote some code to dump the data in the vtk legacy format which works for low resolution versions of the data. I can extract and view the expected isosurface with ParaView or the VTK library. When I increase the resolution by a factor of 10 in each dimension (nx goes from about 100 to 1000, same with ny, nz), paraview and a viewer I wrote using the VTK library are incorrect. They look like a set of slightly off-axis sheets instead of a single "blob". I know from other tests that the data itself is correct.

Is there something wrong with my legacy vtk format dumping code below? I don't understand what the lookup table does, but it seems to work fine for the low resolution case.

std::ofstream out(filename);

out << "# vtk DataFile Version 3.0" << std::endl;
out << "Signed distance/biharmonic visualizer" << std::endl;
out << "ASCII" << std::endl;
out << "DATASET STRUCTURED_POINTS" << std::endl;
out << "DIMENSIONS " << nx << " " << ny << " " << nz << std::endl;
out << "ORIGIN 0 0 0" << std::endl;
out << "SPACING " << h << " " << h << " " << h << std::endl;
out << "POINT_DATA " << nx*ny*nz << std::endl;
out << "SCALARS signedDistance double" << std::endl;
out << "LOOKUP_TABLE default" << std::endl;
for(size_t i = 0; i < nx; ++i)
  for(size_t j = 0; j < ny; ++j)
    for(size_t k = 0; k < nz; ++k)
      out << tempPhi(i,j,k) << std::endl;
out << "SCALARS biharmonic double" << std::endl;
out << "LOOKUP_TABLE default" << std::endl;
for(size_t i = 0; i < nx; ++i)
  for(size_t j = 0; j < ny; ++j)
    for(size_t k = 0; k < nz; ++k)
      out << biharmonic(i,j,k) << std::endl;
out.close();
Was it helpful?

Solution

In the VTK file you provide there are a number of occurrences of 1.79769e+308. To actually 'see' your data I had to replace these with zeros. Having done this and looked at your data file in VisIt I would guess that your method of writing the point data is incorrect (your three nested for loops - which flatten the data from 3D to a 1D list).

I would suggest that you you write some small test data sets with your VTK writer and also with this simple C code, which is supplied with VisIt to write legacy VTK files. Make sure that the data sets written with both methods agree exactly (note that VisItWriterLib.c writes version 2 VTK file formats, whereas you use version 3 - this shouldn't cause a problem however).

Edit: As discussed in the comments, the problem was the ordering of the nested for loops which were used to output the point data and flatten it from 3D to a 1D list. The code

for(size_t i = 0; i < nx; ++i)
  for(size_t j = 0; j < ny; ++j)
    for(size_t k = 0; k < nz; ++k)
      out << tempPhi(i,j,k) << std::endl;

should in fact read

for(size_t k = 0; k < nz; ++k)
  for(size_t j = 0; j < ny; ++j)
    for(size_t i = 0; i < nx; ++i)
      out << tempPhi(i,j,k) << std::endl;

i.e. the data should be written in column major order, not row major. This is a point in which the VTK file formats document is lacking.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top