[vtkusers] Loading a volume object using pointers in C#

Theodore Holden theodoreholden at yahoo.com
Tue Jun 30 16:44:49 EDT 2009


Hi,

The VTK project I've worked on is in good shape other than perhaps going from 5 seconds to load scenes to under a second via parallel processing if possible.

The biggest problem I had was finding the information needed to load volume objects directly.  For the first several weeks the only thing I was able to turn up either in books on on the net for loading objects was the SetScalarComponentFromFloat function which is very slow and the information to load using pointers only turned up accidentally searching for something else.

A reasonable C# routine to load a VTK volume should look more or less like this:

        public unsafe void loadVolume(  int Width, int Height, int NumSlices, ushort[] some3D_data, ...)
         
        {
                ....

                ushort* volptr = (ushort*)sp.GetScalarPointer();
                
                ....
                
                vtkStructuredPoints sp = new vtkStructuredPoints();
                sp.SetExtent(0, Width, 0, Height, 0, NumSlices);
                sp.SetOrigin(0, 0, 0);
                sp.SetDimensions(Width, Height, NumSlices);
                sp.SetSpacing(1.0, 1.0, 1.0);
                sp.SetScalarTypeToUnsignedShort();
                sp.SetNumberOfScalarComponents(1);

                ushort* volptr = (ushort*)sp.GetScalarPointer();                
                
                int volindex = 0;
                for (z = 0; z < NumSlices; z++)
                {
                    for (y = 0; y < Height; y++)
                    {
                        for (x = 0; x < Width; x++)
                        {
                            ii = z * SliceSize + y * Width + x;
                            ww = some3D_data[ii];
                            *(volptr + volindex++) = ww
                        }
                    }
                }
                            ......
                                                       
                }


It would be good if the next person needing this particular piece of information would somehow  have an easier time finding it than I did.


Ted



      
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20090630/21d743b9/attachment.htm>


More information about the vtkusers mailing list