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 =========================================================================*/
25 #ifndef __vtkStructuredExtent_h
26 #define __vtkStructuredExtent_h
27 
28 #include "vtkCommonDataModelModule.h" // For export macro
29 #include "vtkObject.h"
30 
31 class VTKCOMMONDATAMODEL_EXPORT vtkStructuredExtent : public vtkObject
32 {
33 public:
34  static vtkStructuredExtent* New();
36  void PrintSelf(ostream& os, vtkIndent indent);
37 
39  static void Clamp(int ext[6], int wholeExt[6]);
40 
43  static bool StrictlySmaller(const int ext[6], const int wholeExt[6]);
44 
47  static bool Smaller(const int ext[6], const int wholeExt[6]);
48 
50  static void Grow(int ext[6], int count);
51 
53  static void Transform(int ext[6], int wholeExt[6]);
54 
56  static void GetDimensions(const int ext[6], int dims[3]);
57 
58 //BTX
59 protected:
62 
63 private:
64  vtkStructuredExtent(const vtkStructuredExtent&); // Not implemented.
65  void operator=(const vtkStructuredExtent&); // Not implemented.
66 //ETX
67 };
68 
69 //----------------------------------------------------------------------------
70 inline void vtkStructuredExtent::Clamp(int ext[6], int wholeExt[6])
71 {
72  ext[0] = (ext[0] < wholeExt[0])? wholeExt[0] : ext[0];
73  ext[1] = (ext[1] > wholeExt[1])? wholeExt[1] : ext[1];
74 
75  ext[2] = (ext[2] < wholeExt[2])? wholeExt[2] : ext[2];
76  ext[3] = (ext[3] > wholeExt[3])? wholeExt[3] : ext[3];
77 
78  ext[4] = (ext[4] < wholeExt[4])? wholeExt[4] : ext[4];
79  ext[5] = (ext[5] > wholeExt[5])? wholeExt[5] : ext[5];
80 }
81 
82 //----------------------------------------------------------------------------
83 inline bool vtkStructuredExtent::Smaller(const int ext[6], const int wholeExt[6])
84 {
85  if (ext[0] < wholeExt[0] || ext[0] > wholeExt[0 + 1] ||
86  ext[0 + 1] < wholeExt[0] || ext[0 + 1] > wholeExt[0 + 1])
87  {
88  return false;
89  }
90 
91  if (ext[2] < wholeExt[2] || ext[2] > wholeExt[2 + 1] ||
92  ext[2 + 1] < wholeExt[2] || ext[2 + 1] > wholeExt[2 + 1])
93  {
94  return false;
95  }
96 
97  if (ext[4] < wholeExt[4] || ext[4] > wholeExt[4 + 1] ||
98  ext[4 + 1] < wholeExt[4] || ext[4 + 1] > wholeExt[4 + 1])
99  {
100  return false;
101  }
102 
103  return true;
104 }
105 
106 //----------------------------------------------------------------------------
107 inline bool vtkStructuredExtent::StrictlySmaller(const int ext[6], const int wholeExt[6])
108 {
109  if (!vtkStructuredExtent::Smaller(ext, wholeExt))
110  {
111  return false;
112  }
113 
114  if (ext[0] > wholeExt[0] || ext[1] < wholeExt[1] ||
115  ext[2] > wholeExt[2] || ext[3] < wholeExt[3] ||
116  ext[4] > wholeExt[4] || ext[5] < wholeExt[5])
117  {
118  return true;
119  }
120 
121  return false;
122 }
123 
124 
125 //----------------------------------------------------------------------------
126 inline void vtkStructuredExtent::Grow(int ext[6], int count)
127 {
128  ext[0] -= count;
129  ext[2] -= count;
130  ext[4] -= count;
131 
132  ext[1] += count;
133  ext[3] += count;
134  ext[5] += count;
135 }
136 
137 //----------------------------------------------------------------------------
138 inline void vtkStructuredExtent::Transform(int ext[6], int wholeExt[6])
139 {
140  ext[0] -= wholeExt[0];
141  ext[1] -= wholeExt[0];
142 
143  ext[2] -= wholeExt[2];
144  ext[3] -= wholeExt[2];
145 
146  ext[4] -= wholeExt[4];
147  ext[5] -= wholeExt[4];
148 }
149 
150 //----------------------------------------------------------------------------
151 inline void vtkStructuredExtent::GetDimensions(const int ext[6], int dims[3])
152 {
153  dims[0] = ext[1]-ext[0] + 1;
154  dims[1] = ext[3]-ext[2] + 1;
155  dims[2] = ext[5]-ext[4] + 1;
156 }
157 
158 #endif