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 
43 #ifndef vtkPKdTree_h
44 #define vtkPKdTree_h
45 
46 #include "vtkFiltersParallelModule.h" // For export macro
47 #include "vtkKdTree.h"
48 
50 class vtkCommunicator;
51 class vtkSubGroup;
52 class vtkIntArray;
53 class vtkKdNode;
54 
55 class VTKFILTERSPARALLEL_EXPORT vtkPKdTree : public vtkKdTree
56 {
57 public:
58  vtkTypeMacro(vtkPKdTree, vtkKdTree);
59 
60 
61  void PrintSelf(ostream& os, vtkIndent indent);
62  void PrintTiming(ostream& os, vtkIndent indent);
63  void PrintTables(ostream& os, vtkIndent indent);
64 
65  static vtkPKdTree *New();
66 
73  void BuildLocator();
74 
80  vtkIdType GetTotalNumberOfCells(){return this->TotalNumCells;}
81 
90  int CreateProcessCellCountData();
91 
100  int CreateGlobalDataArrayBounds();
101 
103 
106  void SetController(vtkMultiProcessController *c);
107  vtkGetObjectMacro(Controller, vtkMultiProcessController);
109 
111 
120  vtkGetMacro(RegionAssignment, int);
122 
123  static const int NoRegionAssignment;
124  static const int ContiguousAssignment;
125  static const int UserDefinedAssignment;
126  static const int RoundRobinAssignment;
127 
133  int AssignRegions(int *map, int numRegions);
134 
140  int AssignRegionsRoundRobin();
141 
150  int AssignRegionsContiguous();
151 
157  { return this->RegionAssignmentMap; }
158 
160 
163  vtkGetMacro(RegionAssignmentMapLength, int);
165 
171  int GetRegionAssignmentList(int procId, vtkIntArray *list);
172 
181  void GetAllProcessesBorderingOnPoint(float x, float y, float z,
182  vtkIntArray *list);
183 
187  int GetProcessAssignedToRegion(int regionId);
188 
193  int HasData(int processId, int regionId);
194 
199  int GetProcessCellCountForRegion(int processId, int regionId);
200 
205  int GetTotalProcessesInRegion(int regionId);
206 
212  int GetProcessListForRegion(int regionId, vtkIntArray *processes);
213 
221  int GetProcessesCellCountForRegion(int regionId, int *count, int len);
222 
227  int GetTotalRegionsForProcess(int processId);
228 
233  int GetRegionListForProcess(int processId, vtkIntArray *regions);
234 
242  int GetRegionsCellCountForProcess(int ProcessId, int *count, int len);
243 
245 
270  vtkIdType GetCellListsForProcessRegions(int ProcessId, int set,
271  vtkIdList *inRegionCells, vtkIdList *onBoundaryCells);
272  vtkIdType GetCellListsForProcessRegions(int ProcessId, vtkDataSet *set,
273  vtkIdList *inRegionCells, vtkIdList *onBoundaryCells);
274  vtkIdType GetCellListsForProcessRegions(int ProcessId,
275  vtkIdList *inRegionCells,
276  vtkIdList *onBoundaryCells);
278 
286  int ViewOrderAllProcessesInDirection(const double directionOfProjection[3],
287  vtkIntArray *orderedList);
288 
296  int ViewOrderAllProcessesFromPosition(const double cameraPosition[3],
297  vtkIntArray *orderedList);
298 
307  int GetCellArrayGlobalRange(const char *name, float range[2]);
308  int GetPointArrayGlobalRange(const char *name, float range[2]);
309  int GetCellArrayGlobalRange(const char *name, double range[2]);
310  int GetPointArrayGlobalRange(const char *name, double range[2]);
311 
312  int GetCellArrayGlobalRange(int arrayIndex, double range[2]);
313  int GetPointArrayGlobalRange(int arrayIndex, double range[2]);
314  int GetCellArrayGlobalRange(int arrayIndex, float range[2]);
315  int GetPointArrayGlobalRange(int arrayIndex, float range[2]);
316 
317 protected:
318 
319  vtkPKdTree();
320  ~vtkPKdTree();
321 
322  void SingleProcessBuildLocator();
323  int MultiProcessBuildLocator(double *bounds);
324 
325 private:
326 
327  int RegionAssignment;
328 
329  vtkMultiProcessController *Controller;
330 
331  vtkSubGroup *SubGroup;
332 
333  static char *StrDupWithNew(const char *s);
334 
335  int NumProcesses;
336  int MyId;
337 
338  // basic tables - each region is the responsibility of one process, but
339  // one process may be assigned many regions
340 
341  int *RegionAssignmentMap; // indexed by region ID
342  int RegionAssignmentMapLength;
343  int **ProcessAssignmentMap; // indexed by process ID
344  int *NumRegionsAssigned; // indexed by process ID
345 
346  int UpdateRegionAssignment();
347 
348  // basic tables reflecting the data that was read from disk
349  // by each process
350 
351  char *DataLocationMap; // by process, by region
352 
353  int *NumProcessesInRegion; // indexed by region ID
354  int **ProcessList; // indexed by region ID
355 
356  int *NumRegionsInProcess; // indexed by process ID
357  int **RegionList; // indexed by process ID
358 
359  vtkIdType **CellCountList; // indexed by region ID
360 
361  double *CellDataMin; // global range for data arrays
362  double *CellDataMax;
363  double *PointDataMin;
364  double *PointDataMax;
365  char **CellDataName;
366  char **PointDataName;
367  int NumCellArrays;
368  int NumPointArrays;
369 
370  // distribution of indices for select operation
371 
372  int BuildGlobalIndexLists(vtkIdType ncells);
373 
374  vtkIdType *StartVal;
375  vtkIdType *EndVal;
376  vtkIdType *NumCells;
377  vtkIdType TotalNumCells;
378 
379  // local share of points to be partitioned, and local cache
380 
381  int WhoHas(int pos);
382  int _whoHas(int L, int R, int pos);
383  float *GetLocalVal(int pos);
384  float *GetLocalValNext(int pos);
385  void SetLocalVal(int pos, float *val);
386  void ExchangeVals(int pos1, int pos2);
387  void ExchangeLocalVals(int pos1, int pos2);
388 
389  float *PtArray;
390  float *PtArray2;
391  float *CurrentPtArray;
392  float *NextPtArray;
393  int PtArraySize;
394 
395  int *SelectBuffer;
396 
397  // Parallel build of k-d tree
398 
399  int AllCheckForFailure(int rc, const char *where, const char *how);
400  void AllCheckParameters();
401 
403 
407  bool VolumeBounds(double*);
408  int DivideRegion(vtkKdNode *kd, int L, int level, int tag);
409  int BreadthFirstDivide(double *bounds);
410  void enQueueNode(vtkKdNode *kd, int L, int level, int tag);
412 
413  int Select(int dim, int L, int R);
414  void _select(int L, int R, int K, int dim);
415  void DoTransfer(int from, int to, int fromIndex, int toIndex, int count);
416 
417  int *PartitionAboutMyValue(int L, int R, int K, int dim);
418  int *PartitionAboutOtherValue(int L, int R, float T, int dim);
419  int *PartitionSubArray(int L, int R, int K, int dim, int p1, int p2);
420 
421  int CompleteTree();
422 #ifdef YIELDS_INCONSISTENT_REGION_BOUNDARIES
423  void RetrieveData(vtkKdNode *kd, int *buf);
424 #else
425  void ReduceData(vtkKdNode *kd, int *sources);
426  void BroadcastData(vtkKdNode *kd);
427 #endif
428 
429  float *DataBounds(int L, int K, int R);
430  void GetLocalMinMax(int L, int R, int me, float *min, float *max);
431 
432  static int FillOutTree(vtkKdNode *kd, int level);
433  static int ComputeDepth(vtkKdNode *kd);
434  static void PackData(vtkKdNode *kd, double *data);
435  static void UnpackData(vtkKdNode *kd, double *data);
436  static void CheckFixRegionBoundaries(vtkKdNode *tree);
437 
438  // list management
439 
440  int AllocateDoubleBuffer();
441  void FreeDoubleBuffer();
442  void SwitchDoubleBuffer();
443  int AllocateSelectBuffer();
444  void FreeSelectBuffer();
445 
446  void InitializeGlobalIndexLists();
447  int AllocateAndZeroGlobalIndexLists();
448  void FreeGlobalIndexLists();
449  void InitializeRegionAssignmentLists();
450  int AllocateAndZeroRegionAssignmentLists();
451  void FreeRegionAssignmentLists();
452  void InitializeProcessDataLists();
453  int AllocateAndZeroProcessDataLists();
454  void FreeProcessDataLists();
455  void InitializeFieldArrayMinMax();
456  int AllocateAndZeroFieldArrayMinMax();
457  void FreeFieldArrayMinMax();
458 
459  void ReleaseTables();
460 
461  // Assigning regions to processors
462 
463  void AddProcessRegions(int procId, vtkKdNode *kd);
464  void BuildRegionListsForProcesses();
465 
466  // Gather process/region data totals
467 
468  int *CollectLocalRegionProcessData();
469  int BuildRegionProcessTables();
470  int BuildFieldArrayMinMax();
471  void AddEntry(int *list, int len, int id);
472 #ifdef VTK_USE_64BIT_IDS
473  void AddEntry(vtkIdType *list, int len, vtkIdType id);
474 #endif
475  static int BinarySearch(vtkIdType *list, int len, vtkIdType which);
476 
477  static int FindNextLocalArrayIndex(const char *n, const char **names, int len, int start=0);
478 
479  vtkPKdTree(const vtkPKdTree&) VTK_DELETE_FUNCTION;
480  void operator=(const vtkPKdTree&) VTK_DELETE_FUNCTION;
481 };
482 
483 #endif
int DivideRegion(vtkKdNode *kd, float *c1, int *ids, int nlevels)
vtkKdNode ** RegionList
Definition: vtkKdTree.h:680
static const int RoundRobinAssignment
Definition: vtkPKdTree.h:126
This class represents a single spatial region in an 3D axis aligned binary spatial partitioning...
Definition: vtkKdNode.h:45
const int * GetRegionAssignmentMap()
Returns the region assignment map where index is the region and value is the processes id for that re...
Definition: vtkPKdTree.h:156
Build a k-d tree decomposition of a list of points.
Definition: vtkPKdTree.h:55
abstract class to specify dataset behavior
Definition: vtkDataSet.h:62
vtkIdType GetTotalNumberOfCells()
Get the total number of cells distributed across the data files read by all processes.
Definition: vtkPKdTree.h:80
void BuildLocator() override
Create the k-d tree decomposition of the cells of the data set or data sets.
int vtkIdType
Definition: vtkType.h:287
dynamic, self-adjusting array of int
Definition: vtkIntArray.h:45
a simple class to control print indentation
Definition: vtkIndent.h:39
list of point or cell ids
Definition: vtkIdList.h:36
static const int ContiguousAssignment
Definition: vtkPKdTree.h:124
static int Select(int dim, float *c1, int *ids, int nvals, double &coord)
virtual void PrintTiming(ostream &os, vtkIndent indent)
Print timing of k-d tree build.
static vtkKdTree * New()
scalable collective communication for a subset of members of a parallel VTK application ...
Definition: vtkSubGroup.h:51
static const int NoRegionAssignment
Definition: vtkPKdTree.h:120
a Kd-tree spatial decomposition of a set of points
Definition: vtkKdTree.h:78
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
static const int UserDefinedAssignment
Definition: vtkPKdTree.h:125
Used to send/receive messages in a multiprocess environment.
#define max(a, b)
Multiprocessing communication superclass.