[vtkusers] export 3D image data sampled along a spline

David Marshburn marshbur at cs.unc.edu
Mon Oct 4 19:08:12 EDT 2004


I'm wondering about resampling a 3D image (vtkImageData or 
vtkImageToStructuredPoints) along some spline (vtkSplineWidget) and 
exporting the sampled values to a simple comma-separated-value text file 
that can be read by other, data-analysis applications.

I'm specifically wondering if I'm going about this in a reasonable "VTK 
way".  I'm somewhat new to VTK (I inherited from someone else the 
development of the application of which this is a part), and looking at 
the dozen or so classes was a lot for this seemingly simple piece of 
functionality.  I'd appreciate any comments or critiques, please, 
especially about the appropriate use of the various classes or suggestions 
for different ways to do this.

I include below a first-pass idea of how to do this.  The data values 
should be scalars.

Thank you for any assistance!

-David Marshburn



(this uses java-wrapped vtk 4.4)

public static boolean write( File file, vtkSplineWidget spline, vtkPolyDataMapper[] mappers )
throws IOException
{
	vtkProbeFilter[] probes = new vtkProbeFilter[ mappers.length ];
	vtkPolyData polyData = new vtkPolyData();
	spline.GetPolyData(polyData);
	vtkPointData[] pointData = new vtkPointData[ mappers.length ];
	
	// make a probe for each mapper
	for( int i = 0; i <= mappers.length - 1; i++ )
	{
		probes[i] = new vtkProbeFilter();
		probes[i].SetInput( polyData );
		probes[i].SetSource( mappers[i].GetInputAsDataSet() );
		
		pointData[i] = probes[i].GetOutput().GetPointData();
	}
	
	FileWriter out = new FileWriter( file );
	String line = "";

	// write column headers
	for( int i = 0; i <= mappers.length - 1; i++ )
	{
		line += ...
		line += "," + mappers[i].GetArrayName();
	}
	out.write( line );
	
	// write the position of and interpolated data value at each point
	for( int j = 0; j <= polyData.GetNumberOfCells() - 1; j++ )
	{
		line = "";
		// add the xyz position of the point
		double[] point = polyData.GetVerts().GetData().GetTuple3( j );
		line += ...

		// add the interpolated data value
		for( int i = 0; i <= mappers.length - 1; i++ )
		{
			line += ",";
			line += pointData[i].GetScalars().GetTuple1( 0 );
		}
		line += ...
		out.write( line );
	}
	out.flush();
	out.close();
	return true;
}


the vtkPolyDataMappers are all set up in a manner similar to the 
following:

		vtkImageToStructuredPoints colorSource;
		colorSource = new vtkImageToStructuredPoints();
		colorSource.SetInput( ... /* some vtkImageData */ );

		vtkProbeFilter colorProbe = new vtkProbeFilter();
		colorProbe.SetSource(colorSource.GetOutput());
		colorProbe.SetInput(planeFilt.GetOutput());
		
		vtkTransformPolyDataFilter colorFilt = new vtkTransformPolyDataFilter();
		colorFilt.SetInput((vtkPolyData) colorProbe.GetOutput());

		colorPlaneMapper = new vtkPolyDataMapper();
		colorPlaneMapper.SetInput(colorFilt.GetOutput());





More information about the vtkusers mailing list