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 
37  renWin = vtkSmartPointer< vtkRenderWindow >::New();
38  iren = vtkSmartPointer< vtkRenderWindowInteractor >::New();
39  reader = vtkSmartPointer< vtkPGenericIOReader >::New();
40  haloFinder = vtkSmartPointer< vtkPANLHaloFinder >::New();
41  onlyPointsInHalos = vtkSmartPointer< vtkThreshold >::New();
42  maskPoints = vtkSmartPointer< vtkMaskPoints >::New();
43  mapper = vtkSmartPointer< vtkCompositePolyDataMapper2 >::New();
44  }
45  vtkSmartPointer< vtkRenderWindow > renWin;
46  vtkSmartPointer< vtkRenderWindowInteractor > iren;
47  vtkSmartPointer< vtkPGenericIOReader > reader;
48  vtkSmartPointer< vtkPANLHaloFinder > haloFinder;
49  vtkSmartPointer< vtkThreshold > onlyPointsInHalos;
50  vtkSmartPointer< vtkMaskPoints > maskPoints;
51  vtkSmartPointer< vtkCompositePolyDataMapper2 > mapper;
52 };
53 
54 inline std::set< std::string > getFirstOutputArrays()
55 {
56  std::set< std::string > arrayNames;
57  arrayNames.insert("vx");
58  arrayNames.insert("vy");
59  arrayNames.insert("vz");
60  arrayNames.insert("id");
61  arrayNames.insert("fof_halo_tag");
62  return arrayNames;
63 }
64 
65 inline std::set< std::string > getHaloSummaryArrays()
66 {
67  std::set< std::string > arrayNames;
68  arrayNames.insert("fof_halo_tag");
69  arrayNames.insert("fof_halo_com");
70  arrayNames.insert("fof_halo_count");
71  arrayNames.insert("fof_halo_mass");
72  arrayNames.insert("fof_halo_mean_velocity");
73  arrayNames.insert("fof_velocity_dispersion");
74  return arrayNames;
75 }
76 
77 inline std::set< std::string > getHaloSummaryWithCenterInfoArrays()
78 {
79  std::set< std::string > arrayNames = getHaloSummaryArrays();
80  arrayNames.insert("fof_center");
81  return arrayNames;
82 }
83 
84 inline bool pointDataHasTheseArrays(vtkPointData* pd, const std::set< std::string >& arrays)
85 {
86  if (static_cast<size_t>(pd->GetNumberOfArrays()) != arrays.size())
87  {
88  std::cerr << "Wrong number of arrays. There should be " << arrays.size()
89  << " and there are " << pd->GetNumberOfArrays() << std::endl;
90  return false;
91  }
92  for (std::set< std::string >::iterator itr = arrays.begin();
93  itr != arrays.end(); ++itr)
94  {
95  if (!pd->HasArray((*itr).c_str()))
96  {
97  std::cerr << "Point data does not have array: " << *itr << std::endl;
98  return false;
99  }
100  }
101  return true;
102 }
103 
105  int argc, char* argv[],
106  vtkPANLHaloFinder::CenterFindingType centerFinding = vtkPANLHaloFinder::NONE,
107  bool findSubhalos = false)
108 {
109  HaloFinderTestVTKObjects testObjects;
110  char* fname =
111  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(
147  testObjects.haloFinder->GetOutputPort(0));
148  testObjects.onlyPointsInHalos->SetInputArrayToProcess(
149  0,0,0,vtkDataObject::FIELD_ASSOCIATION_POINTS, "fof_halo_tag");
150  testObjects.onlyPointsInHalos->ThresholdByUpper(0.0);
151  testObjects.onlyPointsInHalos->Update();
152 
153  testObjects.maskPoints->SetInputConnection(
154  testObjects.onlyPointsInHalos->GetOutputPort());
155  testObjects.maskPoints->SetMaximumNumberOfPoints(
156  testObjects.haloFinder->GetOutput(0)->GetNumberOfPoints());
157  testObjects.maskPoints->SetOnRatio(1);
158  testObjects.maskPoints->GenerateVerticesOn();
159  testObjects.maskPoints->SingleVertexPerCellOn();
160  testObjects.maskPoints->Update();
161 
162  // So that this test can be easily modified to reproduce ParaView GUI errors
163  testObjects.mapper->SetInputConnection(testObjects.maskPoints->GetOutputPort());
164  testObjects.mapper->Update();
165 
166  vtkNew< vtkActor > actor;
167  actor->SetMapper(testObjects.mapper);
168 
169  vtkNew< vtkRenderer > renderer;
170  renderer->AddActor(actor.GetPointer());
171 
172  testObjects.renWin->AddRenderer(renderer.GetPointer());
173  testObjects.renWin->SetSize(300,300);
174 
175  testObjects.iren->SetRenderWindow(testObjects.renWin);
176 
177  return testObjects;
178 }
179 
180 }
std::set< std::string > getFirstOutputArrays()
vtkSmartPointer< vtkPGenericIOReader > reader
std::set< std::string > getHaloSummaryArrays()
bool pointDataHasTheseArrays(vtkPointData *pd, const std::set< std::string > &arrays)
std::set< std::string > getHaloSummaryWithCenterInfoArrays()
vtkSmartPointer< vtkRenderWindowInteractor > iren
HaloFinderTestVTKObjects SetupHaloFinderTest(int argc, char *argv[], vtkPANLHaloFinder::CenterFindingType centerFinding=vtkPANLHaloFinder::NONE, bool findSubhalos=false)
vtkSmartPointer< vtkPANLHaloFinder > haloFinder
vtkSmartPointer< vtkCompositePolyDataMapper2 > mapper