VTK
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 
32 class VTKCOMMONDATAMODEL_EXPORT vtkStructuredExtent : public vtkObject
33 {
34 public:
35  static vtkStructuredExtent* New();
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 
67 
71  static void Transform(int ext[6], int wholeExt[6]);
72 
76  static void GetDimensions(const int ext[6], int dims[3]);
77 
78 protected:
80  ~vtkStructuredExtent() override;
81 
82 private:
84  void operator=(const vtkStructuredExtent&) = delete;
85 
86 };
87 
88 //----------------------------------------------------------------------------
89 inline void vtkStructuredExtent::Clamp(int ext[6], const int wholeExt[6])
90 {
91  ext[0] = (ext[0] < wholeExt[0])? wholeExt[0] : ext[0];
92  ext[1] = (ext[1] > wholeExt[1])? wholeExt[1] : ext[1];
93 
94  ext[2] = (ext[2] < wholeExt[2])? wholeExt[2] : ext[2];
95  ext[3] = (ext[3] > wholeExt[3])? wholeExt[3] : ext[3];
96 
97  ext[4] = (ext[4] < wholeExt[4])? wholeExt[4] : ext[4];
98  ext[5] = (ext[5] > wholeExt[5])? wholeExt[5] : ext[5];
99 }
100 
101 //----------------------------------------------------------------------------
102 inline bool vtkStructuredExtent::Smaller(const int ext[6], const int wholeExt[6])
103 {
104  if (ext[0] < wholeExt[0] || ext[0] > wholeExt[0 + 1] ||
105  ext[0 + 1] < wholeExt[0] || ext[0 + 1] > wholeExt[0 + 1])
106  {
107  return false;
108  }
109 
110  if (ext[2] < wholeExt[2] || ext[2] > wholeExt[2 + 1] ||
111  ext[2 + 1] < wholeExt[2] || ext[2 + 1] > wholeExt[2 + 1])
112  {
113  return false;
114  }
115 
116  if (ext[4] < wholeExt[4] || ext[4] > wholeExt[4 + 1] ||
117  ext[4 + 1] < wholeExt[4] || ext[4 + 1] > wholeExt[4 + 1])
118  {
119  return false;
120  }
121 
122  return true;
123 }
124 
125 //----------------------------------------------------------------------------
126 inline bool vtkStructuredExtent::StrictlySmaller(const int ext[6], const int wholeExt[6])
127 {
128  if (!vtkStructuredExtent::Smaller(ext, wholeExt))
129  {
130  return false;
131  }
132 
133  if (ext[0] > wholeExt[0] || ext[1] < wholeExt[1] ||
134  ext[2] > wholeExt[2] || ext[3] < wholeExt[3] ||
135  ext[4] > wholeExt[4] || ext[5] < wholeExt[5])
136  {
137  return true;
138  }
139 
140  return false;
141 }
142 
143 
144 //----------------------------------------------------------------------------
145 inline void vtkStructuredExtent::Grow(int ext[6], int count)
146 {
147  ext[0] -= count;
148  ext[2] -= count;
149  ext[4] -= count;
150 
151  ext[1] += count;
152  ext[3] += count;
153  ext[5] += count;
154 }
155 
156 //----------------------------------------------------------------------------
157 inline void vtkStructuredExtent::Grow(int ext[6], int count, int wholeExt[6])
158 {
159  vtkStructuredExtent::Grow(ext, count);
160  vtkStructuredExtent::Clamp(ext, wholeExt);
161 }
162 
163 //----------------------------------------------------------------------------
164 inline void vtkStructuredExtent::Transform(int ext[6], int wholeExt[6])
165 {
166  ext[0] -= wholeExt[0];
167  ext[1] -= wholeExt[0];
168 
169  ext[2] -= wholeExt[2];
170  ext[3] -= wholeExt[2];
171 
172  ext[4] -= wholeExt[4];
173  ext[5] -= wholeExt[4];
174 }
175 
176 //----------------------------------------------------------------------------
177 inline void vtkStructuredExtent::GetDimensions(const int ext[6], int dims[3])
178 {
179  dims[0] = ext[1]-ext[0] + 1;
180  dims[1] = ext[3]-ext[2] + 1;
181  dims[2] = ext[5]-ext[4] + 1;
182 }
183 
184 #endif
static void GetDimensions(const int ext[6], int dims[3])
Given the extents, computes the dimensions.
abstract base class for most VTK objects
Definition: vtkObject.h:53
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 Grow(int ext[6], int count)
Grows the ext on each side by the given count.
static void Clamp(int ext[6], const int wholeExt[])
Clamps ext to fit in wholeExt.
a simple class to control print indentation
Definition: vtkIndent.h:33
static bool StrictlySmaller(const int ext[6], const int wholeExt[6])
Returns true if ext is fits within wholeExt with atleast 1 dimension smaller than the wholeExt...
helper class to aid working with structured extents.
static vtkObject * New()
Create an object with Debug turned off, modified time initialized to zero, and reference counting on...
Transform
Definition: ADIOSDefs.h:40
static void Transform(int ext[6], int wholeExt[6])
Makes ext relative to wholeExt.