KWStyle - itkCovariantVector.h
 
Matrix View
Description

1 /*=========================================================================
2
3   Program:   Insight Segmentation & Registration Toolkit
4   Module:    $RCSfile: itkCovariantVector.h.html,v $
5   Language:  C++
6   Date:      $Date: 2006/01/17 19:15:34 $
7   Version:   $Revision: 1.4 $
8
9   Copyright (c) Insight Software Consortium. All rights reserved.
10   See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
11
12      This software is distributed WITHOUT ANY WARRANTY; without even 
13      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
14      PURPOSE.  See the above copyright notices for more information.
15
16 =========================================================================*/
17 #ifndef __itkCovariantVector_h
18 #define __itkCovariantVector_h
19
20
21 #include "itkFixedArray.h"
22 #include "vnl/vnl_vector_ref.h"
23 #include "itkIndent.h"
24 #include "itkVector.h"
25
26
27 namespace itk
28 {
29
30 /** \class CovariantVector
31  * \brief A templated class holding a n-Dimensional covariant vector.
32  * 
33 LEN  * CovariantVector is a templated class that holds a single vector (i.e., an array
34 LEN  * of values).  CovariantVector can be used as the data type held at each pixel in
35  * an Image or at each vertex of an Mesh. The template parameter T can
36  * be any data type that behaves like a primitive (or atomic) data type (int,
37  * short, float, complex).  The NVectorDimension defines the number of
38  * components in the vector array. 
39  *
40  * CovariantVector is not a dynamically extendible array like std::vector. It is
41  * intended to be used like a mathematical vector.
42  *
43  * If you wish a simpler pixel types, you can use Scalar, which represents
44  * a single data value at a pixel. There is also the more complex type
45 LEN  * ScalarCovariantVector, which supports (for a given pixel) a single scalar value
46  * plus an array of vector values. (The scalar and vectors can be of
47  * different data type.)
48  * 
49  * CovariantVector is the type that should be used for representing normals
50  * to surfaces and gradients of functions. AffineTransform transform
51  * covariant vectors different than vectors.
52  *
53  * \ingroup Geometry
54  * \ingroup DataRepresentation
55  * 
56  * \sa Image
57  * \sa Mesh
58  * \sa Point
59  * \sa Vector
60  * \sa Matrix
61  */
62
63 template<class T, unsigned int NVectorDimension=3>
64 class ITK_EXPORT CovariantVector : public FixedArray<T,NVectorDimension>
65 {
66 IND *public:
67   /** Standard class typedefs. */
68   typedef CovariantVector  Self;
69 TDA   typedef FixedArray<T,NVectorDimension>  Superclass;
70
71   /** ValueType can be used to declare a variable that is the same type
72    * as a data element held in an CovariantVector.   */
73   typedef T ValueType;
74 TDA   typedef typename NumericTraits< ValueType >::RealType   RealValueType;
75
76   /** Dimension of the Space */
77   itkStaticConstMacro(Dimension, unsigned int, NVectorDimension);
78
79   /** I am a covariant vector. */
80   typedef Self CovariantVectorType;
81   
82   /** The Array type from which this CovariantVector is derived. */
83   typedef FixedArray<T, NVectorDimension>                BaseArray;
84     
85   /** Get the dimension (size) of the vector. */
86   static unsigned int GetCovariantVectorDimension() 
87     { return NVectorDimension; }  
88
89   /** Set a vnl_vector_ref referencing the same memory block. */
90   void SetVnlVector( const vnl_vector<T> & );
91
92   /** Get a vnl_vector_ref referencing the same memory block. */
93   vnl_vector_ref<T> GetVnlVector( void );
94
95   /** Get a vnl_vector with a copy of the internal memory block. */
96   vnl_vector<T> GetVnlVector( void ) const;
97
98
99   /** Set a vnl_vector_ref referencing the same memory block.
100    * \deprecated Use SetVnlVector() instead. */
101   void Set_vnl_vector( const vnl_vector<T> & );
102
103   /** Get a vnl_vector_ref referencing the same memory block. 
104    * \deprecated Use GetVnlVector() instead. */
105   vnl_vector_ref<T> Get_vnl_vector( void );
106
107   /** Get a vnl_vector with a copy of the internal memory block. 
108    * \deprecated Use GetVnlVector() instead. */
109   vnl_vector<T> Get_vnl_vector( void ) const;
110
111
112   /** Default constructor has nothing to do. */
113   CovariantVector(): BaseArray() {}
114   CovariantVector(const ValueType& r);
115
116   /** Pass-through constructor for the Array base class. */
117   CovariantVector(const Self& r): BaseArray(r) {}
118   CovariantVector(const ValueType r[Dimension]): BaseArray(r) {}  
119     
120   /** Pass-through assignment operator for the Array base class. */
121   CovariantVector& operator= (const Self& r);
122   CovariantVector& operator= (const ValueType r[NVectorDimension]);
123     
124   /** Scalar operator*=.  Scales elements by a scalar. */
125   const Self& operator*=(const ValueType &value);
126
127   /** Scalar operator/=.  Scales (divides) elements by a scalar. */
128   const Self& operator/=(const ValueType &value);
129
130   /** CovariantVector operator+=.  Adds a vectors to the current vector. */
131   const Self& operator+=(const Self &vec);
132
133   /** CovariantVector operator-=.  Subtracts a vector from a current vector. */
134   const Self& operator-=(const Self &vec);
135
136 LEN   /** CovariantVector negation.  Negate all the elements of a vector. Return a new vector */
137   Self operator-() const;
138   
139   /** CovariantVector addition. Add two vectors. Return a new vector. */
140   Self operator+(const Self &vec) const;
141   
142   /** CovariantVector subtraction. Subtract two vectors. Return a new vector. */
143   Self operator-(const Self &vec) const;
144   
145   /** Scalar operator*. Scale the elements of a vector by a scalar.
146    * Return a new vector. */
147   Self operator*(const ValueType& val) const;
148
149 LEN   /** CovariantVector operator*.  Performs the inner product of two covariant vectors.
150    * \warning This is equivalent to the scalar product only if the reference
151    * system has orthogonal axis and equal scales.  */
152   ValueType operator*(const Self &vec) const;
153
154   /** operator*.  Performs the scalar product with a vector (contravariant).
155    * This scalar product is invariant under affine transformations */
156   ValueType operator*(const Vector<T,NVectorDimension> &vec) const;
157
158   /** Scalar operator/. Scale (divide) the elements of a vector by a scalar.
159    * Return a new vector. */
160   Self operator/(const ValueType& val) const;
161
162   /** Returns the Euclidean Norm of the vector  */
163   RealValueType GetNorm( void ) const;
164
165   /** Returns the number of components in this vector type */
166   static unsigned int GetNumberOfComponents() { return NVectorDimension; }
167   
168   /** Divides the covariant vector componets by the norm */
169   void Normalize(void);
170
171   /** Returns vector's Squared Euclidean Norm  */
172   RealValueType GetSquaredNorm( void ) const;
173
174   /** Copy from another CovariantVector with a different representation type. 
175    *  Casting is done with C-Like rules  */
176   template < typename TCoordRepB >
177   void CastFrom( const CovariantVector<TCoordRepB,NVectorDimension> & pa )
178 IND **{
179     for(unsigned int i=0; i<NVectorDimension; i++ )
180       {
181       (*this)[i] = static_cast<T>( pa[i] );
182       }
183 IND **}
184
185
186 };
187
188 ITKCommon_EXPORT void CrossProduct(  CovariantVector<double,3> &,
189                                      const Vector<double,3> &,
190                                      const Vector<double,3> &  );
191
192 ITKCommon_EXPORT void CrossProduct(  CovariantVector<float,3> &,
193                                      const Vector<float,3> &,
194                                      const Vector<float,3> &  );
195
196 ITKCommon_EXPORT void CrossProduct(  CovariantVector<int,3>,
197                                      const Vector<int,3> &,
198                                      const Vector<int,3> &  );
199
200
201 // end namespace itk
202   
203
204 #ifndef ITK_MANUAL_INSTANTIATION
205 #include "itkCovariantVector.txx"
206 #endif
207
208
209 #endif 
210

Generated by KWStyle 1.0b on Tuesday January,17 at 02:14:04PM
© Kitware Inc.