diff --git a/Rendering/OpenGL2/Testing/Cxx/CMakeLists.txt b/Rendering/OpenGL2/Testing/Cxx/CMakeLists.txt index acdb6cb93da77d6768d561e8694556579e0c292d..7bf401bff35ca4e0d0919ed1530c871638587d72 100644 --- a/Rendering/OpenGL2/Testing/Cxx/CMakeLists.txt +++ b/Rendering/OpenGL2/Testing/Cxx/CMakeLists.txt @@ -99,6 +99,7 @@ vtk_add_test_cxx(vtkRenderingOpenGL2CxxTests tests TestUserShader2.cxx TestUserShader2D.cxx,NO_DATA TestValuePassFloatingPoint.cxx + TestValuePassFloatingPoint2.cxx TestVBOPLYMapper.cxx TestVBOPointsLines.cxx TestWindowBlits.cxx diff --git a/Rendering/OpenGL2/Testing/Cxx/TestValuePassFloatingPoint2.cxx b/Rendering/OpenGL2/Testing/Cxx/TestValuePassFloatingPoint2.cxx new file mode 100644 index 0000000000000000000000000000000000000000..b9afd8165b50998c12650ff3b8c015303aaec634 --- /dev/null +++ b/Rendering/OpenGL2/Testing/Cxx/TestValuePassFloatingPoint2.cxx @@ -0,0 +1,107 @@ +// SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen +// SPDX-License-Identifier: BSD-3-Clause + +// Description: +// Tests vtkValuePass in FLOATING_POINT mode and ensures the depth test is enabled. +// Renders a scalar from a polydata into a float buffer. + +#include "vtkActor.h" +#include "vtkCamera.h" +#include "vtkCameraPass.h" +#include "vtkFloatArray.h" +#include "vtkImageActor.h" +#include "vtkImageData.h" +#include "vtkImageMapToColors.h" +#include "vtkImageSliceMapper.h" +#include "vtkLookupTable.h" +#include "vtkNamedColors.h" +#include "vtkNew.h" +#include "vtkPointData.h" +#include "vtkPolyDataMapper.h" +#include "vtkRenderPassCollection.h" +#include "vtkRenderWindow.h" +#include "vtkRenderWindowInteractor.h" +#include "vtkRenderer.h" +#include "vtkSequencePass.h" +#include "vtkSuperquadricSource.h" +#include "vtkValuePass.h" + +#include <iostream> +#include <string> + +int TestValuePassFloatingPoint2(int, char*[]) +{ + vtkNew<vtkSuperquadricSource> torusSource; + torusSource->SetToroidal(1); + + // Render the scalar into an image + vtkNew<vtkPolyDataMapper> mapper; + mapper->SetInputConnection(torusSource->GetOutputPort()); + + vtkNew<vtkActor> actor; + actor->SetMapper(mapper); + + vtkNew<vtkRenderer> renderer; + renderer->AddActor(actor); + + vtkNew<vtkRenderWindow> renWin; + renWin->AddRenderer(renderer); + renWin->SetMultiSamples(0); + + vtkNew<vtkRenderWindowInteractor> iRen; + iRen->SetRenderWindow(renWin); + + renderer->ResetCamera(); + + vtkNew<vtkValuePass> valuePass; + valuePass->SetInputArrayToProcess(VTK_SCALAR_MODE_USE_POINT_FIELD_DATA, "TextureCoords"); + valuePass->SetInputComponentToProcess(0); + + vtkNew<vtkRenderPassCollection> passes; + passes->AddItem(valuePass); + + vtkNew<vtkSequencePass> sequence; + sequence->SetPasses(passes); + + vtkNew<vtkCameraPass> cameraPass; + cameraPass->SetDelegatePass(sequence); + renderer->SetPass(cameraPass); + renWin->Render(); + + // Get the rendered image + vtkFloatArray* renderedArray = valuePass->GetFloatImageDataArray(renderer); + int* ext = valuePass->GetFloatImageExtents(); + renderedArray->SetName("FloatArray"); + vtkNew<vtkImageData> image; + image->SetExtent(ext); + image->GetPointData()->SetScalars(renderedArray); + + // Now that the floating point array has been rendered, remove the renderer. + renWin->RemoveRenderer(renderer); + + // Sow the rendered image on the screen + vtkNew<vtkLookupTable> lut; + lut->SetHueRange(0.6, 0); + lut->SetSaturationRange(1.0, 0); + lut->SetValueRange(0.5, 1.0); + lut->SetTableRange(image->GetScalarRange()); + + vtkNew<vtkImageMapToColors> mapColors; + mapColors->SetLookupTable(lut); + mapColors->SetInputDataObject(image); + + vtkNew<vtkImageActor> imageActor; + imageActor->GetMapper()->SetInputConnection(mapColors->GetOutputPort()); + + vtkNew<vtkRenderer> newRenderer; + newRenderer->AddActor(imageActor); + + vtkNew<vtkNamedColors> colors; + newRenderer->SetBackground(colors->GetColor3d("DarkSlateGray").GetData()); + renWin->AddRenderer(newRenderer); + renWin->SetWindowName("RenderScalarToFloatBuffer"); + renWin->Render(); + iRen->Start(); + + return EXIT_SUCCESS; +} diff --git a/Rendering/OpenGL2/Testing/Data/Baseline/TestValuePassFloatingPoint2.png.sha512 b/Rendering/OpenGL2/Testing/Data/Baseline/TestValuePassFloatingPoint2.png.sha512 new file mode 100644 index 0000000000000000000000000000000000000000..b5503cd905397601ff97f5b73b743eb3b681e9e9 --- /dev/null +++ b/Rendering/OpenGL2/Testing/Data/Baseline/TestValuePassFloatingPoint2.png.sha512 @@ -0,0 +1 @@ +2849d4a4621bda85ad65ab1d529eca8ec3162f7fd096a5ba601ad8b5f05c922664e7a52687212647f5c9bd529036ccf8e79869059ea200bf9dc9db996d9954b2 diff --git a/Rendering/OpenGL2/vtk.module b/Rendering/OpenGL2/vtk.module index d00d1e7ae42c932ade7b182d84dc3f5cf4d779ec..46151d73847766be8b9e80d8932b4f700760ab80 100644 --- a/Rendering/OpenGL2/vtk.module +++ b/Rendering/OpenGL2/vtk.module @@ -33,6 +33,7 @@ PRIVATE_DEPENDS VTK::vtksys VTK::nlohmannjson TEST_DEPENDS + VTK::CommonColor VTK::CommonSystem VTK::FiltersExtraction VTK::FiltersGeneral