ITK  4.9.0
Insight Segmentation and Registration Toolkit
itkCrossHelper.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0.txt
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  *=========================================================================*/
18 #ifndef itkCrossHelper_h
19 #define itkCrossHelper_h
20 
21 #include "itkNumericTraits.h"
22 
23 namespace itk
24 {
35 template< typename TVector >
37 {
38 public:
39  typedef TVector VectorType;
40  typedef typename VectorType::ValueType ValueType;
41 
42  itkStaticConstMacro (Dimension, unsigned int, VectorType::Dimension);
43 
50  const VectorType & iV) const
51  {
52  VectorType oCross;
53 
54  if ( Dimension > 2 )
55  {
56  oCross[0] = iU[1] * iV[2] - iV[1] * iU[2];
57  oCross[1] = iV[0] * iU[2] - iU[0] * iV[2];
58  oCross[2] = iU[0] * iV[1] - iV[0] * iU[1];
59 
60  if (Dimension > 3)
61  {
62  for ( unsigned int dim = 3; dim < Dimension; dim++ )
63  {
64  oCross[dim] = 0.0;
65  }
66  }
67  }
68  else
69  {
70  oCross.Fill(0.);
71  }
72 
73  return oCross;
74  }
75 };
76 }
77 
78 #endif
static const unsigned int Dimension
VectorType::ValueType ValueType
VectorType operator()(const VectorType &iU, const VectorType &iV) const