VTK
dox/Common/vtkStructuredExtent.h
Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Visualization Toolkit
00004   Module:    vtkStructuredExtent.h
00005 
00006   Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
00007   All rights reserved.
00008   See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
00009 
00010      This software is distributed WITHOUT ANY WARRANTY; without even
00011      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
00012      PURPOSE.  See the above copyright notice for more information.
00013 
00014 =========================================================================*/
00025 #ifndef __vtkStructuredExtent_h
00026 #define __vtkStructuredExtent_h
00027 
00028 #include "vtkObject.h"
00029 
00030 class VTK_COMMON_EXPORT vtkStructuredExtent : public vtkObject
00031 {
00032 public:
00033   static vtkStructuredExtent* New();
00034   vtkTypeMacro(vtkStructuredExtent, vtkObject);
00035   void PrintSelf(ostream& os, vtkIndent indent);
00036 
00038   static void Clamp(int ext[6], int wholeExt[6]);
00039 
00042   static bool StrictlySmaller(const int ext[6], const int wholeExt[6]);
00043 
00046   static bool Smaller(const int ext[6], const int wholeExt[6]);
00047 
00049   static void Grow(int ext[6], int count);
00050 
00052   static void Transform(int ext[6], int wholeExt[6]);
00053 
00055   static void GetDimensions(const int ext[6], int dims[3]);
00056 
00057 //BTX
00058 protected:
00059   vtkStructuredExtent();
00060   ~vtkStructuredExtent();
00061 
00062 private:
00063   vtkStructuredExtent(const vtkStructuredExtent&); // Not implemented.
00064   void operator=(const vtkStructuredExtent&); // Not implemented.
00065 //ETX
00066 };
00067 
00068 //----------------------------------------------------------------------------
00069 inline void vtkStructuredExtent::Clamp(int ext[6], int wholeExt[6])
00070 {
00071   ext[0] = (ext[0] < wholeExt[0])? wholeExt[0] : ext[0];
00072   ext[1] = (ext[1] > wholeExt[1])? wholeExt[1] : ext[1];
00073 
00074   ext[2] = (ext[2] < wholeExt[2])? wholeExt[2] : ext[2];
00075   ext[3] = (ext[3] > wholeExt[3])? wholeExt[3] : ext[3];
00076 
00077   ext[4] = (ext[4] < wholeExt[4])? wholeExt[4] : ext[4];
00078   ext[5] = (ext[5] > wholeExt[5])? wholeExt[5] : ext[5];
00079 }
00080 
00081 //----------------------------------------------------------------------------
00082 inline bool vtkStructuredExtent::Smaller(const int ext[6], const int wholeExt[6])
00083 {
00084   if (ext[0]   < wholeExt[0] || ext[0]     > wholeExt[0 + 1] ||
00085     ext[0 + 1] < wholeExt[0] || ext[0 + 1] > wholeExt[0 + 1])
00086     {
00087     return false;
00088     }
00089 
00090   if (ext[2]   < wholeExt[2] || ext[2]     > wholeExt[2 + 1] ||
00091     ext[2 + 1] < wholeExt[2] || ext[2 + 1] > wholeExt[2 + 1])
00092     {
00093     return false;
00094     }
00095 
00096   if (ext[4]   < wholeExt[4] || ext[4]     > wholeExt[4 + 1] ||
00097     ext[4 + 1] < wholeExt[4] || ext[4 + 1] > wholeExt[4 + 1])
00098     {
00099     return false;
00100     }
00101 
00102   return true;
00103 }
00104 
00105 //----------------------------------------------------------------------------
00106 inline bool vtkStructuredExtent::StrictlySmaller(const int ext[6], const int wholeExt[6])
00107 {
00108   if (!vtkStructuredExtent::Smaller(ext, wholeExt))
00109     {
00110     return false;
00111     }
00112 
00113   if (ext[0] > wholeExt[0] || ext[1] < wholeExt[1] ||
00114     ext[2] > wholeExt[2] || ext[3] < wholeExt[3] ||
00115     ext[4] > wholeExt[4] || ext[5] < wholeExt[5])
00116     {
00117     return true;
00118     }
00119 
00120   return false;
00121 }
00122 
00123 
00124 //----------------------------------------------------------------------------
00125 inline void vtkStructuredExtent::Grow(int ext[6], int count)
00126 {
00127   ext[0] -= count;
00128   ext[2] -= count;
00129   ext[4] -= count;
00130 
00131   ext[1] += count;
00132   ext[3] += count;
00133   ext[5] += count;
00134 }
00135 
00136 //----------------------------------------------------------------------------
00137 inline void vtkStructuredExtent::Transform(int ext[6], int wholeExt[6])
00138 {
00139   ext[0] -= wholeExt[0];
00140   ext[1] -= wholeExt[0];
00141 
00142   ext[2] -= wholeExt[2];
00143   ext[3] -= wholeExt[2];
00144 
00145   ext[4] -= wholeExt[4];
00146   ext[5] -= wholeExt[4];
00147 }
00148 
00149 //----------------------------------------------------------------------------
00150 inline void vtkStructuredExtent::GetDimensions(const int ext[6], int dims[3])
00151 {
00152   dims[0] = ext[1]-ext[0] + 1;
00153   dims[1] = ext[3]-ext[2] + 1;
00154   dims[2] = ext[5]-ext[4] + 1;
00155 }
00156 
00157 #endif