VTK
dox/Common/DataModel/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 =========================================================================*/
00028 #ifndef __vtkStructuredExtent_h
00029 #define __vtkStructuredExtent_h
00030 
00031 #include "vtkCommonDataModelModule.h" // For export macro
00032 #include "vtkObject.h"
00033 
00034 class VTKCOMMONDATAMODEL_EXPORT vtkStructuredExtent : public vtkObject
00035 {
00036 public:
00037   static vtkStructuredExtent* New();
00038   vtkTypeMacro(vtkStructuredExtent, vtkObject);
00039   void PrintSelf(ostream& os, vtkIndent indent);
00040 
00042   static void Clamp(int ext[6], int wholeExt[6]);
00043 
00046   static bool StrictlySmaller(const int ext[6], const int wholeExt[6]);
00047 
00050   static bool Smaller(const int ext[6], const int wholeExt[6]);
00051 
00053   static void Grow(int ext[6], int count);
00054 
00056   static void Transform(int ext[6], int wholeExt[6]);
00057 
00059   static void GetDimensions(const int ext[6], int dims[3]);
00060 
00061 //BTX
00062 protected:
00063   vtkStructuredExtent();
00064   ~vtkStructuredExtent();
00065 
00066 private:
00067   vtkStructuredExtent(const vtkStructuredExtent&); // Not implemented.
00068   void operator=(const vtkStructuredExtent&); // Not implemented.
00069 //ETX
00070 };
00071 
00072 //----------------------------------------------------------------------------
00073 inline void vtkStructuredExtent::Clamp(int ext[6], int wholeExt[6])
00074 {
00075   ext[0] = (ext[0] < wholeExt[0])? wholeExt[0] : ext[0];
00076   ext[1] = (ext[1] > wholeExt[1])? wholeExt[1] : ext[1];
00077 
00078   ext[2] = (ext[2] < wholeExt[2])? wholeExt[2] : ext[2];
00079   ext[3] = (ext[3] > wholeExt[3])? wholeExt[3] : ext[3];
00080 
00081   ext[4] = (ext[4] < wholeExt[4])? wholeExt[4] : ext[4];
00082   ext[5] = (ext[5] > wholeExt[5])? wholeExt[5] : ext[5];
00083 }
00084 
00085 //----------------------------------------------------------------------------
00086 inline bool vtkStructuredExtent::Smaller(const int ext[6], const int wholeExt[6])
00087 {
00088   if (ext[0]   < wholeExt[0] || ext[0]     > wholeExt[0 + 1] ||
00089     ext[0 + 1] < wholeExt[0] || ext[0 + 1] > wholeExt[0 + 1])
00090     {
00091     return false;
00092     }
00093 
00094   if (ext[2]   < wholeExt[2] || ext[2]     > wholeExt[2 + 1] ||
00095     ext[2 + 1] < wholeExt[2] || ext[2 + 1] > wholeExt[2 + 1])
00096     {
00097     return false;
00098     }
00099 
00100   if (ext[4]   < wholeExt[4] || ext[4]     > wholeExt[4 + 1] ||
00101     ext[4 + 1] < wholeExt[4] || ext[4 + 1] > wholeExt[4 + 1])
00102     {
00103     return false;
00104     }
00105 
00106   return true;
00107 }
00108 
00109 //----------------------------------------------------------------------------
00110 inline bool vtkStructuredExtent::StrictlySmaller(const int ext[6], const int wholeExt[6])
00111 {
00112   if (!vtkStructuredExtent::Smaller(ext, wholeExt))
00113     {
00114     return false;
00115     }
00116 
00117   if (ext[0] > wholeExt[0] || ext[1] < wholeExt[1] ||
00118     ext[2] > wholeExt[2] || ext[3] < wholeExt[3] ||
00119     ext[4] > wholeExt[4] || ext[5] < wholeExt[5])
00120     {
00121     return true;
00122     }
00123 
00124   return false;
00125 }
00126 
00127 
00128 //----------------------------------------------------------------------------
00129 inline void vtkStructuredExtent::Grow(int ext[6], int count)
00130 {
00131   ext[0] -= count;
00132   ext[2] -= count;
00133   ext[4] -= count;
00134 
00135   ext[1] += count;
00136   ext[3] += count;
00137   ext[5] += count;
00138 }
00139 
00140 //----------------------------------------------------------------------------
00141 inline void vtkStructuredExtent::Transform(int ext[6], int wholeExt[6])
00142 {
00143   ext[0] -= wholeExt[0];
00144   ext[1] -= wholeExt[0];
00145 
00146   ext[2] -= wholeExt[2];
00147   ext[3] -= wholeExt[2];
00148 
00149   ext[4] -= wholeExt[4];
00150   ext[5] -= wholeExt[4];
00151 }
00152 
00153 //----------------------------------------------------------------------------
00154 inline void vtkStructuredExtent::GetDimensions(const int ext[6], int dims[3])
00155 {
00156   dims[0] = ext[1]-ext[0] + 1;
00157   dims[1] = ext[3]-ext[2] + 1;
00158   dims[2] = ext[5]-ext[4] + 1;
00159 }
00160 
00161 #endif