[vtkusers] contour lines not closed with vtkUnstructuredGrid

Burlen burlen at apollo.sr.unh.edu
Tue Feb 14 14:23:22 EST 2006


Hi, I have an issue with contours of some multiresolution data. The data is 
comprised of adjacent "boxes" that don't overlap represented using 
vtkImageData. Each box may have a different spacing, like dx=0.25 for one and 
dx=0.0125 for another. To visualize I have been using the vtkAppendFilter to 
combine all the boxes into a single unstructured grid for visualization. The 
problem I'm having is that contours of the resulting dataset aren't closed, 
and I can see that where they separate is where the grid spacing changes. I 
think this is a result of less acurate interpolation in the coarser spaced 
regions. even so shouldn't the contours be closed? Is this an issue with the 
contouring algorithm in vtk or do I have to admit defeat and forget about 
visualizing multi resolution datasets?


I have included some test code that illustrates what I'm doing and also 
attahced an image that was saved from the visualization of the data generated 
by the test.


#!/usr/local/bin/python2.3

from math import *
from sys import stdout
import vtk

nx = 8
ny = 8
dx = 0.25

af = vtk.vtkAppendFilter();


#
# create 4 data sets that are adjacent and will be
# appeneded into 1 unstructured grid for visualization
# the resulting dataset will be -2 to 2 square centered
# on the origin
#
boxes = []
boxes.append(vtk.vtkImageData());
boxes.append(vtk.vtkImageData());
boxes.append(vtk.vtkImageData());
boxes.append(vtk.vtkImageData());

data = []
data.append(vtk.vtkFloatArray());
data.append(vtk.vtkFloatArray());
data.append(vtk.vtkFloatArray());
data.append(vtk.vtkFloatArray());

boxes[0].SetOrigin(0.0,0.0,0.0);
boxes[1].SetOrigin(-2.0,-2.0,0.0);
boxes[2].SetOrigin(-2.0,0.0,0.0);
boxes[3].SetOrigin(0.0,-2.0,0.0);



#
# for each dataset
#
m=2;
i=0;
while ( i<4 ):
  data[i].SetNumberOfTuples((m*nx+1)*(m*ny+1));
  data[i].SetNumberOfComponents(1);
  data[i].SetName("data");
  
  boxes[i].SetDimensions(m*nx+1,m*ny+1,1);
  boxes[i].SetSpacing(dx/m,dx/m,dx/m);
  
  bnds = boxes[i].GetBounds();

  #
  # genrate scalar data z=cos(x)cos(y) on varying grid spacing
  # each dataset i has 1/(2i) grid spacing of previous dataset
  #
  q=0;
  j=0;
  while( j<m*ny+1 ):
    k=0;
    while( k<m*nx+1 ):
      x = dx/m*k+bnds[0];
      y = dx/m*j+bnds[2];
      
      data[i].SetTuple1(q,cos(x)*cos(y))
      q+=1
      k+=1

    j+=1

  boxes[i].GetPointData().AddArray(data[i])
  boxes[i].GetPointData().SetActiveScalars("data")
  
  af.AddInput(boxes[i])
  i+=1
  m+=2


#
# write to file for visualization, mayavi or paraview
#
ugw = vtk.vtkUnstructuredGridWriter()
ugw.SetFileName("append.vtk")
ugw.SetInput(af.GetOutput())
ugw.Write()




-- 

Burlen Loring
Space Science Center
Institute for the Study of Earth, Oceans, and Space
University of New Hampshire
39 College Road, Durham, NH 03824
Phone: 603-862-1140
-------------- next part --------------
A non-text attachment was scrubbed...
Name: contours_not_closed.png
Type: image/png
Size: 46933 bytes
Desc: not available
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20060214/946891ee/attachment.png>


More information about the vtkusers mailing list