VTK
dox/Charts/vtkVector.h
Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Visualization Toolkit
00004   Module:    vtkVector.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 =========================================================================*/
00015 
00030 #ifndef __vtkVector_h
00031 #define __vtkVector_h
00032 
00033 template<typename T, int Size>
00034 class vtkVector
00035 {
00036 public:
00037   vtkVector()
00038   {
00039     for (int i = 0; i < Size; ++i)
00040       {
00041       Data[i] = 0;
00042       }
00043   }
00044 
00045   vtkVector(const T* init)
00046   {
00047     for (int i = 0; i < Size; ++i)
00048       {
00049       Data[i] = init[i];
00050       }
00051   }
00052 
00054   int GetSize() const { return Size; }
00055 
00057 
00058   T* GetData() { return this->Data; }
00059   const T* GetData() const { return this->Data; }
00061 
00063 
00065   T& operator[](int i) { return this->Data[i]; }
00066   const T& operator[](int i) const { return this->Data[i]; }
00068 
00071   T operator()(int i) const { return this->Data[i]; }
00072 
00073 protected:
00075   T Data[Size];
00076 };
00077 
00078 // .NAME vtkVector2 - templated base type for storage of 2D vectors.
00079 //
00080 template<typename T>
00081 class vtkVector2 : public vtkVector<T, 2>
00082 {
00083 public:
00084   vtkVector2(const T& x = 0.0, const T& y = 0.0)
00085   {
00086     this->Data[0] = x;
00087     this->Data[1] = y;
00088   }
00089 
00090   vtkVector2(const T* init) : vtkVector<T, 2>(init)
00091   {
00092   }
00093 
00095 
00096   void Set(const T& x, const T& y)
00097   {
00098     this->Data[0] = x;
00099     this->Data[1] = y;
00100   }
00102 
00104   void SetX(const T& x) { this->Data[0] = x; }
00105 
00107 
00108   const T& GetX() const { return this->Data[0]; }
00109   const T& X() const { return this->Data[0]; }
00111 
00113   void SetY(const T& y) { this->Data[1] = y; }
00114 
00116 
00117   const T& GetY() const { return this->Data[1]; }
00118   const T& Y() const { return this->Data[1]; }
00120 };
00121 
00122 // .NAME vtkVector3 - templated base type for storage of 3D vectors.
00123 //
00124 template<typename T>
00125 class vtkVector3 : public vtkVector<T, 3>
00126 {
00127 public:
00128   vtkVector3(const T& x = 0.0, const T& y = 0.0, const T& z = 0.0)
00129   {
00130     this->Data[0] = x;
00131     this->Data[1] = y;
00132     this->Data[2] = z;
00133   }
00134 
00136 
00137   void Set(const T& x, const T& y, const T& z)
00138   {
00139     this->Data[0] = x;
00140     this->Data[1] = y;
00141     this->Data[2] = z;
00142   }
00144 
00146   void SetX(const T& x) { this->Data[0] = x; }
00147 
00149 
00150   const T& GetX() const { return this->Data[0]; }
00151   const T& X() const { return this->Data[0]; }
00153 
00155   void SetY(const T& y) { this->Data[1] = y; }
00156 
00158 
00159   const T& GetY() const { return this->Data[1]; }
00160   const T& Y() const { return this->Data[1]; }
00162 
00164   void SetZ(const T& z) { this->Data[2] = z; }
00165 
00167 
00168   const T& GetZ() const { return this->Data[2]; }
00169   const T& Z() const { return this->Data[2]; }
00171 
00172 };
00173 
00174 // .NAME vtkRect - templated base type for storage of 2D rectangles.
00175 //
00176 template<typename T>
00177 class vtkRect : public vtkVector<T, 4>
00178 {
00179 public:
00180   vtkRect(const T& x = 0.0, const T& y = 0.0, const T width = 0.0,
00181           const T& height = 0.0 )
00182   {
00183     this->Data[0] = x;
00184     this->Data[1] = y;
00185     this->Data[2] = width;
00186     this->Data[3] = height;
00187   }
00188 
00190 
00191   void Set(const T& x, const T& y, const T& width, const T& height)
00192   {
00193     this->Data[0] = x;
00194     this->Data[1] = y;
00195     this->Data[2] = width;
00196     this->Data[3] = height;
00197   }
00199 
00201   void SetX(const T& x) { this->Data[0] = x; }
00202 
00204 
00205   const T& GetX() const { return this->Data[0]; }
00206   const T& X() const { return this->Data[0]; }
00208 
00210   void SetY(const T& y) { this->Data[1] = y; }
00211 
00213 
00214   const T& GetY() const { return this->Data[1]; }
00215   const T& Y() const { return this->Data[1]; }
00217 
00219   void SetWidth(const T& width) { this->Data[2] = width; }
00220 
00222 
00223   const T& GetWidth() const { return this->Data[2]; }
00224   const T& Width() const { return this->Data[2]; }
00226 
00228   void SetHeight(const T& height) { this->Data[3] = height; }
00229 
00231 
00232   const T& GetHeight() const { return this->Data[3]; }
00233   const T& Height() const { return this->Data[3]; }
00235 
00236 };
00237 
00239 class vtkVector2i : public vtkVector2<int>
00240 {
00241 public:
00242   vtkVector2i(int x = 0, int y = 0) : vtkVector2<int>(x, y) {}
00243 };
00244 
00245 class vtkVector2f : public vtkVector2<float>
00246 {
00247 public:
00248   vtkVector2f(float x = 0.0, float y = 0.0) : vtkVector2<float>(x, y) {}
00249   vtkVector2f(const float* i) : vtkVector2<float>(i) {}
00250 };
00251 
00252 class vtkVector2d : public vtkVector2<double>
00253 {
00254 public:
00255   vtkVector2d(double x = 0.0, double y = 0.0) : vtkVector2<double>(x, y) {}
00256 };
00257 
00258 class vtkVector3i : public vtkVector3<int>
00259 {
00260 public:
00261   vtkVector3i(int x = 0, int y = 0, int z = 0) : vtkVector3<int>(x, y, z) {}
00262 };
00263 
00264 class vtkVector3f : public vtkVector3<float>
00265 {
00266 public:
00267   vtkVector3f(float x = 0.0, float y = 0.0, float z = 0.0)
00268     : vtkVector3<float>(x, y, z) {}
00269 };
00270 
00271 class vtkVector3d : public vtkVector3<double>
00272 {
00273 public:
00274   vtkVector3d(double x = 0.0, double y = 0.0, double z = 0.0)
00275     : vtkVector3<double>(x, y, z) {}
00276 };
00277 
00278 class vtkRecti : public vtkRect<int>
00279 {
00280 public:
00281   vtkRecti(int x = 0, int y = 0, int width = 0, int height = 0)
00282     : vtkRect<int>(x, y, width, height) {}
00283 };
00284 
00285 class vtkRectf : public vtkRect<float>
00286 {
00287 public:
00288   vtkRectf(float x = 0.0, float y = 0.0, float width = 0.0, float height = 0.0)
00289     : vtkRect<float>(x, y, width, height) {}
00290 };
00291 
00292 class vtkRectd : public vtkRect<double>
00293 {
00294 public:
00295   vtkRectd(double x = 0.0, double y = 0.0, double width = 0.0,
00296            double height = 0.0)
00297     : vtkRect<double>(x, y, width, height) {}
00298 };
00299 
00300 #endif // __vtkVector_h