00001 #include "BetaGridPresenter.h" 00002 #include "BetaGridPresenter.moc" 00003 00004 #include <iostream> 00005 00006 BetaGridPresenter::BetaGridPresenter(BetaGridGenerator* descriptor, ParameterWidget* peakParameter): 00007 DescriptorPresenter(descriptor, peakParameter) 00008 { 00009 m_descriptorParameter->addDoubleParameter("minRho", "Minimum radial distance", 0.05, 0.); 00010 m_descriptorParameter->addDoubleParameter("maxRho", "Maximum radial distance", 0.4, 0.); 00011 m_descriptorParameter->addIntParameter("binRho", "Number of radial bins", 4, 1); 00012 m_descriptorParameter->addIntParameter("binPhi", "Number of angular bins", 12, 1); 00013 m_descriptorParameter->addEnumParameter("distanceFunction", "Histogram distance function"); 00014 syncronize(); 00015 reconnect(); 00016 } 00017 00018 void BetaGridPresenter::setDescriptor(DescriptorGenerator* descriptor){ 00019 m_descriptor = descriptor; 00020 syncronize(); 00021 } 00022 00023 void BetaGridPresenter::setDescriptorParameter(ParameterWidget* peakParameter){ 00024 disconnect(m_descriptorParameter, 0, this, 0); 00025 m_descriptorParameter = peakParameter; 00026 m_descriptorParameter->clearParameterMap(); 00027 m_descriptorParameter->addDoubleParameter("minRho", "Minimum radial distance", 0.05, 0.); 00028 m_descriptorParameter->addDoubleParameter("maxRho", "Maximum radial distance", 0.4, 0.); 00029 m_descriptorParameter->addIntParameter("binRho", "Number of radial bins", 4, 1); 00030 m_descriptorParameter->addIntParameter("binPhi", "Number of angular bins", 12, 1); 00031 m_descriptorParameter->addEnumParameter("distanceFunction", "Histogram distance function"); 00032 syncronize(); 00033 reconnect(); 00034 } 00035 00036 void BetaGridPresenter::insertDistanceFunction(const QString& name, const HistogramDistance<double>* distanceFunction){ 00037 m_distanceFunctionNames.append(name); 00038 m_distanceFunctions.push_back(distanceFunction); 00039 m_descriptorParameter->insertEnumValue("distanceFunction", name); 00040 if(m_distanceFunctions.size() == 1){ 00041 m_currentDistanceFunction = distanceFunction; 00042 m_currentDistanceFunctionIndex = 0; 00043 BetaGridGenerator *descriptor = (BetaGridGenerator *) m_descriptor; 00044 descriptor->setDistanceFunction(m_currentDistanceFunction); 00045 } 00046 } 00047 00048 void BetaGridPresenter::changeParameter(const QString& name){ 00049 if(!QString::compare(name, "minRho")){ 00050 double guiValue; 00051 bool valid = m_descriptorParameter->getDoubleValue("minRho", guiValue); 00052 if(valid) {changeMinRho(guiValue);} 00053 } else if(!QString::compare(name, "maxRho")){ 00054 double guiValue; 00055 bool valid = m_descriptorParameter->getDoubleValue("maxRho", guiValue); 00056 if(valid) {changeMaxRho(guiValue);} 00057 }else if(!QString::compare(name, "binRho")){ 00058 int guiValue; 00059 bool valid = m_descriptorParameter->getIntValue("binRho", guiValue); 00060 if(valid) {changeBinRho(guiValue);} 00061 }else if(!QString::compare(name, "binPhi")){ 00062 int guiValue; 00063 bool valid = m_descriptorParameter->getIntValue("binPhi", guiValue); 00064 if(valid) {changeBinPhi(guiValue);} 00065 }else if(!QString::compare(name, "distanceFunction")){ 00066 int guiValue; 00067 bool valid = m_descriptorParameter->getEnumValue("distanceFunction", guiValue); 00068 if(valid) {changeDistanceFunction(guiValue);} 00069 } 00070 } 00071 00072 00073 void BetaGridPresenter::changeMinRho(double value){ 00074 BetaGridGenerator *descriptor = (BetaGridGenerator *) m_descriptor; 00075 double guiValue; 00076 m_descriptorParameter->getDoubleValue(QString("minRho"), guiValue); 00077 if(descriptor->getMinRho() != value || guiValue != value){ 00078 descriptor->setEdges(value, descriptor->getMaxRho(), descriptor->getBinRho(), descriptor->getBinPhi()); 00079 m_descriptorParameter->setDoubleValue("minRho", descriptor->getMinRho()); 00080 emit descriptorChanged(); 00081 } 00082 } 00083 00084 void BetaGridPresenter::changeMaxRho(double value){ 00085 BetaGridGenerator *descriptor = (BetaGridGenerator *) m_descriptor; 00086 double guiValue; 00087 m_descriptorParameter->getDoubleValue("maxRho", guiValue); 00088 if(descriptor->getMaxRho() != value || guiValue != value){ 00089 descriptor->setEdges(descriptor->getMinRho(), value, descriptor->getBinRho(), descriptor->getBinPhi()); 00090 m_descriptorParameter->setDoubleValue("maxRho", descriptor->getMaxRho()); 00091 emit descriptorChanged(); 00092 } 00093 } 00094 00095 void BetaGridPresenter::changeBinRho(int value){ 00096 BetaGridGenerator *descriptor = (BetaGridGenerator *) m_descriptor; 00097 int guiValue; 00098 m_descriptorParameter->getIntValue(QString("binRho"), guiValue); 00099 if(descriptor->getBinRho() != (unsigned int)value || guiValue != value){ 00100 descriptor->setEdges(descriptor->getMinRho(), descriptor->getMaxRho(), value, descriptor->getBinPhi()); 00101 m_descriptorParameter->setIntValue("binRho", descriptor->getBinRho()); 00102 emit descriptorChanged(); 00103 } 00104 } 00105 00106 void BetaGridPresenter::changeBinPhi(int value){ 00107 BetaGridGenerator *descriptor = (BetaGridGenerator *) m_descriptor; 00108 int guiValue; 00109 m_descriptorParameter->getIntValue(QString("binPhi"), guiValue); 00110 if(descriptor->getBinPhi() != (unsigned int)value || guiValue != value){ 00111 descriptor->setEdges(descriptor->getMinRho(), descriptor->getMaxRho(), descriptor->getBinRho(), value); 00112 m_descriptorParameter->setIntValue("binPhi", descriptor->getBinPhi()); 00113 emit descriptorChanged(); 00114 } 00115 } 00116 00117 void BetaGridPresenter::changeDistanceFunction(int value){ 00118 BetaGridGenerator *descriptor = (BetaGridGenerator *) m_descriptor; 00119 if(m_currentDistanceFunctionIndex != value){ 00120 m_currentDistanceFunctionIndex = value; 00121 m_currentDistanceFunction = m_distanceFunctions[m_currentDistanceFunctionIndex]; 00122 descriptor->setDistanceFunction(m_currentDistanceFunction); 00123 m_descriptorParameter->setEnumValue("distanceFunction", m_currentDistanceFunctionIndex); 00124 emit descriptorChanged(); 00125 } 00126 } 00127 00128 void BetaGridPresenter::syncronize(){ 00129 BetaGridGenerator *descriptor = (BetaGridGenerator *) m_descriptor; 00130 m_descriptorParameter->setDoubleValue("minRho", descriptor->getMinRho()); 00131 m_descriptorParameter->setDoubleValue("maxRho", descriptor->getMaxRho()); 00132 m_descriptorParameter->setIntValue("binRho", descriptor->getBinRho()); 00133 m_descriptorParameter->setIntValue("binPhi", descriptor->getBinPhi()); 00134 if(m_distanceFunctions.size()){ 00135 m_descriptorParameter->clearEnumParameter("distanceFunction"); 00136 for(int i = 0; i < m_distanceFunctionNames.size(); i++){ 00137 m_descriptorParameter->insertEnumValue("distanceFunction", m_distanceFunctionNames[i]); 00138 } 00139 m_descriptorParameter->setEnumValue("peakFinder", m_currentDistanceFunctionIndex); 00140 descriptor->setDistanceFunction(m_currentDistanceFunction); 00141 } 00142 } 00143 00144 void BetaGridPresenter::reconnect(){ 00145 connect(m_descriptorParameter, SIGNAL(parameterChanged(const QString&)), this, SLOT(changeParameter(const QString&))); 00146 }