00001 #include "MultiScaleCurvatureDetectorPresenter.h" 00002 #include "MultiScaleCurvatureDetectorPresenter.moc" 00003 00004 #include <iostream> 00005 00006 MultiScaleCurvatureDetectorPresenter::MultiScaleCurvatureDetectorPresenter(CurvatureDetector* detector, ParameterWidget* detectorParameter): 00007 DetectorPresenter(detector, detectorParameter), 00008 m_currentPeakPresenter(NULL) 00009 { 00010 m_detectorParameter->addBoolParameter("useMaxRange", "Use max range values", false); 00011 m_detectorParameter->addIntParameter("scale", "Number of scales", 1, 1, 10); 00012 m_detectorParameter->addDoubleParameter("sigma", "Base value of Sigma", 1.6, 0.0, 10e16, 2, 0.1); 00013 m_detectorParameter->addDoubleParameter("sigmaStep", "Step value of Sigma", 1.4, 0.0, 10e16, 2, 0.1); 00014 m_detectorParameter->addIntParameter("dmst", "Number of MST", 4, 1, 10); 00015 m_detectorParameter->addEnumParameter("peakFinder", "Type of peak finder"); 00016 syncronize(); 00017 reconnect(); 00018 } 00019 00020 void MultiScaleCurvatureDetectorPresenter::activate(){ 00021 DetectorPresenter::activate(); 00022 if(m_currentPeakPresenter){ 00023 m_currentPeakPresenter->activate(); 00024 } 00025 } 00026 00027 void MultiScaleCurvatureDetectorPresenter::deactivate(){ 00028 if(m_currentPeakPresenter){ 00029 m_currentPeakPresenter->deactivate(); 00030 } 00031 DetectorPresenter::deactivate(); 00032 } 00033 00034 void MultiScaleCurvatureDetectorPresenter::insertPeakFinder(const QString& name, PeakFinderPresenter* peak){ 00035 m_peakPresenterNames.append(name); 00036 m_peakPresenters.push_back(peak); 00037 m_detectorParameter->insertEnumValue("peakFinder", name); 00038 if(m_peakPresenters.size() == 1){ 00039 m_currentPeakPresenter = peak; 00040 m_currentPeakPresenterIndex = 0; 00041 connect(m_currentPeakPresenter, SIGNAL(peakFinderChanged()), this, SIGNAL(detectorChanged())); 00042 m_currentPeakPresenter->activate(); 00043 }else{ 00044 peak->deactivate(); 00045 } 00046 } 00047 00048 void MultiScaleCurvatureDetectorPresenter::setDetector(Detector* detector){ 00049 m_detector = detector; 00050 syncronize(); 00051 } 00052 00053 void MultiScaleCurvatureDetectorPresenter::setDetectorParameter(ParameterWidget* detectorParameter){ 00054 QStringList filters; 00055 filters << "Gaussian" << "Bessel"; 00056 00057 m_detectorParameter->clearParameterMap(); 00058 m_detectorParameter->addBoolParameter("useMaxRange", "Use max range values", false); 00059 m_detectorParameter->addIntParameter("scale", "Number of scales", 1, 1, 10); 00060 m_detectorParameter->addDoubleParameter("sigma", "Base value of Sigma", 1.6, 0.0, 10e16, 2, 0.1); 00061 m_detectorParameter->addDoubleParameter("sigmaStep", "Step value of Sigma", 1.4, 0.0, 10e16, 2, 0.1); 00062 m_detectorParameter->addIntParameter("dmst", "Number of MST", 4, 1, 10); 00063 m_detectorParameter->addEnumParameter("peakFinder", "Type of peak finder"); 00064 00065 disconnect(m_detectorParameter, 0, this, 0); 00066 m_detectorParameter = detectorParameter; 00067 syncronize(); 00068 reconnect(); 00069 } 00070 00071 void MultiScaleCurvatureDetectorPresenter::changeParameter(const QString& name){ 00072 if(!QString::compare(name, "scale")){ 00073 int guiValue; 00074 bool valid = m_detectorParameter->getIntValue("scale", guiValue); 00075 if(valid) {changeScale(guiValue);} 00076 } else if(!QString::compare(name, "useMaxRange")){ 00077 bool guiValue; 00078 bool valid = m_detectorParameter->getBoolValue("useMaxRange", guiValue); 00079 if(valid) {changeMaxRange(guiValue ? Qt::Checked : Qt::Unchecked);} 00080 } else if(!QString::compare(name, "sigma")){ 00081 double guiValue; 00082 bool valid = m_detectorParameter->getDoubleValue("sigma", guiValue); 00083 if(valid) {changeSigma(guiValue);} 00084 } else if(!QString::compare(name, "sigmaStep")){ 00085 double guiValue; 00086 bool valid = m_detectorParameter->getDoubleValue("sigmaStep", guiValue); 00087 if(valid) {changeSigmaStep(guiValue);} 00088 } else if(!QString::compare(name, "dmst")){ 00089 int guiValue; 00090 bool valid = m_detectorParameter->getIntValue("dmst", guiValue); 00091 if(valid) {changeDmst(guiValue);} 00092 } else if(!QString::compare(name, "peakFinder")){ 00093 int guiValue; 00094 bool valid = m_detectorParameter->getEnumValue("peakFinder", guiValue); 00095 if(valid) {changePeakFinder(guiValue);} 00096 } 00097 } 00098 00099 void MultiScaleCurvatureDetectorPresenter::changeScale(int scale){ 00100 CurvatureDetector *detector = (CurvatureDetector *) m_detector; 00101 if((int)detector->getScaleNumber() != scale || m_detectorParameter->getIntValue("scale") != scale){ 00102 detector->setScaleNumber(scale); 00103 m_detectorParameter->setIntValue("scale", detector->getScaleNumber()); 00104 emit detectorChanged(); 00105 } 00106 } 00107 00108 void MultiScaleCurvatureDetectorPresenter::changeMaxRange(int value){ 00109 CurvatureDetector *detector = (CurvatureDetector *) m_detector; 00110 bool check = value == Qt::Checked; 00111 if(detector->getUseMaxRange() != check || m_detectorParameter->getBoolValue("useMaxRange") != check){ 00112 detector->setUseMaxRange(check); 00113 m_detectorParameter->setBoolValue("useMaxRange", value); 00114 emit detectorChanged(); 00115 } 00116 } 00117 00118 void MultiScaleCurvatureDetectorPresenter::changeSigma(double sigma){ 00119 CurvatureDetector *detector = (CurvatureDetector *) m_detector; 00120 if(detector->getBaseSigma() != sigma || m_detectorParameter->getDoubleValue("sigma") != sigma){ 00121 detector->setBaseSigma(sigma); 00122 m_detectorParameter->setDoubleValue("sigma", detector->getBaseSigma()); 00123 emit detectorChanged(); 00124 } 00125 } 00126 00127 void MultiScaleCurvatureDetectorPresenter::changeSigmaStep(double step){ 00128 CurvatureDetector *detector = (CurvatureDetector *) m_detector; 00129 if(detector->getSigmaStep() != step || m_detectorParameter->getDoubleValue("sigmaStep") != step){ 00130 detector->setSigmaStep(step); 00131 m_detectorParameter->setDoubleValue("sigmaStep", detector->getSigmaStep()); 00132 emit detectorChanged(); 00133 } 00134 } 00135 00136 void MultiScaleCurvatureDetectorPresenter::changeDmst(int dmst){ 00137 CurvatureDetector *detector = (CurvatureDetector *) m_detector; 00138 if(((int) detector->getDmst()) != dmst || m_detectorParameter->getIntValue("dmst") != dmst){ 00139 detector->setDmst(dmst); 00140 m_detectorParameter->setIntValue("dmst", detector->getDmst()); 00141 emit detectorChanged(); 00142 } 00143 } 00144 00145 void MultiScaleCurvatureDetectorPresenter::changePeakFinder(int peakFinder){ 00146 CurvatureDetector *detector = (CurvatureDetector *) m_detector; 00147 if(m_currentPeakPresenterIndex != peakFinder){ 00148 disconnect(m_currentPeakPresenter, SIGNAL(peakFinderChanged()), this, SIGNAL(detectorChanged())); 00149 m_currentPeakPresenter->deactivate(); 00150 m_currentPeakPresenterIndex = peakFinder; 00151 m_currentPeakPresenter = m_peakPresenters[m_currentPeakPresenterIndex]; 00152 detector->setPeakFinder(m_currentPeakPresenter->getPeakFinder()); 00153 m_detectorParameter->setEnumValue("peakFinder", m_currentPeakPresenterIndex); 00154 m_currentPeakPresenter->activate(); 00155 connect(m_currentPeakPresenter, SIGNAL(peakFinderChanged()), this, SIGNAL(detectorChanged())); 00156 emit detectorChanged(); 00157 } 00158 } 00159 00160 00161 void MultiScaleCurvatureDetectorPresenter::syncronize(){ 00162 CurvatureDetector *detector = (CurvatureDetector *) m_detector; 00163 m_detectorParameter->setIntValue("scale", detector->getScaleNumber()); 00164 m_detectorParameter->setDoubleValue("sigma", detector->getBaseSigma()); 00165 m_detectorParameter->setDoubleValue("sigmaStep", detector->getSigmaStep()); 00166 m_detectorParameter->setIntValue("dmst", detector->getDmst()); 00167 m_detectorParameter->setBoolValue("useMaxRange", detector->getUseMaxRange()); 00168 if(m_peakPresenters.size()){ 00169 m_detectorParameter->clearEnumParameter("peakFinder"); 00170 for(int i = 0; i < m_peakPresenterNames.size(); i++){ 00171 m_detectorParameter->insertEnumValue("peakFinder", m_peakPresenterNames[i]); 00172 } 00173 m_detectorParameter->setEnumValue("peakFinder", m_currentPeakPresenterIndex); 00174 detector->setPeakFinder(m_currentPeakPresenter->getPeakFinder()); 00175 m_currentPeakPresenter->activate(); 00176 } 00177 } 00178 00179 void MultiScaleCurvatureDetectorPresenter::reconnect(){ 00180 disconnect(m_detectorParameter, 0, this, SLOT(changeParameter(const QString&))); 00181 connect(m_detectorParameter, SIGNAL(parameterChanged(const QString&)), this, SLOT(changeParameter(const QString&))); 00182 }