KWStyle - itkEllipsoidInteriorExteriorSpatialFunction.txx
 
Matrix View
Description

1 /*=========================================================================
2
3   Program:   Insight Segmentation & Registration Toolkit
4   Module:    $RCSfile: itkEllipsoidInteriorExteriorSpatialFunction.txx.html,v $
5   Language:  C++
6   Date:      $Date: 2006/01/17 19:15:35 $
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 __itkEllipsoidInteriorExteriorSpatialFunction_txx
18 #define __itkEllipsoidInteriorExteriorSpatialFunction_txx
19
20 #include "itkEllipsoidInteriorExteriorSpatialFunction.h"
21 #include <math.h>
22
23 namespace itk 
24 {
25
26 template <unsigned int VDimension, typename TInput>
27 EllipsoidInteriorExteriorSpatialFunction<VDimension, TInput>
28 ::EllipsoidInteriorExteriorSpatialFunction()
29 {
30   m_Orientations = NULL;
31   m_Axes.Fill(1.0);   // Lengths of ellipsoid axes.
32   m_Center.Fill(0.0); // Origin of ellipsoid
33 }
34
35 template <unsigned int VDimension, typename TInput >
36 EllipsoidInteriorExteriorSpatialFunction<VDimension, TInput>
37 ::~EllipsoidInteriorExteriorSpatialFunction()
38 {
39   unsigned int i;
40   if (m_Orientations)
41     {
42     for(i = 0; i < VDimension; i++)
43       {
44       delete []m_Orientations[i];
45       }
46     delete []m_Orientations;
47     }
48 }
49
50 template <unsigned int VDimension, typename TInput>
51 LEN typename EllipsoidInteriorExteriorSpatialFunction<VDimension, TInput>::OutputType
52 EllipsoidInteriorExteriorSpatialFunction<VDimension, TInput>
53 ::Evaluate(const InputType& position) const
54 {  
55   double distanceSquared = 0; 
56   Vector<double, VDimension> orientationVector;
57   Vector<double, VDimension> pointVector;
58
59   // Project the position onto each of the axes, normalize by axis length, 
60   // and determine whether position is inside ellipsoid. The length of axis0,
61   // m_Axis[0] is orientated in the direction of m_Orientations[0].
62   for(unsigned int i = 0; i < VDimension; i++)
63     {
64     pointVector[i] = position[i] - m_Center[i];
65     }
66
67   for(unsigned int i = 0; i < VDimension; i++)
68     {  
69     for(unsigned int j = 0; j < VDimension; j++)
70       {      
71       orientationVector[j] = m_Orientations[i][j];
72       }
73 LEN     distanceSquared += pow(static_cast<double>((orientationVector * pointVector)/(.5*m_Axes[i])),static_cast<double>(2));
74     }        
75
76   if(distanceSquared <= 1)
77     {    
78     return 1; // Inside the ellipsoid.
79     }
80   //Default return value assumes outside the ellipsoid  
81   return 0; // Outside the ellipsoid.
82 }
83
84 template <unsigned int VDimension, typename TInput>
85 void EllipsoidInteriorExteriorSpatialFunction<VDimension, TInput>
86 ::SetOrientations(const OrientationType &orientations)
87 {
88   unsigned int i, j;
89   // Initialize orientation vectors.
90   if (m_Orientations)
91     {
92     for(i = 0; i < VDimension; i++)
93       {
94       delete []m_Orientations[i];
95       }
96     delete []m_Orientations;
97     }
98   m_Orientations = new double * [VDimension];
99   for(i = 0; i < VDimension; i++)
100     {
101     m_Orientations[i] = new double[VDimension];
102     }
103
104   // Set orientation vectors (must be orthogonal).
105   for(i = 0; i < VDimension; i++)
106     {
107     for(j = 0; j < VDimension; j++)
108       {
109       m_Orientations[i][j] = orientations[i][j];
110       }
111     }
112 }
113
114 template <unsigned int VDimension, typename TInput>
115 void EllipsoidInteriorExteriorSpatialFunction<VDimension, TInput>
116 ::PrintSelf(std::ostream& os, Indent indent) const
117 {
118   unsigned int i, j;
119
120   Superclass::PrintSelf(os, indent);
121
122   os << indent << "Lengths of Ellipsoid Axes: " << m_Axes << std::endl;
123   os << indent << "Origin of Ellipsoid: " << m_Center << std::endl;
124   if (m_Orientations)
125     {
126     os << indent << "Orientations: " << std::endl;
127     for (i = 0; i < VDimension; i++)
128       {
129       for (j = 0; j < VDimension; j++)
130         {
131         os << indent << indent <<  m_Orientations[i][j] << " ";
132         }
133       os << std::endl;
134       }
135     }
136 }
137
138 // end namespace itk
139
140 #endif
141

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