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 __cmtkReformatVolume_h_included_
00034 #define __cmtkReformatVolume_h_included_
00035
00036 #include <cmtkconfig.h>
00037
00038 #ifdef HAVE_VALUES_H
00039 # include <values.h>
00040 #endif
00041
00042 #include <Base/cmtkVolume.h>
00043 #include <Base/cmtkUniformVolume.h>
00044 #include <Base/cmtkInterpolator.h>
00045 #include <Base/cmtkUniformVolumeInterpolator.h>
00046 #include <Base/cmtkTypedArray.h>
00047 #include <Base/cmtkAffineXform.h>
00048 #include <Base/cmtkWarpXform.h>
00049 #include <Base/cmtkSplineWarpXform.h>
00050 #include <Base/cmtkMathUtil.h>
00051 #include <Base/cmtkMacros.h>
00052 #include <Base/cmtkBitVector.h>
00053 #include <Base/cmtkXformList.h>
00054
00055 #include <System/cmtkThreads.h>
00056 #include <System/cmtkProgress.h>
00057
00058 #include <cstddef>
00059 #include <math.h>
00060 #include <vector>
00061
00062 namespace
00063 cmtk
00064 {
00065
00068
00076 class ReformatVolume
00077 {
00078 public:
00080 typedef ReformatVolume Self;
00081
00083 typedef SmartPointer<Self> SmartPtr;
00084
00086 cmtkGetSetMacroDefault(float,LowerThresholdReference,FLT_MIN);
00087
00089 cmtkGetSetMacroDefault(float,LowerThresholdFloating,FLT_MIN);
00090
00092 cmtkGetSetMacroDefault(float,UpperThresholdReference,FLT_MAX);
00093
00095 cmtkGetSetMacroDefault(float,UpperThresholdFloating,FLT_MAX);
00096
00099 cmtkGetSetMacroDefault(bool,UsePaddingValue,true);
00100
00103 cmtkGetSetMacro(Types::DataItem,PaddingValue);
00104
00106 ReformatVolume();
00107
00109 void SetInterpolation( const cmtk::Interpolators::InterpolationEnum interpolation )
00110 {
00111 Interpolation = interpolation;
00112 }
00113
00115 UniformVolumeInterpolatorBase::SmartPtr CreateInterpolator( const UniformVolume::SmartConstPtr& volume );
00116
00118 static UniformVolumeInterpolatorBase::SmartPtr CreateInterpolator( const cmtk::Interpolators::InterpolationEnum interpolation, const UniformVolume::SmartConstPtr& volume );
00119
00121 void SetUserDataType( const ScalarDataType dataType )
00122 {
00123 this->m_UserDataType = dataType;
00124 }
00125
00127 void SetReferenceVolume( const UniformVolume::SmartConstPtr& referenceVolume );
00128
00130 void SetFloatingVolume( const UniformVolume::SmartConstPtr& floatingVolume );
00131
00133 void SetAffineXform( const AffineXform::SmartPtr& affineXform );
00134
00136 void SetWarpXform( const WarpXform::SmartPtr& warpXform );
00137
00140 const UniformVolume::SmartPtr PlainReformat();
00141
00147 TypedArray::SmartPtr PlainReformat( const int plane, TypedArray::SmartPtr& target = TypedArray::SmartPtr::Null, const size_t targetOffset = 0 );
00148
00150 typedef enum
00151 {
00152 MODE_MEAN,
00153 MODE_MEDIAN,
00154 MODE_ROBUST90
00155 } AveragingMode;
00156
00158 UniformVolume* GetTransformedReference
00159 ( const std::vector<SplineWarpXform::SmartPtr>* xformList, std::vector<UniformVolume::SmartPtr>* volumeList,
00160 Types::Coordinate *const volumeOffset = NULL, const bool includeReferenceData = true );
00161
00163 UniformVolume* GetTransformedReference( Types::Coordinate *const volumeOffset = NULL );
00164
00166 UniformVolume* GetTransformedReferenceJacobianAvg
00167 ( const std::vector<SplineWarpXform::SmartPtr>* xformList, Types::Coordinate *const volumeOffset = NULL, const bool includeReferenceData = true );
00168
00170 template<class TInterpolator, class Fct> static TypedArray::SmartPtr ReformatMasked
00171 ( const UniformVolume* target, const cmtk::XformList& targetToRef, const cmtk::XformList& refToFloat, Fct& fct, const UniformVolume* floating = NULL, TInterpolator& interpolator = TInterpolator::Null );
00172
00174 template<class TInterpolator, class Fct> static TypedArray::SmartPtr ReformatUnmasked
00175 ( const UniformVolume* target, const cmtk::XformList& targetToRef, const cmtk::XformList& refToFloat, Fct& fct, const UniformVolume* floating = NULL, TInterpolator& interpolator = TInterpolator::Null );
00176
00178 typedef enum
00179 {
00180 REFORMAT_PLAIN,
00181 REFORMAT_JACOBIAN
00182 } Mode;
00183
00185 class Plain
00186 {
00187 public:
00189 Plain( const ScalarDataType dataType = TYPE_NONE )
00190 : DataType( dataType ),
00191 PaddingValue( 0 ),
00192 UsePaddingValue( false )
00193 {};
00194
00196 void SetPaddingValue( const Types::DataItem paddingValue )
00197 {
00198 this->PaddingValue = paddingValue;
00199 this->UsePaddingValue = true;
00200 }
00201
00203 template <class TInterpolatorInstantiationPtr>
00204 bool operator()( Types::DataItem& value, const Vector3D& inRef, const cmtk::XformList& refToFloat, TInterpolatorInstantiationPtr& interpolator );
00205
00207 ScalarDataType GetDataType( const UniformVolume& fltImage ) const
00208 {
00209 if ( this->DataType != TYPE_NONE )
00210 return this->DataType;
00211 else
00212 return fltImage.GetData()->GetType();
00213 }
00214
00215 protected:
00218 ScalarDataType DataType;
00219
00220 public:
00222 Types::DataItem PaddingValue;
00223
00225 bool UsePaddingValue;
00226 };
00227
00229 class Jacobian :
00231 public ReformatVolume::Plain
00232 {
00233 public:
00235 Jacobian( const ScalarDataType dataType = TYPE_FLOAT, const bool correctGlobalScale = true )
00236 : Plain( dataType ), CorrectGlobalScale( correctGlobalScale ) {};
00237
00239 template <class TInterpolatorInstantiationPtr>
00240 bool operator()( Types::DataItem& value, const Vector3D& inRef, const cmtk::XformList& refToFloat, TInterpolatorInstantiationPtr& interpolator );
00241
00243 ScalarDataType GetDataType( const UniformVolume& ) const
00244 {
00245 if ( this->DataType != TYPE_NONE )
00246 return this->DataType;
00247 else
00248 return TYPE_FLOAT;
00249 }
00250
00251 private:
00257 bool CorrectGlobalScale;
00258 };
00259
00260 private:
00262 cmtk::Interpolators::InterpolationEnum Interpolation;
00263
00265 ScalarDataType m_UserDataType;
00266
00268 UniformVolume::SmartConstPtr ReferenceVolume;
00269
00271 UniformVolume::SmartConstPtr FloatingVolume;
00272
00274 const UniformVolume::SmartPtr MakeTargetVolume() const;
00275
00277 AffineXform::SmartConstPtr m_AffineXform;
00278
00280 WarpXform::SmartConstPtr m_WarpXform;
00281
00282 class GetTransformedReferenceTP :
00283 public ThreadParameters<ReformatVolume>
00284 {
00285 public:
00286 GetTransformedReferenceTP() : m_Offset( 0 ), m_Stride( 1 ) {};
00287 TypedArray::SmartPtr dataArray;
00288 const SplineWarpXform* splineXform;
00289 DataGrid::IndexType dims;
00291 size_t m_Offset;
00292 size_t m_Stride;
00293 const Types::Coordinate* delta;
00294 const Types::Coordinate* bbFrom;
00295 unsigned int numberOfImages;
00296 const std::vector<SplineWarpXform::SmartPtr>* xformList;
00297 const std::vector<UniformVolume::SmartPtr>* volumeList;
00298 const std::vector<UniformVolumeInterpolatorBase::SmartConstPtr>* interpolatorList;
00299 const UniformVolumeInterpolatorBase* referenceInterpolator;
00300 int maxLabel;
00301 AveragingMode avgMode;
00302 bool IncludeReferenceData;
00303 };
00304
00306 static CMTK_THREAD_RETURN_TYPE GetTransformedReferenceGrey( void *const arg );
00307
00309 static CMTK_THREAD_RETURN_TYPE GetTransformedReferenceGreyAvg( void *const arg );
00310
00312 static CMTK_THREAD_RETURN_TYPE GetTransformedReferenceLabel( void *const arg );
00313
00315 static CMTK_THREAD_RETURN_TYPE GetTransformedReferenceJacobianAvgThread( void *const arg );
00316
00318 UniformVolume* CreateTransformedReference( Types::Coordinate *const bbFrom, Types::Coordinate *const delta, Types::Coordinate *const volumeOffset = NULL );
00319
00320 };
00321
00323
00324 }
00325
00326 #include "cmtkReformatVolumeReformat.txx"
00327 #include "cmtkReformatVolumePlain.txx"
00328 #include "cmtkReformatVolumeJacobian.txx"
00329
00330 #endif // #ifndef __cmtkReformatVolume_h_included_