18#ifndef vtkPixelExtent_h
19#define vtkPixelExtent_h
21#include "vtkCommonDataModelModule.h"
29VTK_ABI_NAMESPACE_BEGIN
44 this->SetData(T(0), width - T(1), T(0), height - T(1));
55 const int&
operator[](
int i)
const {
return this->Data[i]; }
63 void SetData(
const T* ext);
66 void SetData(T ilo, T ihi, T jlo, T jhi);
73 const int*
GetData()
const {
return this->Data; }
76 void GetData(T data[4])
const;
78 unsigned int*
GetDataU() {
return reinterpret_cast<unsigned int*
>(this->Data); }
80 const unsigned int*
GetDataU()
const {
return reinterpret_cast<const unsigned int*
>(this->Data); }
86 void GetStartIndex(
int first[2])
const;
87 void GetStartIndex(
int first[2],
const int origin[2])
const;
88 void GetEndIndex(
int last[2])
const;
106 int Contains(
int i,
int j)
const;
117 template <
typename T>
118 void Size(T nCells[2])
const;
140 void Grow(
int q,
int n);
141 void GrowLow(
int q,
int n);
142 void GrowHigh(
int q,
int n);
150 void Shrink(
int q,
int n);
171 void Shift(
int q,
int n);
192 template <
typename T>
264 static void Merge(std::deque<vtkPixelExtent>& exts);
273VTKCOMMONDATAMODEL_EXPORT
280 Data[0] =
static_cast<int>(ext[0]);
281 Data[1] =
static_cast<int>(ext[1]);
282 Data[2] =
static_cast<int>(ext[2]);
283 Data[3] =
static_cast<int>(ext[3]);
290 T ext[4] = { ilo, ihi, jlo, jhi };
304 data[0] =
static_cast<T
>(this->Data[0]);
305 data[1] =
static_cast<T
>(this->Data[1]);
306 data[2] =
static_cast<T
>(this->Data[2]);
307 data[3] =
static_cast<T
>(this->Data[3]);
313 this->SetData<int>(INT_MAX, INT_MIN, INT_MAX, INT_MIN);
333 this->
SetData(ilo, ihi, jlo, jhi);
341 this->Data[0] = other.Data[0];
342 this->Data[1] = other.Data[1];
343 this->Data[2] = other.Data[2];
344 this->Data[3] = other.Data[3];
359 nCells[0] = ext[1] - ext[0] + 1;
360 nCells[1] = ext[3] - ext[2] + 1;
366 return (ext[1] - ext[0] + 1) * (ext[3] - ext[2] + 1);
385 first[0] = this->Data[0];
386 first[1] = this->Data[2];
392 first[0] = this->Data[0] - origin[0];
393 first[1] = this->Data[2] - origin[1];
399 last[0] = this->Data[1];
400 last[1] = this->Data[3];
406 if (this->Data[0] > this->Data[1] || this->Data[2] > this->Data[3])
416 if ((this->Data[0] == other.Data[0]) && (this->Data[1] == other.Data[1]) &&
417 (this->Data[2] == other.Data[2]) && (this->Data[3] == other.Data[3]))
427 if ((this->Data[0] <= other.Data[0]) && (this->Data[1] >= other.Data[1]) &&
428 (this->Data[2] <= other.Data[2]) && (this->Data[3] >= other.Data[3]))
438 if ((this->Data[0] <= i) && (this->Data[1] >= i) && (this->Data[2] <= j) && (this->Data[3] >= j))
459 this->Data[0] = (std::max)(this->Data[0], other.Data[0]);
460 this->Data[1] = (std::min)(this->Data[1], other.Data[1]);
461 this->Data[2] = (std::max)(this->Data[2], other.Data[2]);
462 this->Data[3] = (std::min)(this->Data[3], other.Data[3]);
484 this->Data[0] = (std::min)(this->Data[0], other.Data[0]);
485 this->Data[1] = (std::max)(this->Data[1], other.Data[1]);
486 this->Data[2] = (std::min)(this->Data[2], other.Data[2]);
487 this->Data[3] = (std::max)(this->Data[3], other.Data[3]);
494 return other.
Empty();
512 this->Data[q + 1] += n;
518 this->Data[2 * q] -= n;
524 this->Data[2 * q + 1] += n;
541 this->Data[q + 1] -= n;
547 this->Data[0] += n[0];
548 this->Data[1] += n[0];
549 this->Data[2] += n[1];
550 this->Data[3] += n[1];
558 this->Data[q + 1] += n;
564 for (
int q = 0; q < 2; ++q)
570 this->Data[qq + 1] += n;
577 for (
int q = 0; q < 2; ++q)
580 int n = -this->Data[qq];
583 this->Data[qq + 1] += n;
593 int l = this->Data[q + 1] - this->Data[q] + 1;
601 this->Data[q + 1] = s - 1;
Representation of a cartesian pixel plane and common operations on it.
void CellToNode()
In-place conversion from cell based to node based extent, and vise-versa.
static vtkPixelExtent Grow(const vtkPixelExtent &inputExt, const vtkPixelExtent &problemDomain, int n)
static vtkPixelExtent GrowLow(const vtkPixelExtent &ext, int q, int n)
vtkPixelExtent & operator=(const vtkPixelExtent &other)
const int * GetData() const
vtkPixelExtent Split(int dir)
Divide the extent in half in the given direction.
bool operator==(const vtkPixelExtent &other) const
Test for equivalence.
vtkPixelExtent(T width, T height)
static vtkPixelExtent Grow(const vtkPixelExtent &inputExt, int n)
Add or remove ghost cells.
void SetData(const vtkPixelExtent &ext)
Set the extent.
static void Merge(std::deque< vtkPixelExtent > &exts)
Merge compatible extents in the list.
size_t Size() const
Get the total number.
void operator&=(const vtkPixelExtent &other)
In place intersection.
static vtkPixelExtent Shrink(const vtkPixelExtent &inputExt, const vtkPixelExtent &problemDomain, int n)
Remove ghost cells.
static vtkPixelExtent GrowHigh(const vtkPixelExtent &ext, int q, int n)
void NodeToCell()
In-place conversion from cell based to node based extent, and vise-versa.
const unsigned int * GetDataU() const
int Disjoint(vtkPixelExtent other) const
Return non-zero if the extent is disjoint from the other.
static vtkPixelExtent Shrink(const vtkPixelExtent &inputExt, int n)
int & operator[](int i)
Element access.
void GetStartIndex(int first[2]) const
Get the start/end index.
void Shrink(int n)
Shrink the extent by n.
void Shift()
Shifts by low corner of this, moving to the origin.
int * GetData()
Direct access to internal data.
static void Shift(int *ij, int n)
Shift by the given amount while respecting mode.
int Contains(const vtkPixelExtent &other) const
Return non-zero if this extent contains the other.
static vtkPixelExtent NodeToCell(const vtkPixelExtent &inputExt)
Convert from point extent to cell extent while respecting the dimensionality of the data.
unsigned int * GetDataU()
void GetEndIndex(int last[2]) const
Get the start/end index.
void Size(T nCells[2]) const
Get the number in each direction.
int Empty() const
Return true if empty.
const int & operator[](int i) const
static void Split(int i, int j, const vtkPixelExtent &ext, std::deque< vtkPixelExtent > &newExts)
Split ext at i,j, resulting extents (up to 4) are appended to newExts.
static void Subtract(const vtkPixelExtent &A, const vtkPixelExtent &B, std::deque< vtkPixelExtent > &C)
A - B = C C is a set of disjoint extents such that the intersection of B and C is empty and the inter...
static void Shift(int *ij, int *n)
Shift by the given amount while respecting mode.
void GrowLow(int q, int n)
Expand the extents by n.
void operator|=(const vtkPixelExtent &other)
In place union.
void Grow(int n)
Expand the extents by n.
static vtkPixelExtent CellToNode(const vtkPixelExtent &inputExt)
Convert from cell extent to point extent while respecting the dimensionality of the data.
void GrowHigh(int q, int n)
Expand the extents by n.
bool operator<(const vtkPixelExtent &l, const vtkPixelExtent &r)
VTKCOMMONDATAMODEL_EXPORT std::ostream & operator<<(std::ostream &os, const vtkPixelExtent &ext)
Stream insertion operator for formatted output of pixel extents.
bool VTKCOMMONCORE_EXPORT operator==(const std::string &a, const vtkStringToken &b)