00001 /** 00002 * \file CoarseCC.h 00003 * \brief Perform coarse fitting between two density objects. 00004 * 00005 * Copyright 2007-2010 IMP Inventors. All rights reserved. 00006 * 00007 */ 00008 00009 #ifndef IMPEM_COARSE_CC_H 00010 #define IMPEM_COARSE_CC_H 00011 00012 #include "em_config.h" 00013 #include "exp.h" 00014 #include "DensityMap.h" 00015 #include "SampledDensityMap.h" 00016 #include "def.h" 00017 #include <vector> 00018 00019 IMPEM_BEGIN_NAMESPACE 00020 00021 //! Responsible for performing coarse fitting between two density objects. 00022 /** The pixels involved are derived from the positions of N particles. 00023 */ 00024 class IMPEMEXPORT CoarseCC 00025 { 00026 00027 public: 00028 00029 //! Evaluates the value of the EM fitting term. 00030 /** \note The function returns scalefac*(1-ccc) 00031 to support minimization optimization. The ccc value (cross 00032 correlation coefficient) is calculate by the 00033 cross_correlation_coefficient function. 00034 \param[in] data DensityMap class containing the EM map. note: 00035 correct RMSD and mean MUST be in the header! 00036 \param[in] model_map SampledDensityMap class prepared to contain the 00037 simulated EM map for the model. 00038 \param[in] dvx vector to contain the xpartial derivatives 00039 \param[in] dvy vector to contain the y partial derivatives 00040 \param[in] dvz vector to contain the z partial derivatives 00041 \param[in] scalefactor scale factor to apply to the value of the cross 00042 correlation term 00043 \param[in] lderiv if true, the derivatives of the term are computed 00044 \param[in] divide_by_rms determines wheather the model_map should be 00045 normalized prior to the correlation calculation. false is 00046 faster, but potentially innacurate 00047 \param[in] resample if true, the model density map is resampled 00048 \return the value of the cross correlation term: scalefac*(1-ccc) 00049 \relatesalso cross_correlation_coefficient 00050 */ 00051 static float evaluate(DensityMap &data, SampledDensityMap &model_map, 00052 std::vector<float> &dvx, std::vector<float>&dvy, 00053 std::vector<float>&dvz, float scalefactor, bool lderiv, 00054 bool divide_by_rms=true,bool resample=true); 00055 00056 00057 /*! 00058 Computes the derivatives of the cross correlation term scalefac*(1-ccc) at each 00059 voxel of the map. 00060 \param[in] em_map the target density map. 00061 \param[in] model_map the sampled density map of the model 00062 \param[in] scalefac scale factor to apply to the value of the cross 00063 correlation term 00064 \param[out] dvx vector to contain the x partial derivatives 00065 \param[out] dvy vector to contain the y partial derivatives 00066 \param[out] dvz vector to contain the z partial derivatives 00067 \note: The function assumes that correct RMS are calculated for the densities 00068 */ 00069 static void calc_derivatives(const DensityMap &em_map, 00070 SampledDensityMap &model_map, 00071 const float &scalefac, 00072 std::vector<float> &dvx, std::vector<float>&dvy, 00073 std::vector<float>&dvz); 00074 00075 00076 //!Calculates the cross correlation coefficient between two maps 00077 /** Cross correlation coefficient between the em density and the density of a 00078 model. The function applied is: 00079 \f$\frac{\sum_{i=1}^{N}{{td}_i}{{md}_i}-{N} 00080 {{mean}_{td}} 00081 {{mean}_{md}}} 00082 {N\sigma_{{td}}\sigma_{{md}}}\f$, such that \f$N\f$ is the number of 00083 voxels, \f${td}\f$ is the target density, 00084 \f${tm}\f$ is the model density, 00085 \param[in] em_map the target map (experimentally determined) 00086 \param[in] model_map the sampled density map of the model 00087 \param[in] voxel_data_threshold voxels with value lower than threshold 00088 in model_map are not summed (avoid calculating correlation on 00089 voxels below the threshold) 00090 \param[in] recalc_ccnormfac determines wheather the model_map should be 00091 normalized prior to the correlation calculation. false is 00092 faster, but potentially innacurate 00093 \param[in] divide_by_rms determines wheather the model_map should be 00094 normalized prior to the correlation calculation. false is 00095 faster, but potentially innacurate 00096 \return the cross correlation coefficient value between two density maps 00097 \note This is not the local CC function 00098 \todo check that the mean is always substracted from the em-density. 00099 The problem is that we divide by nvox*d1_mean*d2_mean, but if we 00100 use voxel_data_threshold that does not consist of the entire map 00101 this would be wrong. Fix it. 00102 */ 00103 static float cross_correlation_coefficient(const DensityMap &em_map, 00104 DensityMap &model_map, 00105 float voxel_data_threshold, 00106 bool recalc_ccnormfac = true, 00107 bool divide_by_rms=true); 00108 }; 00109 00110 IMPEM_END_NAMESPACE 00111 00112 #endif /* IMPEM_COARSE_CC_H */