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