Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 namespace
00034 cmtk
00035 {
00036
00039
00040 template<class TMetricFunctional>
00041 void
00042 SplineWarpMultiChannelRegistrationFunctional<TMetricFunctional>
00043 ::EvaluateThreadFunction( void* args, const size_t taskIdx, const size_t taskCnt, const size_t, const size_t )
00044 {
00045 ThreadParameters<Self>* params = static_cast<ThreadParameters<Self>*>( args );
00046
00047 Self* This = params->thisObject;
00048 const Self* constThis = This;
00049
00050 typename Self::MetricData metricData;
00051 metricData.Init( This );
00052
00053 const DataGrid::IndexType& dims = constThis->m_ReferenceDims;
00054 const int dimsX = dims[0], dimsY = dims[1], dimsZ = dims[2];
00055 std::vector<Vector3D> pFloating( dimsX );
00056
00057 for ( int pZ = taskIdx; pZ < dimsZ; pZ += taskCnt )
00058 {
00059 for ( int pY = 0; pY < dimsY; ++pY )
00060 {
00061 constThis->m_Transformation.GetTransformedGridRow( dimsX, &pFloating[0], 0, pY, pZ );
00062
00063 size_t r = dimsX * (pY + dimsY * pZ );
00064 for ( int pX = 0; pX < dimsX; ++pX, ++r )
00065 {
00066
00067 This->ContinueMetricStoreReformatted( metricData, r, pFloating[pX] );
00068 }
00069 }
00070 }
00071
00072 This->m_MetricDataMutex.Lock();
00073 This->m_MetricData += metricData;
00074 This->m_MetricDataMutex.Unlock();
00075 }
00076
00077 template<class TMetricFunctional>
00078 void
00079 SplineWarpMultiChannelRegistrationFunctional<TMetricFunctional>
00080 ::EvaluateWithGradientThreadFunction( void* args, const size_t taskIdx, const size_t taskCnt, const size_t threadIdx, const size_t )
00081 {
00082 EvaluateGradientThreadParameters* params = static_cast<EvaluateGradientThreadParameters*>( args );
00083
00084 Self* This = params->thisObject;
00085 const Self* constThis = This;
00086
00087 const size_t numberOfParameters = This->VariableParamVectorDim();
00088 const size_t numberOfControlPoints = numberOfParameters / 3;
00089
00090 SplineWarpXform::SmartPtr transformation = constThis->m_ThreadTransformations[threadIdx];
00091 transformation->SetParamVector( *(params->m_ParameterVector) );
00092
00093 for ( size_t cp = taskIdx; cp < numberOfControlPoints; cp += taskCnt )
00094 {
00095 typename Superclass::MetricData localMetricDataCP = constThis->m_MetricData;
00096 This->BacktraceMetric( localMetricDataCP, constThis->m_VolumeOfInfluenceVector[cp] );
00097
00098 size_t idx = 3 * cp;
00099 for ( int dim = 0; dim < 3; ++dim, ++idx )
00100 {
00101 if ( constThis->m_StepScaleVector[idx] <= 0 )
00102 {
00103 params->m_Gradient[idx] = 0;
00104 }
00105 else
00106 {
00107 const Types::Coordinate vOld = transformation->GetParameter( idx );
00108
00109 Types::Coordinate thisStep = params->m_Step * constThis->m_StepScaleVector[idx];
00110
00111 typename Superclass::MetricData localMetricData = localMetricDataCP;
00112 transformation->SetParameter( idx, vOld + thisStep );
00113 double upper = This->EvaluateIncremental( transformation, localMetricData, constThis->m_VolumeOfInfluenceVector[cp] );
00114
00115 localMetricData = localMetricDataCP;
00116 transformation->SetParameter( idx, vOld - thisStep );
00117 double lower = This->EvaluateIncremental( transformation, localMetricData, constThis->m_VolumeOfInfluenceVector[cp] );
00118
00119 transformation->SetParameter( idx, vOld );
00120
00121 if ( constThis->m_JacobianConstraintWeight > 0 )
00122 {
00123 double lowerConstraint = 0, upperConstraint = 0;
00124 transformation->GetJacobianConstraintDerivative( lowerConstraint, upperConstraint, idx, constThis->m_VolumeOfInfluenceVector[cp], thisStep );
00125 lower -= constThis->m_JacobianConstraintWeight * lowerConstraint;
00126 upper -= constThis->m_JacobianConstraintWeight * upperConstraint;
00127 }
00128
00129 if ( finite( upper ) && finite(lower) && ((upper > params->m_MetricBaseValue ) || (lower > params->m_MetricBaseValue)) )
00130 {
00131 params->m_Gradient[idx] = upper-lower;
00132 }
00133 else
00134 {
00135 params->m_Gradient[idx] = 0;
00136 }
00137 }
00138 }
00139 }
00140 }
00141
00142 }