1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411
|
/*=========================================================================
Program: Visualization Toolkit
Module: vtkAMRResampleFilter.h
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
/**
* @class vtkAMRResampleFilter
*
*
* This filter is a concrete instance of vtkMultiBlockDataSetAlgorithm and
* provides functionality for extracting portion of the AMR dataset, specified
* by a bounding box, in a uniform grid of the desired level of resolution.
* The resulting uniform grid is stored in a vtkMultiBlockDataSet where the
* number of blocks correspond to the number of processors utilized for the
* operation.
*
* @warning
* Data of the input AMR dataset is assumed to be cell-centered.
*
* @sa
* vtkOverlappingAMR, vtkUniformGrid
*/
#ifndef vtkAMRResampleFilter_h
#define vtkAMRResampleFilter_h
#include "vtkFiltersAMRModule.h" // For export macro
#include "vtkMultiBlockDataSetAlgorithm.h"
#include <vector> // For STL vector
class vtkInformation;
class vtkInformationVector;
class vtkUniformGrid;
class vtkOverlappingAMR;
class vtkMultiBlockDataSet;
class vtkMultiProcessController;
class vtkFieldData;
class vtkCellData;
class vtkPointData;
class vtkIndent;
class vtkAMRBox;
class VTKFILTERSAMR_EXPORT vtkAMRResampleFilter : public vtkMultiBlockDataSetAlgorithm
{
public:
static vtkAMRResampleFilter *New();
vtkTypeMacro(vtkAMRResampleFilter,vtkMultiBlockDataSetAlgorithm);
void PrintSelf(ostream &oss, vtkIndent indent);
//@{
/**
* Set & Get macro for the number of samples (cells) in each dimension.
* Nominal value for the number of samples is 10x10x10.
*/
vtkSetVector3Macro(NumberOfSamples,int);
vtkGetVector3Macro(NumberOfSamples,int);
//@}
//@{
/**
* Set & Get macro for the TransferToNodes flag
*/
vtkSetMacro(TransferToNodes,int);
vtkGetMacro(TransferToNodes,int);
//@}
//@{
/**
* Set & Get macro to allow the filter to operate in both demand-driven
* and standard modes
*/
vtkSetMacro(DemandDrivenMode,int);
vtkGetMacro(DemandDrivenMode,int);
//@}
//@{
/**
* Set & Get macro for the number of subdivisions
*/
vtkSetMacro(NumberOfPartitions,int);
vtkGetMacro(NumberOfPartitions,int);
//@}
//@{
/**
* Set and Get the min corner
*/
vtkSetVector3Macro(Min,double);
vtkGetVector3Macro(Min,double);
//@}
//@{
/**
* Set and Get the max corner
*/
vtkSetVector3Macro(Max,double);
vtkGetVector3Macro(Max,double);
//@}
//@{
/**
* Set & Get macro for the number of subdivisions
*/
vtkSetMacro(UseBiasVector,bool);
vtkGetMacro(UseBiasVector,bool);
//@}
//@{
/**
* Set and Get the bias vector. If UseBiasVector is true
* then the largest component of this vector can not have
* the max number of samples
*/
vtkSetVector3Macro(BiasVector,double);
vtkGetVector3Macro(BiasVector,double);
//@}
//@{
/**
* Set & Get macro for the multi-process controller
*/
vtkSetMacro(Controller, vtkMultiProcessController*);
vtkGetMacro(Controller, vtkMultiProcessController*);
//@}
// Standard pipeline routines
/**
* Gets the metadata from upstream module and determines which blocks
* should be loaded by this instance.
*/
virtual int RequestInformation(
vtkInformation *rqst,
vtkInformationVector **inputVector,
vtkInformationVector *outputVector );
virtual int RequestData(
vtkInformation*,vtkInformationVector**,vtkInformationVector*);
virtual int FillInputPortInformation(int port, vtkInformation *info);
virtual int FillOutputPortInformation(int port, vtkInformation *info);
/**
* Performs upstream requests to the reader
*/
virtual int RequestUpdateExtent(
vtkInformation*, vtkInformationVector**, vtkInformationVector* );
protected:
vtkAMRResampleFilter();
virtual ~vtkAMRResampleFilter();
vtkOverlappingAMR *AMRMetaData;
vtkMultiBlockDataSet *ROI; // Pointer to the region of interest.
int NumberOfSamples[3];
int GridNumberOfSamples[3];
double Min[3];
double Max[3];
double GridMin[3];
double GridMax[3];
int LevelOfResolution;
int NumberOfPartitions;
int TransferToNodes;
int DemandDrivenMode;
vtkMultiProcessController *Controller;
bool UseBiasVector;
double BiasVector[3];
// Debugging Stuff
int NumberOfBlocksTestedForLevel;
int NumberOfBlocksTested;
int NumberOfBlocksVisSkipped;
int NumberOfTimesFoundOnDonorLevel;
int NumberOfTimesLevelUp;
int NumberOfTimesLevelDown;
int NumberOfFailedPoints;
double AverageLevel;
std::vector< int > BlocksToLoad; // Holds the ids of the blocks to load.
/**
* Checks if this filter instance is running on more than one processes
*/
bool IsParallel();
/**
* Given the Region ID this function returns whether or not the region
* belongs to this process or not.
*/
bool IsRegionMine( const int regionIdx );
/**
* Given the Region ID, this method computes the corresponding process ID
* that owns the region based on static block-cyclic distribution.
*/
int GetRegionProcessId( const int regionIdx );
/**
* Given a cell index and a grid, this method computes the cell centroid.
*/
void ComputeCellCentroid(
vtkUniformGrid *g, const vtkIdType cellIdx, double c[3] );
/**
* Given the source cell data of an AMR grid, this method initializes the
* field values, i.e., the number of arrays with the prescribed size. Note,
* the size must correspond to the number of points if node-centered or the
* the number of cells if cell-centered.
*/
void InitializeFields( vtkFieldData *f, vtkIdType size, vtkCellData *src );
/**
* Copies the data to the target from the given source.
*/
void CopyData( vtkFieldData *target, vtkIdType targetIdx,
vtkCellData *src, vtkIdType srcIdx );
/**
* Given a query point q and a candidate donor grid, this method checks for
* the corresponding donor cell containing the point in the given grid.
*/
bool FoundDonor(double q[3],vtkUniformGrid *&donorGrid,int &cellIdx);
/**
* Given a query point q and a target level, this method finds a suitable
* grid at the given level that contains the point if one exists. If a grid
* is not found, donorGrid is set to NULL.
*/
bool SearchForDonorGridAtLevel(
double q[3], vtkOverlappingAMR *amrds,
unsigned int level, unsigned int& gridId,
int &donorCellIdx);
/**
* Finds the AMR grid that contains the point q. If donorGrid points to a
* valid AMR grid in the hierarchy, the algorithm will search this grid
* first. The method returns the ID of the cell w.r.t. the donorGrid that
* contains the probe point q.
*/
int ProbeGridPointInAMR(
double q[3], unsigned int &donorLevel, unsigned int& donorGridId,
vtkOverlappingAMR *amrds, unsigned int maxLevel, bool useCached);
/**
* Finds the AMR grid that contains the point q. If donorGrid points to a
* valid AMR grid in the hierarchy, the algorithm will search this grid
* first. The method returns the ID of the cell w.r.t. the donorGrid that
* contains the probe point q. - Makes use of Parent/Child Info
*/
int ProbeGridPointInAMRGraph(double q[3],
unsigned int &donorLevel, unsigned int &donorGridId,
vtkOverlappingAMR *amrds, unsigned int maxLevel, bool useCached);
/**
* Transfers the solution from the AMR dataset to the cell-centers of
* the given uniform grid.
*/
void TransferToCellCenters(
vtkUniformGrid *g, vtkOverlappingAMR *amrds );
/**
* Transfer the solution from the AMR dataset to the nodes of the
* given uniform grid.
*/
void TransferToGridNodes(
vtkUniformGrid *g, vtkOverlappingAMR *amrds );
/**
* Transfers the solution
*/
void TransferSolution(
vtkUniformGrid *g, vtkOverlappingAMR *amrds);
/**
* Extract the region (as a multiblock) from the given AMR dataset.
*/
void ExtractRegion(
vtkOverlappingAMR *amrds, vtkMultiBlockDataSet *mbds,
vtkOverlappingAMR *metadata );
/**
* Checks if the AMR block, described by a uniform grid, is within the
* bounds of the ROI perscribed by the user.
*/
bool IsBlockWithinBounds( double *grd );
/**
* Given a user-supplied region of interest and the metadata by a module
* upstream, this method generates the list of linear AMR block indices
* that need to be loaded.
*/
void ComputeAMRBlocksToLoad( vtkOverlappingAMR *metadata );
/**
* Computes the region parameters
*/
void ComputeRegionParameters(
vtkOverlappingAMR *amrds,
int N[3], double min[3], double max[3], double h[3] );
/**
* This method accesses the domain boundaries
*/
void GetDomainParameters(
vtkOverlappingAMR *amr,
double domainMin[3], double domainMax[3], double h[3],
int dims[3], double &rf );
/**
* Checks if the domain and requested region intersect.
*/
bool RegionIntersectsWithAMR(
double domainMin[3], double domainMax[3],
double regionMin[3], double regionMax[3] );
/**
* This method adjust the numbers of samples in the region, N, if the
* requested region falls outside, but, intersects the domain.
*/
void AdjustNumberOfSamplesInRegion(const double Rh[3],
const bool outside[6], int N[3] );
/**
* This method computes the level of resolution based on the number of
* samples requested, N, the root level spacing h0, the length of the box,
* L (actual length after snapping) and the refinement ratio.
*/
void ComputeLevelOfResolution(
const int N[3], const double h0[3], const double L[3], const double rf);
/**
* This method snaps the bounds s.t. they are within the interior of the
* domain described the root level uniform grid with h0, domainMin and
* domain Max. The method computes and returns the new min/max bounds and
* the corresponding ijkmin/ijkmax coordinates w.r.t. the root level.
*/
void SnapBounds(
const double h0[3], const double domainMin[3], const double domainMax[3],
const int dims[3], bool outside[6] );
/**
* This method computes and adjusts the region parameters s.t. the requested
* region always fall within the AMR region and the number of samples is
* adjusted if the region of interest moves outsided the domain.
*/
void ComputeAndAdjustRegionParameters(
vtkOverlappingAMR *amrds, double h[3] );
/**
* This method gets the region of interest as perscribed by the user.
*/
void GetRegion( double h[3] );
/**
* Checks if two uniform grids intersect.
*/
bool GridsIntersect( double *g1, double *g2 );
/**
* Returns a reference grid from the amrdataset.
*/
vtkUniformGrid* GetReferenceGrid( vtkOverlappingAMR *amrds );
/**
* Writes a uniform grid to a file. Used for debugging purposes.
* void WriteUniformGrid( vtkUniformGrid *g, std::string prefix );
* void WriteUniformGrid(
* double origin[3], int dims[3], double h[3],
* std::string prefix );
*/
/**
* Find a decendant of the specified grid that contains the point.
* If none is found then the original grid information is returned.
* The search is limited to levels < maxLevel
*/
void SearchGridDecendants(double q[3],
vtkOverlappingAMR *amrds,
unsigned int maxLevel,
unsigned int &level,
unsigned int &gridId,
int &id);
/**
* Find an ancestor of the specified grid that contains the point.
* If none is found then the original grid information is returned
*/
bool SearchGridAncestors(double q[3],
vtkOverlappingAMR *amrds,
unsigned int &level,
unsigned int &gridId,
int &id);
private:
vtkAMRResampleFilter(const vtkAMRResampleFilter&) VTK_DELETE_FUNCTION;
void operator=(const vtkAMRResampleFilter&) VTK_DELETE_FUNCTION;
};
#endif /* vtkAMRResampleFilter_h */
|