KWStyle - itkSphereSignedDistanceFunction.txx
 
Matrix View
Description

1 /*=========================================================================
2
3   Program:   Insight Segmentation & Registration Toolkit
4   Module:    $RCSfile: itkSphereSignedDistanceFunction.txx.html,v $
5   Language:  C++
6   Date:      $Date: 2006/01/17 19:15:48 $
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 DEF #ifndef _itkSphereSignedDistanceFunction_txx
18 DEF #define _itkSphereSignedDistanceFunction_txx
19
20 #include "itkSphereSignedDistanceFunction.h"
21
22
23 namespace itk
24 {
25
26 // Constructor with default arguments
27 template<typename TCoordRep, unsigned int VSpaceDimension>
28 SphereSignedDistanceFunction<TCoordRep, VSpaceDimension>
29 ::SphereSignedDistanceFunction()
30 {
31   this->GetParameters().SetSize( SpaceDimension + 1 );
32   this->GetParameters().Fill( 0.0 );
33   this->GetParameters()[0] = 1.0;
34   m_Translation.Fill( 0.0 );
35   m_Radius = 1.0;
36 }
37     
38
39 // Set the parameters
40 template<typename TCoordRep, unsigned int VSpaceDimension>
41 void
42 SphereSignedDistanceFunction<TCoordRep, VSpaceDimension>
43 ::SetParameters( const ParametersType & parameters )
44 {
45   if ( parameters != this->GetParameters() )
46     {
47     this->m_Parameters = parameters;
48
49     m_Radius = parameters[0];
50
51     for( unsigned int i=0; i<SpaceDimension; i++ )
52       {
53       m_Translation[i] = parameters[i+1];
54       }
55
56     this->Modified();
57     }
58 }
59
60 // Print self
61 template<typename TCoordRep, unsigned int VSpaceDimension>
62 void
63 SphereSignedDistanceFunction<TCoordRep, VSpaceDimension>
64 ::PrintSelf(std::ostream &os, Indent indent) const
65 {
66   Superclass::PrintSelf(os,indent);
67   
68   os << indent << "Translation: " << m_Translation << std::endl;
69   os << indent << "Radius: " << m_Radius << std::endl;
70 }
71
72 // Evaluate the signed distance
73 template<typename TCoordRep, unsigned int VSpaceDimension>
74 typename SphereSignedDistanceFunction<TCoordRep, VSpaceDimension>
75 ::OutputType
76 SphereSignedDistanceFunction<TCoordRep, VSpaceDimension>
77 ::Evaluate( const PointType& point ) const
78 {
79   typedef typename NumericTraits<OutputType>::RealType RealType;
80   RealType output = 0.0;
81
82   for( unsigned int j = 0; j < SpaceDimension; j++ )
83     {
84     output += vnl_math_sqr( ( point[j] - m_Translation[j] ) );
85     }
86   
87   output = vcl_sqrt(output) - m_Radius;
88
89   return output;
90
91 }
92   
93 // namespace
94
95 #endif
96

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