[vtkusers] Contour surface from vtkUnstructuredGrid data

Bjorn Oksnevad boksnevad at gmail.com
Tue Mar 15 10:04:22 EDT 2011


Hello,
I am trying to visualize a contour surface from a set of measured values in
3d space.  The measured 3d points are irregular because of the experiment
design.  I'm trying to accomplish the visualization by using
the vtkUnstructuredGrid and vtkContourFilter objects.  My code is below.  I
have verified the pipeline and visualization setup by testing with a
vtkRectilinearGrid and that works great.  However, nothing is displayed when
I swap in the vtkUnstructuredGrid.

Has anyone had success visualizing a contour surface from vtkUnstructredGrid
data?

Thanks in advance!
Bjorn

const string positionFileName = @"Positions.txt";
const string thresholdFileName = @"Thresholds.txt";

// Read in points (375 non-repeating points)
var points = new vtkPoints();
var positionFile = File.OpenText(positionFileName);
string line = null;
while ((line = positionFile.ReadLine()) != null)
{
var tokens = line.Trim().Split(' ');
var x = double.Parse(tokens[0]);
var y = double.Parse(tokens[1]);
var z = double.Parse(tokens[2]);

points.InsertNextPoint(x, y, z);
}
positionFile.Close();

// Read in thresholds (375 floats ranging from 0.217 to 349.9)
var thresholds = new vtkFloatArray();
var thresholdFile = File.OpenText(thresholdFileName);
while ((line = thresholdFile.ReadLine()) != null)
{
var threshold = float.Parse(line.Trim());
thresholds.InsertNextValue(threshold);
}
thresholdFile.Close();

// Temp sgrid code to verify pipeline and visualization setup
#region TEMP CODE
var xarray = new float[] { 0.0f, 1.0f, 2.0f };
var yarray = new float[] { 0.0f, 1.0f, 2.0f };
var zarray = new float[] { 0.0f, 1.0f, 2.0f };
var thresholdCount = xarray.Length*yarray.Length*zarray.Length;

var xCoords = new vtkFloatArray();
for (int i = 0; i < xarray.Length; i++) xCoords.InsertNextValue(xarray[i]);
var yCoords = new vtkFloatArray();
for (int i = 0; i < yarray.Length; i++) yCoords.InsertNextValue(yarray[i]);
var zCoords = new vtkFloatArray();
for (int i = 0; i < zarray.Length; i++) zCoords.InsertNextValue(zarray[i]);
var tValues = new vtkFloatArray();
for (int i = 0; i < thresholdCount; i++) tValues.InsertNextValue(i*0.1f +
10.0f);

var sgrid = new vtkRectilinearGrid();
sgrid.SetDimensions(xCoords.GetSize(), yCoords.GetSize(),
zCoords.GetSize());
sgrid.SetXCoordinates(xCoords);
sgrid.SetYCoordinates(yCoords);
sgrid.SetZCoordinates(zCoords);
sgrid.GetPointData().SetScalars(tValues);
#endregion

// Setup pipeline and visualization
var ugrid = new vtkUnstructuredGrid();
ugrid.SetPoints(points);
ugrid.GetPointData().SetScalars(thresholds);

var contour = new vtkContourFilter();
//contour.SetInputConnection(sgrid.GetProducerPort());  // Works great
contour.SetInputConnection(ugrid.GetProducerPort());  // Displays nothing
contour.SetValue(0, 10.5);

var mapper = vtkPolyDataMapper.New();
mapper.SetInputConnection(contour.GetOutputPort());

var actor = new vtkActor();
actor.SetMapper(mapper);

renderer.AddActor(actor);
renderer.ResetCamera();
renderWindow.Render();
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20110315/a3657062/attachment.htm>


More information about the vtkusers mailing list