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 #ifndef __cmtkVoxelMatchingAffineFunctional_h_included_
00033 #define __cmtkVoxelMatchingAffineFunctional_h_included_
00034
00035 #include <cmtkconfig.h>
00036
00037 #include <Registration/cmtkVoxelMatchingFunctional.h>
00038
00039 #include <Base/cmtkVector.h>
00040 #include <Base/cmtkAffineXform.h>
00041 #include <Base/cmtkVolume.h>
00042 #include <Base/cmtkUniformVolume.h>
00043 #include <Base/cmtkVolumeClipping.h>
00044 #include <Base/cmtkMathUtil.h>
00045 #include <Base/cmtkTypes.h>
00046
00047 #include <System/cmtkException.h>
00048 #include <System/cmtkThreadPool.h>
00049
00050 #include <cassert>
00051
00052 namespace
00053 cmtk
00054 {
00055
00058
00061 class VoxelMatchingAffineFunctional :
00063 public VoxelMatchingFunctional
00064 {
00065 public:
00067 typedef VoxelMatchingAffineFunctional Self;
00068
00070 typedef VoxelMatchingFunctional Superclass;
00071
00073 typedef SmartPointer<Self> SmartPtr;
00074
00076 virtual void GetParamVector ( CoordinateVector& v )
00077 {
00078 this->m_AffineXform->GetParamVector( v );
00079 }
00080
00082 virtual Types::Coordinate GetParamStep( const size_t idx, const Types::Coordinate mmStep = 1 ) const
00083 {
00084 return this->m_AffineXform->GetParamStep( idx, Vector3D( FloatingSize ), mmStep );
00085 }
00086
00088 virtual size_t ParamVectorDim() const
00089 {
00090 return this->m_AffineXform->ParamVectorDim();
00091 }
00092
00094 virtual size_t VariableParamVectorDim() const
00095 {
00096 return this->m_AffineXform->VariableParamVectorDim();
00097 }
00098
00099 protected:
00101 AffineXform::SmartPtr m_AffineXform;
00102
00104 VolumeClipping Clipper;
00105
00122 int ClipZ ( const VolumeClipping& clipper, const Vector3D& origin, DataGrid::IndexType::ValueType& start, DataGrid::IndexType::ValueType &end ) const
00123 {
00124
00125 Types::Coordinate fromFactor, toFactor;
00126 if (! clipper.ClipZ( fromFactor, toFactor, origin ) )
00127 return 0;
00128
00129
00130 start = static_cast<DataGrid::IndexType::ValueType>( (ReferenceDims[2]-1)*fromFactor );
00131 end = 1+std::min( (int)(ReferenceDims[2]-1), (int)(1 + ((ReferenceDims[2]-1)*toFactor) ) );
00132
00133
00134 start = std::max<DataGrid::IndexType::ValueType>( start, this->m_ReferenceCropRegion.From()[2] );
00135 end = std::min<DataGrid::IndexType::ValueType>( end, this->m_ReferenceCropRegion.To()[2] );
00136
00137
00138 return (start < end );
00139 }
00140
00167 int ClipX ( const VolumeClipping& clipper, const Vector3D& origin, DataGrid::IndexType::ValueType& start, DataGrid::IndexType::ValueType &end ) const
00168 {
00169
00170 Types::Coordinate fromFactor, toFactor;
00171 if ( ! clipper.ClipX( fromFactor, toFactor, origin, 0, 2, false, true ) )
00172 return 0;
00173
00174 fromFactor = std::min<Types::Coordinate>( 1.0, fromFactor );
00175
00176
00177 start = std::max( 0, (int)((ReferenceDims[0]-1)*fromFactor)-1 );
00178 while ( ( start*ReferenceGrid->m_Delta[0] < fromFactor*ReferenceSize[0]) && ( start < ReferenceDims[0] ) )
00179 ++start;
00180
00181 if ( (toFactor > 1.0) || (start == ReferenceDims[0]) )
00182 {
00183 end = ReferenceDims[0];
00184 }
00185 else
00186 {
00187 end = std::min( ReferenceDims[0]-2, (int)(1 + (ReferenceDims[0]-1)*toFactor));
00188 while ( end*ReferenceGrid->m_Delta[0] > toFactor*ReferenceSize[0] )
00189 --end;
00190 ++end;
00191 }
00192
00193
00194 start = std::max<DataGrid::IndexType::ValueType>( start, this->m_ReferenceCropRegion.From()[0] );
00195 end = std::min<DataGrid::IndexType::ValueType>( end, this->m_ReferenceCropRegion.To()[0] );
00196
00197
00198 return (start < end );
00199 }
00200
00217 int ClipY ( const VolumeClipping& clipper, const Vector3D& origin, DataGrid::IndexType::ValueType& start, DataGrid::IndexType::ValueType &end ) const
00218 {
00219
00220 Types::Coordinate fromFactor, toFactor;
00221 if ( !clipper.ClipY( fromFactor, toFactor, origin ) )
00222 return 0;
00223
00224
00225 start = static_cast<DataGrid::IndexType::ValueType>( (ReferenceDims[1]-1)*fromFactor );
00226
00227 if ( toFactor > 1.0 )
00228 {
00229 end = ReferenceDims[1];
00230 }
00231 else
00232 {
00233 end = 1+std::min( ReferenceDims[1]-1, (int)(1+(ReferenceDims[1]-1)*toFactor ) );
00234 }
00235
00236 start = std::max<DataGrid::IndexType::ValueType>( start, this->m_ReferenceCropRegion.From()[1] );
00237 end = std::min<DataGrid::IndexType::ValueType>( end, this->m_ReferenceCropRegion.To()[1] );
00238
00239
00240 return (start < end );
00241 }
00242
00243 public:
00245 VoxelMatchingAffineFunctional( UniformVolume::SmartPtr refVolume, UniformVolume::SmartPtr modVolume, AffineXform::SmartPtr& affineXform )
00246 : VoxelMatchingFunctional( refVolume, modVolume ),
00247 m_AffineXform( affineXform )
00248 {}
00249
00251 virtual ~VoxelMatchingAffineFunctional() {}
00252
00259 static VoxelMatchingAffineFunctional* Create( const int metric, UniformVolume::SmartPtr& refVolume, UniformVolume::SmartPtr& modVolume, AffineXform::SmartPtr& affineXform );
00260
00261 };
00262
00264
00265 }
00266
00267 #endif // #ifndef __cmtkVoxelMatchingAffineFunctional_h_included_