VTK
|
00001 /*========================================================================= 00002 00003 Program: Visualization Toolkit 00004 Module: vtkPKdTree.h 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 vtkTypeMacro(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 00068 void BuildLocator(); 00069 00073 vtkIdType GetTotalNumberOfCells(){return this->TotalNumCells;} 00074 00080 int CreateProcessCellCountData(); 00081 00087 int CreateGlobalDataArrayBounds(); 00088 00090 00091 void SetController(vtkMultiProcessController *c); 00092 vtkGetObjectMacro(Controller, vtkMultiProcessController); 00094 00096 00103 vtkGetMacro(RegionAssignment, int); 00105 00106 static const int NoRegionAssignment; 00107 static const int ContiguousAssignment; 00108 static const int UserDefinedAssignment; 00109 static const int RoundRobinAssignment; 00110 00114 int AssignRegions(int *map, int numRegions); 00115 00119 int AssignRegionsRoundRobin(); 00120 00126 int AssignRegionsContiguous(); 00127 00129 00131 const int* GetRegionAssignmentMap() 00132 { return this->RegionAssignmentMap; } 00134 00136 00137 vtkGetMacro(RegionAssignmentMapLength, int); 00139 00143 int GetRegionAssignmentList(int procId, vtkIntArray *list); 00144 00146 00151 void GetAllProcessesBorderingOnPoint(float x, float y, float z, 00152 vtkIntArray *list); 00154 00156 int GetProcessAssignedToRegion(int regionId); 00157 00159 int HasData(int processId, int regionId); 00160 00163 int GetProcessCellCountForRegion(int processId, int regionId); 00164 00167 int GetTotalProcessesInRegion(int regionId); 00168 00171 int GetProcessListForRegion(int regionId, vtkIntArray *processes); 00172 00177 int GetProcessesCellCountForRegion(int regionId, int *count, int len); 00178 00181 int GetTotalRegionsForProcess(int processId); 00182 00185 int GetRegionListForProcess(int processId, vtkIntArray *regions); 00186 00191 int GetRegionsCellCountForProcess(int ProcessId, int *count, int len); 00192 00194 00211 vtkIdType GetCellListsForProcessRegions(int ProcessId, int set, 00212 vtkIdList *inRegionCells, vtkIdList *onBoundaryCells); 00213 vtkIdType GetCellListsForProcessRegions(int ProcessId, vtkDataSet *set, 00214 vtkIdList *inRegionCells, vtkIdList *onBoundaryCells); 00215 vtkIdType GetCellListsForProcessRegions(int ProcessId, 00216 vtkIdList *inRegionCells, 00217 vtkIdList *onBoundaryCells); 00219 00221 00224 VTK_LEGACY(int DepthOrderAllProcesses(double *directionOfProjection, 00225 vtkIntArray *orderedList)); 00227 00229 00234 int ViewOrderAllProcessesInDirection(const double directionOfProjection[3], 00235 vtkIntArray *orderedList); 00237 00239 00244 int ViewOrderAllProcessesFromPosition(const double cameraPosition[3], 00245 vtkIntArray *orderedList); 00247 00253 int GetCellArrayGlobalRange(const char *name, float range[2]); 00254 int GetPointArrayGlobalRange(const char *name, float range[2]); 00255 int GetCellArrayGlobalRange(const char *name, double range[2]); 00256 int GetPointArrayGlobalRange(const char *name, double range[2]); 00257 00258 int GetCellArrayGlobalRange(int arrayIndex, double range[2]); 00259 int GetPointArrayGlobalRange(int arrayIndex, double range[2]); 00260 int GetCellArrayGlobalRange(int arrayIndex, float range[2]); 00261 int GetPointArrayGlobalRange(int arrayIndex, float range[2]); 00262 00263 protected: 00264 00265 vtkPKdTree(); 00266 ~vtkPKdTree(); 00267 00268 void SingleProcessBuildLocator(); 00269 int MultiProcessBuildLocator(double *bounds); 00270 00271 private: 00272 00273 int RegionAssignment; 00274 00275 vtkMultiProcessController *Controller; 00276 00277 vtkSubGroup *SubGroup; 00278 00279 static char *StrDupWithNew(const char *s); 00280 00281 int NumProcesses; 00282 int MyId; 00283 00284 // basic tables - each region is the responsibility of one process, but 00285 // one process may be assigned many regions 00286 00287 int *RegionAssignmentMap; // indexed by region ID 00288 int RegionAssignmentMapLength; 00289 int **ProcessAssignmentMap; // indexed by process ID 00290 int *NumRegionsAssigned; // indexed by process ID 00291 00292 int UpdateRegionAssignment(); 00293 00294 // basic tables reflecting the data that was read from disk 00295 // by each process 00296 00297 char *DataLocationMap; // by process, by region 00298 00299 int *NumProcessesInRegion; // indexed by region ID 00300 int **ProcessList; // indexed by region ID 00301 00302 int *NumRegionsInProcess; // indexed by process ID 00303 int **RegionList; // indexed by process ID 00304 00305 vtkIdType **CellCountList; // indexed by region ID 00306 00307 double *CellDataMin; // global range for data arrays 00308 double *CellDataMax; 00309 double *PointDataMin; 00310 double *PointDataMax; 00311 char **CellDataName; 00312 char **PointDataName; 00313 int NumCellArrays; 00314 int NumPointArrays; 00315 00316 // distribution of indices for select operation 00317 00318 int BuildGlobalIndexLists(vtkIdType ncells); 00319 00320 vtkIdType *StartVal; 00321 vtkIdType *EndVal; 00322 vtkIdType *NumCells; 00323 vtkIdType TotalNumCells; 00324 00325 // local share of points to be partitioned, and local cache 00326 00327 int WhoHas(int pos); 00328 int _whoHas(int L, int R, int pos); 00329 float *GetLocalVal(int pos); 00330 float *GetLocalValNext(int pos); 00331 void SetLocalVal(int pos, float *val); 00332 void ExchangeVals(int pos1, int pos2); 00333 void ExchangeLocalVals(int pos1, int pos2); 00334 00335 float *PtArray; 00336 float *PtArray2; 00337 float *CurrentPtArray; 00338 float *NextPtArray; 00339 int PtArraySize; 00340 00341 int *SelectBuffer; 00342 00343 // Parallel build of k-d tree 00344 00345 int AllCheckForFailure(int rc, const char *where, const char *how); 00346 void AllCheckParameters(); 00347 00349 00351 bool VolumeBounds(double*); 00352 int DivideRegion(vtkKdNode *kd, int L, int level, int tag); 00353 int BreadthFirstDivide(double *bounds); 00354 void enQueueNode(vtkKdNode *kd, int L, int level, int tag); 00356 00357 int Select(int dim, int L, int R); 00358 void _select(int L, int R, int K, int dim); 00359 void DoTransfer(int from, int to, int fromIndex, int toIndex, int count); 00360 00361 int *PartitionAboutMyValue(int L, int R, int K, int dim); 00362 int *PartitionAboutOtherValue(int L, int R, float T, int dim); 00363 int *PartitionSubArray(int L, int R, int K, int dim, int p1, int p2); 00364 00365 int CompleteTree(); 00366 #ifdef YIELDS_INCONSISTENT_REGION_BOUNDARIES 00367 void RetrieveData(vtkKdNode *kd, int *buf); 00368 #else 00369 void ReduceData(vtkKdNode *kd, int *sources); 00370 void BroadcastData(vtkKdNode *kd); 00371 #endif 00372 00373 float *DataBounds(int L, int K, int R); 00374 void GetLocalMinMax(int L, int R, int me, float *min, float *max); 00375 00376 static int FillOutTree(vtkKdNode *kd, int level); 00377 static int ComputeDepth(vtkKdNode *kd); 00378 static void PackData(vtkKdNode *kd, double *data); 00379 static void UnpackData(vtkKdNode *kd, double *data); 00380 static void CheckFixRegionBoundaries(vtkKdNode *tree); 00381 00382 // list management 00383 00384 int AllocateDoubleBuffer(); 00385 void FreeDoubleBuffer(); 00386 void SwitchDoubleBuffer(); 00387 int AllocateSelectBuffer(); 00388 void FreeSelectBuffer(); 00389 00390 void InitializeGlobalIndexLists(); 00391 int AllocateAndZeroGlobalIndexLists(); 00392 void FreeGlobalIndexLists(); 00393 void InitializeRegionAssignmentLists(); 00394 int AllocateAndZeroRegionAssignmentLists(); 00395 void FreeRegionAssignmentLists(); 00396 void InitializeProcessDataLists(); 00397 int AllocateAndZeroProcessDataLists(); 00398 void FreeProcessDataLists(); 00399 void InitializeFieldArrayMinMax(); 00400 int AllocateAndZeroFieldArrayMinMax(); 00401 void FreeFieldArrayMinMax(); 00402 00403 void ReleaseTables(); 00404 00405 // Assigning regions to processors 00406 00407 void AddProcessRegions(int procId, vtkKdNode *kd); 00408 void BuildRegionListsForProcesses(); 00409 00410 // Gather process/region data totals 00411 00412 int *CollectLocalRegionProcessData(); 00413 int BuildRegionProcessTables(); 00414 int BuildFieldArrayMinMax(); 00415 void AddEntry(int *list, int len, int id); 00416 #ifdef VTK_USE_64BIT_IDS 00417 void AddEntry(vtkIdType *list, int len, vtkIdType id); 00418 #endif 00419 static int BinarySearch(vtkIdType *list, int len, vtkIdType which); 00420 00421 static int FindNextLocalArrayIndex(const char *n, const char **names, int len, int start=0); 00422 00423 vtkPKdTree(const vtkPKdTree&); // Not implemented 00424 void operator=(const vtkPKdTree&); // Not implemented 00425 }; 00426 00427 #endif