00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00053 #ifndef __vtkPKdTree_h
00054 #define __vtkPKdTree_h
00055
00056 #include "vtkKdTree.h"
00057
00058 class vtkMultiProcessController;
00059 class vtkCommunicator;
00060 class vtkSubGroup;
00061 class vtkIntArray;
00062
00063 class VTK_PARALLEL_EXPORT vtkPKdTree : public vtkKdTree
00064 {
00065 public:
00066 vtkTypeRevisionMacro(vtkPKdTree, vtkKdTree);
00067
00068
00069 void PrintSelf(ostream& os, vtkIndent indent);
00070 void PrintTiming(ostream& os, vtkIndent indent);
00071 void PrintTables(ostream& os, vtkIndent indent);
00072
00073 static vtkPKdTree *New();
00074
00079 void BuildLocator();
00080
00085 int GetTotalNumberOfCells(){return this->TotalNumCells;}
00086
00093 int CreateProcessCellCountData();
00094
00101 int CreateGlobalDataArrayBounds();
00102
00107 vtkGetMacro(NumRegionsOrLess, int);
00108 vtkSetMacro(NumRegionsOrLess, int);
00109
00117 vtkGetMacro(NumRegionsOrMore, int);
00118 vtkSetMacro(NumRegionsOrMore, int);
00119
00122 void SetController(vtkMultiProcessController *c);
00123 vtkGetObjectMacro(Controller, vtkMultiProcessController);
00124
00133 vtkGetMacro(RegionAssignment, int);
00134
00135 static const int NoRegionAssignment;
00136 static const int ContiguousAssignment;
00137 static const int UserDefinedAssignment;
00138 static const int RoundRobinAssignment;
00139
00144 int AssignRegions(int *map, int numRegions);
00145
00150 int AssignRegionsRoundRobin();
00151
00158 int AssignRegionsContiguous();
00159
00164 int GetRegionAssignmentList(int procId, vtkIntArray *list);
00165
00172 void GetAllProcessesBorderingOnPoint(float x, float y, float z,
00173 vtkIntArray *list);
00174
00177 int GetProcessAssignedToRegion(int regionId);
00178
00181 int HasData(int processId, int regionId);
00182
00186 int GetProcessCellCountForRegion(int processId, int regionId);
00187
00191 int GetTotalProcessesInRegion(int regionId);
00192
00196 int GetProcessListForRegion(int regionId, vtkIntArray *processes);
00197
00203 int GetProcessesCellCountForRegion(int regionId, int *count, int len);
00204
00208 int GetTotalRegionsForProcess(int processId);
00209
00213 int GetRegionListForProcess(int processId, vtkIntArray *regions);
00214
00220 int GetRegionsCellCountForProcess(int ProcessId, int *count, int len);
00221
00240 vtkIdType GetCellListsForProcessRegions(int ProcessId, int set,
00241 vtkIdList *inRegionCells, vtkIdList *onBoundaryCells);
00242 vtkIdType GetCellListsForProcessRegions(int ProcessId, vtkDataSet *set,
00243 vtkIdList *inRegionCells, vtkIdList *onBoundaryCells);
00244 vtkIdType GetCellListsForProcessRegions(int ProcessId, vtkIdList *inRegionCells,
00245 vtkIdList *onBoundaryCells);
00246
00254 int DepthOrderAllProcesses(vtkCamera *camera, vtkIntArray *orderedList);
00255
00261 int GetCellArrayGlobalRange(int arrayIndex, float range[2]);
00262 int GetPointArrayGlobalRange(int arrayIndex, float range[2]);
00263 int GetCellArrayGlobalRange(int arrayIndex, double range[2]);
00264 int GetPointArrayGlobalRange(int arrayIndex, double range[2]);
00265
00266 int GetCellArrayGlobalRange(const char *name, float range[2]);
00267 int GetPointArrayGlobalRange(const char *name, float range[2]);
00268 int GetCellArrayGlobalRange(const char *name, double range[2]);
00269 int GetPointArrayGlobalRange(const char *name, double range[2]);
00270
00271 protected:
00272
00273 vtkPKdTree();
00274 ~vtkPKdTree();
00275
00276 void SingleProcessBuildLocator();
00277 int MultiProcessBuildLocator();
00278
00279 private:
00280
00281 int NumRegionsOrLess;
00282 int NumRegionsOrMore;
00283 int RegionAssignment;
00284
00285 vtkMultiProcessController *Controller;
00286
00287 vtkSubGroup *SubGroup;
00288
00289 static char *StrDupWithNew(const char *s);
00290
00291 int NumProcesses;
00292 int MyId;
00293
00294
00295
00296
00297 int *RegionAssignmentMap;
00298 int RegionAssignmentMapLength;
00299 int **ProcessAssignmentMap;
00300 int *NumRegionsAssigned;
00301
00302 int UpdateRegionAssignment();
00303
00304
00305
00306
00307 char *DataLocationMap;
00308
00309 int *NumProcessesInRegion;
00310 int **ProcessList;
00311
00312 int *NumRegionsInProcess;
00313 int **RegionList;
00314
00315 int **CellCountList;
00316
00317 double *CellDataMin;
00318 double *CellDataMax;
00319 double *PointDataMin;
00320 double *PointDataMax;
00321 char **CellDataName;
00322 char **PointDataName;
00323 int NumCellArrays;
00324 int NumPointArrays;
00325
00326
00327
00328 int BuildGlobalIndexLists(int ncells);
00329
00330 int *StartVal;
00331 int *EndVal;
00332 int *NumCells;
00333 int TotalNumCells;
00334
00335
00336
00337 int WhoHas(int pos);
00338 int _whoHas(int L, int R, int pos);
00339 float *GetLocalVal(int pos);
00340 float *GetLocalValNext(int pos);
00341 void SetLocalVal(int pos, float *val);
00342 void ExchangeVals(int pos1, int pos2);
00343 void ExchangeLocalVals(int pos1, int pos2);
00344
00345 float *PtArray;
00346 float *PtArray2;
00347 float *CurrentPtArray;
00348 float *NextPtArray;
00349 int PtArraySize;
00350
00351 int *SelectBuffer;
00352
00353
00354
00355 int AllCheckForFailure(int rc, const char *where, const char *how);
00356 void AllCheckParameters();
00357 double *VolumeBounds();
00358 int DivideTest(int L, int R, int level);
00359 int DivideRegion(vtkKdNode *kd, int L, int level, int tag);
00360 int BreadthFirstDivide(double *bounds);
00361 void enQueueNode(vtkKdNode *kd, int L, int level, int tag);
00362
00363 int Select(int dim, int L, int R);
00364 void _select(int L, int R, int K, int dim);
00365 void DoTransfer(int from, int to, int fromIndex, int toIndex, int count);
00366 int PartitionAboutMyValue(int L, int R, int K, int dim);
00367 int PartitionAboutOtherValue(int L, int R, float T, int dim);
00368 int PartitionSubArray(int L, int R, int K, int dim, int p1, int p2);
00369
00370 int CompleteTree();
00371 #ifdef YIELDS_INCONSISTENT_REGION_BOUNDARIES
00372 void RetrieveData(vtkKdNode *kd, int *buf);
00373 #else
00374 void ReduceData(vtkKdNode *kd, int *sources);
00375 void BroadcastData(vtkKdNode *kd);
00376 #endif
00377
00378 float *DataBounds(int L, int K, int R);
00379 void GetLocalMinMax(int L, int R, int me, float *min, float *max);
00380
00381 static int FillOutTree(vtkKdNode *kd, int level);
00382 static int ComputeDepth(vtkKdNode *kd);
00383 static void PackData(vtkKdNode *kd, float *data);
00384 static void UnpackData(vtkKdNode *kd, float *data);
00385 static void CheckFixRegionBoundaries(vtkKdNode *tree);
00386
00387
00388
00389 int AllocateDoubleBuffer();
00390 void FreeDoubleBuffer();
00391 void SwitchDoubleBuffer();
00392 int AllocateSelectBuffer();
00393 void FreeSelectBuffer();
00394
00395 void InitializeGlobalIndexLists();
00396 int AllocateAndZeroGlobalIndexLists();
00397 void FreeGlobalIndexLists();
00398 void InitializeRegionAssignmentLists();
00399 int AllocateAndZeroRegionAssignmentLists();
00400 void FreeRegionAssignmentLists();
00401 void InitializeProcessDataLists();
00402 int AllocateAndZeroProcessDataLists();
00403 void FreeProcessDataLists();
00404 void InitializeFieldArrayMinMax();
00405 int AllocateAndZeroFieldArrayMinMax();
00406 void FreeFieldArrayMinMax();
00407
00408 void ReleaseTables();
00409
00410
00411
00412 void AddProcessRegions(int procId, vtkKdNode *kd);
00413 void BuildRegionListsForProcesses();
00414
00415
00416
00417 int *CollectLocalRegionProcessData();
00418 int BuildRegionProcessTables();
00419 int BuildFieldArrayMinMax();
00420 void AddEntry(int *list, int len, int id);
00421 static int BinarySearch(int *list, int len, int which);
00422
00423 static int FindLocalArrayIndex(const char *n, const char **names, int len);
00424
00425
00426 vtkPKdTree(const vtkPKdTree&);
00427 void operator=(const vtkPKdTree&);
00428 };
00429
00430 #endif