[vtkusers] Volume Rendering & Mesa

Randall Hand randall.hand at gmail.com
Mon Apr 3 16:22:38 EDT 2006


I've got a dataset in legacy VTK format with several fields, and i'm trying
to do a volume rendering of it.  I've been having alot of trouble with it,
so I finally boiled it down to the following sample:

#include <vtkDataSetReader.h>
#include <vtkDataSetTriangleFilter.h>
#include <vtkProjectedTetrahedraMapper.h>
#include <vtkVolumeProperty.h>
#include <vtkColorTransferFunction.h>
#include <vtkPiecewiseFunction.h>
#include <vtkVolume.h>
#include <vtkRenderWindow.h>
#include <vtkRenderer.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkDataSet.h>
#include <vtkPNGWriter.h>
#include <vtkRenderLargeImage.h>
#include <vtkWindowToImageFilter.h>
#include <vtkGraphicsFactory.h>
#include <vtkImagingFactory.h>
int main(void) {
#ifdef _USE_MESA_
    vtkGraphicsFactory *factGraphics = vtkGraphicsFactory::New();
    factGraphics->SetUseMesaClasses(1);
    factGraphics->SetOffScreenOnlyMode(1);
    factGraphics->Delete();
    vtkImagingFactory *factImage = vtkImagingFactory::New();
    factImage->SetUseMesaClasses(1);
    factImage->Delete();

#endif

    vtkDataSetReader *in = vtkDataSetReader::New();
    in->SetFileName("output.vtk");
    in->ReadAllFieldsOn();
    in->ReadAllScalarsOn();
    in->ReadAllVectorsOn();
    in->ReadAllTensorsOn();
    in->ReadAllNormalsOn();
    in->ReadAllColorScalarsOn();
    in->ReadAllTCoordsOn();
    in->Update();

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

    vtkProjectedTetrahedraMapper *projTet =
vtkProjectedTetrahedraMapper::New();
    projTet->SetInput(tri->GetOutput());
    projTet->SelectScalarArray("Function0");

    vtkVolumeProperty *volProp = vtkVolumeProperty::New();
    volProp->ShadeOff();

    vtkColorTransferFunction *cmap = vtkColorTransferFunction::New();
    cmap->AddHSVPoint(0.0, 0.6667,1,1);
    cmap->AddHSVPoint(0.001, 0.3333,1,1);
    cmap->AddHSVPoint(0.002, 0.0,1,1);

    vtkPiecewiseFunction *omap = vtkPiecewiseFunction::New();
    omap->AddPoint(0.0, 1.0);
    omap->AddPoint(0.001, 1.0);
    omap->AddPoint(0.002, 1.0);

    volProp->SetColor(cmap);
    volProp->SetScalarOpacity(omap);

    vtkVolume *volume = vtkVolume::New();
    volume->SetMapper(projTet);
    volume->SetProperty(volProp);

    vtkRenderWindow *renWin = vtkRenderWindow::New();
    vtkRenderer *ren1 = vtkRenderer::New();

    renWin->OffScreenRenderingOn();
    renWin->AddRenderer(ren1);
    ren1->AddVolume(volume);
    renWin->SetSize(800,600);

    renWin->Modified();
    vtkWindowToImageFilter *w2if = vtkWindowToImageFilter::New();
    w2if->SetInput(renWin);
    //vtkRenderLargeImage *w2if = vtkRenderLargeImage::New();
    //w2if->SetInput(ren1);
    //w2if->SetMagnification(1);

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

}


When _USE_MESA_ is disabled, then it momentarily flashes a window on the
screen, and the resulting PNG on disk is correct (pretty much).  When
_USE_MESA_ is enabled, then it takes noticably longer to process and no
window appears, but the resulting PNG on disk is a big empty blackness.  Any
idea what's going on here?
--
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/20060403/317bbe5d/attachment.htm>


More information about the vtkusers mailing list