1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194
|
/*=========================================================================
Program: Insight Segmentation & Registration Toolkit
Module: $RCSfile: itkLevelSetFunctionWithRefitTerm.txx,v $
Language: C++
Date: $Date: 2008-03-03 13:58:44 $
Version: $Revision: 1.7 $
Copyright (c) Insight Software Consortium. All rights reserved.
See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
#ifndef __itkLevelSetFunctionWithRefitTerm_txx_
#define __itkLevelSetFunctionWithRefitTerm_txx_
#include "itkLevelSetFunctionWithRefitTerm.h"
#include "itkSparseImage.h"
#include "itkNumericTraits.h"
#include "itkVector.h"
namespace itk {
template <class TImageType, class TSparseImageType>
const unsigned long
LevelSetFunctionWithRefitTerm <TImageType, TSparseImageType>
::m_NumVertex = 1 << TImageType::ImageDimension;
template <class TImageType, class TSparseImageType>
const typename LevelSetFunctionWithRefitTerm <TImageType,
TSparseImageType>::ScalarValueType
LevelSetFunctionWithRefitTerm <TImageType, TSparseImageType>
::m_DimConst = static_cast <ScalarValueType> (2.0/m_NumVertex);
template <class TImageType, class TSparseImageType>
LevelSetFunctionWithRefitTerm<TImageType, TSparseImageType>
::LevelSetFunctionWithRefitTerm()
{
m_SparseTargetImage = SparseImageType::New();
this->SetPropagationWeight (NumericTraits<ScalarValueType>::One);
m_RefitWeight = NumericTraits<ScalarValueType>::One;
m_OtherPropagationWeight = NumericTraits<ScalarValueType>::Zero;
m_MinVectorNorm = static_cast<ScalarValueType> (1.0e-6);
}
template <class TImageType, class TSparseImageType>
void
LevelSetFunctionWithRefitTerm<TImageType, TSparseImageType>
::PrintSelf(std::ostream& os, Indent indent) const
{
Superclass::PrintSelf(os, indent);
os << indent << "RefitWeight: " << m_RefitWeight << std::endl;
os << indent << "OtherPropagationWeight: "
<< m_OtherPropagationWeight << std::endl;
os << indent << "MinVectorNorm: "<< m_MinVectorNorm << std::endl;
os << indent << "DimConst: "<< m_DimConst << std::endl;
os << indent << "NumVertex: "<< m_NumVertex << std::endl;
}
template <class TImageType, class TSparseImageType>
typename LevelSetFunctionWithRefitTerm<TImageType,
TSparseImageType>::TimeStepType
LevelSetFunctionWithRefitTerm<TImageType, TSparseImageType>
::ComputeGlobalTimeStep(void *GlobalData) const
{
TimeStepType dt = Superclass::ComputeGlobalTimeStep (GlobalData);
dt = vnl_math_min ( dt, this->m_WaveDT );
return dt;
}
template <class TImageType, class TSparseImageType>
typename LevelSetFunctionWithRefitTerm <TImageType,
TSparseImageType>::ScalarValueType
LevelSetFunctionWithRefitTerm<TImageType, TSparseImageType>
::ComputeCurvature( const NeighborhoodType &neighborhood ) const
{
unsigned int j, k;
unsigned int counterN, counterP;
unsigned long positionN, positionP,
stride[TImageType::ImageDimension], indicator[TImageType::ImageDimension];
const unsigned long center = neighborhood.Size()/2;
const NeighborhoodScalesType neighborhoodScales = this->ComputeNeighborhoodScales();
NormalVectorType normalvector;
ScalarValueType curvature;
for( j = 0; j < TImageType::ImageDimension; j++ )
{
stride[j] = neighborhood.GetStride(j);
indicator[j] = 1 << j;
}
curvature = NumericTraits<ScalarValueType>::Zero;
for (counterN = 0; counterN < m_NumVertex; counterN++)
{
// compute position of normal vector
positionN = center;
for (k = 0; k < TImageType::ImageDimension; k++)
{
if (counterN & indicator[k])
{
positionN -= stride[k];
}
}
// compute the normal vector
for (j = 0; j < TImageType::ImageDimension; j++) // derivative axis
{
normalvector[j] = NumericTraits<ScalarValueType>::Zero;
for (counterP = 0; counterP < m_NumVertex; counterP++)
{
positionP = positionN;
for (k = 0; k < TImageType::ImageDimension; k++)
{
if (counterP & indicator[k])
{
positionP += stride[k];
}
}
if ( counterP & indicator[j] )
{
normalvector[j] += neighborhood.GetPixel (positionP) * neighborhoodScales[j];
}
else
{
normalvector[j] -= neighborhood.GetPixel (positionP) * neighborhoodScales[j];
}
} // end counterP
} // end derivative axis
normalvector = normalvector / (m_MinVectorNorm + normalvector.GetNorm());
// add normal to curvature computation
for (j = 0; j < TImageType::ImageDimension; j++) // derivative axis
{
if ( counterN & indicator[j] )
{
curvature -= normalvector[j] * neighborhoodScales[j];
}
else
{
curvature += normalvector[j] * neighborhoodScales[j];
}
} // end derivative axis
} // end counterN
curvature *= m_DimConst;
return curvature;
}
template <class TImageType, class TSparseImageType>
typename LevelSetFunctionWithRefitTerm <TImageType,
TSparseImageType>::ScalarValueType
LevelSetFunctionWithRefitTerm<TImageType, TSparseImageType>
::PropagationSpeed(const NeighborhoodType &neighborhood,
const FloatOffsetType &offset,
GlobalDataStruct *globaldata) const
{
IndexType idx = neighborhood.GetIndex();
NodeType *targetnode = m_SparseTargetImage->GetPixel (idx);
ScalarValueType refitterm, cv, tcv;
if ((targetnode == 0)||(targetnode->m_CurvatureFlag == false))
{
if (targetnode == 0)
{
itkExceptionMacro( << "required node has null pointer\n");
}
else
{
itkExceptionMacro( << "required node has CurvatureFlag = false\n");
}
refitterm = NumericTraits<ScalarValueType>::Zero;
}
else
{
cv = this->ComputeCurvature (neighborhood);
tcv = targetnode->m_Curvature;
refitterm = static_cast<ScalarValueType> (tcv - cv);
}
return m_RefitWeight*refitterm +
m_OtherPropagationWeight*
OtherPropagationSpeed (neighborhood, offset, globaldata);
}
} //end namespace itk
#endif
|