Main Page | Class Hierarchy | Alphabetical List | Class List | Directories | 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 
00042 #ifndef __vtkPKdTree_h
00043 #define __vtkPKdTree_h
00044 
00045 #include "vtkKdTree.h"
00046 
00047 class vtkMultiProcessController;
00048 class vtkCommunicator;
00049 class vtkSubGroup;
00050 class vtkIntArray;
00051 class vtkKdNode;
00052 
00053 class VTK_PARALLEL_EXPORT vtkPKdTree : public vtkKdTree
00054 {
00055 public:
00056   vtkTypeRevisionMacro(vtkPKdTree, vtkKdTree);
00057 
00058 
00059   void PrintSelf(ostream& os, vtkIndent indent);
00060   void PrintTiming(ostream& os, vtkIndent indent);
00061   void PrintTables(ostream& os, vtkIndent indent);
00062 
00063   static vtkPKdTree *New();
00064 
00069   void BuildLocator();
00070 
00075   int GetTotalNumberOfCells(){return this->TotalNumCells;}
00076 
00083   int CreateProcessCellCountData();
00084 
00091   int CreateGlobalDataArrayBounds();
00092 
00095   void SetController(vtkMultiProcessController *c);
00096   vtkGetObjectMacro(Controller, vtkMultiProcessController);
00097 
00106   vtkGetMacro(RegionAssignment, int);
00107 
00108   static const int NoRegionAssignment;
00109   static const int ContiguousAssignment;
00110   static const int UserDefinedAssignment;
00111   static const int RoundRobinAssignment;
00112 
00117   int AssignRegions(int *map, int numRegions);
00118 
00123   int AssignRegionsRoundRobin();
00124 
00131   int AssignRegionsContiguous();
00132 
00137   int GetRegionAssignmentList(int procId, vtkIntArray *list);
00138 
00145   void GetAllProcessesBorderingOnPoint(float x, float y, float z, 
00146                           vtkIntArray *list);
00147 
00150   int GetProcessAssignedToRegion(int regionId);
00151 
00154   int HasData(int processId, int regionId);
00155 
00159   int GetProcessCellCountForRegion(int processId, int regionId);
00160 
00164   int GetTotalProcessesInRegion(int regionId);
00165 
00169   int GetProcessListForRegion(int regionId, vtkIntArray *processes);
00170 
00176   int GetProcessesCellCountForRegion(int regionId, int *count, int len);
00177 
00181   int GetTotalRegionsForProcess(int processId);
00182 
00186   int GetRegionListForProcess(int processId, vtkIntArray *regions);
00187 
00193   int GetRegionsCellCountForProcess(int ProcessId, int *count, int len);
00194 
00213   vtkIdType GetCellListsForProcessRegions(int ProcessId, int set, 
00214             vtkIdList *inRegionCells, vtkIdList *onBoundaryCells);
00215   vtkIdType GetCellListsForProcessRegions(int ProcessId, vtkDataSet *set,
00216             vtkIdList *inRegionCells, vtkIdList *onBoundaryCells);
00217   vtkIdType GetCellListsForProcessRegions(int ProcessId, vtkIdList *inRegionCells,
00218                                     vtkIdList *onBoundaryCells);
00219 
00223   int DepthOrderAllProcesses(double *directionOfProjection, 
00224                                  vtkIntArray *orderedList);
00225 
00231   int GetCellArrayGlobalRange(const char *name, float range[2]);
00232   int GetPointArrayGlobalRange(const char *name, float range[2]);
00233   int GetCellArrayGlobalRange(const char *name, double range[2]);
00234   int GetPointArrayGlobalRange(const char *name, double range[2]);
00235 
00236   int GetCellArrayGlobalRange(int arrayIndex, double range[2]);
00237   int GetPointArrayGlobalRange(int arrayIndex, double range[2]);
00238   int GetCellArrayGlobalRange(int arrayIndex, float range[2]);
00239   int GetPointArrayGlobalRange(int arrayIndex, float range[2]);
00240 
00241 protected:
00242 
00243   vtkPKdTree();
00244   ~vtkPKdTree();
00245 
00246   void SingleProcessBuildLocator();
00247   int MultiProcessBuildLocator(double *bounds);
00248 
00249 private:
00250 
00251   int RegionAssignment;
00252 
00253   vtkMultiProcessController *Controller;
00254 
00255   vtkSubGroup *SubGroup;
00256 
00257   static char *StrDupWithNew(const char *s);
00258 
00259   int NumProcesses;
00260   int MyId;
00261 
00262   // basic tables - each region is the responsibility of one process, but
00263   //                one process may be assigned many regions
00264 
00265   int *RegionAssignmentMap;        // indexed by region ID
00266   int RegionAssignmentMapLength;
00267   int **ProcessAssignmentMap;      // indexed by process ID
00268   int *NumRegionsAssigned;         // indexed by process ID
00269 
00270   int UpdateRegionAssignment();
00271 
00272   // basic tables reflecting the data that was read from disk
00273   // by each process
00274 
00275   char *DataLocationMap;              // by process, by region
00276 
00277   int *NumProcessesInRegion;          // indexed by region ID
00278   int **ProcessList;                  // indexed by region ID
00279 
00280   int *NumRegionsInProcess;           // indexed by process ID
00281   int **RegionList;                   // indexed by process ID
00282 
00283   int **CellCountList;                // indexed by region ID
00284 
00285   double *CellDataMin;           // global range for data arrays
00286   double *CellDataMax;
00287   double *PointDataMin;
00288   double *PointDataMax;
00289   char **CellDataName;
00290   char **PointDataName;
00291   int NumCellArrays;
00292   int NumPointArrays; 
00293 
00294   // distribution of indices for select operation
00295 
00296   int BuildGlobalIndexLists(int ncells);
00297 
00298   int *StartVal;
00299   int *EndVal;
00300   int *NumCells;
00301   int TotalNumCells;
00302 
00303   // local share of points to be partitioned, and local cache
00304 
00305   int WhoHas(int pos);
00306   int _whoHas(int L, int R, int pos);
00307   float *GetLocalVal(int pos);
00308   float *GetLocalValNext(int pos);
00309   void SetLocalVal(int pos, float *val);
00310   void ExchangeVals(int pos1, int pos2);
00311   void ExchangeLocalVals(int pos1, int pos2);
00312 
00313   float *PtArray;
00314   float *PtArray2;
00315   float *CurrentPtArray;
00316   float *NextPtArray;
00317   int PtArraySize;
00318 
00319   int *SelectBuffer;
00320 
00321   // Parallel build of k-d tree
00322 
00323   int AllCheckForFailure(int rc, const char *where, const char *how);
00324   void AllCheckParameters();
00325   double *VolumeBounds();
00326   int DivideRegion(vtkKdNode *kd, int L, int level, int tag);
00327   int BreadthFirstDivide(double *bounds);
00328   void enQueueNode(vtkKdNode *kd, int L, int level, int tag);
00329 
00330   int Select(int dim, int L, int R);
00331   void _select(int L, int R, int K, int dim);
00332   void DoTransfer(int from, int to, int fromIndex, int toIndex, int count);
00333 
00334   int *PartitionAboutMyValue(int L, int R, int K, int dim);
00335   int *PartitionAboutOtherValue(int L, int R, float T, int dim);
00336   int *PartitionSubArray(int L, int R, int K, int dim, int p1, int p2);
00337 
00338   int CompleteTree();
00339 #ifdef YIELDS_INCONSISTENT_REGION_BOUNDARIES
00340   void RetrieveData(vtkKdNode *kd, int *buf);
00341 #else
00342   void ReduceData(vtkKdNode *kd, int *sources);
00343   void BroadcastData(vtkKdNode *kd);
00344 #endif
00345 
00346   float *DataBounds(int L, int K, int R);
00347   void GetLocalMinMax(int L, int R, int me, float *min, float *max);
00348 
00349   static int FillOutTree(vtkKdNode *kd, int level);
00350   static int ComputeDepth(vtkKdNode *kd);
00351   static void PackData(vtkKdNode *kd, double *data);
00352   static void UnpackData(vtkKdNode *kd, double *data);
00353   static void CheckFixRegionBoundaries(vtkKdNode *tree);
00354 
00355   // list management
00356 
00357   int AllocateDoubleBuffer();
00358   void FreeDoubleBuffer();
00359   void SwitchDoubleBuffer();
00360   int AllocateSelectBuffer();
00361   void FreeSelectBuffer();
00362 
00363   void InitializeGlobalIndexLists();
00364   int AllocateAndZeroGlobalIndexLists();
00365   void FreeGlobalIndexLists();
00366   void InitializeRegionAssignmentLists();
00367   int AllocateAndZeroRegionAssignmentLists();
00368   void FreeRegionAssignmentLists();
00369   void InitializeProcessDataLists();
00370   int AllocateAndZeroProcessDataLists();
00371   void FreeProcessDataLists();
00372   void InitializeFieldArrayMinMax();
00373   int AllocateAndZeroFieldArrayMinMax();
00374   void FreeFieldArrayMinMax();
00375 
00376   void ReleaseTables();
00377 
00378   // Assigning regions to processors
00379 
00380   void AddProcessRegions(int procId, vtkKdNode *kd);
00381   void BuildRegionListsForProcesses();
00382 
00383   // Gather process/region data totals
00384 
00385   int *CollectLocalRegionProcessData();
00386   int BuildRegionProcessTables();
00387   int BuildFieldArrayMinMax();
00388   void AddEntry(int *list, int len, int id);
00389   static int BinarySearch(int *list, int len, int which);
00390 
00391   static int FindNextLocalArrayIndex(const char *n, const char **names, int len, int start=0);
00392 
00393   vtkPKdTree(const vtkPKdTree&); // Not implemented
00394   void operator=(const vtkPKdTree&); // Not implemented
00395 };
00396 
00397 #endif

Generated on Mon Jan 21 23:07:33 2008 for VTK by  doxygen 1.4.3-20050530