[vtkusers] How to set data programmatically...
Theodore Holden
theodoreholden at yahoo.com
Tue May 5 11:26:41 EDT 2009
Hi,
I have an 3d visualization application which reads data from a file which isn't related to vtk and at present I'm having to write the data out in vtk format to disk and then let a vtk reader read it a second time.
It would help considerably if I was able to simply pass the data to vtk internally but thus far I've not been able to figure out how to do it and nothing I see on the web helps. The data is unsigned char and the piece of code which presents it looks like this:
void AddBagVolumeToWindow4(vtk.vtkRenderWindow renWin)
{
// 3d texture map
vtkStructuredPointsReader reader = new vtkStructuredPointsReader();
vtkVolume volume = new vtkVolume();
vtkVolumeProperty volumeProperty = new vtkVolumeProperty();
vtkRenderer renderer = new vtkRenderer();
vtkRenderWindowInteractor interactor = new vtkRenderWindowInteractor();
vtkVolumeTextureMapper3D volumeMapper = new vtkVolumeTextureMapper3D();
//vtkVolumeRayCastCompositeFunction compositeFunction = new vtkVolumeRayCastCompositeFunction();
vtkPiecewiseFunction opacity = new vtkPiecewiseFunction();
vtkColorTransferFunction color = new vtkColorTransferFunction();
reader.SetFileName("c:\\zz.vtk");
reader.Update();
opacity.AddPoint(0, 0);
opacity.AddPoint(64, .005);
opacity.AddPoint(128, .01);
opacity.AddPoint(200, .05);
opacity.AddPoint(220, .4);
color.AddRGBPoint(64, .665, .84, .88);
color.AddRGBPoint(128, 0, .746, .95);
color.AddRGBPoint(220, 0, 1, 0);
color.AddRGBPoint(230, 1, 0, 0);
volumeProperty.SetColor(color);
volumeProperty.SetScalarOpacity(opacity);
volumeProperty.SetInterpolationTypeToLinear();
volumeProperty.ShadeOn();
volumeMapper.SetInput(reader.GetOutput());
//int[] iiex = reader.GetOutput().GetExtent();
volume.SetMapper(volumeMapper);
volume.SetProperty(volumeProperty);
renderer.SetBackground(1, 1, 1);
renderer.AddVolume(volume);
interactor.SetRenderWindow(renWin);
renWin.AddRenderer(renderer);
renx = renderer;
volx = volume;
renWin.Render();
interactor.Start();
vtk.vtkWin32OpenGLRenderWindow win32win =
vtk.vtkWin32OpenGLRenderWindow.SafeDownCast(renWin);
win32win.Clean();
}
That's after the data has been written out to "c:\\zz.vtk" of course. What it looks like I'd want to do, rather than use the vtkStructuredPointsReader, is to set up my own vtkStructuredPoints object something like:
vtkStructuredPoints bsp = new vtkStructuredPoints();
bsp.SetScalarTypeToUnsignedChar();
bsp.SetDimensions(Width, Height, NumSlices);
bsp.SetOrigin(0, 0, 0);
bsp.SetExtent(0, Width - 1, 0, Height - 1, 0, NumSlices - 1);
and then set the data array but, again, I've no clue as to how to do that. Any help would be apreciated.
Ted
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20090505/ce4a7a49/attachment.htm>
More information about the vtkusers
mailing list