[vtkusers] Re: Volume Rendering & Mesa

Randall Hand randall.hand at gmail.com
Tue Apr 4 00:01:06 EDT 2006


Ok, after alot of digging I found the problem. It seems that none of the new
unstructured volume renderers properly support Mesa. My best guess is that
it was setting up the scene with mangled-mesa contexts, and then the Volume
Rendering was using true OpenGL.  Every command probably returned an error
(no GL context), but nothing checks it, so it rendering blindly & ignorant
of what was going on.

After alot of work, I managed to apply the same structure as the other
objects to the vtkProjectedTetrahedraMapper successfully. There is now a
vtkProjectedTetrahedraMapper that, with the help of the
vtkVolumeRenderingFactory, can properly instantiate either a
vtkOpenGLProjectedTetrahedraMapper or a vtkMesaProjectedTetrahedraMapper.
>From the testing I've done here (with the hello-world code shown
originally), I've been able to switch between the two pretty easily and get
almost identical results.  There are a few discrepancies, but since this is
a hardware accelerated version it's very susceptible to the fine variations
between how Mesa emulates the hardware and various hardware platforms
actually work.

So, who @Kitware do I need to talk to to get this patch back to mainstream?
I plan to file a bug on it, with code attached, tomorrow morning when I
return to the office.  This is a little larger patch that I usually deal
with (4 new files, extensive changes to a few others), so what's the
preferred format for a patch this size?  I know there's a command with 'cvs
diff' to get "patch"-style diffs, which seems the best option, but I always
forget it...

On 4/3/06, Randall Hand <randall.hand at gmail.com> wrote:
>
> 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
>



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


More information about the vtkusers mailing list