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

vtkKdTree.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Visualization Toolkit
00004   Module:    $RCSfile: vtkKdTree.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 
00055 #ifndef __vtkKdTree_h
00056 #define __vtkKdTree_h
00057 
00058 #include "vtkLocator.h"
00059 
00060 class vtkTimerLog;
00061 class vtkIdList;
00062 class vtkIdTypeArray;
00063 class vtkIntArray;
00064 class vtkPoints;
00065 class vtkCellArray;
00066 class vtkCell;
00067 class vtkKdNode;
00068 class vtkBSPCuts;
00069 class vtkBSPIntersections;
00070 
00071 class VTK_GRAPHICS_EXPORT vtkKdTree : public vtkLocator
00072 {
00073 public:
00074   vtkTypeRevisionMacro(vtkKdTree, vtkLocator);
00075   void PrintSelf(ostream& os, vtkIndent indent);
00076 
00077   static vtkKdTree *New();
00078 
00080 
00081   vtkBooleanMacro(Timing, int);
00082   vtkSetMacro(Timing, int);
00083   vtkGetMacro(Timing, int);
00085 
00087 
00088   vtkSetMacro(MinCells, int);
00089   vtkGetMacro(MinCells, int);
00091 
00096   vtkGetMacro(NumberOfRegionsOrLess, int);
00097   vtkSetMacro(NumberOfRegionsOrLess, int);
00098 
00103   vtkGetMacro(NumberOfRegionsOrMore, int);
00104   vtkSetMacro(NumberOfRegionsOrMore, int);
00105   
00111   vtkGetMacro(FudgeFactor, double);
00112   vtkSetMacro(FudgeFactor, double);
00113 
00117   vtkGetObjectMacro(Cuts, vtkBSPCuts);
00118 
00123   void SetCuts(vtkBSPCuts *cuts);
00124 
00126   void OmitXPartitioning();
00127   
00129   void OmitYPartitioning();
00130 
00132   void OmitZPartitioning();
00133 
00135   void OmitXYPartitioning();
00136 
00138   void OmitYZPartitioning();
00139   
00141   void OmitZXPartitioning();
00142 
00144   void OmitNoPartitioning();
00145 
00153   void SetDataSet(vtkDataSet *set);
00154   void SetNthDataSet(int index, vtkDataSet *set);
00155   void RemoveDataSet(int index);
00156   void RemoveDataSet(vtkDataSet *set);
00157   void AddDataSet(vtkDataSet *set);
00158 
00160   int GetNumberOfDataSets(){return this->NumDataSets;};
00161 
00166   vtkDataSet *GetDataSet(int n);
00167   vtkDataSet *GetDataSet(){ return this->GetDataSet(0); }
00168 
00171   int GetDataSet(vtkDataSet *set);
00172 
00175   void GetBounds(double *bounds);
00176 
00183   void SetNewBounds(double *bounds);
00184 
00186 
00187   vtkGetMacro(NumberOfRegions, int);
00189 
00191   void GetRegionBounds(int regionID, double bounds[6]);
00192 
00194   void GetRegionDataBounds(int regionID, double bounds[6]);
00195 
00197 
00198   void PrintTree();
00199   void PrintVerboseTree();
00201   
00203   void PrintRegion(int id);
00204   
00213   void CreateCellLists(int DataSet, int *regionReqList, 
00214                        int reqListSize);
00215   void CreateCellLists(vtkDataSet *set, int *regionReqList,
00216                        int reqListSize);
00217   void CreateCellLists(int *regionReqList, int listSize);
00218   void CreateCellLists(); 
00219   
00221 
00225   vtkSetMacro(IncludeRegionBoundaryCells, int);
00226   vtkGetMacro(IncludeRegionBoundaryCells, int);
00227   vtkBooleanMacro(IncludeRegionBoundaryCells, int);
00229 
00231   void DeleteCellLists();
00232 
00235   vtkIdList *GetCellList(int regionID);
00236 
00244   vtkIdList *GetBoundaryCellList(int regionID);
00245 
00247 
00261   vtkIdType GetCellLists(vtkIntArray *regions, int set, 
00262                    vtkIdList *inRegionCells, vtkIdList *onBoundaryCells);
00263   vtkIdType GetCellLists(vtkIntArray *regions, vtkDataSet *set,
00264             vtkIdList *inRegionCells, vtkIdList *onBoundaryCells);
00265   vtkIdType GetCellLists(vtkIntArray *regions, vtkIdList *inRegionCells,
00266                                     vtkIdList *onBoundaryCells);
00268   
00270 
00273   int GetRegionContainingCell(vtkDataSet *set, vtkIdType cellID);
00274   int GetRegionContainingCell(int set, vtkIdType cellID);
00275   int GetRegionContainingCell(vtkIdType cellID);
00277 
00282   int *AllGetRegionContainingCell();
00283 
00285   int GetRegionContainingPoint(double x, double y, double z);
00286   
00290   void BuildLocator();
00291 
00303   int MinimalNumberOfConvexSubRegions(vtkIntArray *regionIdList,
00304                                       double **convexRegionBounds);
00305 
00314   int DepthOrderAllRegions(double *dop, vtkIntArray *orderedList);
00315 
00321   int DepthOrderRegions(vtkIntArray *regionIds, double *dop,
00322                         vtkIntArray *orderedList);
00323 
00325 
00333   void BuildLocatorFromPoints(vtkPoints *ptArray);
00334   void BuildLocatorFromPoints(vtkPoints **ptArray, int numPtArrays);
00336   
00346   vtkIdTypeArray *BuildMapForDuplicatePoints(float tolerance);
00347 
00349 
00352   vtkIdType FindPoint(double *x);
00353   vtkIdType FindPoint(double x, double y, double z);
00355 
00357 
00360   vtkIdType FindClosestPoint(double *x, double &dist2);
00361   vtkIdType FindClosestPoint(double x, double y, double z, double &dist2);
00363 
00365 
00368   vtkIdType FindClosestPointInRegion(int regionId, double *x, double &dist2);
00369   vtkIdType FindClosestPointInRegion(int regionId, double x, double y, double z, 
00370                                      double &dist2);
00372 
00375   vtkIdTypeArray *GetPointsInRegion(int regionId);
00376 
00379   void FreeSearchStructure();
00380   
00383   void GenerateRepresentation(int level, vtkPolyData *pd);
00384   
00387   void GenerateRepresentation(int *regionList, int len, vtkPolyData *pd);
00388 
00390 
00394   vtkBooleanMacro(GenerateRepresentationUsingDataBounds, int);
00395   vtkSetMacro(GenerateRepresentationUsingDataBounds, int);
00396   vtkGetMacro(GenerateRepresentationUsingDataBounds, int);
00398 
00400   virtual void PrintTiming(ostream& os, vtkIndent indent);
00401 
00404   int NewGeometry();
00405 
00408   int NewGeometry(vtkDataSet **sets, int numDataSets);
00409 
00413   static vtkKdNode *CopyTree(vtkKdNode *kd);
00414 
00415 protected:
00416 
00417   vtkKdTree();
00418   ~vtkKdTree();
00419 
00420   vtkBSPIntersections *BSPCalculator;
00421   int UserDefinedCuts;
00422 
00423   void SetCalculator(vtkKdNode *kd);
00424 
00425   int ProcessUserDefinedCuts(double *bounds);
00426 
00427   void SetCuts(vtkBSPCuts *cuts, int userDefined);
00428 
00432   void UpdateBuildTime();
00433 
00439   int DivideTest(int numberOfPoints, int level);
00440 
00441 //BTX
00442   enum {
00443     XDIM = 0,  // don't change these values
00444     YDIM = 1,
00445     ZDIM = 2
00446   };
00447 //ETX
00448 
00449   int ValidDirections;
00450 
00451   vtkKdNode *Top;
00452   vtkKdNode **RegionList;      // indexed by region ID
00453 
00454   vtkTimerLog *TimerLog;
00455 
00456   static void DeleteAllDescendants(vtkKdNode *nd);
00457 
00458   void BuildRegionList();
00459   virtual int SelectCutDirection(vtkKdNode *kd);
00460   void SetActualLevel(){this->Level = vtkKdTree::ComputeLevel(this->Top);}
00461 
00465   void GetRegionsAtLevel(int level, vtkKdNode **nodes);
00466 
00470   static void GetLeafNodeIds(vtkKdNode *node, vtkIntArray *ids);
00471 
00472 
00475   int GetNumberOfCells();
00476 
00479   int GetDataSetsNumberOfCells(int set1, int set2);
00480 
00485   void ComputeCellCenter(vtkDataSet *set, int cellId, float *center);
00486   void ComputeCellCenter(vtkDataSet *set, int cellId, double *center);
00487 
00494   float *ComputeCellCenters();
00495   float *ComputeCellCenters(int set);
00496   float *ComputeCellCenters(vtkDataSet *set);
00497 
00498   virtual void ReportReferences(vtkGarbageCollector*);
00499 
00500 private:
00501 
00502   static void _SetNewBounds(vtkKdNode *kd, double *b, int *fixDim);
00503   static void CopyChildNodes(vtkKdNode *to, vtkKdNode *from);
00504   static void CopyKdNode(vtkKdNode *to, vtkKdNode *from);
00505   static void SetDataBoundsToSpatialBounds(vtkKdNode *kd);
00506   static void ZeroNumberOfPoints(vtkKdNode *kd);
00507 
00508 //BTX
00509   int DivideRegion(vtkKdNode *kd, float *c1, int *ids, int nlevels);
00510 
00511   void DoMedianFind(vtkKdNode *kd, float *c1, int *ids, int d1, int d2, int d3);
00512 
00513   void SelfRegister(vtkKdNode *kd);
00514 
00515   struct _cellList{
00516     vtkDataSet *dataSet;        // cell lists for which data set
00517     int *regionIds;            // NULL if listing all regions
00518     int nRegions;
00519     vtkIdList **cells;
00520     vtkIdList **boundaryCells;
00521     vtkIdList *emptyList;
00522   };
00523 //ETX
00524 
00525   void InitializeCellLists();
00526   vtkIdList *GetList(int regionId, vtkIdList **which);
00527 
00528   void ComputeCellCenter(vtkCell* cell, double *center, double *weights);
00529 
00530   void GenerateRepresentationDataBounds(int level, vtkPolyData *pd);
00531   void _generateRepresentationDataBounds(vtkKdNode *kd, vtkPoints *pts,
00532                                          vtkCellArray *polys, int level);
00533 
00534   void GenerateRepresentationWholeSpace(int level, vtkPolyData *pd);
00535   void _generateRepresentationWholeSpace(vtkKdNode *kd, vtkPoints *pts,
00536                                          vtkCellArray *polys, int level);
00537 
00538   void AddPolys(vtkKdNode *kd, vtkPoints *pts, vtkCellArray *polys);
00539 
00540   void _printTree(int verbose);
00541 
00542   int SearchNeighborsForDuplicate(int regionId, float *point,
00543                                   int **pointsSoFar, int *len, 
00544                                   float tolerance, float tolerance2);
00545 
00546   int SearchRegionForDuplicate(float *point, int *pointsSoFar, 
00547                                int len, float tolerance2);
00548 
00549   int _FindClosestPointInRegion(int regionId, 
00550                           double x, double y, double z, double &dist2);
00551 
00552   int FindClosestPointInSphere(double x, double y, double z, double radius,
00553                                int skipRegion, double &dist2);
00554 
00555   int _DepthOrderRegions(vtkIntArray *IdsOfInterest, double *dop,
00556                                 vtkIntArray *orderedList);
00557 
00558   static int __DepthOrderRegions(vtkKdNode *node, vtkIntArray *list, 
00559                           vtkIntArray *IdsOfInterest, double *dir, int nextId);
00560   static int __ConvexSubRegions(int *ids, int len, vtkKdNode *tree, vtkKdNode **nodes);
00561   static int FoundId(vtkIntArray *idArray, int id);
00562 
00563   void NewParitioningRequest(int req);
00564   void SetInputDataInfo(int i, 
00565        int dims[3], double origin[3], double spacing[3]);
00566   int CheckInputDataInfo(int i, 
00567        int dims[3], double origin[3], double spacing[3]);
00568   void ClearLastBuildCache();
00569 
00570 //BTX
00571   static void __printTree(vtkKdNode *kd, int depth, int verbose);
00572 //ETX
00573 
00574   static int MidValue(int dim, float *c1, int nvals, double &coord);
00575 
00576   static int Select(int dim, float *c1, int *ids, int nvals, double &coord);
00577   static float FindMaxLeftHalf(int dim, float *c1, int K);
00578   static void _Select(int dim, float *X, int *ids, int L, int R, int K);
00579 
00580 //BTX
00581   static int ComputeLevel(vtkKdNode *kd);
00582   static int SelfOrder(int id, vtkKdNode *kd);
00583   static int findRegion(vtkKdNode *node, float x, float y, float z);
00584   static int findRegion(vtkKdNode *node, double x, double y, double z);
00585 //ETX
00586 
00587   static vtkKdNode **_GetRegionsAtLevel(int level, vtkKdNode **nodes, 
00588                                         vtkKdNode *kd);
00589 
00590   static void AddNewRegions(vtkKdNode *kd, float *c1, 
00591                             int midpt, int dim, double coord);
00592 
00593   void NewPartitioningRequest(int req);
00594 
00595   int NumDataSetsAllocated;
00596 
00597   int NumberOfRegionsOrLess;
00598   int NumberOfRegionsOrMore;
00599 
00600   int IncludeRegionBoundaryCells;
00601   double CellBoundsCache[6];       // to optimize IntersectsCell()
00602 
00603   int GenerateRepresentationUsingDataBounds;
00604 
00605 //BTX
00606   struct _cellList CellList;
00607 //ETX
00608 
00609   // Region Ids, by data set by cell id - this list is large (one
00610   // int per cell) but accelerates creation of cell lists
00611 
00612   int *CellRegionList;
00613 
00614   int MinCells;
00615   int NumberOfRegions;              // number of leaf nodes
00616 
00617   int Timing;
00618   double FudgeFactor;   // a very small distance, relative to the dataset's size
00619 
00620   vtkDataSet **DataSets;
00621   int NumDataSets;
00622 
00623   // These instance variables are used by the special locator created
00624   // to find duplicate points. (BuildLocatorFromPoints)
00625 
00626   int NumberOfLocatorPoints;
00627   float *LocatorPoints;
00628   int *LocatorIds;
00629   int *LocatorRegionLocation;
00630 
00631   float MaxWidth;
00632 
00633   // These Last* values are here to save state so we can
00634   // determine later if k-d tree must be rebuilt.
00635 
00636   int LastNumDataSets;
00637   int LastDataCacheSize;
00638   vtkDataSet **LastInputDataSets;
00639   int *LastDataSetType;
00640   double *LastInputDataInfo;
00641   double *LastBounds;
00642   int *LastNumPoints;
00643   int *LastNumCells;
00644 
00645   vtkBSPCuts *Cuts;
00646 
00647   vtkKdTree(const vtkKdTree&); // Not implemented
00648   void operator=(const vtkKdTree&); // Not implemented
00649 };
00650 #endif

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