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 #ifndef __cmtkWarpXform_h_included_
00034 #define __cmtkWarpXform_h_included_
00035
00036 #include <cmtkconfig.h>
00037
00038 #include <Base/cmtkXform.h>
00039
00040 #include <Base/cmtkMacros.h>
00041 #include <Base/cmtkVector.h>
00042 #include <Base/cmtkFixedVector.h>
00043
00044 #include <Base/cmtkVolume.h>
00045 #include <Base/cmtkUniformVolume.h>
00046
00047 #include <Base/cmtkAffineXform.h>
00048 #include <Base/cmtkBitVector.h>
00049
00050 #include <Base/cmtkControlPoint.h>
00051 #include <Base/cmtkMatchedLandmarkList.h>
00052
00053 #include <System/cmtkSmartPtr.h>
00054
00055 namespace
00056 cmtk
00057 {
00058
00061
00064 class WarpXform :
00066 public Xform
00067 {
00068 public:
00070 typedef WarpXform Self;
00071
00073 typedef SmartPointer<Self> SmartPtr;
00074
00076 typedef SmartConstPointer<Self> SmartConstPtr;
00077
00079 typedef FixedVector<3,int> IndexType;
00080
00082 Self::IndexType m_Dims;
00083
00085 FixedVector<3,Types::Coordinate> Domain;
00086
00088 Types::Coordinate Spacing[3];
00089
00091 Self::SpaceVectorType m_Offset;
00092
00094 virtual Types::Coordinate GetGlobalScaling() const
00095 { return this->GlobalScaling; }
00096
00098 cmtkGetSetMacro(AffineXform::SmartPtr,InitialAffineXform);
00099
00106 void ReplaceInitialAffine( const AffineXform* newAffineXform = NULL );
00107
00109 void ConcatAffine( const AffineXform* affineXform );
00110
00112 size_t GetNumberOfControlPoints() const
00113 {
00114 return this->NumberOfControlPoints;
00115 }
00116
00117 protected:
00119 size_t NumberOfControlPoints;
00120
00125 Types::Coordinate InverseSpacing[3];
00126
00128 cmtkGetSetMacro(unsigned int,IgnoreEdge);
00129
00131 cmtkGetSetMacroDefault(bool,FastMode,true);
00132
00134 Types::Coordinate GlobalScaling;
00135
00137 Types::Coordinate InverseAffineScaling[3];
00138
00140 int nextI;
00141
00143 int nextJ;
00144
00146 int nextIJ;
00147
00149 int nextK;
00150
00152 int nextIK;
00153
00155 int nextJK;
00156
00158 int nextIJK;
00159
00160 public:
00162 WarpXform () :
00163 m_InitialAffineXform( NULL ),
00164 m_ActiveFlags( NULL )
00165 {
00166 this->m_IgnoreEdge = 0;
00167 this->m_FastMode = false;
00168 this->m_Dims[0] = this->m_Dims[1] = this->m_Dims[2] = 0;
00169 this->InverseSpacing[0] = this->InverseSpacing[1] = this->InverseSpacing[2] = 0.0;
00170 }
00171
00173 virtual ~WarpXform () {}
00174
00176 virtual void InitGrid( const FixedVector<3,Types::Coordinate>& domain, const Self::IndexType& dims );
00177
00179 virtual bool InDomain( const Self::SpaceVectorType& v ) const
00180 {
00181 return
00182 ( v[0] >= 0 ) && ( v[0] <= Domain[0] ) &&
00183 ( v[1] >= 0 ) && ( v[1] <= Domain[1] ) &&
00184 ( v[2] >= 0 ) && ( v[2] <= Domain[2] );
00185 }
00186
00188 virtual void Update( const bool exactDelta = false );
00189
00191 virtual void Refine() {}
00192
00194 virtual Self::SpaceVectorType Apply ( const Self::SpaceVectorType& v ) const
00195 {
00196 Self::SpaceVectorType w(v);
00197 this->ApplyInPlace( w );
00198 return w;
00199 }
00200
00203 virtual void GetDerivativeLandmarksMSD( double& lowerMSD, double& upperMSD, const MatchedLandmarkList* ll, const unsigned int idx, const Types::Coordinate step );
00204
00207 virtual Types::Coordinate GetInverseConsistencyError( const Self* inverse, const UniformVolume* volume, const UniformVolume::RegionType* voi = NULL ) const;
00208
00211 virtual void GetDerivativeInverseConsistencyError
00212 ( double& lower, double& upper, const Self* inverse, const UniformVolume* volume, const UniformVolume::RegionType* voi,
00213 const unsigned int idx, const Types::Coordinate step );
00214
00216 virtual void GetOriginalControlPointPosition( Self::SpaceVectorType& cp, const Types::Coordinate x, const Types::Coordinate y, const Types::Coordinate z) const
00217 {
00218 cp[0] = this->m_Offset[0] + x*this->Spacing[0];
00219 cp[1] = this->m_Offset[1] + y*this->Spacing[1];
00220 cp[2] = this->m_Offset[2] + z*this->Spacing[2];
00221 }
00222
00224 virtual void GetOriginalControlPointPositionByOffset( Self::SpaceVectorType& v, const size_t offset ) const
00225 {
00226 this->GetOriginalControlPointPosition( v, offset % this->m_Dims[0], (offset % (this->m_Dims[0]*this->m_Dims[1])) / this->m_Dims[0], offset / (this->m_Dims[0]*this->m_Dims[1]) );
00227 }
00228
00230 virtual void GetShiftedControlPointPosition( Self::SpaceVectorType& v, const int x, const int y, const int z ) const
00231 {
00232 this->GetShiftedControlPointPositionByOffset( v, x + this->m_Dims[0] * (y + this->m_Dims[1] * z ) );
00233 }
00234
00236 virtual void GetShiftedControlPointPositionByOffset( Self::SpaceVectorType& v, const size_t offset ) const
00237 {
00238 for ( size_t i = 0; i<3; ++i )
00239 v[i] = this->m_Parameters[offset*3+i];
00240 }
00241
00243 virtual void SetShiftedControlPointPositionByOffset( const Self::SpaceVectorType& v, const int x, const int y, const int z ) const
00244 {
00245 this->SetShiftedControlPointPositionByOffset( v, x + this->m_Dims[0] * (y + this->m_Dims[1] * z ) );
00246 }
00247
00249 virtual void SetShiftedControlPointPositionByOffset( const Self::SpaceVectorType& v, const size_t offset ) const
00250 {
00251 for ( int idx = 0; idx < 3; ++idx )
00252 this->m_Parameters[idx+offset*3] = v[idx];
00253 }
00254
00256 virtual Types::Coordinate GetParamStep( const size_t, const Self::SpaceVectorType& volSize, const Types::Coordinate mmStep = 1 ) const;
00257
00259 void DeleteParameterActiveFlags();
00260
00262 void SetParametersActive();
00263
00265 void SetParametersActive( const UniformVolume::RegionType& roi );
00266
00268 void SetParametersActive( const int axis, const bool active = true );
00269
00275 void SetParameterActive( const size_t index, const bool active = true );
00276
00278 void SetParameterInactive( const size_t index );
00279
00287 void SetParametersActive( const char* axes );
00288
00293 int GetParameterActive( const size_t index ) const;
00294
00295 private:
00302 cmtkGetSetMacro(BitVector::SmartPtr,ActiveFlags);
00303
00305 friend class SplineWarpXformUniformVolume;
00306 };
00307
00309
00310 }
00311
00312 #endif // #ifndef __cmtkWarpXform_h_included_