Issues with rendering streaming 3D data

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Issues with rendering streaming 3D data

Neel Patel 0-0-0
Hi all. I'm trying to render streaming 3d data and I have a couple questions.

1) Does anyone have experience doing this and if so how did you structure your code to update data and render it, and how fast was it?

2) I have some code that does work for about a couple seconds before I get an exception in Kitware.VTK.dll as I'm using ActiViz. If I take out the render call in the code below, it seems to be ok. It only seems to have a problem rendering.

                try
                {
                    byte[] myByteArray =StreamObject.Bytes;

                    GCHandle gPointer = GCHandle.Alloc(myByteArray, GCHandleType.Pinned);
                    imageImport.SetImportVoidPointer(gPointer.AddrOfPinnedObject());
                    imageImport.Update();
                    imageImport.Modified();

                    // Set up renderer
                    vtkRenderer renderer = renderWindowControl1.RenderWindow.GetRenderers().GetFirstRenderer();
                    //renderer.ResetCamera();

                    // Create transfer mapping scalar value to opacity
                    vtkPiecewiseFunction opacityTransferFunction = vtkPiecewiseFunction.New();
                    opacityTransferFunction.AddPoint(70, 0.0);
                    opacityTransferFunction.AddPoint(255, 0.1);

                    // Create transfer mapping scalar value to color
                    vtkColorTransferFunction colorTransferFunction = vtkColorTransferFunction.New();
                    colorTransferFunction.AddRGBPoint(0.0, 0.0, 0.0, 0.0);
                    //colorTransferFunction.AddRGBPoint(100.0, 0.0, 0.0, 1.0);
                    colorTransferFunction.AddRGBPoint(255.0, 1.0, 1.0, 1.0);

                    // The property describes how the data will look
                    vtkVolumeProperty volumeProperty = vtkVolumeProperty.New();
                    volumeProperty.SetColor(colorTransferFunction);
                    volumeProperty.SetScalarOpacity(opacityTransferFunction);
                    //volumeProperty.ShadeOn();
                    //volumeProperty.SetInterpolationTypeToLinear();

                    // The mapper / ray cast function know how to render the data
                    vtkVolumeRayCastCompositeFunction compositeFunction = vtkVolumeRayCastCompositeFunction.New();
                    vtkVolumeRayCastMapper volumeMapper = vtkVolumeRayCastMapper.New();
                    volumeMapper.SetVolumeRayCastFunction(compositeFunction);

                    // Link the volume render object to the byte array data
                    // volumeMapper.SetInput(myVtkImageData);
                    volumeMapper.SetInput(imageImport.GetOutput());
                    volumeMapper.Modified();

                    // The volume holds the mapper and the property and can be used to position/orient the volume
                    vtkVolume volume = vtkVolume.New();
                    volume.SetMapper(volumeMapper);
                    volume.SetProperty(volumeProperty);
                    volume.Modified();

                    // Add volume to renderer
                    renderer.AddVolume(volume);
                    renderer.SetBackground(0, 0, 0);
                    renderer.Modified();

                    renderer.GetRenderWindow().Render();
                    gPointer.Free();
                    myByteArray = null;


                }
                catch (Exception ex) {
                    throw;
                }


The issue is that when the program starts the first pass through the renderer goes through and it displays as it should, the second time I get an access violation exception. If I use similar coed for 2D however it seems to run fine.

Any help, tips, general advice on streaming with VTK are welcome.

                                    Regards,
                                          Neel
Loading...