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 =========================================================================*/
29 #ifndef vtkStructuredExtent_h
30 #define vtkStructuredExtent_h
31 
32 #include "vtkCommonDataModelModule.h" // For export macro
33 #include "vtkObject.h"
34 
35 class VTKCOMMONDATAMODEL_EXPORT vtkStructuredExtent : public vtkObject
36 {
37 public:
38  static vtkStructuredExtent* New();
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 
70 
74  static void Transform(int ext[6], int wholeExt[6]);
75 
79  static void GetDimensions(const int ext[6], int dims[3]);
80 
81 protected:
83  ~vtkStructuredExtent() override;
84 
85 private:
87  void operator=(const vtkStructuredExtent&) = delete;
88 
89 };
90 
91 //----------------------------------------------------------------------------
92 inline void vtkStructuredExtent::Clamp(int ext[6], const int wholeExt[6])
93 {
94  ext[0] = (ext[0] < wholeExt[0])? wholeExt[0] : ext[0];
95  ext[1] = (ext[1] > wholeExt[1])? wholeExt[1] : ext[1];
96 
97  ext[2] = (ext[2] < wholeExt[2])? wholeExt[2] : ext[2];
98  ext[3] = (ext[3] > wholeExt[3])? wholeExt[3] : ext[3];
99 
100  ext[4] = (ext[4] < wholeExt[4])? wholeExt[4] : ext[4];
101  ext[5] = (ext[5] > wholeExt[5])? wholeExt[5] : ext[5];
102 }
103 
104 //----------------------------------------------------------------------------
105 inline bool vtkStructuredExtent::Smaller(const int ext[6], const int wholeExt[6])
106 {
107  if (ext[0] < wholeExt[0] || ext[0] > wholeExt[0 + 1] ||
108  ext[0 + 1] < wholeExt[0] || ext[0 + 1] > wholeExt[0 + 1])
109  {
110  return false;
111  }
112 
113  if (ext[2] < wholeExt[2] || ext[2] > wholeExt[2 + 1] ||
114  ext[2 + 1] < wholeExt[2] || ext[2 + 1] > wholeExt[2 + 1])
115  {
116  return false;
117  }
118 
119  if (ext[4] < wholeExt[4] || ext[4] > wholeExt[4 + 1] ||
120  ext[4 + 1] < wholeExt[4] || ext[4 + 1] > wholeExt[4 + 1])
121  {
122  return false;
123  }
124 
125  return true;
126 }
127 
128 //----------------------------------------------------------------------------
129 inline bool vtkStructuredExtent::StrictlySmaller(const int ext[6], const int wholeExt[6])
130 {
131  if (!vtkStructuredExtent::Smaller(ext, wholeExt))
132  {
133  return false;
134  }
135 
136  if (ext[0] > wholeExt[0] || ext[1] < wholeExt[1] ||
137  ext[2] > wholeExt[2] || ext[3] < wholeExt[3] ||
138  ext[4] > wholeExt[4] || ext[5] < wholeExt[5])
139  {
140  return true;
141  }
142 
143  return false;
144 }
145 
146 
147 //----------------------------------------------------------------------------
148 inline void vtkStructuredExtent::Grow(int ext[6], int count)
149 {
150  ext[0] -= count;
151  ext[2] -= count;
152  ext[4] -= count;
153 
154  ext[1] += count;
155  ext[3] += count;
156  ext[5] += count;
157 }
158 
159 //----------------------------------------------------------------------------
160 inline void vtkStructuredExtent::Grow(int ext[6], int count, int wholeExt[6])
161 {
162  vtkStructuredExtent::Grow(ext, count);
163  vtkStructuredExtent::Clamp(ext, wholeExt);
164 }
165 
166 //----------------------------------------------------------------------------
167 inline void vtkStructuredExtent::Transform(int ext[6], int wholeExt[6])
168 {
169  ext[0] -= wholeExt[0];
170  ext[1] -= wholeExt[0];
171 
172  ext[2] -= wholeExt[2];
173  ext[3] -= wholeExt[2];
174 
175  ext[4] -= wholeExt[4];
176  ext[5] -= wholeExt[4];
177 }
178 
179 //----------------------------------------------------------------------------
180 inline void vtkStructuredExtent::GetDimensions(const int ext[6], int dims[3])
181 {
182  dims[0] = ext[1]-ext[0] + 1;
183  dims[1] = ext[3]-ext[2] + 1;
184  dims[2] = ext[5]-ext[4] + 1;
185 }
186 
187 #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:59
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:39
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...
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.