[vtkusers] Volume Rendering with vtkUnstructuredGridRayCastMapper

Randall Hand randall.hand at gmail.com
Wed Dec 28 14:38:30 EST 2005


I'm attempting to render an unstructured dataset that contains 1 vector
field and 7 scalar fields.  I want to map Color & Opacity to one of the 1
scalar fields (both to the same one) and volume render it.  I can do this in
Paraview easily (screenie attached), but my VTK code returns a blank black
window everytime.  Am I missing something here?

I'm doing it all offscreen on an SGI Irix box (Onyx340) with the VTK
5.0Branch installed & MangledMesa.  The code I'm using is below:

==============================
#include <vtkColorTransferFunction.h >
#include <vtkDataSetReader.h>
#include <vtkPiecewiseFunction.h>
#include <vtkUnstructuredGridVolumeRayCastMapper.h>
#include <vtkUnstructuredGrid.h>
#include < vtkDataSet.h>
#include <vtkRenderWindow.h>
#include <vtkRenderer.h>
#include <vtkRenderLargeImage.h>
#include <vtkPNGWriter.h>
#include <vtkVolumeProperty.h>
#include <vtkDataSetTriangleFilter.h >
#include <vtkImagingFactory.h>
#include <vtkGraphicsFactory.h>
void main(void) {
    vtkGraphicsFactory *factGraphics = vtkGraphicsFactory::New();
    factGraphics->SetUseMesaClasses(1);
    factGraphics->SetOffScreenOnlyMode(1);
    factGraphics->Delete();
    vtkImagingFactory *factImage = vtkImagingFactory::New();
    factImage->SetUseMesaClasses(1);
    factImage->Delete();
    vtkDataSetReader *reader = vtkDataSetReader::New();
    reader->SetFileName("../VTK/step_127.vtk");
    reader->ReadAllScalarsOn();

    vtkDataSetTriangleFilter *tri = vtkDataSetTriangleFilter::New();
    tri->SetInput(reader->GetOutput());


    vtkColorTransferFunction *color = vtkColorTransferFunction::New();

    color->AddRGBPoint(250, 0, 0, 1);
    color->AddRGBPoint(450, 1, 0, 0);
    color->AddRGBPoint(2600, 1, 1, 0);
    color->AddRGBPoint(5000, 1, 1, 1);

    vtkPiecewiseFunction *opacity = vtkPiecewiseFunction::New();
    opacity->AddPoint(250, 0.1);
    opacity->AddPoint(450, 0.1);
    opacity->AddPoint(2600, 0.25);
    opacity->AddPoint(5000, 1.0);

    vtkVolumeProperty *volProp = vtkVolumeProperty::New();
    volProp->SetColor(color);
    volProp->SetScalarOpacity(opacity);
    volProp->SetInterpolationTypeToLinear();

    vtkUnstructuredGridVolumeRayCastMapper *mapper =
            vtkUnstructuredGridVolumeRayCastMapper::New();
    mapper->SetScalarModeToUsePointFieldData();
    mapper->SelectScalarArray("Temperature");
    mapper->SetInput(tri->GetOutput());

    vtkVolume *volume = vtkVolume::New();
    volume->SetMapper(mapper);
    volume->SetProperty(volProp);
    volume->Update();
    vtkRenderWindow *renWin = vtkRenderWindow::New();
    vtkRenderer *ren1 = vtkRenderer::New();
    renWin->OffScreenRenderingOn();
    renWin->AddRenderer(ren1);

    ren1->AddVolume(volume);
    ren1->ResetCamera();
    renWin->SetSize(1024, 1024);
    renWin->Modified();

    vtkRenderLargeImage *w2if = vtkRenderLargeImage::New();
    w2if->SetInput(ren1);
    w2if->SetMagnification(1);

    vtkPNGWriter *png  = vtkPNGWriter::New();
    png->SetInput(w2if->GetOutput());
    png->SetFileName("output.png");
    png->Write();
}
===============


--
Randall Hand
Visualization Scientist,
ERDC-MSRC Vicksburg, MS
Homepage: http://www.yeraze.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20051228/5dee0f6a/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: volrend.jpg
Type: image/jpeg
Size: 43884 bytes
Desc: not available
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20051228/5dee0f6a/attachment.jpg>


More information about the vtkusers mailing list