[vtkusers] How to set data programmatically...

Mike Jackson mike.jackson at bluequartz.net
Tue May 5 13:51:36 EDT 2009


You probably want to write your own custom reader object. There are
lots of examples floating around the internet on that. The basics are:

Select a vtk class in which to inherit from. In your case probably
vtkStructuredPointsAlgorithm?
programatically set the "numberOfInputs=0".
Implement the RequestInformation and RequestData methods.

In the RequestInformation method you should read just enough
information from your file to be able to setup the output type with
its extents  and all that.

In the RequestData method do the actual reading of data from your file
and convert it into a vtk object as appropriate.

HTH
Mike

On Tue, May 5, 2009 at 11:26 AM, Theodore Holden
<theodoreholden at yahoo.com> wrote:
> 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
>
>
>
>
>
>
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the VTK FAQ at:
> http://www.vtk.org/Wiki/VTK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers
>
>



More information about the vtkusers mailing list