File indexing completed on 2024-12-22 04:18:05
0001 /*************************************************************************** 0002 * * 0003 * copyright : (C) 2007 The University of Toronto * 0004 * netterfield@astro.utoronto.ca * 0005 * copyright : (C) 2005 University of British Columbia * 0006 * dscott@phas.ubc.ca * 0007 * * 0008 * This program is free software; you can redistribute it and/or modify * 0009 * it under the terms of the GNU General Public License as published by * 0010 * the Free Software Foundation; either version 2 of the License, or * 0011 * (at your option) any later version. * 0012 * * 0013 ***************************************************************************/ 0014 0015 0016 #include "csplineperiodic.h" 0017 #include "objectstore.h" 0018 #include "ui_csplineperiodicconfig.h" 0019 0020 #include <gsl/gsl_spline.h> 0021 #include "../interpolations.h" 0022 0023 static const QString& VECTOR_IN_X = "Vector X In"; 0024 static const QString& VECTOR_IN_Y = "Vector Y In"; 0025 static const QString& VECTOR_IN_X1 = "Vector X' In"; 0026 static const QString& VECTOR_OUT = "Y Interpolated"; 0027 0028 class ConfigWidgetCubicSplinePeriodicPlugin : public Kst::DataObjectConfigWidget, public Ui_CubicSplinePeriodicConfig { 0029 public: 0030 ConfigWidgetCubicSplinePeriodicPlugin(QSettings* cfg) : DataObjectConfigWidget(cfg), Ui_CubicSplinePeriodicConfig() { 0031 _store = 0; 0032 setupUi(this); 0033 } 0034 0035 ~ConfigWidgetCubicSplinePeriodicPlugin() {} 0036 0037 void setObjectStore(Kst::ObjectStore* store) { 0038 _store = store; 0039 _vectorX->setObjectStore(store); 0040 _vectorY->setObjectStore(store); 0041 _vectorX1->setObjectStore(store); 0042 } 0043 0044 void setupSlots(QWidget* dialog) { 0045 if (dialog) { 0046 connect(_vectorX, SIGNAL(selectionChanged(QString)), dialog, SIGNAL(modified())); 0047 connect(_vectorY, SIGNAL(selectionChanged(QString)), dialog, SIGNAL(modified())); 0048 connect(_vectorX1, SIGNAL(selectionChanged(QString)), dialog, SIGNAL(modified())); 0049 } 0050 } 0051 0052 Kst::VectorPtr selectedVectorX() { return _vectorX->selectedVector(); }; 0053 void setSelectedVectorX(Kst::VectorPtr vector) { return _vectorX->setSelectedVector(vector); }; 0054 0055 Kst::VectorPtr selectedVectorY() { return _vectorY->selectedVector(); }; 0056 void setSelectedVectorY(Kst::VectorPtr vector) { return _vectorY->setSelectedVector(vector); }; 0057 0058 Kst::VectorPtr selectedVectorX1() { return _vectorX1->selectedVector(); }; 0059 void setSelectedVectorX1(Kst::VectorPtr vector) { return _vectorX1->setSelectedVector(vector); }; 0060 0061 virtual void setupFromObject(Kst::Object* dataObject) { 0062 if (CubicSplinePeriodicSource* source = static_cast<CubicSplinePeriodicSource*>(dataObject)) { 0063 setSelectedVectorX(source->vectorX()); 0064 setSelectedVectorY(source->vectorY()); 0065 setSelectedVectorX1(source->vectorX1()); 0066 } 0067 } 0068 0069 virtual bool configurePropertiesFromXml(Kst::ObjectStore *store, QXmlStreamAttributes& attrs) { 0070 Q_UNUSED(store); 0071 Q_UNUSED(attrs); 0072 0073 bool validTag = true; 0074 0075 // QStringRef av; 0076 // av = attrs.value("value"); 0077 // if (!av.isNull()) { 0078 // _configValue = QVariant(av.toString()).toBool(); 0079 // } 0080 0081 return validTag; 0082 } 0083 0084 public slots: 0085 virtual void save() { 0086 if (_cfg) { 0087 _cfg->beginGroup("Interpolation Cubic Spline Periodic DataObject Plugin"); 0088 _cfg->setValue("Input Vector X", _vectorX->selectedVector()->Name()); 0089 _cfg->setValue("Input Vector Y", _vectorY->selectedVector()->Name()); 0090 _cfg->setValue("Input Vector X1", _vectorX1->selectedVector()->Name()); 0091 _cfg->endGroup(); 0092 } 0093 } 0094 0095 virtual void load() { 0096 if (_cfg && _store) { 0097 _cfg->beginGroup("Interpolation Cubic Spline Periodic DataObject Plugin"); 0098 QString vectorName = _cfg->value("Input Vector X").toString(); 0099 Kst::Object* object = _store->retrieveObject(vectorName); 0100 Kst::Vector* vector = static_cast<Kst::Vector*>(object); 0101 if (vector) { 0102 setSelectedVectorX(vector); 0103 } 0104 vectorName = _cfg->value("Input Vector Y").toString(); 0105 object = _store->retrieveObject(vectorName); 0106 Kst::Vector* vector2 = static_cast<Kst::Vector*>(object); 0107 if (vector2) { 0108 setSelectedVectorY(vector2); 0109 } 0110 vectorName = _cfg->value("Input Vector X'").toString(); 0111 object = _store->retrieveObject(vectorName); 0112 Kst::Vector* vectorX1 = static_cast<Kst::Vector*>(object); 0113 if (vectorX1) { 0114 setSelectedVectorX1(vectorX1); 0115 } 0116 _cfg->endGroup(); 0117 } 0118 } 0119 0120 private: 0121 Kst::ObjectStore *_store; 0122 0123 }; 0124 0125 0126 CubicSplinePeriodicSource::CubicSplinePeriodicSource(Kst::ObjectStore *store) 0127 : Kst::BasicPlugin(store) { 0128 } 0129 0130 0131 CubicSplinePeriodicSource::~CubicSplinePeriodicSource() { 0132 } 0133 0134 0135 QString CubicSplinePeriodicSource::_automaticDescriptiveName() const { 0136 return tr("Interpolation Cubic Spline Periodic Plugin Object"); 0137 } 0138 0139 0140 void CubicSplinePeriodicSource::change(Kst::DataObjectConfigWidget *configWidget) { 0141 if (ConfigWidgetCubicSplinePeriodicPlugin* config = static_cast<ConfigWidgetCubicSplinePeriodicPlugin*>(configWidget)) { 0142 setInputVector(VECTOR_IN_X, config->selectedVectorX()); 0143 setInputVector(VECTOR_IN_Y, config->selectedVectorY()); 0144 setInputVector(VECTOR_IN_X1, config->selectedVectorX1()); 0145 } 0146 } 0147 0148 0149 void CubicSplinePeriodicSource::setupOutputs() { 0150 setOutputVector(VECTOR_OUT, ""); 0151 } 0152 0153 0154 bool CubicSplinePeriodicSource::algorithm() { 0155 Kst::VectorPtr inputVectorX = _inputVectors[VECTOR_IN_X]; 0156 Kst::VectorPtr inputVectorY = _inputVectors[VECTOR_IN_Y]; 0157 Kst::VectorPtr inputVectorX1 = _inputVectors[VECTOR_IN_X1]; 0158 Kst::VectorPtr outputVector = _outputVectors[VECTOR_OUT]; 0159 0160 return interpolate( inputVectorX, inputVectorY, inputVectorX1, outputVector, gsl_interp_cspline_periodic); 0161 } 0162 0163 0164 Kst::VectorPtr CubicSplinePeriodicSource::vectorX() const { 0165 return _inputVectors[VECTOR_IN_X]; 0166 } 0167 0168 0169 Kst::VectorPtr CubicSplinePeriodicSource::vectorY() const { 0170 return _inputVectors[VECTOR_IN_Y]; 0171 } 0172 0173 0174 Kst::VectorPtr CubicSplinePeriodicSource::vectorX1() const { 0175 return _inputVectors[VECTOR_IN_X1]; 0176 } 0177 0178 0179 QStringList CubicSplinePeriodicSource::inputVectorList() const { 0180 QStringList vectors(VECTOR_IN_X); 0181 vectors += VECTOR_IN_Y; 0182 vectors += VECTOR_IN_X1; 0183 return vectors; 0184 } 0185 0186 0187 QStringList CubicSplinePeriodicSource::inputScalarList() const { 0188 return QStringList( /*SCALAR_IN*/ ); 0189 } 0190 0191 0192 QStringList CubicSplinePeriodicSource::inputStringList() const { 0193 return QStringList( /*STRING_IN*/ ); 0194 } 0195 0196 0197 QStringList CubicSplinePeriodicSource::outputVectorList() const { 0198 return QStringList(VECTOR_OUT); 0199 } 0200 0201 0202 QStringList CubicSplinePeriodicSource::outputScalarList() const { 0203 return QStringList( /*SCALAR_OUT*/ ); 0204 } 0205 0206 0207 QStringList CubicSplinePeriodicSource::outputStringList() const { 0208 return QStringList( /*STRING_OUT*/ ); 0209 } 0210 0211 0212 void CubicSplinePeriodicSource::saveProperties(QXmlStreamWriter &s) { 0213 Q_UNUSED(s); 0214 // s.writeAttribute("value", _configValue); 0215 } 0216 0217 0218 QString CubicSplinePeriodicPlugin::pluginName() const { return tr("Interpolation Cubic Spline Periodic Spline"); } 0219 QString CubicSplinePeriodicPlugin::pluginDescription() const { return tr("Generates a cubic spline interpolation for a set of data."); } 0220 0221 0222 Kst::DataObject *CubicSplinePeriodicPlugin::create(Kst::ObjectStore *store, Kst::DataObjectConfigWidget *configWidget, bool setupInputsOutputs) const { 0223 0224 if (ConfigWidgetCubicSplinePeriodicPlugin* config = static_cast<ConfigWidgetCubicSplinePeriodicPlugin*>(configWidget)) { 0225 0226 CubicSplinePeriodicSource* object = store->createObject<CubicSplinePeriodicSource>(); 0227 0228 if (setupInputsOutputs) { 0229 object->setupOutputs(); 0230 object->setInputVector(VECTOR_IN_X, config->selectedVectorX()); 0231 object->setInputVector(VECTOR_IN_Y, config->selectedVectorY()); 0232 object->setInputVector(VECTOR_IN_X1, config->selectedVectorX1()); 0233 } 0234 0235 object->setPluginName(pluginName()); 0236 0237 object->writeLock(); 0238 object->registerChange(); 0239 object->unlock(); 0240 0241 return object; 0242 } 0243 return 0; 0244 } 0245 0246 0247 Kst::DataObjectConfigWidget *CubicSplinePeriodicPlugin::configWidget(QSettings *settingsObject) const { 0248 ConfigWidgetCubicSplinePeriodicPlugin *widget = new ConfigWidgetCubicSplinePeriodicPlugin(settingsObject); 0249 return widget; 0250 } 0251 0252 #ifndef QT5 0253 Q_EXPORT_PLUGIN2(kstplugin_ConvolvePlugin, CubicSplinePeriodicPlugin) 0254 #endif 0255 0256 // vim: ts=2 sw=2 et