diff --git a/Filters/Parallel/Testing/CMakeLists.txt b/Filters/Parallel/Testing/CMakeLists.txt index 3a3ec3498e3f87092e726539e8dc5b2191c848d9..12189a62fc55fb8e8c7637214f4c87710d7fe9bd 100644 --- a/Filters/Parallel/Testing/CMakeLists.txt +++ b/Filters/Parallel/Testing/CMakeLists.txt @@ -3,7 +3,8 @@ vtk_module_test_data( Data/SampleStructGrid.vtk Data/ironProt.vtk Data/periodicPiece.vtu - Data/tetraMesh.vtk) + Data/tetraMesh.vtk + Data/two_vtk_logos_stacked.png) add_subdirectory(Cxx) diff --git a/Filters/Parallel/Testing/Cxx/CMakeLists.txt b/Filters/Parallel/Testing/Cxx/CMakeLists.txt index ba88d292fa8d2080b497df4162d60e6a8a7fe79d..bca74644bef5d8d27bd15cbf34835d0b33d168a4 100644 --- a/Filters/Parallel/Testing/Cxx/CMakeLists.txt +++ b/Filters/Parallel/Testing/Cxx/CMakeLists.txt @@ -9,6 +9,7 @@ if (TARGET VTK::ParallelMPI) TESTING_DATA DistributedData.cxx DistributedDataRenderPass.cxx + PTextureMapToSphere.cxx TestPExtractDataArraysOverTime.cxx,NO_VALID TransmitImageData.cxx TransmitImageDataRenderPass.cxx diff --git a/Filters/Parallel/Testing/Cxx/PTextureMapToSphere.cxx b/Filters/Parallel/Testing/Cxx/PTextureMapToSphere.cxx new file mode 100644 index 0000000000000000000000000000000000000000..d9d83a85748cdaeddd96d546a2f2fd59de3bfcfb --- /dev/null +++ b/Filters/Parallel/Testing/Cxx/PTextureMapToSphere.cxx @@ -0,0 +1,196 @@ +/*========================================================================= + + Program: Visualization Toolkit + Module: PTextureMapToSphere.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. + +=========================================================================*/ + +// Tests PTextureMapToSphere. + +/* +** This test only builds if MPI is in use +*/ +#include "vtkActor.h" +#include "vtkCompositeRenderManager.h" +#include "vtkMPICommunicator.h" +#include "vtkMPIController.h" +#include "vtkNew.h" +#include "vtkObjectFactory.h" +#include "vtkPNGReader.h" +#include "vtkPTextureMapToSphere.h" +#include "vtkPolyDataMapper.h" +#include "vtkProcess.h" +#include "vtkRegressionTestImage.h" +#include "vtkRenderWindow.h" +#include "vtkRenderer.h" +#include "vtkSphereSource.h" +#include "vtkSuperquadricSource.h" +#include "vtkTestUtilities.h" +#include "vtkTesting.h" +#include "vtkTexture.h" +#include <vtk_mpi.h> + +namespace +{ + +class MyProcess : public vtkProcess +{ +public: + static MyProcess* New(); + + virtual void Execute(); + + void SetArgs(int anArgc, char* anArgv[]); + +protected: + MyProcess(); + + int Argc; + char** Argv; +}; + +vtkStandardNewMacro(MyProcess); + +MyProcess::MyProcess() +{ + this->Argc = 0; + this->Argv = nullptr; +} + +void MyProcess::SetArgs(int anArgc, char* anArgv[]) +{ + this->Argc = anArgc; + this->Argv = anArgv; +} + +void MyProcess::Execute() +{ + this->ReturnValue = 1; + int numProcs = this->Controller->GetNumberOfProcesses(); + int me = this->Controller->GetLocalProcessId(); + cout << "Nb process found: " << numProcs << endl; + + vtkNew<vtkCompositeRenderManager> prm; + vtkNew<vtkSuperquadricSource> superquadric; + vtkNew<vtkSphereSource> sphere; + vtkNew<vtkPTextureMapToSphere> textureMap; + vtkNew<vtkPolyDataMapper> mapper; + + superquadric->ToroidalOff(); + sphere->SetThetaResolution(16); + sphere->SetPhiResolution(16); + + // Testing with superquadric which produces processes with no input data + textureMap->SetInputConnection(superquadric->GetOutputPort()); + + mapper->SetInputConnection(textureMap->GetOutputPort()); + mapper->SetScalarRange(0, numProcs); + mapper->SetPiece(me); + mapper->SetSeamlessU(true); + mapper->SetNumberOfPieces(numProcs); + mapper->Update(); + + // Actually testing in parallel + textureMap->SetInputConnection(sphere->GetOutputPort()); + mapper->Update(); + + char* fname = + vtkTestUtilities::ExpandDataFileName(this->Argc, this->Argv, "Data/two_vtk_logos_stacked.png"); + + vtkNew<vtkPNGReader> PNGReader; + PNGReader->SetFileName(fname); + PNGReader->Update(); + + vtkNew<vtkTexture> texture; + texture->SetInputConnection(PNGReader->GetOutputPort()); + texture->InterpolateOn(); + + vtkNew<vtkActor> actor; + actor->SetTexture(texture); + actor->SetMapper(mapper); + + vtkRenderer* renderer = prm->MakeRenderer(); + renderer->AddActor(actor); + renderer->SetBackground(0.5, 0.7, 0.7); + + vtkRenderWindow* renWin = prm->MakeRenderWindow(); + renWin->AddRenderer(renderer); + renWin->SetSize(400, 400); + + prm->SetRenderWindow(renWin); + prm->SetController(this->Controller); + + prm->InitializeOffScreen(); // Mesa GL only + + constexpr int MY_RETURN_VALUE_MESSAGE = 21545; + + if (me == 0) + { + renWin->Render(); + this->ReturnValue = vtkRegressionTester::Test(this->Argc, this->Argv, renWin, 10); + + for (int i = 1; i < numProcs; ++i) + { + this->Controller->Send(&this->ReturnValue, 1, i, MY_RETURN_VALUE_MESSAGE); + } + prm->StopServices(); + } + else + { + prm->StartServices(); + this->Controller->Receive(&this->ReturnValue, 1, 0, MY_RETURN_VALUE_MESSAGE); + } + renderer->Delete(); + renWin->Delete(); +} + +} + +int PTextureMapToSphere(int argc, char* argv[]) +{ + // This is here to avoid false leak messages from vtkDebugLeaks when + // using mpich. It appears that the root process which spawns all the + // main processes waits in MPI_Init() and calls exit() when + // the others are done, causing apparent memory leaks for any objects + // created before MPI_Init(). + MPI_Init(&argc, &argv); + + // Note that this will create a vtkMPIController if MPI + // is configured, vtkThreadedController otherwise. + vtkNew<vtkMPIController> contr; + contr->Initialize(&argc, &argv, 1); + + int retVal = 1; + + vtkMultiProcessController::SetGlobalController(contr); + + int me = contr->GetLocalProcessId(); + + if (!contr->IsA("vtkMPIController")) + { + if (me == 0) + { + cout << "DistributedData test requires MPI" << endl; + } + return retVal; // is this the right error val? TODO + } + + vtkNew<MyProcess> p; + p->SetArgs(argc, argv); + contr->SetSingleProcessObject(p); + contr->SingleMethodExecute(); + + retVal = p->GetReturnValue(); + + contr->Finalize(); + + return !retVal; +} diff --git a/Filters/Parallel/Testing/Data/Baseline/PTextureMapToSphere.png.sha512 b/Filters/Parallel/Testing/Data/Baseline/PTextureMapToSphere.png.sha512 new file mode 100644 index 0000000000000000000000000000000000000000..5f69d0a6d4786f39b1fc325c31d56ea2465742e1 --- /dev/null +++ b/Filters/Parallel/Testing/Data/Baseline/PTextureMapToSphere.png.sha512 @@ -0,0 +1 @@ +e91299cb1f859e915f4c97f93a87c85dba2b0e51b3c88804726b266383532eecd4aa450508a398ddf3a4f062be03234e500a129c55930dcf5dd5a42b1a593622 diff --git a/Filters/Parallel/vtk.module b/Filters/Parallel/vtk.module index fe53ac94e12d478dcd871da9d18b2ad22cc0bb08..d1933ccd947639feafbd5aa5ffa4a11690ad4b65 100644 --- a/Filters/Parallel/vtk.module +++ b/Filters/Parallel/vtk.module @@ -26,6 +26,7 @@ PRIVATE_DEPENDS TEST_DEPENDS VTK::FiltersFlowPaths VTK::FiltersParallelImaging + VTK::IOImage VTK::IOLegacy VTK::IOParallelExodus VTK::IOXML