1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180
|
/*=========================================================================
Program: Visualization Toolkit
Module: HaloFinderTestHelpers.h
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.
=========================================================================*/
#include "vtkActor.h"
#include "vtkCompositePolyDataMapper2.h"
#include "vtkMaskPoints.h"
#include "vtkNew.h"
#include "vtkPANLHaloFinder.h"
#include "vtkPGenericIOReader.h"
#include "vtkPointData.h"
#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkSmartPointer.h"
#include "vtkTestUtilities.h"
#include "vtkThreshold.h"
#include "vtkUnstructuredGrid.h"
#include <set>
namespace HaloFinderTestHelpers {
struct HaloFinderTestVTKObjects {
HaloFinderTestVTKObjects() {
renWin = vtkSmartPointer< vtkRenderWindow >::New();
iren = vtkSmartPointer< vtkRenderWindowInteractor >::New();
reader = vtkSmartPointer< vtkPGenericIOReader >::New();
haloFinder = vtkSmartPointer< vtkPANLHaloFinder >::New();
onlyPointsInHalos = vtkSmartPointer< vtkThreshold >::New();
maskPoints = vtkSmartPointer< vtkMaskPoints >::New();
mapper = vtkSmartPointer< vtkCompositePolyDataMapper2 >::New();
}
vtkSmartPointer< vtkRenderWindow > renWin;
vtkSmartPointer< vtkRenderWindowInteractor > iren;
vtkSmartPointer< vtkPGenericIOReader > reader;
vtkSmartPointer< vtkPANLHaloFinder > haloFinder;
vtkSmartPointer< vtkThreshold > onlyPointsInHalos;
vtkSmartPointer< vtkMaskPoints > maskPoints;
vtkSmartPointer< vtkCompositePolyDataMapper2 > mapper;
};
inline std::set< std::string > getFirstOutputArrays()
{
std::set< std::string > arrayNames;
arrayNames.insert("vx");
arrayNames.insert("vy");
arrayNames.insert("vz");
arrayNames.insert("id");
arrayNames.insert("fof_halo_tag");
return arrayNames;
}
inline std::set< std::string > getHaloSummaryArrays()
{
std::set< std::string > arrayNames;
arrayNames.insert("fof_halo_tag");
arrayNames.insert("fof_halo_com");
arrayNames.insert("fof_halo_count");
arrayNames.insert("fof_halo_mass");
arrayNames.insert("fof_halo_mean_velocity");
arrayNames.insert("fof_velocity_dispersion");
return arrayNames;
}
inline std::set< std::string > getHaloSummaryWithCenterInfoArrays()
{
std::set< std::string > arrayNames = getHaloSummaryArrays();
arrayNames.insert("fof_center");
return arrayNames;
}
inline bool pointDataHasTheseArrays(vtkPointData* pd, const std::set< std::string >& arrays)
{
if (static_cast<size_t>(pd->GetNumberOfArrays()) != arrays.size())
{
std::cerr << "Wrong number of arrays. There should be " << arrays.size()
<< " and there are " << pd->GetNumberOfArrays() << std::endl;
return false;
}
for (std::set< std::string >::iterator itr = arrays.begin();
itr != arrays.end(); ++itr)
{
if (!pd->HasArray((*itr).c_str()))
{
std::cerr << "Point data does not have array: " << *itr << std::endl;
return false;
}
}
return true;
}
inline HaloFinderTestVTKObjects SetupHaloFinderTest(
int argc, char* argv[],
vtkPANLHaloFinder::CenterFindingType centerFinding = vtkPANLHaloFinder::NONE,
bool findSubhalos = false)
{
HaloFinderTestVTKObjects testObjects;
char* fname =
vtkTestUtilities::ExpandDataFileName(argc,argv,"genericio/m000.499.allparticles");
testObjects.reader->SetFileName(fname);
testObjects.reader->UpdateInformation();
testObjects.reader->SetXAxisVariableName("x");
testObjects.reader->SetYAxisVariableName("y");
testObjects.reader->SetZAxisVariableName("z");
testObjects.reader->SetPointArrayStatus("vx",1);
testObjects.reader->SetPointArrayStatus("vy",1);
testObjects.reader->SetPointArrayStatus("vz",1);
testObjects.reader->SetPointArrayStatus("id",1);
testObjects.reader->Update();
delete[] fname;
testObjects.haloFinder->SetInputConnection(testObjects.reader->GetOutputPort());
testObjects.haloFinder->SetRL(128);
testObjects.haloFinder->SetParticleMass(13070871810);
testObjects.haloFinder->SetNP(128);
testObjects.haloFinder->SetPMin(100);
testObjects.haloFinder->SetCenterFindingMode(centerFinding);
testObjects.haloFinder->SetOmegaDM(0.2068);
testObjects.haloFinder->SetDeut(0.0224);
testObjects.haloFinder->SetHubble(0.72);
if (findSubhalos)
{
testObjects.haloFinder->SetRunSubHaloFinder(1);
testObjects.haloFinder->SetMinFOFSubhaloSize(7000);
testObjects.haloFinder->SetMinCandidateSize(20);
// Expand the linking length a bit for the subhalo finding test, we need big
// halos to have interesting subhalos
testObjects.haloFinder->SetBB(0.2);
}
testObjects.haloFinder->Update();
testObjects.onlyPointsInHalos->SetInputConnection(
testObjects.haloFinder->GetOutputPort(0));
testObjects.onlyPointsInHalos->SetInputArrayToProcess(
0,0,0,vtkDataObject::FIELD_ASSOCIATION_POINTS, "fof_halo_tag");
testObjects.onlyPointsInHalos->ThresholdByUpper(0.0);
testObjects.onlyPointsInHalos->Update();
testObjects.maskPoints->SetInputConnection(
testObjects.onlyPointsInHalos->GetOutputPort());
testObjects.maskPoints->SetMaximumNumberOfPoints(
testObjects.haloFinder->GetOutput(0)->GetNumberOfPoints());
testObjects.maskPoints->SetOnRatio(1);
testObjects.maskPoints->GenerateVerticesOn();
testObjects.maskPoints->SingleVertexPerCellOn();
testObjects.maskPoints->Update();
// So that this test can be easily modified to reproduce ParaView GUI errors
testObjects.mapper->SetInputConnection(testObjects.maskPoints->GetOutputPort());
testObjects.mapper->Update();
vtkNew< vtkActor > actor;
actor->SetMapper(testObjects.mapper);
vtkNew< vtkRenderer > renderer;
renderer->AddActor(actor.GetPointer());
testObjects.renWin->AddRenderer(renderer.GetPointer());
testObjects.renWin->SetSize(300,300);
testObjects.iren->SetRenderWindow(testObjects.renWin);
return testObjects;
}
}
|