[vtkusers] Volume Rendering with vtkUnstructuredGridRayCastMapper

Randall Hand randall.hand at gmail.com
Wed Dec 28 16:03:08 EST 2005


I had to make some changes (not enough memory for the Bunyk on my linux box)
but I got it running on Linux.  Still, just a big black window. I also added
a small piece of code to remove all the Arrays except the 1 I want.

 Here's the modified code:

=======================
#include <vtkColorTransferFunction.h>
#include <vtkDataSetReader.h>
#include <vtkPiecewiseFunction.h>
#include <vtkProjectedTetrahedraMapper.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>
#include "stat.h"
int main(void) {
    int i;
    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("step_127.vtk");
    reader->ReadAllScalarsOn();
    reader->Update();
    PrintStatistics(reader->GetOutput());

    for(i=0; i< reader->GetOutput()->GetPointData()->GetNumberOfArrays();) {
        if
(strcmp(reader->GetOutput()->GetPointData()->GetArray(i)->GetName(),
                    "Temperature") == 0) {
            i++;
        } else {
            reader->GetOutput()->GetPointData()->RemoveArray(

reader->GetOutput()->GetPointData()->GetArray(i)->GetName());
        }
    }

    vtkDataSetTriangleFilter *tri = vtkDataSetTriangleFilter::New();
    tri->SetInput(reader->GetOutput());
    tri->Update();
    PrintStatistics(tri->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->SetInterpolationTypeToNearest();

    vtkProjectedTetrahedraMapper *mapper =
            vtkProjectedTetrahedraMapper::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();
}





==================

On 12/28/05, Dominik Szczerba <domi at vision.ee.ethz.ch> wrote:
>
> smells like platform specific problems. get a linux test box.
> --domi
>
> Randall Hand wrote:
>
>

--
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/a9eb61e7/attachment.htm>


More information about the vtkusers mailing list