Main Page | Directories | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members | Related Pages

vtkPKdTree.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Visualization Toolkit
00004   Module:    $RCSfile: vtkPKdTree.h,v $
00005 
00006   Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
00007   All rights reserved.
00008   See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
00009 
00010      This software is distributed WITHOUT ANY WARRANTY; without even
00011      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
00012      PURPOSE.  See the above copyright notice for more information.
00013 
00014 =========================================================================*/
00015 /*----------------------------------------------------------------------------
00016  Copyright (c) Sandia Corporation
00017  See Copyright.txt or http://www.paraview.org/HTML/Copyright.html for details.
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   // basic tables - each region is the responsibility of one process, but
00295   //                one process may be assigned many regions
00296 
00297   int *RegionAssignmentMap;        // indexed by region ID
00298   int RegionAssignmentMapLength;
00299   int **ProcessAssignmentMap;      // indexed by process ID
00300   int *NumRegionsAssigned;         // indexed by process ID
00301 
00302   int UpdateRegionAssignment();
00303 
00304   // basic tables reflecting the data that was read from disk
00305   // by each process
00306 
00307   char *DataLocationMap;              // by process, by region
00308 
00309   int *NumProcessesInRegion;          // indexed by region ID
00310   int **ProcessList;                  // indexed by region ID
00311 
00312   int *NumRegionsInProcess;           // indexed by process ID
00313   int **RegionList;                   // indexed by process ID
00314 
00315   int **CellCountList;                // indexed by region ID
00316 
00317   double *CellDataMin;           // global range for data arrays
00318   double *CellDataMax;
00319   double *PointDataMin;
00320   double *PointDataMax;
00321   char **CellDataName;
00322   char **PointDataName;
00323   int NumCellArrays;
00324   int NumPointArrays; 
00325 
00326   // distribution of indices for select operation
00327 
00328   int BuildGlobalIndexLists(int ncells);
00329 
00330   int *StartVal;
00331   int *EndVal;
00332   int *NumCells;
00333   int TotalNumCells;
00334 
00335   // local share of points to be partitioned, and local cache
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   // Parallel build of k-d tree
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   // list management
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   // Assigning regions to processors
00411 
00412   void AddProcessRegions(int procId, vtkKdNode *kd);
00413   void BuildRegionListsForProcesses();
00414 
00415   // Gather process/region data totals
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&); // Not implemented
00427   void operator=(const vtkPKdTree&); // Not implemented
00428 };
00429 
00430 #endif