VTK  9.2.6
vtkStructuredExtent.h
Go to the documentation of this file.
1/*=========================================================================
2
3 Program: Visualization Toolkit
4 Module: vtkStructuredExtent.h
5
6 Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7 All rights reserved.
8 See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9
10 This software is distributed WITHOUT ANY WARRANTY; without even
11 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12 PURPOSE. See the above copyright notice for more information.
13
14=========================================================================*/
28
29#ifndef vtkStructuredExtent_h
30#define vtkStructuredExtent_h
31
32#include "vtkCommonDataModelModule.h" // For export macro
33#include "vtkObject.h"
34
35class VTKCOMMONDATAMODEL_EXPORT vtkStructuredExtent : public vtkObject
36{
37public:
40 void PrintSelf(ostream& os, vtkIndent indent) override;
41
45 static void Clamp(int ext[6], const int wholeExt[]);
46
51 static bool StrictlySmaller(const int ext[6], const int wholeExt[6]);
52
57 static bool Smaller(const int ext[6], const int wholeExt[6]);
58
62 static void Grow(int ext[6], int count);
63
68 static void Grow(int ext[6], int count, int wholeExt[6]);
69
73 static void Transform(int ext[6], int wholeExt[6]);
74
78 static void GetDimensions(const int ext[6], int dims[3]);
79
80protected:
83
84private:
86 void operator=(const vtkStructuredExtent&) = delete;
87};
88
89//----------------------------------------------------------------------------
90inline void vtkStructuredExtent::Clamp(int ext[6], const int wholeExt[6])
91{
92 ext[0] = (ext[0] < wholeExt[0]) ? wholeExt[0] : ext[0];
93 ext[1] = (ext[1] > wholeExt[1]) ? wholeExt[1] : ext[1];
94
95 ext[2] = (ext[2] < wholeExt[2]) ? wholeExt[2] : ext[2];
96 ext[3] = (ext[3] > wholeExt[3]) ? wholeExt[3] : ext[3];
97
98 ext[4] = (ext[4] < wholeExt[4]) ? wholeExt[4] : ext[4];
99 ext[5] = (ext[5] > wholeExt[5]) ? wholeExt[5] : ext[5];
100}
101
102//----------------------------------------------------------------------------
103inline bool vtkStructuredExtent::Smaller(const int ext[6], const int wholeExt[6])
104{
105 if (ext[0] < wholeExt[0] || ext[0] > wholeExt[0 + 1] || ext[0 + 1] < wholeExt[0] ||
106 ext[0 + 1] > wholeExt[0 + 1])
107 {
108 return false;
109 }
110
111 if (ext[2] < wholeExt[2] || ext[2] > wholeExt[2 + 1] || ext[2 + 1] < wholeExt[2] ||
112 ext[2 + 1] > wholeExt[2 + 1])
113 {
114 return false;
115 }
116
117 if (ext[4] < wholeExt[4] || ext[4] > wholeExt[4 + 1] || ext[4 + 1] < wholeExt[4] ||
118 ext[4 + 1] > wholeExt[4 + 1])
119 {
120 return false;
121 }
122
123 return true;
124}
125
126//----------------------------------------------------------------------------
127inline bool vtkStructuredExtent::StrictlySmaller(const int ext[6], const int wholeExt[6])
128{
129 if (!vtkStructuredExtent::Smaller(ext, wholeExt))
130 {
131 return false;
132 }
133
134 if (ext[0] > wholeExt[0] || ext[1] < wholeExt[1] || ext[2] > wholeExt[2] ||
135 ext[3] < wholeExt[3] || ext[4] > wholeExt[4] || ext[5] < wholeExt[5])
136 {
137 return true;
138 }
139
140 return false;
141}
142
143//----------------------------------------------------------------------------
144inline void vtkStructuredExtent::Grow(int ext[6], int count)
145{
146 ext[0] -= count;
147 ext[2] -= count;
148 ext[4] -= count;
149
150 ext[1] += count;
151 ext[3] += count;
152 ext[5] += count;
153}
154
155//----------------------------------------------------------------------------
156inline void vtkStructuredExtent::Grow(int ext[6], int count, int wholeExt[6])
157{
158 vtkStructuredExtent::Grow(ext, count);
159 vtkStructuredExtent::Clamp(ext, wholeExt);
160}
161
162//----------------------------------------------------------------------------
163inline void vtkStructuredExtent::Transform(int ext[6], int wholeExt[6])
164{
165 ext[0] -= wholeExt[0];
166 ext[1] -= wholeExt[0];
167
168 ext[2] -= wholeExt[2];
169 ext[3] -= wholeExt[2];
170
171 ext[4] -= wholeExt[4];
172 ext[5] -= wholeExt[4];
173}
174
175//----------------------------------------------------------------------------
176inline void vtkStructuredExtent::GetDimensions(const int ext[6], int dims[3])
177{
178 dims[0] = ext[1] - ext[0] + 1;
179 dims[1] = ext[3] - ext[2] + 1;
180 dims[2] = ext[5] - ext[4] + 1;
181}
182
183#endif
a simple class to control print indentation
Definition vtkIndent.h:40
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 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.
static void Clamp(int ext[6], const int wholeExt[])
Clamps ext to fit in wholeExt.