VTK  9.1.0
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=========================================================================*/
26#ifndef vtkStructuredExtent_h
27#define vtkStructuredExtent_h
28
29#include "vtkCommonDataModelModule.h" // For export macro
30#include "vtkObject.h"
31
32class VTKCOMMONDATAMODEL_EXPORT vtkStructuredExtent : public vtkObject
33{
34public:
37 void PrintSelf(ostream& os, vtkIndent indent) override;
38
42 static void Clamp(int ext[6], const int wholeExt[]);
43
48 static bool StrictlySmaller(const int ext[6], const int wholeExt[6]);
49
54 static bool Smaller(const int ext[6], const int wholeExt[6]);
55
59 static void Grow(int ext[6], int count);
60
65 static void Grow(int ext[6], int count, int wholeExt[6]);
66
70 static void Transform(int ext[6], int wholeExt[6]);
71
75 static void GetDimensions(const int ext[6], int dims[3]);
76
77protected:
80
81private:
83 void operator=(const vtkStructuredExtent&) = delete;
84};
85
86//----------------------------------------------------------------------------
87inline void vtkStructuredExtent::Clamp(int ext[6], const int wholeExt[6])
88{
89 ext[0] = (ext[0] < wholeExt[0]) ? wholeExt[0] : ext[0];
90 ext[1] = (ext[1] > wholeExt[1]) ? wholeExt[1] : ext[1];
91
92 ext[2] = (ext[2] < wholeExt[2]) ? wholeExt[2] : ext[2];
93 ext[3] = (ext[3] > wholeExt[3]) ? wholeExt[3] : ext[3];
94
95 ext[4] = (ext[4] < wholeExt[4]) ? wholeExt[4] : ext[4];
96 ext[5] = (ext[5] > wholeExt[5]) ? wholeExt[5] : ext[5];
97}
98
99//----------------------------------------------------------------------------
100inline bool vtkStructuredExtent::Smaller(const int ext[6], const int wholeExt[6])
101{
102 if (ext[0] < wholeExt[0] || ext[0] > wholeExt[0 + 1] || ext[0 + 1] < wholeExt[0] ||
103 ext[0 + 1] > wholeExt[0 + 1])
104 {
105 return false;
106 }
107
108 if (ext[2] < wholeExt[2] || ext[2] > wholeExt[2 + 1] || ext[2 + 1] < wholeExt[2] ||
109 ext[2 + 1] > wholeExt[2 + 1])
110 {
111 return false;
112 }
113
114 if (ext[4] < wholeExt[4] || ext[4] > wholeExt[4 + 1] || ext[4 + 1] < wholeExt[4] ||
115 ext[4 + 1] > wholeExt[4 + 1])
116 {
117 return false;
118 }
119
120 return true;
121}
122
123//----------------------------------------------------------------------------
124inline bool vtkStructuredExtent::StrictlySmaller(const int ext[6], const int wholeExt[6])
125{
126 if (!vtkStructuredExtent::Smaller(ext, wholeExt))
127 {
128 return false;
129 }
130
131 if (ext[0] > wholeExt[0] || ext[1] < wholeExt[1] || ext[2] > wholeExt[2] ||
132 ext[3] < wholeExt[3] || ext[4] > wholeExt[4] || ext[5] < wholeExt[5])
133 {
134 return true;
135 }
136
137 return false;
138}
139
140//----------------------------------------------------------------------------
141inline void vtkStructuredExtent::Grow(int ext[6], int count)
142{
143 ext[0] -= count;
144 ext[2] -= count;
145 ext[4] -= count;
146
147 ext[1] += count;
148 ext[3] += count;
149 ext[5] += count;
150}
151
152//----------------------------------------------------------------------------
153inline void vtkStructuredExtent::Grow(int ext[6], int count, int wholeExt[6])
154{
155 vtkStructuredExtent::Grow(ext, count);
156 vtkStructuredExtent::Clamp(ext, wholeExt);
157}
158
159//----------------------------------------------------------------------------
160inline void vtkStructuredExtent::Transform(int ext[6], int wholeExt[6])
161{
162 ext[0] -= wholeExt[0];
163 ext[1] -= wholeExt[0];
164
165 ext[2] -= wholeExt[2];
166 ext[3] -= wholeExt[2];
167
168 ext[4] -= wholeExt[4];
169 ext[5] -= wholeExt[4];
170}
171
172//----------------------------------------------------------------------------
173inline void vtkStructuredExtent::GetDimensions(const int ext[6], int dims[3])
174{
175 dims[0] = ext[1] - ext[0] + 1;
176 dims[1] = ext[3] - ext[2] + 1;
177 dims[2] = ext[5] - ext[4] + 1;
178}
179
180#endif
a simple class to control print indentation
Definition: vtkIndent.h:113
abstract base class for most VTK objects
Definition: vtkObject.h:73
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 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.
@ Transform
Definition: vtkX3D.h:47