/*========================================================================= Program: Visualization Toolkit Module: TestGPURayCastTextureStreaming.cxx Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen All rights reserved. See Copyright.txt or http://www.kitware.com/Copyright.htm for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notice for more information. =========================================================================*/ // Description: // Tests infrastructure to volume render a 3D texture bigger than the available // graphics memory by splitting it and individually streaming each block (bricking) // into the GPU. #include "vtkCamera.h" #include "vtkColorTransferFunction.h" #include "vtkGPUVolumeRayCastMapper.h" #include "vtkImageResample.h" #include "vtkImageResize.h" #include "vtkInteractorStyleTrackballCamera.h" #include "vtkNew.h" #include "vtkOpenGLGPUVolumeRayCastMapper.h" #include "vtkPiecewiseFunction.h" #include "vtkRegressionTestImage.h" #include "vtkRenderWindow.h" #include "vtkRenderWindowInteractor.h" #include "vtkRenderer.h" #include "vtkTestUtilities.h" #include "vtkVolume.h" #include "vtkVolume16Reader.h" #include "vtkVolumeProperty.h" #include "vtkAbstractMapper.h" #include "vtkImageData.h" #include "vtkMatrix4x4.h" #include "vtkOutlineFilter.h" #include "vtkPolyDataMapper.h" int TestGPURayCastTextureStreaming(int argc, char* argv[]) { // cout << "CTEST_FULL_OUTPUT (Avoid ctest truncation of output)" << endl; // Load data vtkNew reader; reader->SetDataDimensions(64, 64); reader->SetImageRange(1, 93); reader->SetDataByteOrderToLittleEndian(); char* fname = vtkTestUtilities::ExpandDataFileName(argc, argv, "Data/headsq/quarter"); reader->SetFilePrefix(fname); delete[] fname; reader->SetDataSpacing(3.2, 3.2, 1.5); // Upsample data vtkNew resample; resample->SetInputConnection(reader->GetOutputPort()); resample->SetResizeMethodToOutputDimensions(); resample->SetOutputDimensions(512, 512, 512); resample->Update(); // Prepare TFs vtkNew ctf; ctf->AddRGBPoint(0, 0.0, 0.0, 0.0); ctf->AddRGBPoint(500, 1.0, 0.5, 0.3); ctf->AddRGBPoint(1000, 1.0, 0.5, 0.3); ctf->AddRGBPoint(1150, 1.0, 1.0, 0.9); vtkNew pf; pf->AddPoint(0, 0.00); pf->AddPoint(500, 0.15); pf->AddPoint(1000, 0.15); pf->AddPoint(1150, 0.85); vtkNew gf; gf->AddPoint(0, 0.0); gf->AddPoint(90, 0.5); gf->AddPoint(100, 1.0); vtkNew volumeProperty; volumeProperty->SetScalarOpacity(pf); volumeProperty->SetGradientOpacity(gf); volumeProperty->SetColor(ctf); volumeProperty->ShadeOn(); // Setup rendering context vtkNew renWin; renWin->SetSize(512, 512); renWin->SetMultiSamples(0); vtkNew ren; renWin->AddRenderer(ren); ren->SetBackground(0.1, 0.1, 0.1); vtkNew mapper; mapper->SetInputConnection(resample->GetOutputPort()); mapper->SetUseJittering(0); // Force a number of partition blocks vtkOpenGLGPUVolumeRayCastMapper* mappergl = vtkOpenGLGPUVolumeRayCastMapper::SafeDownCast(mapper); mappergl->SetPartitions(2, 1, 2); vtkNew volume; volume->SetMapper(mapper); volume->SetProperty(volumeProperty); ren->AddVolume(volume); ren->ResetCamera(); ren->GetActiveCamera()->Zoom(1.4); // Interactor vtkNew iren; iren->SetRenderWindow(renWin); vtkNew style; iren->SetInteractorStyle(style); renWin->Render(); int retVal = vtkTesting::Test(argc, argv, renWin, 90); if (retVal == vtkRegressionTester::DO_INTERACTOR) { iren->Start(); } return !((retVal == vtkTesting::PASSED) || (retVal == vtkTesting::DO_INTERACTOR)); }