VTK
vtkPKdTree.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: vtkPKdTree.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  Copyright (c) Sandia Corporation
17  See Copyright.txt or http://www.paraview.org/HTML/Copyright.html for details.
18 ----------------------------------------------------------------------------*/
19 
42 #ifndef vtkPKdTree_h
43 #define vtkPKdTree_h
44 
45 #include "vtkFiltersParallelModule.h" // For export macro
46 #include "vtkKdTree.h"
47 
49 class vtkCommunicator;
50 class vtkSubGroup;
51 class vtkIntArray;
52 class vtkKdNode;
53 
55 {
56 public:
57  vtkTypeMacro(vtkPKdTree, vtkKdTree);
58 
59 
60  void PrintSelf(ostream& os, vtkIndent indent);
61  void PrintTiming(ostream& os, vtkIndent indent);
62  void PrintTables(ostream& os, vtkIndent indent);
63 
64  static vtkPKdTree *New();
65 
69  void BuildLocator();
70 
74  vtkIdType GetTotalNumberOfCells(){return this->TotalNumCells;}
75 
81  int CreateProcessCellCountData();
82 
88  int CreateGlobalDataArrayBounds();
89 
91 
92  void SetController(vtkMultiProcessController *c);
93  vtkGetObjectMacro(Controller, vtkMultiProcessController);
95 
97 
104  vtkGetMacro(RegionAssignment, int);
106 
107  static const int NoRegionAssignment;
108  static const int ContiguousAssignment;
109  static const int UserDefinedAssignment;
110  static const int RoundRobinAssignment;
111 
115  int AssignRegions(int *map, int numRegions);
116 
120  int AssignRegionsRoundRobin();
121 
127  int AssignRegionsContiguous();
128 
130 
133  { return this->RegionAssignmentMap; }
135 
137 
138  vtkGetMacro(RegionAssignmentMapLength, int);
140 
144  int GetRegionAssignmentList(int procId, vtkIntArray *list);
145 
147 
152  void GetAllProcessesBorderingOnPoint(float x, float y, float z,
153  vtkIntArray *list);
155 
157  int GetProcessAssignedToRegion(int regionId);
158 
160  int HasData(int processId, int regionId);
161 
164  int GetProcessCellCountForRegion(int processId, int regionId);
165 
168  int GetTotalProcessesInRegion(int regionId);
169 
172  int GetProcessListForRegion(int regionId, vtkIntArray *processes);
173 
178  int GetProcessesCellCountForRegion(int regionId, int *count, int len);
179 
182  int GetTotalRegionsForProcess(int processId);
183 
186  int GetRegionListForProcess(int processId, vtkIntArray *regions);
187 
192  int GetRegionsCellCountForProcess(int ProcessId, int *count, int len);
193 
195 
212  vtkIdType GetCellListsForProcessRegions(int ProcessId, int set,
213  vtkIdList *inRegionCells, vtkIdList *onBoundaryCells);
214  vtkIdType GetCellListsForProcessRegions(int ProcessId, vtkDataSet *set,
215  vtkIdList *inRegionCells, vtkIdList *onBoundaryCells);
216  vtkIdType GetCellListsForProcessRegions(int ProcessId,
217  vtkIdList *inRegionCells,
218  vtkIdList *onBoundaryCells);
220 
222 
227  int ViewOrderAllProcessesInDirection(const double directionOfProjection[3],
228  vtkIntArray *orderedList);
230 
232 
237  int ViewOrderAllProcessesFromPosition(const double cameraPosition[3],
238  vtkIntArray *orderedList);
240 
246  int GetCellArrayGlobalRange(const char *name, float range[2]);
247  int GetPointArrayGlobalRange(const char *name, float range[2]);
248  int GetCellArrayGlobalRange(const char *name, double range[2]);
249  int GetPointArrayGlobalRange(const char *name, double range[2]);
250 
251  int GetCellArrayGlobalRange(int arrayIndex, double range[2]);
252  int GetPointArrayGlobalRange(int arrayIndex, double range[2]);
253  int GetCellArrayGlobalRange(int arrayIndex, float range[2]);
254  int GetPointArrayGlobalRange(int arrayIndex, float range[2]);
255 
256 protected:
257 
258  vtkPKdTree();
259  ~vtkPKdTree();
260 
261  void SingleProcessBuildLocator();
262  int MultiProcessBuildLocator(double *bounds);
263 
264 private:
265 
266  int RegionAssignment;
267 
268  vtkMultiProcessController *Controller;
269 
270  vtkSubGroup *SubGroup;
271 
272  static char *StrDupWithNew(const char *s);
273 
274  int NumProcesses;
275  int MyId;
276 
277  // basic tables - each region is the responsibility of one process, but
278  // one process may be assigned many regions
279 
280  int *RegionAssignmentMap; // indexed by region ID
281  int RegionAssignmentMapLength;
282  int **ProcessAssignmentMap; // indexed by process ID
283  int *NumRegionsAssigned; // indexed by process ID
284 
285  int UpdateRegionAssignment();
286 
287  // basic tables reflecting the data that was read from disk
288  // by each process
289 
290  char *DataLocationMap; // by process, by region
291 
292  int *NumProcessesInRegion; // indexed by region ID
293  int **ProcessList; // indexed by region ID
294 
295  int *NumRegionsInProcess; // indexed by process ID
296  int **RegionList; // indexed by process ID
297 
298  vtkIdType **CellCountList; // indexed by region ID
299 
300  double *CellDataMin; // global range for data arrays
301  double *CellDataMax;
302  double *PointDataMin;
303  double *PointDataMax;
304  char **CellDataName;
305  char **PointDataName;
306  int NumCellArrays;
307  int NumPointArrays;
308 
309  // distribution of indices for select operation
310 
311  int BuildGlobalIndexLists(vtkIdType ncells);
312 
313  vtkIdType *StartVal;
314  vtkIdType *EndVal;
315  vtkIdType *NumCells;
316  vtkIdType TotalNumCells;
317 
318  // local share of points to be partitioned, and local cache
319 
320  int WhoHas(int pos);
321  int _whoHas(int L, int R, int pos);
322  float *GetLocalVal(int pos);
323  float *GetLocalValNext(int pos);
324  void SetLocalVal(int pos, float *val);
325  void ExchangeVals(int pos1, int pos2);
326  void ExchangeLocalVals(int pos1, int pos2);
327 
328  float *PtArray;
329  float *PtArray2;
330  float *CurrentPtArray;
331  float *NextPtArray;
332  int PtArraySize;
333 
334  int *SelectBuffer;
335 
336  // Parallel build of k-d tree
337 
338  int AllCheckForFailure(int rc, const char *where, const char *how);
339  void AllCheckParameters();
340 
342 
344  bool VolumeBounds(double*);
345  int DivideRegion(vtkKdNode *kd, int L, int level, int tag);
346  int BreadthFirstDivide(double *bounds);
347  void enQueueNode(vtkKdNode *kd, int L, int level, int tag);
349 
350  int Select(int dim, int L, int R);
351  void _select(int L, int R, int K, int dim);
352  void DoTransfer(int from, int to, int fromIndex, int toIndex, int count);
353 
354  int *PartitionAboutMyValue(int L, int R, int K, int dim);
355  int *PartitionAboutOtherValue(int L, int R, float T, int dim);
356  int *PartitionSubArray(int L, int R, int K, int dim, int p1, int p2);
357 
358  int CompleteTree();
359 #ifdef YIELDS_INCONSISTENT_REGION_BOUNDARIES
360  void RetrieveData(vtkKdNode *kd, int *buf);
361 #else
362  void ReduceData(vtkKdNode *kd, int *sources);
363  void BroadcastData(vtkKdNode *kd);
364 #endif
365 
366  float *DataBounds(int L, int K, int R);
367  void GetLocalMinMax(int L, int R, int me, float *min, float *max);
368 
369  static int FillOutTree(vtkKdNode *kd, int level);
370  static int ComputeDepth(vtkKdNode *kd);
371  static void PackData(vtkKdNode *kd, double *data);
372  static void UnpackData(vtkKdNode *kd, double *data);
373  static void CheckFixRegionBoundaries(vtkKdNode *tree);
374 
375  // list management
376 
377  int AllocateDoubleBuffer();
378  void FreeDoubleBuffer();
379  void SwitchDoubleBuffer();
380  int AllocateSelectBuffer();
381  void FreeSelectBuffer();
382 
383  void InitializeGlobalIndexLists();
384  int AllocateAndZeroGlobalIndexLists();
385  void FreeGlobalIndexLists();
386  void InitializeRegionAssignmentLists();
387  int AllocateAndZeroRegionAssignmentLists();
388  void FreeRegionAssignmentLists();
389  void InitializeProcessDataLists();
390  int AllocateAndZeroProcessDataLists();
391  void FreeProcessDataLists();
392  void InitializeFieldArrayMinMax();
393  int AllocateAndZeroFieldArrayMinMax();
394  void FreeFieldArrayMinMax();
395 
396  void ReleaseTables();
397 
398  // Assigning regions to processors
399 
400  void AddProcessRegions(int procId, vtkKdNode *kd);
401  void BuildRegionListsForProcesses();
402 
403  // Gather process/region data totals
404 
405  int *CollectLocalRegionProcessData();
406  int BuildRegionProcessTables();
407  int BuildFieldArrayMinMax();
408  void AddEntry(int *list, int len, int id);
409 #ifdef VTK_USE_64BIT_IDS
410  void AddEntry(vtkIdType *list, int len, vtkIdType id);
411 #endif
412  static int BinarySearch(vtkIdType *list, int len, vtkIdType which);
413 
414  static int FindNextLocalArrayIndex(const char *n, const char **names, int len, int start=0);
415 
416  vtkPKdTree(const vtkPKdTree&); // Not implemented
417  void operator=(const vtkPKdTree&); // Not implemented
418 };
419 
420 #endif
int DivideRegion(vtkKdNode *kd, float *c1, int *ids, int nlevels)
vtkKdNode ** RegionList
Definition: vtkKdTree.h:541
static const int RoundRobinAssignment
Definition: vtkPKdTree.h:110
This class represents a single spatial region in an 3D axis aligned binary spatial partitioning...
Definition: vtkKdNode.h:44
const int * GetRegionAssignmentMap()
Definition: vtkPKdTree.h:132
Build a k-d tree decomposition of a list of points.
Definition: vtkPKdTree.h:54
abstract class to specify dataset behavior
Definition: vtkDataSet.h:61
void BuildLocator()
vtkIdType GetTotalNumberOfCells()
Definition: vtkPKdTree.h:74
int vtkIdType
Definition: vtkType.h:275
#define VTKFILTERSPARALLEL_EXPORT
void operator=(const vtkKdTree &)
dynamic, self-adjusting array of int
Definition: vtkIntArray.h:49
a simple class to control print indentation
Definition: vtkIndent.h:38
list of point or cell ids
Definition: vtkIdList.h:35
static const int ContiguousAssignment
Definition: vtkPKdTree.h:108
static int Select(int dim, float *c1, int *ids, int nvals, double &coord)
virtual void PrintTiming(ostream &os, vtkIndent indent)
static vtkKdTree * New()
scalable collective communication for a subset of members of a parallel VTK application ...
Definition: vtkSubGroup.h:50
static const int NoRegionAssignment
Definition: vtkPKdTree.h:104
a Kd-tree spatial decomposition of a set of points
Definition: vtkKdTree.h:80
static const int UserDefinedAssignment
Definition: vtkPKdTree.h:109
Used to send/receive messages in a multiprocess environment.
void PrintSelf(ostream &os, vtkIndent indent)
#define max(a, b)
Multiprocessing communication superclass.