00001 #include "RansacPresenter.h" 00002 #include "RansacPresenter.moc" 00003 00004 #include <iostream> 00005 00006 RansacPresenter::RansacPresenter(RansacFeatureSetMatcher* featureSetMatcher, ParameterWidget* featureSetMatcherParameter): 00007 FeatureSetMatcherPresenter(featureSetMatcher, featureSetMatcherParameter) 00008 { 00009 m_featureSetMatcherParameter->addDoubleParameter("successProbability", "Probability of success", 0.95, 0., 1., 2, 0.01); 00010 m_featureSetMatcherParameter->addDoubleParameter("inlierProbability", "Probability of inlier", 0.5, 0., 1., 2, 0.01); 00011 m_featureSetMatcherParameter->addDoubleParameter("distanceThreshold", "Threshold on the descriptor", 0.4, 0., 1., 2, 0.01); 00012 m_featureSetMatcherParameter->addBoolParameter("adaptive", "Adaptive iteration estimation", false); 00013 syncronize(); 00014 reconnect(); 00015 } 00016 00017 void RansacPresenter::setFeatureSetMatcher(AbstractFeatureSetMatcher* featureSetMatcher){ 00018 m_featureSetMatcher = featureSetMatcher; 00019 syncronize(); 00020 } 00021 00022 void RansacPresenter::setFeatureSetMatcherParameter(ParameterWidget* featureSetMatcherParameter){ 00023 disconnect(m_featureSetMatcherParameter, 0, this, 0); 00024 m_featureSetMatcherParameter = featureSetMatcherParameter; 00025 m_featureSetMatcherParameter->clearParameterMap(); 00026 m_featureSetMatcherParameter->addDoubleParameter("successProbability", "Probability of success", 0.95, 0., 1., 2, 0.01); 00027 m_featureSetMatcherParameter->addDoubleParameter("inlierProbability", "Probability of inlier", 0.5, 0., 1., 2, 0.01); 00028 m_featureSetMatcherParameter->addDoubleParameter("distanceThreshold", "Threshold on the descriptor", 0.4, 0., 1., 2, 0.01); 00029 m_featureSetMatcherParameter->addBoolParameter("adaptive", "Adaptive iteration estimation", false); 00030 syncronize(); 00031 reconnect(); 00032 } 00033 00034 void RansacPresenter::changeParameter(const QString& name){ 00035 if(!QString::compare(name, "successProbability")){ 00036 double guiValue; 00037 bool valid = m_featureSetMatcherParameter->getDoubleValue("successProbability", guiValue); 00038 if(valid) {changeSuccessProbability(guiValue);} 00039 } else if(!QString::compare(name, "inlierProbability")){ 00040 double guiValue; 00041 bool valid = m_featureSetMatcherParameter->getDoubleValue("inlierProbability", guiValue); 00042 if(valid) {changeInlierProbability(guiValue);} 00043 } else if(!QString::compare(name, "distanceThreshold")){ 00044 double guiValue; 00045 bool valid = m_featureSetMatcherParameter->getDoubleValue("distanceThreshold", guiValue); 00046 if(valid) {changeDistanceThreshold(guiValue);} 00047 } else if(!QString::compare(name, "adaptive")){ 00048 bool guiValue; 00049 bool valid = m_featureSetMatcherParameter->getBoolValue("adaptive", guiValue); 00050 if(valid) {changeAdaptive(guiValue ? Qt::Checked : Qt::Unchecked);} 00051 } else { 00052 FeatureSetMatcherPresenter::changeParameter(name); 00053 } 00054 } 00055 00056 00057 void RansacPresenter::changeSuccessProbability(double value){ 00058 RansacFeatureSetMatcher *featureSetMatcher = (RansacFeatureSetMatcher *) m_featureSetMatcher; 00059 double guiValue; 00060 m_featureSetMatcherParameter->getDoubleValue("successProbability", guiValue); 00061 if(featureSetMatcher->getSuccessProbability() != value || guiValue != value){ 00062 featureSetMatcher->setSuccessProbability(value); 00063 m_featureSetMatcherParameter->setDoubleValue("successProbability", featureSetMatcher->getSuccessProbability()); 00064 emit featureSetMatcherChanged(); 00065 } 00066 } 00067 00068 void RansacPresenter::changeInlierProbability(double value){ 00069 RansacFeatureSetMatcher *featureSetMatcher = (RansacFeatureSetMatcher *) m_featureSetMatcher; 00070 double guiValue; 00071 m_featureSetMatcherParameter->getDoubleValue("inlierProbability", guiValue); 00072 if(featureSetMatcher->getInlierProbability() != value || guiValue != value){ 00073 featureSetMatcher->setInlierProbability(value); 00074 m_featureSetMatcherParameter->setDoubleValue("inlierProbability", featureSetMatcher->getInlierProbability()); 00075 emit featureSetMatcherChanged(); 00076 } 00077 } 00078 00079 void RansacPresenter::changeDistanceThreshold(double value){ 00080 RansacFeatureSetMatcher *featureSetMatcher = (RansacFeatureSetMatcher *) m_featureSetMatcher; 00081 double guiValue; 00082 m_featureSetMatcherParameter->getDoubleValue("distanceThreshold", guiValue); 00083 if(featureSetMatcher->getDistanceThreshold() != value || guiValue != value){ 00084 featureSetMatcher->setDistanceThreshold(value); 00085 m_featureSetMatcherParameter->setDoubleValue("distanceThreshold", featureSetMatcher->getDistanceThreshold()); 00086 emit featureSetMatcherChanged(); 00087 } 00088 } 00089 00090 void RansacPresenter::changeAdaptive(int value){ 00091 RansacFeatureSetMatcher *featureSetMatcher = (RansacFeatureSetMatcher *) m_featureSetMatcher; 00092 bool check = value == Qt::Checked; 00093 if(featureSetMatcher->getAdaptive() != check || m_featureSetMatcherParameter->getBoolValue("adaptive") != check){ 00094 featureSetMatcher->setAdaptive(check); 00095 m_featureSetMatcherParameter->setBoolValue("adaptive", value); 00096 emit featureSetMatcherChanged(); 00097 } 00098 } 00099 00100 void RansacPresenter::syncronize(){ 00101 RansacFeatureSetMatcher *featureSetMatcher = (RansacFeatureSetMatcher *) m_featureSetMatcher; 00102 m_featureSetMatcherParameter->setDoubleValue("successProbability", featureSetMatcher->getSuccessProbability()); 00103 m_featureSetMatcherParameter->setDoubleValue("inlierProbability", featureSetMatcher->getInlierProbability()); 00104 m_featureSetMatcherParameter->setBoolValue("adaptive", featureSetMatcher->getAdaptive()); 00105 FeatureSetMatcherPresenter::syncronize(); 00106 } 00107 00108 void RansacPresenter::reconnect(){ 00109 disconnect(m_featureSetMatcherParameter, 0, this, 0); 00110 connect(m_featureSetMatcherParameter, SIGNAL(parameterChanged(const QString&)), this, SLOT(changeParameter(const QString&))); 00111 }