VTK  9.4.20241221
vtkStructuredExtent.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
2// SPDX-License-Identifier: BSD-3-Clause
17#ifndef vtkStructuredExtent_h
18#define vtkStructuredExtent_h
19
20#include "vtkCommonDataModelModule.h" // For export macro
21#include "vtkObject.h"
22
23VTK_ABI_NAMESPACE_BEGIN
24class VTKCOMMONDATAMODEL_EXPORT vtkStructuredExtent : public vtkObject
25{
26public:
29 void PrintSelf(ostream& os, vtkIndent indent) override;
30
34 static void Clamp(int ext[6], const int wholeExt[6]);
35
40 static bool StrictlySmaller(const int ext[6], const int wholeExt[6]);
41
46 static bool Smaller(const int ext[6], const int wholeExt[6]);
47
51 static void Grow(int ext[6], int count);
52
57 static void Grow(int ext[6], int count, int wholeExt[6]);
58
62 static void Transform(int ext[6], int wholeExt[6]);
63
67 static void GetDimensions(const int ext[6], int dims[3]);
68
69protected:
72
73private:
75 void operator=(const vtkStructuredExtent&) = delete;
76};
77
78//----------------------------------------------------------------------------
79inline void vtkStructuredExtent::Clamp(int ext[6], const int wholeExt[6])
80{
81 ext[0] = (ext[0] < wholeExt[0]) ? wholeExt[0] : ext[0];
82 ext[1] = (ext[1] > wholeExt[1]) ? wholeExt[1] : ext[1];
83
84 ext[2] = (ext[2] < wholeExt[2]) ? wholeExt[2] : ext[2];
85 ext[3] = (ext[3] > wholeExt[3]) ? wholeExt[3] : ext[3];
86
87 ext[4] = (ext[4] < wholeExt[4]) ? wholeExt[4] : ext[4];
88 ext[5] = (ext[5] > wholeExt[5]) ? wholeExt[5] : ext[5];
89}
90
91//----------------------------------------------------------------------------
92inline bool vtkStructuredExtent::Smaller(const int ext[6], const int wholeExt[6])
93{
94 if (ext[0] < wholeExt[0] || ext[0] > wholeExt[0 + 1] || ext[0 + 1] < wholeExt[0] ||
95 ext[0 + 1] > wholeExt[0 + 1])
96 {
97 return false;
98 }
99
100 if (ext[2] < wholeExt[2] || ext[2] > wholeExt[2 + 1] || ext[2 + 1] < wholeExt[2] ||
101 ext[2 + 1] > wholeExt[2 + 1])
102 {
103 return false;
104 }
105
106 if (ext[4] < wholeExt[4] || ext[4] > wholeExt[4 + 1] || ext[4 + 1] < wholeExt[4] ||
107 ext[4 + 1] > wholeExt[4 + 1])
108 {
109 return false;
110 }
111
112 return true;
113}
114
115//----------------------------------------------------------------------------
116inline bool vtkStructuredExtent::StrictlySmaller(const int ext[6], const int wholeExt[6])
117{
118 if (!vtkStructuredExtent::Smaller(ext, wholeExt))
119 {
120 return false;
121 }
122
123 if (ext[0] > wholeExt[0] || ext[1] < wholeExt[1] || ext[2] > wholeExt[2] ||
124 ext[3] < wholeExt[3] || ext[4] > wholeExt[4] || ext[5] < wholeExt[5])
125 {
126 return true;
127 }
128
129 return false;
130}
131
132//----------------------------------------------------------------------------
133inline void vtkStructuredExtent::Grow(int ext[6], int count)
134{
135 ext[0] -= count;
136 ext[2] -= count;
137 ext[4] -= count;
138
139 ext[1] += count;
140 ext[3] += count;
141 ext[5] += count;
142}
143
144//----------------------------------------------------------------------------
145inline void vtkStructuredExtent::Grow(int ext[6], int count, int wholeExt[6])
146{
147 vtkStructuredExtent::Grow(ext, count);
148 vtkStructuredExtent::Clamp(ext, wholeExt);
149}
150
151//----------------------------------------------------------------------------
152inline void vtkStructuredExtent::Transform(int ext[6], int wholeExt[6])
153{
154 ext[0] -= wholeExt[0];
155 ext[1] -= wholeExt[0];
156
157 ext[2] -= wholeExt[2];
158 ext[3] -= wholeExt[2];
159
160 ext[4] -= wholeExt[4];
161 ext[5] -= wholeExt[4];
162}
163
164//----------------------------------------------------------------------------
165inline void vtkStructuredExtent::GetDimensions(const int ext[6], int dims[3])
166{
167 dims[0] = ext[1] - ext[0] + 1;
168 dims[1] = ext[3] - ext[2] + 1;
169 dims[2] = ext[5] - ext[4] + 1;
170}
171
172VTK_ABI_NAMESPACE_END
173#endif
a simple class to control print indentation
Definition vtkIndent.h:108
abstract base class for most VTK objects
Definition vtkObject.h:162
helper class to aid working with structured extents.
static vtkStructuredExtent * New()
static void Grow(int ext[6], int count)
Grows the ext on each side by the given count.
~vtkStructuredExtent() override
static bool StrictlySmaller(const int ext[6], const int wholeExt[6])
Returns true if ext is fits within wholeExt with at least 1 dimension smaller than the wholeExt.
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
static void Clamp(int ext[6], const int wholeExt[6])
Clamps ext to fit in wholeExt.
static bool Smaller(const int ext[6], const int wholeExt[6])
Returns if ext fits within wholeExt.
static void Transform(int ext[6], int wholeExt[6])
Makes ext relative to wholeExt.
static void GetDimensions(const int ext[6], int dims[3])
Given the extents, computes the dimensions.