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